// Copyright (2019-2024) Paul Scherrer Institute #include "CPUSpotFinder.h" template void FindSpots(StrongPixelSet& set, int big_column, int big_row, const SpotFindingSettings& settings, const int16_t* image) { uint64_t sum = 0; uint64_t sum2 = 0; uint64_t valid_count = 0; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { size_t coord = (big_row * N + y) * RAW_MODULE_COLS + big_column * N + x; if ((image[coord] != INT16_MIN) || (image[coord] != INT16_MAX)) { sum += image[coord]; sum2 += image[coord] * image[coord]; valid_count++; } } } int64_t variance = valid_count * sum2 - sum * sum; float threshold = variance * settings.signal_to_noise_threshold * settings.signal_to_noise_threshold; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { size_t coord = (big_row * N + y) * RAW_MODULE_COLS + big_column * N + x; bool strong_pixel = true; if ((settings.photon_count_threshold < 0) && (settings.signal_to_noise_threshold <= 0)) strong_pixel = false; if ((settings.photon_count_threshold >= 0) && (image[coord] < settings.photon_count_threshold)) { strong_pixel = false; } if (settings.signal_to_noise_threshold > 0) { int64_t in_minus_mean = image[coord] * valid_count - sum; if ((in_minus_mean * in_minus_mean <= threshold) || (in_minus_mean <= 0) || (valid_count < N * N / 2)) strong_pixel = false; } if (strong_pixel) set.AddStrongPixel(big_column * N + x, big_row * N + y, image[coord]); } } } void FindSpots(StrongPixelSet& set, const SpotFindingSettings& settings, const int16_t* image) { for (int i = 0; i < RAW_MODULE_LINES / 32; i++) { for (int j = 0; j < RAW_MODULE_COLS / 32; j++) FindSpots<32>(set, j, i, settings, image); } }