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); + } + } +}