- Layout from the file: its NXmx module groups, else the modules the gaps of its pixel mask mark (any placement and orientation of 1030 x 514 modules); a module without a stated readout direction is read out along its long side from its box's corner (the multipixels are symmetric, so the frames are the same). The file's modules also go to the analysis. - Distinct images per card = (its generator module frames - 1) / its modules, the run takes the smallest over the cards, at most FPGA_INTERNAL_GENERATOR_MAX_IMAGES (frame_cell, 128) and within FPGA_INTERNAL_GENERATOR_MAX_MODULE_FRAMES (mem_cell, 1024). The broker's 64-image limit stays: DetectorSettings::InternalGeneratorImages takes the maximum as a parameter, defaulting to it. The mapping (cards, modules, module frames used) is printed at start. - -K defaults to 64 MiB of mock generator memory = 128 module frames. - Squeeze round-trip tests for a 4M and a 9M layout and a 16-module layout with turned and standing modules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UqXYdHHZ4cogS1mrGUtfN7
583 lines
25 KiB
C++
583 lines
25 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include "../common/RawToConvertedGeometry.h"
|
|
|
|
TEST_CASE("RawToConvertedGeometry_Half_and_quarter","[RawToConvertedGeometry]") {
|
|
REQUIRE(half<int32_t>(7, -10, 20) == 3);
|
|
REQUIRE(half<int32_t>(7, 9, 20) == 7);
|
|
REQUIRE(half<int32_t>(27, 9, 20) == 27);
|
|
|
|
REQUIRE(half<double>(7, -10, 20) == Catch::Approx(3.5));
|
|
REQUIRE(half<double>(7, 9, 20) == 7);
|
|
REQUIRE(half<double>(27, 9, 20) == 27);
|
|
|
|
REQUIRE(quarter<int16_t>(6, -10, 20) == 1);
|
|
REQUIRE(quarter<int16_t>(26, -10, 20) == 26);
|
|
REQUIRE(quarter<int16_t>(-16, -10, 20) == -16);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_LineCopyAndAddMultipixel","[RawToConvertedGeometry]") {
|
|
int16_t in[1024];
|
|
int16_t out[1030];
|
|
for (int16_t i = 0; i < 1024; i++)
|
|
in[i] = i;
|
|
|
|
LineCopyAndAddMultipixel<int16_t>(out, in);
|
|
REQUIRE(out[0] == 0);
|
|
REQUIRE(out[100] == 100);
|
|
REQUIRE(out[255] == 255);
|
|
REQUIRE(out[255+1] == 255);
|
|
REQUIRE(out[256+1] == 256);
|
|
REQUIRE(out[256+2] == 256);
|
|
REQUIRE(out[259+2] == 259);
|
|
REQUIRE(out[400+2] == 400);
|
|
REQUIRE(out[600+4] == 600);
|
|
REQUIRE(out[768+5] == 768);
|
|
REQUIRE(out[768+6] == 768);
|
|
REQUIRE(out[1000+6] == 1000);
|
|
REQUIRE(out[1015+6] == 1015);
|
|
REQUIRE(out[1029] == 1029 - 6);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_LineCopyAndAddMultipixelNormalRow","[RawToConvertedGeometry]") {
|
|
int16_t in[1024];
|
|
int16_t out[1030];
|
|
for (int16_t i = 0; i < 1024; i++)
|
|
in[i] = i;
|
|
|
|
LineCopyAndAdjustMultipixel<int16_t, int16_t>(out, in, 0, 500);
|
|
REQUIRE(out[0] == 0);
|
|
REQUIRE(out[100] == 100);
|
|
REQUIRE(out[255] == 255/2);
|
|
REQUIRE(out[255+1] == 255/2);
|
|
REQUIRE(out[256+1] == 256/2);
|
|
REQUIRE(out[256+2] == 256/2);
|
|
REQUIRE(out[259+2] == 259);
|
|
REQUIRE(out[400+2] == 400);
|
|
REQUIRE(out[600+4] == 600);
|
|
REQUIRE(out[768+5] == 768); // > 500 so not modified
|
|
REQUIRE(out[768+6] == 768); // > 500 so not modified
|
|
REQUIRE(out[1000+6] == 1000);
|
|
REQUIRE(out[1015+6] == 1015);
|
|
REQUIRE(out[1029] == 1029 - 6);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_LineCopyAndAddMultipixelMiddleRow","[RawToConvertedGeometry]") {
|
|
int16_t in[1024];
|
|
int16_t out[1030];
|
|
for (int16_t i = 0; i < 1024; i++)
|
|
in[i] = i;
|
|
|
|
LineCopyAndAdjustMultipixelMidRow<int16_t, int16_t>(out, in, 0, 500);
|
|
REQUIRE(out[0] == 0);
|
|
REQUIRE(out[100] == 100/2);
|
|
REQUIRE(out[255] == 255/4);
|
|
REQUIRE(out[255+1] == 255/4);
|
|
REQUIRE(out[256+1] == 256/4);
|
|
REQUIRE(out[256+2] == 256/4);
|
|
REQUIRE(out[259+2] == 259/2);
|
|
REQUIRE(out[400+2] == 400/2);
|
|
REQUIRE(out[600+4] == 600); // > 500 so not modified
|
|
REQUIRE(out[768+5] == 768); // > 500 so not modified
|
|
REQUIRE(out[768+6] == 768); // > 500 so not modified
|
|
REQUIRE(out[1000+6] == 1000); // > 500 so not modified
|
|
REQUIRE(out[1015+6] == 1015); // > 500 so not modified
|
|
REQUIRE(out[1029] == 1029 - 6); // > 500 so not modified
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_Transform","[RawToConvertedGeometry]") {
|
|
DiffractionExperiment x(DetJF(20, 2, 0, 0, false));
|
|
x.DataStreams(4);
|
|
|
|
REQUIRE(x.GetModulesNum(2) == 5);
|
|
REQUIRE(x.GetPixelsNum() == CONVERTED_MODULE_SIZE * x.GetModulesNum());
|
|
|
|
std::vector<uint32_t> input(x.GetModulesNum(0) * RAW_MODULE_SIZE);
|
|
std::vector<uint32_t> output(x.GetPixelsNum());
|
|
|
|
for (uint32_t i = 0; i < x.GetModulesNum(0) * RAW_MODULE_SIZE; i++) input[i] = i;
|
|
|
|
for (int i = 0; i < x.GetModulesNum(0); i++)
|
|
TransferModule<uint32_t, uint32_t>(output.data() + x.GetPixel0OfModuleConv(i + x.GetFirstModuleOfDataStream(0)),
|
|
input.data() + i * RAW_MODULE_SIZE,
|
|
x.GetModuleSlowDirectionStep(i + x.GetFirstModuleOfDataStream(0)),
|
|
x.GetModuleFastDirectionStep(i + x.GetFirstModuleOfDataStream(0)));
|
|
|
|
REQUIRE(output[0] == input[0]);
|
|
REQUIRE(output[253] == input[253]);
|
|
REQUIRE(output[256] == input[255]);
|
|
REQUIRE(output[1029] == input[1023]);
|
|
|
|
// Row just below middle row
|
|
REQUIRE(output[254*(2*1030)+1006] == input[254*1024+1000]);
|
|
|
|
// Middle row
|
|
REQUIRE(output[255*(2*1030)+518] == input[255*1024+514]);
|
|
REQUIRE(output[256*(2*1030)+518] == input[255*1024+514]);
|
|
|
|
// Split corner (module 0)
|
|
REQUIRE(output[255*(2*1030)+255] == input[255*1024+255]);
|
|
REQUIRE(output[256*(2*1030)+255] == input[255*1024+255]);
|
|
REQUIRE(output[255*(2*1030)+256] == input[255*1024+255]);
|
|
REQUIRE(output[256*(2*1030)+256] == input[255*1024+255]);
|
|
|
|
// Split corner (module 0)
|
|
REQUIRE(output[258*(2*1030)+255] == input[256*1024+255]);
|
|
REQUIRE(output[257*(2*1030)+255] == input[256*1024+255]);
|
|
REQUIRE(output[258*(2*1030)+256] == input[256*1024+255]);
|
|
REQUIRE(output[257*(2*1030)+256] == input[256*1024+255]);
|
|
|
|
// Row just above middle row
|
|
REQUIRE(output[259*(2*1030)+302] == input[257*1024+300]);
|
|
|
|
// Split corner (module 1)
|
|
REQUIRE(output[255*(2*1030)+1030+255] == input[512*1024+255*1024+255]);
|
|
REQUIRE(output[256*(2*1030)+1030+255] == input[512*1024+255*1024+255]);
|
|
REQUIRE(output[255*(2*1030)+1030+256] == input[512*1024+255*1024+255]);
|
|
REQUIRE(output[256*(2*1030)+1030+256] == input[512*1024+255*1024+255]);
|
|
|
|
// Module 1
|
|
REQUIRE(output[1030+5] == input[512*1024 + 5]);
|
|
REQUIRE(output[1030+256] == input[512*1024 + 255]);
|
|
|
|
// Module 2
|
|
REQUIRE(output[1030*514*2 + 256] == input[512*1024*2 + 255]);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_Transform_AdjustMultipixels","[RawToConvertedGeometry]") {
|
|
DiffractionExperiment x(DetJF(20, 2, 0, 0, false));
|
|
x.DataStreams(4);
|
|
|
|
x.PixelSigned(true).BitDepthImage(32);
|
|
REQUIRE(x.GetByteDepthImage() == 4);
|
|
|
|
REQUIRE(x.GetModulesNum(0) == 5);
|
|
REQUIRE(x.GetPixelsNum() == CONVERTED_MODULE_SIZE * x.GetModulesNum());
|
|
|
|
std::vector<int32_t> input(x.GetModulesNum(0) * RAW_MODULE_SIZE);
|
|
std::vector<int32_t> output(x.GetPixelsNum());
|
|
|
|
for (int32_t i = 0; i < x.GetModulesNum(0) * RAW_MODULE_SIZE; i++) input[i] = i % x.GetSaturationLimit();
|
|
|
|
for (int i = 0; i < x.GetModulesNum(0); i++)
|
|
TransferModuleAdjustMultipixels<int32_t, int32_t>(output.data() + x.GetPixel0OfModuleConv(i + x.GetFirstModuleOfDataStream(0)),
|
|
input.data() + i * RAW_MODULE_SIZE,
|
|
x.GetModuleSlowDirectionStep(i + x.GetFirstModuleOfDataStream(0)),
|
|
x.GetUnderflow(), x.GetSaturationLimit(),
|
|
x.GetModuleFastDirectionStep(i + x.GetFirstModuleOfDataStream(0)));
|
|
|
|
REQUIRE(output[0] == input[0]);
|
|
REQUIRE(output[253] == input[253]);
|
|
REQUIRE(output[256] == input[255]/2);
|
|
REQUIRE(output[1029] == input[1023]);
|
|
|
|
// Row just below middle row
|
|
REQUIRE(output[254*(2*1030)+1006] == input[254*1024+1000]);
|
|
|
|
// Middle row
|
|
REQUIRE(output[255*(2*1030)+518] == input[255*1024+514]/2);
|
|
REQUIRE(output[256*(2*1030)+518] == input[255*1024+514]/2);
|
|
|
|
// Split corner (module 0)
|
|
REQUIRE(output[255*(2*1030)+255] == input[255*1024+255]/4);
|
|
REQUIRE(output[256*(2*1030)+255] == input[255*1024+255]/4);
|
|
REQUIRE(output[255*(2*1030)+256] == input[255*1024+255]/4);
|
|
REQUIRE(output[256*(2*1030)+256] == input[255*1024+255]/4);
|
|
|
|
// Split corner (module 0)
|
|
REQUIRE(output[258*(2*1030)+255] == input[256*1024+255]/4);
|
|
REQUIRE(output[257*(2*1030)+255] == input[256*1024+255]/4);
|
|
REQUIRE(output[258*(2*1030)+256] == input[256*1024+255]/4);
|
|
REQUIRE(output[257*(2*1030)+256] == input[256*1024+255]/4);
|
|
|
|
// Row just above middle row
|
|
REQUIRE(output[259*(2*1030)+302] == input[257*1024+300]);
|
|
|
|
// Split corner (module 1)
|
|
REQUIRE(output[255*(2*1030)+1030+255] == input[512*1024+255*1024+255]/4);
|
|
REQUIRE(output[256*(2*1030)+1030+255] == input[512*1024+255*1024+255]/4);
|
|
REQUIRE(output[255*(2*1030)+1030+256] == input[512*1024+255*1024+255]/4);
|
|
REQUIRE(output[256*(2*1030)+1030+256] == input[512*1024+255*1024+255]/4);
|
|
|
|
// Module 1
|
|
REQUIRE(output[1030+5] == input[512*1024 + 5]);
|
|
REQUIRE(output[1030+256] == input[512*1024 + 255] / 2);
|
|
|
|
// Module 2
|
|
REQUIRE(output[1030*514*2 + 256] == input[512*1024*2 + 255] / 2);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_Transform_upside_down","[RawToConvertedGeometry]") {
|
|
DiffractionExperiment x(DetJF(24, 2, 0, 0, true));
|
|
x.DataStreams(4);
|
|
|
|
REQUIRE(x.GetModulesNum(3) == 6);
|
|
REQUIRE(x.GetPixelsNum() == CONVERTED_MODULE_SIZE * x.GetModulesNum());
|
|
|
|
auto input = (uint32_t *) calloc(x.GetModulesNum(2) * RAW_MODULE_SIZE, sizeof(uint32_t));
|
|
auto output = (uint32_t *) calloc(x.GetPixelsNum(), sizeof(uint32_t));
|
|
for (uint32_t i = 0; i < x.GetModulesNum(3) * RAW_MODULE_SIZE; i++) input[i] = i;
|
|
|
|
for (int i = 0; i < x.GetModulesNum(3); i++)
|
|
TransferModule<uint32_t, uint32_t>(output + x.GetPixel0OfModuleConv(i + x.GetFirstModuleOfDataStream(3)),
|
|
input + i * RAW_MODULE_SIZE,
|
|
x.GetModuleSlowDirectionStep(i + x.GetFirstModuleOfDataStream(3)));
|
|
|
|
REQUIRE(output[514*1030*4+0] == input[511*1024+0]);
|
|
REQUIRE(output[514*1030*4+253] == input[511*1024+253]);
|
|
REQUIRE(output[514*1030*4+256] == input[511*1024+255]);
|
|
REQUIRE(output[514*1030*4+1029] == input[511*1024+1023]);
|
|
|
|
// Row just below middle row
|
|
REQUIRE(output[514*1030*4+254*(2*1030)+1006] == input[257*1024+1000]);
|
|
|
|
// Middle row
|
|
REQUIRE(output[514*1030*4+255*(2*1030)+518] == input[256*1024+514]);
|
|
REQUIRE(output[514*1030*4+256*(2*1030)+518] == input[256*1024+514]);
|
|
|
|
// Split corner (module 0)
|
|
REQUIRE(output[514*1030*4+255*(2*1030)+255] == input[256*1024+255]);
|
|
REQUIRE(output[514*1030*4+256*(2*1030)+255] == input[256*1024+255]);
|
|
REQUIRE(output[514*1030*4+255*(2*1030)+256] == input[256*1024+255]);
|
|
REQUIRE(output[514*1030*4+256*(2*1030)+256] == input[256*1024+255]);
|
|
|
|
// Split corner (module 0)
|
|
REQUIRE(output[514*1030*4+258*(2*1030)+255] == input[255*1024+255]);
|
|
REQUIRE(output[514*1030*4+257*(2*1030)+255] == input[255*1024+255]);
|
|
REQUIRE(output[514*1030*4+258*(2*1030)+256] == input[255*1024+255]);
|
|
REQUIRE(output[514*1030*4+257*(2*1030)+256] == input[255*1024+255]);
|
|
|
|
// Row just above middle row
|
|
REQUIRE(output[514*1030*4+259*(2*1030)+302] == input[254*1024+300]);
|
|
|
|
// Split corner (module 1)
|
|
REQUIRE(output[514*1030*4+257*(2*1030)+1030+255] == input[512*1024+255*1024+255]);
|
|
REQUIRE(output[514*1030*4+258*(2*1030)+1030+255] == input[512*1024+255*1024+255]);
|
|
REQUIRE(output[514*1030*4+257*(2*1030)+1030+256] == input[512*1024+255*1024+255]);
|
|
REQUIRE(output[514*1030*4+258*(2*1030)+1030+256] == input[512*1024+255*1024+255]);
|
|
|
|
// Module 1
|
|
REQUIRE(output[514*1030*4+1030+5] == input[512*1024 + 511*1024 + 5]);
|
|
REQUIRE(output[514*1030*4+1030+256] == input[512*1024 + 511*1024 + 255]);
|
|
|
|
// Module 2
|
|
REQUIRE(output[1030*514*2 + 256] == input[512*1024*2 + 511*1024 + 255]);
|
|
|
|
free(input);
|
|
free(output);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_TransformModule_rotate","[RawToConvertedGeometry]") {
|
|
std::vector<int32_t> raw_image(RAW_MODULE_SIZE);
|
|
std::vector<int32_t> conv_image(CONVERTED_MODULE_SIZE);
|
|
|
|
for (int i = 0; i < raw_image.size(); i++)
|
|
raw_image[i] = i;
|
|
|
|
TransferModule(conv_image.data(), raw_image.data(), 1, CONVERTED_MODULE_LINES, 0);
|
|
|
|
CHECK(conv_image[0] == raw_image[0]);
|
|
CHECK(conv_image[1] == raw_image[RAW_MODULE_COLS]);
|
|
CHECK(conv_image[5] == raw_image[RAW_MODULE_COLS*5]);
|
|
CHECK(conv_image[255] == raw_image[RAW_MODULE_COLS*255]);
|
|
CHECK(conv_image[256] == raw_image[RAW_MODULE_COLS*255]);
|
|
CHECK(conv_image[257] == raw_image[RAW_MODULE_COLS*256]);
|
|
CHECK(conv_image[258] == raw_image[RAW_MODULE_COLS*256]);
|
|
CHECK(conv_image[513] == raw_image[RAW_MODULE_COLS*511]);
|
|
|
|
CHECK(conv_image[5 * CONVERTED_MODULE_LINES] == raw_image[5]);
|
|
CHECK(conv_image[255 * CONVERTED_MODULE_LINES] == raw_image[255]);
|
|
CHECK(conv_image[256 * CONVERTED_MODULE_LINES] == raw_image[255]);
|
|
CHECK(conv_image[257 * CONVERTED_MODULE_LINES] == raw_image[256]);
|
|
CHECK(conv_image[258 * CONVERTED_MODULE_LINES] == raw_image[256]);
|
|
CHECK(conv_image[1029 * CONVERTED_MODULE_LINES] == raw_image[1023]);
|
|
|
|
CHECK(conv_image[CONVERTED_MODULE_SIZE-1] == raw_image[RAW_MODULE_SIZE-1]);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_TransformModuleAdjustMultipixel_rotate","[RawToConvertedGeometry]") {
|
|
std::vector<int32_t> raw_image(RAW_MODULE_SIZE);
|
|
std::vector<int32_t> conv_image(CONVERTED_MODULE_SIZE);
|
|
|
|
for (int i = 0; i < raw_image.size(); i++)
|
|
raw_image[i] = i;
|
|
|
|
TransferModuleAdjustMultipixels(conv_image.data(), raw_image.data(), 1, INT32_MIN, INT32_MAX,
|
|
CONVERTED_MODULE_LINES, 0);
|
|
|
|
CHECK(conv_image[0] == raw_image[0]);
|
|
CHECK(conv_image[1] == raw_image[RAW_MODULE_COLS]);
|
|
CHECK(conv_image[5] == raw_image[RAW_MODULE_COLS*5]);
|
|
CHECK(conv_image[513] == raw_image[RAW_MODULE_COLS*511]);
|
|
|
|
CHECK(conv_image[255] == raw_image[RAW_MODULE_COLS*255]/2);
|
|
CHECK(conv_image[256] == raw_image[RAW_MODULE_COLS*255]/2);
|
|
CHECK(conv_image[257] == raw_image[RAW_MODULE_COLS*256]/2);
|
|
CHECK(conv_image[258] == raw_image[RAW_MODULE_COLS*256]/2);
|
|
|
|
CHECK(conv_image[5 * CONVERTED_MODULE_LINES] == raw_image[5]);
|
|
CHECK(conv_image[255 * CONVERTED_MODULE_LINES] == raw_image[255]/2);
|
|
CHECK(conv_image[256 * CONVERTED_MODULE_LINES] == raw_image[255]/2);
|
|
CHECK(conv_image[257 * CONVERTED_MODULE_LINES] == raw_image[256]/2);
|
|
CHECK(conv_image[258 * CONVERTED_MODULE_LINES] == raw_image[256]/2);
|
|
CHECK(conv_image[1029 * CONVERTED_MODULE_LINES] == raw_image[1023]);
|
|
|
|
CHECK(conv_image[CONVERTED_MODULE_SIZE-1] == raw_image[RAW_MODULE_SIZE-1]);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_TransformModuleAdjustMultipixel_rotate_negative","[RawToConvertedGeometry]") {
|
|
std::vector<int32_t> raw_image(RAW_MODULE_SIZE);
|
|
std::vector<int32_t> conv_image(CONVERTED_MODULE_SIZE);
|
|
|
|
for (int i = 0; i < raw_image.size(); i++)
|
|
raw_image[i] = i;
|
|
|
|
TransferModuleAdjustMultipixels(conv_image.data(), raw_image.data(),
|
|
-1,
|
|
INT32_MIN, INT32_MAX,
|
|
-CONVERTED_MODULE_LINES,
|
|
CONVERTED_MODULE_SIZE - 1);
|
|
|
|
CHECK(conv_image[0] == raw_image[RAW_MODULE_SIZE - 1]);
|
|
CHECK(conv_image[1] == raw_image[RAW_MODULE_SIZE - 1 - RAW_MODULE_COLS]);
|
|
CHECK(conv_image[5] == raw_image[RAW_MODULE_SIZE - 1 - RAW_MODULE_COLS*5]);
|
|
CHECK(conv_image[513] == raw_image[RAW_MODULE_SIZE - 1 - RAW_MODULE_COLS*511]);
|
|
|
|
CHECK(conv_image[255] == raw_image[RAW_MODULE_SIZE - 1 - RAW_MODULE_COLS*255]/2);
|
|
CHECK(conv_image[256] == raw_image[RAW_MODULE_SIZE - 1 - RAW_MODULE_COLS*255]/2);
|
|
CHECK(conv_image[257] == raw_image[RAW_MODULE_SIZE - 1 - RAW_MODULE_COLS*256]/2);
|
|
CHECK(conv_image[258] == raw_image[RAW_MODULE_SIZE - 1 - RAW_MODULE_COLS*256]/2);
|
|
|
|
CHECK(conv_image[5 * CONVERTED_MODULE_LINES] == raw_image[RAW_MODULE_SIZE - 1 - 5]);
|
|
CHECK(conv_image[255 * CONVERTED_MODULE_LINES] == raw_image[RAW_MODULE_SIZE - 1 - 255]/2);
|
|
CHECK(conv_image[256 * CONVERTED_MODULE_LINES] == raw_image[RAW_MODULE_SIZE - 1 - 255]/2);
|
|
CHECK(conv_image[257 * CONVERTED_MODULE_LINES] == raw_image[RAW_MODULE_SIZE - 1 - 256]/2);
|
|
CHECK(conv_image[258 * CONVERTED_MODULE_LINES] == raw_image[RAW_MODULE_SIZE - 1 - 256]/2);
|
|
CHECK(conv_image[1029 * CONVERTED_MODULE_LINES] == raw_image[RAW_MODULE_SIZE - 1 - 1023]);
|
|
|
|
CHECK(conv_image[CONVERTED_MODULE_SIZE-1] == raw_image[0]);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry","[RawToConvertedGeometry]") {
|
|
DiffractionExperiment x(DetJF(20, 2, 0, 0, true));
|
|
x.DataStreams(4);
|
|
|
|
REQUIRE(x.GetModulesNum(2) == 5);
|
|
REQUIRE(x.GetPixelsNum() == CONVERTED_MODULE_SIZE * x.GetModulesNum());
|
|
|
|
auto input = (uint32_t *) calloc(x.GetModulesNum() * RAW_MODULE_SIZE, sizeof(uint32_t));
|
|
auto output = (uint32_t *) calloc(x.GetPixelsNum(), sizeof(uint32_t));
|
|
|
|
auto input2 = (uint32_t *) calloc(x.GetModulesNum() * RAW_MODULE_SIZE, sizeof(uint32_t));
|
|
|
|
for (uint32_t i = 0; i < x.GetModulesNum() * RAW_MODULE_SIZE; i++)
|
|
input[i] = 3*i-1;
|
|
|
|
RawToConvertedGeometry<uint32_t, uint32_t>(x, output, input);
|
|
ConvertedToRawGeometry<uint32_t>(x, input2, output);
|
|
|
|
uint64_t diff = 0;
|
|
for (int i = 0; i < x.GetModulesNum(2) * RAW_MODULE_SIZE; i++) {
|
|
if (input[i] != input2[i]) diff++;
|
|
}
|
|
REQUIRE(diff == 0);
|
|
|
|
free(input);
|
|
free(output);
|
|
free(input2);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_int64","[RawToConvertedGeometry]") {
|
|
DiffractionExperiment x(DetJF(20, 2, 0, 0, true));
|
|
x.DataStreams(4);
|
|
|
|
REQUIRE(x.GetModulesNum(2) == 5);
|
|
REQUIRE(x.GetPixelsNum() == CONVERTED_MODULE_SIZE * x.GetModulesNum());
|
|
|
|
std::vector<uint32_t> input(x.GetModulesNum() * RAW_MODULE_SIZE);
|
|
std::vector<uint64_t> output(x.GetPixelsNum());
|
|
std::vector<uint64_t> input2(x.GetModulesNum() * RAW_MODULE_SIZE);
|
|
|
|
for (uint32_t i = 0; i < x.GetModulesNum() * RAW_MODULE_SIZE; i++)
|
|
input[i] = 3*i-1;
|
|
|
|
RawToConvertedGeometry<uint64_t, uint32_t>(x, output.data(), input.data());
|
|
ConvertedToRawGeometry<uint64_t>(x, input2.data(), output.data());
|
|
|
|
uint64_t diff = 0;
|
|
for (int i = 0; i < x.GetModulesNum(2) * RAW_MODULE_SIZE; i++) {
|
|
if (input[i] != input2[i]) diff++;
|
|
}
|
|
REQUIRE(diff == 0);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_FP","[RawToConvertedGeometry]") {
|
|
DiffractionExperiment x(DetJF(20, 2, 0, 0, true));
|
|
x.DataStreams(4);
|
|
|
|
REQUIRE(x.GetModulesNum(2) == 5);
|
|
REQUIRE(x.GetPixelsNum() == CONVERTED_MODULE_SIZE * x.GetModulesNum());
|
|
|
|
std::vector<uint32_t> input(x.GetModulesNum() * RAW_MODULE_SIZE);
|
|
std::vector<double> output(x.GetPixelsNum());
|
|
std::vector<double> input2(x.GetModulesNum() * RAW_MODULE_SIZE);
|
|
|
|
for (uint32_t i = 0; i < x.GetModulesNum() * RAW_MODULE_SIZE; i++)
|
|
input[i] = 3*i-1;
|
|
|
|
RawToConvertedGeometry<double, uint32_t>(x, output.data(), input.data());
|
|
ConvertedToRawGeometry<double>(x, input2.data(), output.data());
|
|
|
|
uint64_t diff = 0;
|
|
for (int i = 0; i < x.GetModulesNum(2) * RAW_MODULE_SIZE; i++) {
|
|
if (input[i] != Catch::Approx(input2[i])) diff++;
|
|
}
|
|
REQUIRE(diff == 0);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_Gaps","[RawToConvertedGeometry]") {
|
|
DiffractionExperiment x(DetJF(8, 2, 8, 36, true));
|
|
x.DataStreams(2);
|
|
|
|
REQUIRE(x.GetModulesNum(1) == 4);
|
|
REQUIRE(x.GetXPixelsNum() == 2 * CONVERTED_MODULE_COLS + 8);
|
|
REQUIRE(x.GetYPixelsNum() == 4 * CONVERTED_MODULE_LINES + 3*36);
|
|
REQUIRE(x.GetPixelsNum() == x.GetXPixelsNum() * x.GetYPixelsNum());
|
|
|
|
auto input = (uint32_t *) calloc(x.GetModulesNum() * RAW_MODULE_SIZE, sizeof(uint32_t));
|
|
auto output = (uint32_t *) calloc(x.GetPixelsNum(), sizeof(uint32_t));
|
|
|
|
auto input2 = (uint32_t *) calloc(x.GetModulesNum() * RAW_MODULE_SIZE, sizeof(uint32_t));
|
|
|
|
for (uint32_t i = 0; i < x.GetModulesNum() * RAW_MODULE_SIZE; i++)
|
|
input[i] = 3*i-1;
|
|
|
|
RawToConvertedGeometry<uint32_t, uint32_t>(x, output, input);
|
|
ConvertedToRawGeometry<uint32_t>(x, input2, output);
|
|
|
|
uint64_t diff = 0;
|
|
for (int i = 0; i < x.GetModulesNum() * RAW_MODULE_SIZE; i++) {
|
|
if (input[i] != input2[i]) diff++;
|
|
}
|
|
REQUIRE(diff == 0);
|
|
|
|
free(input);
|
|
free(output);
|
|
free(input2);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_Vertical","[RawToConvertedGeometry]") {
|
|
std::vector<DetectorModuleGeometry> module_geom;
|
|
|
|
REQUIRE_NOTHROW(module_geom.emplace_back(2999, 2999, DetectorModuleGeometry::Direction::Xneg,
|
|
DetectorModuleGeometry::Direction::Yneg));
|
|
|
|
REQUIRE_NOTHROW(module_geom.emplace_back(0, 0, DetectorModuleGeometry::Direction::Ypos,
|
|
DetectorModuleGeometry::Direction::Xpos));
|
|
|
|
REQUIRE_NOTHROW(module_geom.emplace_back(5000, 0, DetectorModuleGeometry::Direction::Ypos,
|
|
DetectorModuleGeometry::Direction::Xpos));
|
|
|
|
DetectorGeometryModular geometry(module_geom);
|
|
DiffractionExperiment x(DetJF(geometry));
|
|
x.DataStreams(3);
|
|
|
|
std::vector<uint32_t> input(x.GetModulesNum() * RAW_MODULE_SIZE);
|
|
std::vector<uint32_t> input2(x.GetModulesNum() * RAW_MODULE_SIZE);
|
|
std::vector<uint32_t> output(x.GetPixelsNum(), UINT32_MAX);
|
|
|
|
for (uint32_t i = 0; i < x.GetModulesNum() * RAW_MODULE_SIZE; i++)
|
|
input[i] = 3*i-1;
|
|
|
|
RawToConvertedGeometry<uint32_t, uint32_t>(x, output.data(), input.data());
|
|
ConvertedToRawGeometry<uint32_t>(x, input2.data(), output.data());
|
|
|
|
uint64_t diff = 0;
|
|
for (int i = 0; i < x.GetModulesNum(2) * RAW_MODULE_SIZE; i++) {
|
|
if (input[i] != input2[i]) diff++;
|
|
}
|
|
REQUIRE(diff == 0);
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedCoordinate","[RawToConvertedGeometry]") {
|
|
DiffractionExperiment experiment(DetJF(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
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedCoordinate_Coord","[RawToConvertedGeometry]") {
|
|
DiffractionExperiment experiment(DetJF(4, 2, 8, 36, true));
|
|
Coord input(800.5, 300.25, 0);
|
|
Coord c = RawToConvertedCoordinate(experiment, 1, input);
|
|
|
|
REQUIRE(Catch::Approx(c.x) == CONVERTED_MODULE_COLS + 8 + 800.5 + 6); // col 800 becomes 806 due to 3 chip boundaries
|
|
REQUIRE(Catch::Approx(c.y) == CONVERTED_MODULE_LINES * 2 + 36 - 1 - 300.25 - 2); // line 300 becomes 302 due to 1 chip boundary
|
|
}
|
|
|
|
namespace {
|
|
// Assembled with the multipixels split, then squeezed back: the raw frames, where the split divides evenly
|
|
void CheckSqueezeRoundTrip(const DetectorSetup &detector) {
|
|
DiffractionExperiment x(detector);
|
|
x.PixelSigned(true).BitDepthImage(16);
|
|
|
|
std::vector<int16_t> raw(x.GetModulesNum() * RAW_MODULE_SIZE);
|
|
for (size_t i = 0; i < raw.size(); i++)
|
|
raw[i] = static_cast<int16_t>(4 * (i % 5000) - 400);
|
|
raw[255 * RAW_MODULE_COLS + 255] = INT16_MIN; // error, chip corner
|
|
raw[RAW_MODULE_SIZE + 10 * RAW_MODULE_COLS + 256] = INT16_MAX; // saturated, multipixel
|
|
|
|
std::vector<int32_t> image(x.GetPixelsNum(), INT32_MIN);
|
|
for (int m = 0; m < x.GetModulesNum(); m++)
|
|
TransferModuleAdjustMultipixels<int32_t, int16_t>(image.data(), raw.data() + m * RAW_MODULE_SIZE,
|
|
x.GetModuleSlowDirectionStep(m), INT16_MIN, INT16_MAX,
|
|
x.GetModuleFastDirectionStep(m),
|
|
x.GetPixel0OfModuleConv(m));
|
|
for (auto &v: image) {
|
|
if (v == INT16_MIN)
|
|
v = INT32_MIN;
|
|
else if (v == INT16_MAX)
|
|
v = INT32_MAX;
|
|
}
|
|
|
|
std::vector<int16_t> squeezed(raw.size());
|
|
SqueezeToRawGeometry<int16_t, int32_t>(x, squeezed.data(), image.data(), INT32_MIN, INT32_MAX,
|
|
INT16_MIN, INT16_MAX);
|
|
CHECK(squeezed == raw);
|
|
|
|
// A sum past the 16-bit range is saturated
|
|
image[x.GetPixel0OfModuleConv(0)] = 40000;
|
|
SqueezeToRawGeometry<int16_t, int32_t>(x, squeezed.data(), image.data(), INT32_MIN, INT32_MAX,
|
|
INT16_MIN, INT16_MAX);
|
|
CHECK(squeezed[0] == INT16_MAX);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_SqueezeToRawGeometry_4M","[RawToConvertedGeometry]") {
|
|
CheckSqueezeRoundTrip(DetJF(8, 2, 8, 36, true));
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_SqueezeToRawGeometry_9M","[RawToConvertedGeometry]") {
|
|
CheckSqueezeRoundTrip(DetJF(18, 3, 8, 36, true));
|
|
}
|
|
|
|
TEST_CASE("RawToConvertedGeometry_SqueezeToRawGeometry_16_modules_turned","[RawToConvertedGeometry]") {
|
|
// 12 modules in rows of two, every other row read out the other way, and 4 standing modules beside them
|
|
using Direction = DetectorModuleGeometry::Direction;
|
|
std::vector<DetectorModuleGeometry> modules;
|
|
for (int row = 0; row < 6; row++)
|
|
for (int col = 0; col < 2; col++) {
|
|
if (row % 2 == 0)
|
|
modules.emplace_back(col * 1038, row * 550, Direction::Xpos, Direction::Ypos);
|
|
else
|
|
modules.emplace_back(col * 1038 + 1029, row * 550 + 513, Direction::Xneg, Direction::Yneg);
|
|
}
|
|
for (int row = 0; row < 2; row++)
|
|
for (int col = 0; col < 2; col++)
|
|
modules.emplace_back(2076 + col * 522 + 513, row * 1038, Direction::Ypos, Direction::Xneg);
|
|
CheckSqueezeRoundTrip(DetJF(DetectorGeometryModular(modules)));
|
|
}
|