All checks were successful
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 7m51s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 7m19s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 7m46s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 8m32s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 8m6s
Build Packages / build:rpm (rocky8) (push) Successful in 8m7s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 7m37s
Build Packages / Generate python client (push) Successful in 17s
Build Packages / Create release (push) Has been skipped
Build Packages / Build documentation (push) Successful in 32s
Build Packages / build:rpm (rocky9) (push) Successful in 9m6s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 6m53s
Build Packages / Unit tests (push) Successful in 1h9m39s
This is an UNSTABLE release. * jfjoch_viewer: Minor improvements to the viewer * jfjoch_broker: Change behavior for modular detectors: coordinates of 0-th pixel can be now arbitrary and detector will be cropped to the smallest rectangle limited by module coordinates Reviewed-on: #8 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch> Co-committed-by: Filip Leonarski <filip.leonarski@psi.ch>
176 lines
6.4 KiB
C++
176 lines
6.4 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "DetectorGeometryModular.h"
|
|
#include "JFJochException.h"
|
|
|
|
DetectorGeometryModular::DetectorGeometryModular(const std::vector<DetectorModuleGeometry> &in_modules, bool vertical_flip)
|
|
: modules(in_modules) {
|
|
if (modules.empty())
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Module number must be positive");
|
|
|
|
width = 0;
|
|
height = 0;
|
|
|
|
int64_t min_x = modules[0].GetMinX();
|
|
int64_t max_x = modules[0].GetMaxX();
|
|
int64_t min_y = modules[0].GetMinY();
|
|
int64_t max_y = modules[0].GetMaxY();
|
|
|
|
for (auto &m: modules) {
|
|
min_x = std::min<int64_t>(min_x, m.GetMinX());
|
|
max_x = std::max<int64_t>(max_x, m.GetMaxX());
|
|
min_y = std::min<int64_t>(min_y, m.GetMinY());
|
|
max_y = std::max<int64_t>(max_y, m.GetMaxY());
|
|
}
|
|
|
|
width = max_x - min_x + 1;
|
|
height = max_y - min_y + 1;
|
|
|
|
for (auto &m: modules)
|
|
m.Translate(-min_x, -min_y);
|
|
|
|
if (vertical_flip)
|
|
VerticalFlip();
|
|
}
|
|
|
|
DetectorGeometryModular::DetectorGeometryModular(int32_t nmodules, int32_t horizontal_stacking, int32_t gap_x,
|
|
int32_t gap_y, bool mirror_y) {
|
|
if (horizontal_stacking <= 0)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Horizontal stacking must be positive");
|
|
if (nmodules <= 0)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Module number must be positive");
|
|
if (gap_x < 0)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Gap x has to be non-negative");
|
|
if (gap_y < 0)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Gap y has to be non-negative");
|
|
if (nmodules < horizontal_stacking)
|
|
horizontal_stacking = nmodules;
|
|
|
|
width = horizontal_stacking * CONVERTED_MODULE_COLS + (horizontal_stacking - 1) * gap_x;
|
|
int64_t conv_lines = nmodules / horizontal_stacking + (nmodules % horizontal_stacking > 0 ? 1 : 0);
|
|
height = conv_lines * CONVERTED_MODULE_LINES + (conv_lines - 1) * gap_y;
|
|
|
|
for (int m = 0; m < nmodules; m++) {
|
|
int64_t module_x = m % horizontal_stacking;
|
|
int64_t module_y = m / horizontal_stacking;
|
|
|
|
int64_t x0 = module_x * (CONVERTED_MODULE_COLS + gap_x);
|
|
int64_t y0 = module_y * (CONVERTED_MODULE_LINES + gap_y);
|
|
|
|
DetectorModuleGeometry::Direction fast = DetectorModuleGeometry::Direction::Xpos;
|
|
DetectorModuleGeometry::Direction slow = DetectorModuleGeometry::Direction::Ypos;
|
|
|
|
DetectorModuleGeometry mgeom(x0,y0,fast, slow);
|
|
|
|
modules.emplace_back(mgeom);
|
|
}
|
|
|
|
if (mirror_y)
|
|
VerticalFlip();
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetModulesNum() const {
|
|
return modules.size();
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetWidth(bool geom_transformed) const {
|
|
if (geom_transformed)
|
|
return width;
|
|
else
|
|
return RAW_MODULE_COLS;
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetHeight(bool geom_transformed) const {
|
|
if (geom_transformed)
|
|
return height;
|
|
else
|
|
return RAW_MODULE_LINES * modules.size();
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetPixel0(int64_t m, bool geom_transformed) const {
|
|
if ((m < 0) || (m >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
if (geom_transformed)
|
|
return modules[m].GetPixel0_X() + width * modules[m].GetPixel0_Y();
|
|
else
|
|
return m * RAW_MODULE_SIZE;
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetX0(int64_t module_number) const {
|
|
if ((module_number < 0) || (module_number >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
return modules[module_number].GetPixel0_X();
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetY0(int64_t module_number) const {
|
|
if ((module_number < 0) || (module_number >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
return modules[module_number].GetPixel0_Y();
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetFastDirectionStep(int64_t m) const {
|
|
if ((m < 0) || (m >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
return GetDirectionStep(modules[m].GetFastAxis());
|
|
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetSlowDirectionStep(int64_t m) const {
|
|
if ((m < 0) || (m >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
return GetDirectionStep(modules[m].GetSlowAxis());
|
|
}
|
|
|
|
Coord DetectorGeometryModular::GetFastDirection(int64_t module_number) const {
|
|
if ((module_number < 0) || (module_number >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
|
|
return GetDirection(modules[module_number].GetFastAxis());
|
|
}
|
|
|
|
Coord DetectorGeometryModular::GetSlowDirection(int64_t module_number) const {
|
|
if ((module_number < 0) || (module_number >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
|
|
return GetDirection(modules[module_number].GetSlowAxis());
|
|
}
|
|
|
|
void DetectorGeometryModular::VerticalFlip() {
|
|
for (auto &m: modules)
|
|
m.VerticalFlip(height);
|
|
}
|
|
|
|
bool DetectorGeometryModular::IsModularDetector() const {
|
|
return false;
|
|
}
|
|
|
|
int64_t DetectorGeometryModular::GetDirectionStep(DetectorModuleGeometry::Direction direction) const {
|
|
switch (direction) {
|
|
case DetectorModuleGeometry::Direction::Xneg:
|
|
return -1;
|
|
case DetectorModuleGeometry::Direction::Xpos:
|
|
return 1;
|
|
case DetectorModuleGeometry::Direction::Yneg:
|
|
return -width;
|
|
case DetectorModuleGeometry::Direction::Ypos:
|
|
return width;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
Coord DetectorGeometryModular::GetDirection(DetectorModuleGeometry::Direction direction) {
|
|
switch (direction) {
|
|
case DetectorModuleGeometry::Direction::Xneg:
|
|
return {-1, 0, 0};
|
|
case DetectorModuleGeometry::Direction::Yneg:
|
|
return { 0, -1, 0};
|
|
case DetectorModuleGeometry::Direction::Ypos:
|
|
return { 0, 1, 0};
|
|
default:
|
|
case DetectorModuleGeometry::Direction::Xpos:
|
|
return { 1, 0, 0};
|
|
}
|
|
}
|