// Copyright (2019-2023) Paul Scherrer Institute #include #include #include #include #include "../jungfrau/JFPedestalCalc.h" #include "../common/Logger.h" #include "../jungfrau/JFCalibration.h" #include "../jungfrau/JFConversionFloatingPoint.h" #include "../tests/FPGAUnitTest.h" void test_pedestal(Logger &logger) { size_t nframes = 5000; DiffractionExperiment x(DetectorGeometry(1)); x.Mode(DetectorMode::Conversion); std::vector data(nframes * RAW_MODULE_SIZE); for (size_t i = 0; i < nframes * RAW_MODULE_SIZE; i++) data[i] = 3000 + (i % 881) + (i % 557); JFPedestalCalc calc_cpu(x); auto start_time = std::chrono::system_clock::now(); for (int i = 0; i < nframes; i++) calc_cpu.AnalyzeImage(data.data() + i * RAW_MODULE_SIZE); auto end_time = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end_time - start_time); logger.Info("CPU pedestal performance: {:5d} us/module {:5.2f} GB/s", std::lround(elapsed.count() / ((double) nframes)), nframes * RAW_MODULE_SIZE * sizeof(uint16_t) * 1000 * 1000/ ((double) elapsed.count() * 1024 * 1024 * 1024)); } template void test_conversion(Logger &logger) { size_t nframes = 128; int64_t nmodules = 8; int64_t ntries = 8; DiffractionExperiment x((DetectorGeometry(nmodules))); std::vector input(nframes * nmodules * RAW_MODULE_SIZE); std::vector output(nframes * nmodules * RAW_MODULE_SIZE); for (int i = 0; i < nmodules * nframes; i++) { std::string image_path = "../../tests/test_data/mod5_raw" + std::to_string(i % 20) + ".bin"; LoadBinaryFile(image_path, input.data() + i * RAW_MODULE_SIZE, RAW_MODULE_SIZE); } std::vector v(nmodules); JFModuleGainCalibration gain_calib = GainCalibrationFromTestFile(); for (int m = 0; m < nmodules; m++) { JFModulePedestal pedestal_g0; JFModulePedestal pedestal_g1; JFModulePedestal pedestal_g2; for (int i = 0; i < RAW_MODULE_SIZE; i++) { pedestal_g0.GetPedestal()[i] = 3000 + i % 50 + m * 135; pedestal_g1.GetPedestal()[i] = 15000 + i % 50 - m * 135; pedestal_g2.GetPedestal()[i] = 14000 + i % 50 - m * 135; } v[m].Setup(gain_calib, pedestal_g0, pedestal_g1, pedestal_g2, 12.4); } x.Mode(DetectorMode::Conversion); auto start_time = std::chrono::system_clock::now(); for (int z = 0; z < ntries; z++) { for (int i = 0; i < nframes; i++) { for (int m = 0; m < nmodules; m++) { v[m].ConvertModule(output.data() + (i * nmodules + m) * RAW_MODULE_SIZE, input.data() + (i * nmodules + m) * RAW_MODULE_SIZE); } } } auto end_time = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end_time - start_time); logger.Info("Conversion performance: {:5d} us/module {:5.2f} GB/s", std::lround(elapsed.count() / ((double) (ntries * nframes * nmodules))), ntries * nframes * nmodules * RAW_MODULE_SIZE * sizeof(uint16_t) * 1000 * 1000/ ((double) elapsed.count() * 1024 * 1024 * 1024)); } int main () { Logger logger("JFCalibrationPerfTest"); test_pedestal(logger); logger.Info("Floating point conversion"); test_conversion(logger); }