// Copyright (2019-2024) Paul Scherrer Institute #include "PixelMask.h" #include "RawToConvertedGeometry.h" #include "JFJochException.h" PixelMask::PixelMask(const DetectorSetup &detector) : nmodules(detector.GetModulesNum()), mask(detector.GetModulesNum() * RAW_MODULE_SIZE, 0) { } PixelMask::PixelMask(const DiffractionExperiment& experiment) : PixelMask(experiment.GetDetectorSetup()) {} void PixelMask::LoadDetectorBadPixelMask(const std::vector &input_mask, uint8_t bit) { if (input_mask.size() != mask.size()) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Input match doesn't fit the detector "); for (int i = 0; i < mask.size(); i++) { if (input_mask[i] != 0) mask[i] |= (1< PixelMask::GetMask(const DiffractionExperiment &experiment) { std::vector mask_out = mask; // apply edge mask for (int64_t module = 0; module < nmodules; module++) { for (int64_t line = 0; line < RAW_MODULE_LINES; line++) { for (int64_t col = 0; col < RAW_MODULE_COLS; col++) { int64_t pixel = module * RAW_MODULE_SIZE + line * RAW_MODULE_COLS + col; if (experiment.GetMaskModuleEdges()) { if ((line == 0) || (line == RAW_MODULE_LINES - 1) || (col == 0) || (col == RAW_MODULE_COLS - 1)) mask_out[pixel] |= (1 << 30); } if (experiment.GetMaskChipEdges()) { if ((col == 255) || (col == 256) || (col == 511) || (col == 512) || (col == 767) || (col == 768) || (line == 255) || (line== 256)) mask_out[pixel] |= (1 << 31); } } } } if (experiment.GetDetectorMode() == DetectorMode::Conversion) { std::vector tmp(experiment.GetPixelsNum(), 1); // nonfuctional areas (i.e. gaps) are filled with 1 RawToConvertedGeometry(experiment, tmp.data(), mask_out.data()); return tmp; } else return mask_out; } void PixelMask::LoadUserMask(const DiffractionExperiment &experiment, const std::vector &in_mask, uint8_t bit) { if (experiment.GetModulesNum() != nmodules) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Mismatch in module size"); if (in_mask.size() == nmodules * RAW_MODULE_SIZE) { LoadDetectorBadPixelMask(in_mask, bit); } else if (in_mask.size() == experiment.GetPixelsNum()) { std::vector raw_mask(nmodules * RAW_MODULE_SIZE); ConvertedToRawGeometry(experiment, raw_mask.data(), in_mask.data()); LoadDetectorBadPixelMask(in_mask, bit); } else throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Size of input user mask invalid"); }