Fixes after MAX IV experiment

This commit is contained in:
2024-02-05 17:18:16 +01:00
parent 91a0960303
commit babb1a5c8d
151 changed files with 4395 additions and 1477 deletions

View File

@@ -1426,6 +1426,24 @@ TEST_CASE("HLS_C_Simulation_internal_packet_generator_integration", "[FPGA][Full
CHECK(integration_result[54].count == RAW_MODULE_SIZE);
}
bool spot_finder_output_contains(const SpotFindingResult& output, uint32_t number) {
bool ret = false;
for (const auto &i: output.strong_pixel_number) {
if ((i & (((1<<21UL) - 1))) == number)
ret = true;
}
return ret;
}
bool spot_finder_output_connectivity(const SpotFindingResult& output, uint32_t number, uint8_t bit) {
bool ret = false;
for (const auto &i: output.strong_pixel_number) {
if ((i & (((1<<21UL) - 1))) == number)
ret = i & (1LU << (24 + bit));
}
return ret;
}
TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_count_threshold", "[FPGA][Full]") {
const uint16_t nmodules = 4;
@@ -1445,7 +1463,12 @@ TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_count_threshol
test.SetInternalGeneratorFrameForAllModules(frame);
test.SetSpotFinderParameters(10, 0.0);
SpotFindingSettings parameters{
.signal_to_noise_threshold = 0.0,
.photon_count_threshold = 10,
.min_pix_per_spot = 1
};
test.SetSpotFinderParameters(parameters);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
@@ -1461,9 +1484,197 @@ TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_count_threshol
REQUIRE (spot_finder_result.strong_pixel_count == 3);
REQUIRE (spot_finder_result.snr_threshold == 0);
REQUIRE (spot_finder_result.count_threshold == 10);
REQUIRE (spot_finder_result.strong_pixel[0] == (1<<0));
REQUIRE (spot_finder_result.strong_pixel[(123*1024 + 578) / 8] == (1<<2)); // 578 % 8 == 2
REQUIRE (spot_finder_result.strong_pixel[(121*1024 + 800) / 8] == (1<<0)); // 800 % 8 == 0
CHECK (spot_finder_output_contains(spot_finder_result, 0));
CHECK (spot_finder_output_contains(spot_finder_result, 123*1024 + 578));
CHECK (spot_finder_output_contains(spot_finder_result, 121*1024 + 800));
}
TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_connectivity", "[FPGA][Full]") {
const uint16_t nmodules = 4;
DiffractionExperiment x((DetectorGeometry(nmodules)));
x.Mode(DetectorMode::Raw);
x.UseInternalPacketGenerator(true).ImagesPerTrigger(1).PedestalG0Frames(0);
HLSSimulatedDevice test(0, 64);
std::vector<uint16_t> frame(RAW_MODULE_SIZE, 0);
frame [ 0] = 11;
frame [ 1] = 10;
frame [ 1024] = 12;
frame [2*1024] = 12;
frame [ 99*1024+200] = 12;
frame [100*1024+200] = 11;
frame [100*1024+201] = 10;
frame [101*1024+200] = 12;
frame [RAW_MODULE_SIZE - 1] = 20;
test.SetInternalGeneratorFrameForAllModules(frame);
SpotFindingSettings parameters{
.signal_to_noise_threshold = 0.0,
.photon_count_threshold = 10,
.min_pix_per_spot = 1
};
test.SetSpotFinderParameters(parameters);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
REQUIRE(test.OutputStream().size() == 1);
REQUIRE(test.GetBytesReceived() == 128 * nmodules * JUNGFRAU_PACKET_SIZE_BYTES);
auto imageBuf = test.GetDeviceOutput(0, 0)->pixels;
REQUIRE(memcmp(imageBuf, frame.data(), RAW_MODULE_SIZE * sizeof(uint16_t)) == 0);
auto spot_finder_result = test.GetDeviceOutput(0, 0)->spot_finding_result;
REQUIRE (spot_finder_result.strong_pixel_count == 9);
REQUIRE (spot_finder_result.snr_threshold == 0);
REQUIRE (spot_finder_result.count_threshold == 10);
CHECK (spot_finder_output_contains(spot_finder_result, 0));
CHECK (spot_finder_output_contains(spot_finder_result, 1));
CHECK (spot_finder_output_contains(spot_finder_result, 1024));
CHECK (spot_finder_output_contains(spot_finder_result, RAW_MODULE_SIZE-1));
CHECK(spot_finder_output_connectivity(spot_finder_result, 0, 4));
CHECK(spot_finder_output_connectivity(spot_finder_result, 0, 6));
CHECK(spot_finder_output_connectivity(spot_finder_result, 1, 1));
CHECK(spot_finder_output_connectivity(spot_finder_result, 1, 2));
CHECK(spot_finder_output_connectivity(spot_finder_result, 1024, 3));
CHECK(spot_finder_output_connectivity(spot_finder_result, 1024, 4));
CHECK(spot_finder_output_connectivity(spot_finder_result, 1024, 5));
CHECK(spot_finder_output_connectivity(spot_finder_result, 2048, 3));
CHECK(spot_finder_output_connectivity(spot_finder_result, 100*1024+201, 0));
CHECK(spot_finder_output_connectivity(spot_finder_result, 100*1024+201, 1));
CHECK(spot_finder_output_connectivity(spot_finder_result, 100*1024+201, 2));
CHECK(!spot_finder_output_connectivity(spot_finder_result, 100*1024+201, 3));
CHECK(!spot_finder_output_connectivity(spot_finder_result, 100*1024+201, 4));
CHECK(!spot_finder_output_connectivity(spot_finder_result, 100*1024+201, 5));
CHECK(!spot_finder_output_connectivity(spot_finder_result, 100*1024+201, 6));
CHECK(!spot_finder_output_connectivity(spot_finder_result, 100*1024+201, 7));
CHECK(spot_finder_output_connectivity(spot_finder_result, 99*1024+200, 7));
CHECK(spot_finder_output_connectivity(spot_finder_result, 99*1024+200, 4));
for (int i = 0; i < 8; i++)
CHECK(!spot_finder_output_connectivity(spot_finder_result, RAW_MODULE_SIZE-1, i));
}
TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_min_pix_per_spot", "[FPGA][Full]") {
const uint16_t nmodules = 4;
DiffractionExperiment x((DetectorGeometry(nmodules)));
x.Mode(DetectorMode::Raw);
x.UseInternalPacketGenerator(true).ImagesPerTrigger(1).PedestalG0Frames(0);
HLSSimulatedDevice test(0, 64);
std::vector<uint16_t> frame(RAW_MODULE_SIZE, 0);
frame [ 0] = 11;
frame [ 1] = 10;
frame [ 1024] = 12;
frame [2*1024] = 12;
frame [ 89*1024+154] = 12;
frame [ 99*1024+200] = 12;
frame [100*1024+200] = 11;
frame [100*1024+201] = 10;
frame [101*1024+200] = 12;
frame [RAW_MODULE_SIZE - 1] = 20;
test.SetInternalGeneratorFrameForAllModules(frame);
SpotFindingSettings parameters{
.signal_to_noise_threshold = 0.0,
.photon_count_threshold = 10,
.min_pix_per_spot = 2
};
test.SetSpotFinderParameters(parameters);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
REQUIRE(test.OutputStream().size() == 1);
REQUIRE(test.GetBytesReceived() == 128 * nmodules * JUNGFRAU_PACKET_SIZE_BYTES);
auto imageBuf = test.GetDeviceOutput(0, 0)->pixels;
REQUIRE(memcmp(imageBuf, frame.data(), RAW_MODULE_SIZE * sizeof(uint16_t)) == 0);
auto spot_finder_result = test.GetDeviceOutput(0, 0)->spot_finding_result;
REQUIRE (spot_finder_result.strong_pixel_count == 8);
REQUIRE (spot_finder_result.snr_threshold == 0);
REQUIRE (spot_finder_result.count_threshold == 10);
CHECK (spot_finder_output_contains(spot_finder_result, 0));
CHECK (spot_finder_output_contains(spot_finder_result, 1));
CHECK (spot_finder_output_contains(spot_finder_result, 1024));
CHECK (!spot_finder_output_contains(spot_finder_result, RAW_MODULE_SIZE-1));
CHECK (!spot_finder_output_contains(spot_finder_result, 89*1024+154));
}
TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_d_min_max", "[FPGA][Full]") {
const uint16_t nmodules = 4;
DiffractionExperiment x((DetectorGeometry(nmodules)));
x.Mode(DetectorMode::Raw);
x.UseInternalPacketGenerator(true).ImagesPerTrigger(1).PedestalG0Frames(0);
HLSSimulatedDevice test(0, 64);
std::vector<float> d_map(RAW_MODULE_SIZE * nmodules, 0.0);
d_map[0] = 2.5;
d_map[1] = 4.0;
d_map[2] = 1.0;
d_map[3] = 1.5;
std::vector<uint16_t> frame(RAW_MODULE_SIZE, 0);
frame [ 0] = 11;
frame [ 1] = 10;
frame [ 2] = 12;
frame [ 3] = 12;
test.InitializeSpotFinderResolutionMap(x, d_map);
test.SetInternalGeneratorFrameForAllModules(frame);
SpotFindingSettings parameters{
.signal_to_noise_threshold = 0.0,
.photon_count_threshold = 10,
.min_pix_per_spot = 1,
.high_resolution_limit = 1.25,
.low_resolution_limit = 3.0
};
test.SetSpotFinderParameters(parameters);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
REQUIRE(test.OutputStream().size() == 1);
REQUIRE(test.GetBytesReceived() == 128 * nmodules * JUNGFRAU_PACKET_SIZE_BYTES);
auto imageBuf = test.GetDeviceOutput(0, 0)->pixels;
REQUIRE(memcmp(imageBuf, frame.data(), RAW_MODULE_SIZE * sizeof(uint16_t)) == 0);
auto spot_finder_result = test.GetDeviceOutput(0, 0)->spot_finding_result;
REQUIRE (spot_finder_result.strong_pixel_count == 2);
REQUIRE (spot_finder_result.snr_threshold == 0);
REQUIRE (spot_finder_result.count_threshold == 10);
CHECK (spot_finder_output_contains(spot_finder_result, 0));
CHECK (spot_finder_output_contains(spot_finder_result, 3));
}
TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_snr_threshold", "[FPGA][Full]") {
@@ -1491,8 +1702,12 @@ TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_snr_threshold"
frame [300*1024 + 0] = 3;
test.SetInternalGeneratorFrameForAllModules(frame);
test.SetSpotFinderParameters(0, 10);
SpotFindingSettings parameters{
.signal_to_noise_threshold = 10.0,
.photon_count_threshold = 0,
.min_pix_per_spot = 1
};
test.SetSpotFinderParameters(parameters);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
@@ -1508,8 +1723,10 @@ TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_snr_threshold"
REQUIRE (spot_finder_result.strong_pixel_count == 2);
REQUIRE (spot_finder_result.snr_threshold == 10.0);
REQUIRE (spot_finder_result.count_threshold == 0);
REQUIRE (spot_finder_result.strong_pixel[0] == (1<<0));
REQUIRE (spot_finder_result.strong_pixel[(89*1024 + 300) / 8] == (1<<4)); // 300 % 8 == 4
REQUIRE (spot_finder_output_contains(spot_finder_result, 0));
REQUIRE (spot_finder_output_contains(spot_finder_result, 89*1024 + 300));
}
TEST_CASE("HLS_C_Simulation_internal_packet_generator_32bit", "[FPGA][Full]") {