PixelMask: Don't cache statistics, only calc when needed + add extra categories
This commit is contained in:
+24
-31
@@ -17,19 +17,7 @@ PixelMask::PixelMask(const DiffractionExperiment &experiment)
|
||||
CalcEdgePixels(experiment);
|
||||
}
|
||||
|
||||
PixelMask::PixelMask(const std::vector<uint32_t> &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<uint32_t> &in_mask) : mask(in_mask) {}
|
||||
|
||||
uint32_t PixelMask::LoadMask(const std::vector<uint32_t> &input_mask, uint8_t bit) {
|
||||
uint32_t ret = 0;
|
||||
@@ -130,11 +118,8 @@ std::vector<uint32_t> 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<uint32_t> input_mask(experiment.GetModulesNum() * RAW_MODULE_SIZE, 0);
|
||||
std::vector<uint32_t> input_mask_rms(experiment.GetModulesNum() * RAW_MODULE_SIZE, 0);
|
||||
@@ -167,27 +152,44 @@ void PixelMask::LoadDetectorBadPixelMask(const DiffractionExperiment &experiment
|
||||
|
||||
std::vector<uint32_t> 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<uint32_t> 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<uint32_t> &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<uint32_t> 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<uint32_t> &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<uint32_t> &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<uint32_t> &input_mask) {
|
||||
|
||||
if (input_mask[i] != 0) {
|
||||
mask[i] |= (1 << NoisyPixelBit);
|
||||
++statistics.noisy_pixel;
|
||||
} else {
|
||||
mask[i] &= ~(1 << NoisyPixelBit);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user