From 5f30f0d1ac870799ffd502260924b2da10b5d898 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 2 Aug 2026 19:14:32 +0200 Subject: [PATCH] tests: hold the integer coordinate conversion to the module map ConvertToImageCoordinates now transforms the photon-weighted sums instead of the centroid, which is only equivalent because a module's raw -> image map is a signed axis swap plus an integer translation. Check that against the map itself on every module of a detector whose modules do not share an orientation, and either side of the 256-column multipixel gaps where the translation changes. A wrong sign or a dropped gap term on any single module would otherwise only show up as mispositioned spots on that module. Co-Authored-By: Claude Opus 5 (1M context) --- tests/DiffractionSpotTest.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/DiffractionSpotTest.cpp b/tests/DiffractionSpotTest.cpp index 7803a542..2a15fe1b 100644 --- a/tests/DiffractionSpotTest.cpp +++ b/tests/DiffractionSpotTest.cpp @@ -3,6 +3,7 @@ #include #include "../common/DiffractionSpot.h" +#include "../common/RawToConvertedGeometry.h" TEST_CASE("DiffractionSpot_ConvertToImageCoordinates", "[LinearAlgebra][Coord]") { DiffractionExperiment experiment(DetJF(4, 2, 8, 36, true)); @@ -20,3 +21,30 @@ TEST_CASE("DiffractionSpot_ConvertToImageCoordinates", "[LinearAlgebra][Coord]") REQUIRE(spot_1.RawCoord().y == Catch::Approx(CONVERTED_MODULE_LINES * 2 + 36 - 1 - 300.25 - 2)); REQUIRE(spot_1.Count() == 12 * 2 + 4 * 2); } + +// ConvertToImageCoordinates transforms the photon-weighted SUMS in integers rather than converting +// the centroid, which is only equivalent because the module map is a signed axis swap plus an +// integer translation. Hold it to the map it is standing in for, on every module of a detector +// whose modules do not all share an orientation, and either side of the 256-column multipixel gaps +// where the translation changes. +TEST_CASE("DiffractionSpot_ConvertMatchesModuleMap", "[LinearAlgebra][Coord]") { + DiffractionExperiment experiment(DetJF(8, 2, 8, 36, true)); + + for (uint16_t module = 0; module < experiment.GetModulesNum(); module++) { + for (const auto [col, line] : {std::pair{3, 5}, + {255, 255}, {256, 256}, {700, 300}, {1020, 505}}) { + INFO("module " << module << " pixel " << col << "," << line); + // Two pixels of unequal weight, so the centroid is a genuine fraction rather than a + // pixel centre - a whole-pixel centroid would not notice a lost fractional part. + DiffractionSpot spot(col, line, 7); + spot += DiffractionSpot(col, line + 1, 3); + const Coord raw = spot.RawCoord(); + + spot.ConvertToImageCoordinates(experiment, module); + const Coord expected = RawToConvertedCoordinate(experiment, module, raw); + REQUIRE(spot.RawCoord().x == Catch::Approx(expected.x)); + REQUIRE(spot.RawCoord().y == Catch::Approx(expected.y)); + REQUIRE(spot.Count() == 10); + } + } +}