Files
Jungfraujoch/tests/RawToConvertedGeometryTest.cpp
leonarski_f 4809c1622c
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 16m43s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 28m46s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 32m5s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 39m44s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m7s
Build Packages / Create release (push) Successful in 8s
Build Packages / Build documentation (push) Successful in 49s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 22m30s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 31m54s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 11m29s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 23m51s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 26m7s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 29m38s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 28m6s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 29m44s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 33m22s
Build Packages / Generate python client (push) Successful in 47s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 34m6s
Build Packages / Unit tests (push) Successful in 1h2m47s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 35m59s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 34m8s
Build Packages / Validation Battery (push) Successful in 38m31s
v1.0.0-rc.187 (#98)
* Rugnux: Refinement several times faster, one protocol on the CPU and the GPU, parts of it on the Apple GPU; its random draws are the same on every platform.
* Rugnux: Refinement follows common practice: the free set decides only the restraint weights and the displacement model (isotropic, TLS or anisotropic, by Hamilton's test), everything else is decided on the working set; lower R-free for placed and predicted models.
* Rugnux: Restraint dictionaries via `--restraints` (or among the inputs) and more built-in ligands; a model whose space group is a subgroup of the data's is refined in its own group; reflections plus a model select `--mode refine` on their own.
* Rugnux: `-C` fixes the crystal system on the axes as typed; `-S` alone fixes the space group only, the cell is still found and reduced; a space group or cell stored in the input file is ignored, with a line in the log.
* Rugnux: More reliable multi-sweep merging; `--mode scale` merges several stills runs as one; `_plot.txt` and the report name each input; a second crystal form is reported for stills given a cell.
* jfjoch_broker (experimental): Live Rugnux on FPGA detectors (JUNGFRAU) takes the same path as a DECTRIS stream, rotation and serial alike, model step included, with analysis threads per GPU; frames waiting for the analysis can be viewed; no host stage drops a frame - a source faster than the analysis is held at the card.
* jfjoch_broker: Summation of more than 256 frames per image is split between the card and the host (`summation_mode` is then `hybrid`), and live Rugnux runs on such collections; pedestal runs take a receiver of their own.
* jfjoch_broker (experimental): `stills_downsample` analyses 1 of every N serial images (chosen by a hash; the first 2000 all; the others written without analysis; reset to 1 by `/initialize`); `max_spot_count` left out means 250 for per-image indexing and up to 1000 for live stills; the live status gives the merge before the model work, the fitted resolution and the anomalous peak height of each unexplained blob.
* jfjoch_broker: Without a `pcie` entry the broker runs on a mock of the card instead of the HLS simulation; its spot, ROI and azimuthal results are zero then.
* Web frontend: Redesigned Rugnux live page; Vite 8, TypeScript 6, Mol* 5.13 and dependency security updates.
* Tools: `jfjoch_fpga_stills_test` measures live stills on the cards with a stored dataset; `jfjoch_fpga_test` loses the HLS-simulation option.
* Other: FFTW no longer fetched or linked (the CPU FFT indexer keeps the name `FFTW`); PCIe driver now GPL-2.0-or-later and third-party notices complete; several crash fixes.

Reviewed-on: #98
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-11-19 20:49:28 +01:00

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