* Enhancements for EIGER * Writer is more flexible and capable of handling DECTRIS data
128 lines
4.5 KiB
C++
128 lines
4.5 KiB
C++
// Copyright (2019-2023) Paul Scherrer Institute
|
|
|
|
#include "DetectorGeometry.h"
|
|
#include "JFJochException.h"
|
|
#include "Definitions.h"
|
|
|
|
DetectorGeometry::DetectorGeometry(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;
|
|
|
|
for (auto &m: modules) {
|
|
width = std::max<int64_t>(width, m.GetMaxX()+1);
|
|
height = std::max<int64_t>(height, m.GetMaxY()+1);
|
|
}
|
|
|
|
if (vertical_flip) {
|
|
for (auto &m: modules) m.VerticalFlip(height);
|
|
}
|
|
|
|
}
|
|
|
|
DetectorGeometry::DetectorGeometry(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);
|
|
|
|
if (mirror_y)
|
|
mgeom.VerticalFlip(height);
|
|
|
|
modules.emplace_back(mgeom);
|
|
}
|
|
}
|
|
|
|
int64_t DetectorGeometry::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;
|
|
}
|
|
}
|
|
|
|
int64_t DetectorGeometry::GetModulesNum() const {
|
|
return modules.size();
|
|
}
|
|
|
|
int64_t DetectorGeometry::GetWidth() const {
|
|
return width;
|
|
}
|
|
|
|
int64_t DetectorGeometry::GetHeight() const {
|
|
return height;
|
|
}
|
|
|
|
int64_t DetectorGeometry::GetPixel0(int64_t m) const {
|
|
if ((m < 0) || (m >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
return modules[m].GetPixel0_X() + width * modules[m].GetPixel0_Y();
|
|
}
|
|
|
|
int64_t DetectorGeometry::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 DetectorGeometry::GetSlowDirectionStep(int64_t m) const {
|
|
if ((m < 0) || (m >= modules.size()))
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Wrong module number");
|
|
return GetDirectionStep(modules[m].GetSlowAxis());
|
|
}
|
|
|
|
Coord DetectorGeometry::GetFastDirection(int64_t module_number) const {
|
|
return GetDirection(modules[module_number].GetFastAxis());
|
|
}
|
|
|
|
Coord DetectorGeometry::GetSlowDirection(int64_t module_number) const {
|
|
return GetDirection(modules[module_number].GetSlowAxis());
|
|
}
|
|
|
|
Coord DetectorGeometry::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};
|
|
}
|
|
}
|