// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include #include "../common/DiffractionSpot.h" #include "../common/RawToConvertedGeometry.h" TEST_CASE("DiffractionSpot_ConvertToImageCoordinates", "[LinearAlgebra][Coord]") { DiffractionExperiment experiment(DetJF(4, 2, 8, 36, true)); DiffractionSpot spot_1(800, 300, 12); spot_1 += DiffractionSpot(800, 301, 4); spot_1 += DiffractionSpot(801, 300, 12); spot_1 += DiffractionSpot(801, 301, 4); REQUIRE(spot_1.RawCoord().x == 800.5); REQUIRE(spot_1.RawCoord().y == 300.25); REQUIRE(spot_1.Count() == 12 * 2 + 4 * 2); spot_1.ConvertToImageCoordinates(experiment, 1); REQUIRE(spot_1.RawCoord().x == Catch::Approx(CONVERTED_MODULE_COLS + 8 + 800.5 + 6)); 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); } } }