From a338a1743b243684211558910286feeb057573ea Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 20 Oct 2023 13:27:21 +0200 Subject: [PATCH] RawToConvertedGeometry: Add function to calculate location of a raw pixel in converted geometry --- common/RawToConvertedGeometry.h | 19 ++++++++++++++++++- tests/RawToConvertedGeometryTest.cpp | 7 +++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/common/RawToConvertedGeometry.h b/common/RawToConvertedGeometry.h index ec59d178..88ccbae7 100644 --- a/common/RawToConvertedGeometry.h +++ b/common/RawToConvertedGeometry.h @@ -4,6 +4,7 @@ #define JUNGFRAUJOCH_RAWTOCONVERTEDGEOMETRY_H #include +#include "Coord.h" #include "DiffractionExperiment.h" // Take half of the number, but only if not bad pixel/overload @@ -69,7 +70,6 @@ void LineCopyAndAddMultipixel(Td *destination, const Ts *source, } } - template T Bin2x2_sum(T a, T b, T c, T d, T underload, T overload) { T ret; @@ -150,6 +150,23 @@ void RawToConvertedGeometry(const DiffractionExperiment &experiment, Td *destina experiment.GetModuleFastDirectionStep(module_number)); } +inline std::pair RawToConvertedCoordinate(const DiffractionExperiment& experiment, + uint32_t module_number, + uint32_t pixel_within_module) { + int64_t pixel0 = experiment.GetPixel0OfModule(module_number); + + int64_t line = pixel_within_module / RAW_MODULE_COLS; + int64_t col = pixel_within_module % RAW_MODULE_COLS; + + line += (line / 256) * 2; + col += (col / 256) * 2; + + int64_t pixel = pixel0 + + col * experiment.GetModuleFastDirectionStep(module_number) + + line * experiment.GetModuleSlowDirectionStep(module_number); + return {pixel % experiment.GetXPixelsNum() , pixel / experiment.GetXPixelsNum()}; +} + template void LineConvtToRaw(T *destination, const T *source) { for (int chip = 0; chip < 4; chip++) { diff --git a/tests/RawToConvertedGeometryTest.cpp b/tests/RawToConvertedGeometryTest.cpp index cebec8c2..2572c198 100644 --- a/tests/RawToConvertedGeometryTest.cpp +++ b/tests/RawToConvertedGeometryTest.cpp @@ -473,3 +473,10 @@ TEST_CASE("RawToConvertedGeometry_Gaps","[RawToConvertedGeometry]") { free(output); free(input2); } + +TEST_CASE("RawToConvertedCoordinate","[RawToConvertedGeometry]") { + DiffractionExperiment experiment(DetectorGeometry(4, 2, 8, 36, true)); + auto [x,y] = RawToConvertedCoordinate(experiment, 1, 300 * RAW_MODULE_COLS + 800); + REQUIRE(x == CONVERTED_MODULE_COLS + 8 + 806); // col 800 becomes 806 due to 3 chip boundaries + REQUIRE(y == CONVERTED_MODULE_LINES * 2 + 36 - 1 - 302); // line 300 becomes 302 due to 1 chip boundary +}