From 44cfbdd8b4535687e265e9967ed877d5e3a99ca4 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 5 Nov 2025 14:56:48 +0100 Subject: [PATCH] PixelMask: Don't cache statistics, only calc when needed + add extra categories --- common/PixelMask.cpp | 55 +++++++++++++++++++------------------------- common/PixelMask.h | 4 +++- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/common/PixelMask.cpp b/common/PixelMask.cpp index 4bf317ac..42e8e9ee 100644 --- a/common/PixelMask.cpp +++ b/common/PixelMask.cpp @@ -17,19 +17,7 @@ PixelMask::PixelMask(const DiffractionExperiment &experiment) CalcEdgePixels(experiment); } -PixelMask::PixelMask(const std::vector &in_mask) : mask(in_mask) { - statistics.user_mask = 0; - statistics.error_pixel = 0; - statistics.noisy_pixel = 0; - for (unsigned int i : mask) { - if (i & (1 << UserMaskedPixelBit)) - statistics.user_mask++; - if (i & (1 << ErrorPixelBit)) - statistics.error_pixel++; - if (i & (1 << NoisyPixelBit)) - statistics.noisy_pixel++; - } -} +PixelMask::PixelMask(const std::vector &in_mask) : mask(in_mask) {} uint32_t PixelMask::LoadMask(const std::vector &input_mask, uint8_t bit) { uint32_t ret = 0; @@ -130,11 +118,8 @@ std::vector PixelMask::GetUserMask(const DiffractionExperiment& experi void PixelMask::LoadDetectorBadPixelMask(const DiffractionExperiment &experiment, const JFCalibration *calib) { - if (experiment.GetDetectorType() == DetectorType::DECTRIS) { - statistics.error_pixel = 0; - statistics.noisy_pixel = 0; + if (experiment.GetDetectorType() == DetectorType::DECTRIS) return; - } std::vector input_mask(experiment.GetModulesNum() * RAW_MODULE_SIZE, 0); std::vector input_mask_rms(experiment.GetModulesNum() * RAW_MODULE_SIZE, 0); @@ -167,27 +152,44 @@ void PixelMask::LoadDetectorBadPixelMask(const DiffractionExperiment &experiment std::vector input_mask_conv(experiment.GetPixelsNumConv(), 0); RawToConvertedGeometry(experiment, input_mask_conv.data(), input_mask.data()); - statistics.error_pixel = LoadMask(input_mask_conv, ErrorPixelBit); std::vector input_mask_rms_conv(experiment.GetPixelsNumConv(), 0); RawToConvertedGeometry(experiment, input_mask_rms_conv.data(), input_mask_rms.data()); - statistics.noisy_pixel = LoadMask(input_mask_rms_conv, NoisyPixelBit); CalcEdgePixels(experiment); } PixelMaskStatistics PixelMask::GetStatistics() const { - return statistics; + PixelMaskStatistics ret{}; + for (const auto &i: mask) { + + if (mask[i] & (1 << ModuleGapPixelBit)) + ret.module_gap_pixel++; + else { + if (mask[i] != 0) + ret.total_masked++; + if (mask[i] & (1 << ErrorPixelBit)) + ret.error_pixel++; + if (mask[i] & (1 << NoisyPixelBit)) + ret.noisy_pixel++; + if (mask[i] & (1 << UserMaskedPixelBit)) + ret.user_mask++; + if (mask[i] & ((1 << ChipGapPixelBit) | (1 << ModuleEdgePixelBit))) + ret.chip_gap_pixel++; + } + } + + return ret; } void PixelMask::LoadUserMask(const DiffractionExperiment& experiment, const std::vector &in_mask) { if (in_mask.size() == mask.size()) { - statistics.user_mask = LoadMask(in_mask, UserMaskedPixelBit); + LoadMask(in_mask, UserMaskedPixelBit); } else if (in_mask.size() == experiment.GetModulesNum() * RAW_MODULE_SIZE) { std::vector tmp(experiment.GetPixelsNumConv(), 0); RawToConvertedGeometry(experiment, tmp.data(), in_mask. data()); - statistics.user_mask = LoadMask(tmp, UserMaskedPixelBit); + LoadMask(tmp, UserMaskedPixelBit); } else throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Size of input user mask invalid"); @@ -201,22 +203,16 @@ void PixelMask::LoadDECTRISBadPixelMask(const std::vector &input_mask) uint32_t user_bitmask = (1 << UserMaskedPixelBit); uint32_t bad_pixel_bitmask = ~((1 << UserMaskedPixelBit) | (1 << ModuleGapPixelBit) | (1 << ChipGapPixelBit)); - statistics.user_mask = 0; - statistics.error_pixel = 0; - statistics.noisy_pixel = 0; - for (int i = 0; i < mask.size(); i++) { if ((input_mask[i] & (1 << ModuleGapPixelBit)) != 0) { mask[i] = (1 << ModuleGapPixelBit); } else { mask[i] = 0; if (input_mask[i] & bad_pixel_bitmask) { - ++statistics.error_pixel; mask[i] |= (1 << ErrorPixelBit); } // User and chip gap are just transferred if ((input_mask[i] & (1 << UserMaskedPixelBit)) != 0) { - ++statistics.user_mask; mask[i] |= (1 << UserMaskedPixelBit); } if ((input_mask[i] & (1 << ChipGapPixelBit)) != 0) { @@ -231,8 +227,6 @@ void PixelMask::LoadDarkBadPixelMask(const std::vector &input_mask) { throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Input match doesn't fit the detector "); - statistics.noisy_pixel = 0; - for (int i = 0; i < mask.size(); i++) { // Ignore module gap (doesn't matter) or bad pixels if ((mask[i] & (1 << ModuleGapPixelBit | 1 << ErrorPixelBit)) != 0) @@ -240,7 +234,6 @@ void PixelMask::LoadDarkBadPixelMask(const std::vector &input_mask) { if (input_mask[i] != 0) { mask[i] |= (1 << NoisyPixelBit); - ++statistics.noisy_pixel; } else { mask[i] &= ~(1 << NoisyPixelBit); } diff --git a/common/PixelMask.h b/common/PixelMask.h index 4e2cb485..cc0e3001 100644 --- a/common/PixelMask.h +++ b/common/PixelMask.h @@ -12,12 +12,14 @@ struct PixelMaskStatistics { uint32_t user_mask; uint32_t noisy_pixel; uint32_t error_pixel; + uint32_t chip_gap_pixel; + uint32_t total_masked; + uint32_t module_gap_pixel; }; class PixelMask { std::vector mask; uint32_t LoadMask(const std::vector& mask, uint8_t bit); - PixelMaskStatistics statistics{0,0,0}; public: // NXmx bits constexpr static const uint8_t ModuleGapPixelBit = 0;