Modifications in preparation to MAX IV experiment

This commit is contained in:
2024-01-27 21:23:56 +01:00
parent 2446643489
commit f5f86d9ab6
250 changed files with 9363 additions and 3022 deletions
+32 -23
View File
@@ -1,8 +1,23 @@
// Copyright (2019-2023) Paul Scherrer Institute
#include <bitset>
#include "StrongPixelSet.h"
#include "../common/RawToConvertedGeometry.h"
void FilterSpotsByResolution(const DiffractionExperiment& experiment,
const std::vector<DiffractionSpot> &input,
std::vector<DiffractionSpot> &output) {
std::multimap<double, DiffractionSpot> spots_map;
for (const auto &i: input) {
double d = i.GetResolution(experiment);
spots_map.insert(std::make_pair(-static_cast<float>(d), i));
}
for (auto &[x, spot]: spots_map)
output.push_back(spot);
if (experiment.GetMaxSpotCount() > 0)
output.resize(std::min<size_t>(output.size(), experiment.GetMaxSpotCount()));
}
StrongPixelSet::StrongPixelSet(const DiffractionExperiment &experiment)
: xpixel(experiment.GetXPixelsNum()),
@@ -91,26 +106,20 @@ void StrongPixelSet::ExtendSpot(DiffractionSpot &spot, std::unordered_map<uint32
}
void StrongPixelSet::FindSpots(const DiffractionExperiment &experiment, const SpotFindingSettings &settings,
std::vector<DiffractionSpot> &spots) {
std::multimap<double, DiffractionSpot> spots_map;
std::vector<DiffractionSpot> &spots, uint16_t module_number) {
while (!strong_pixel_map.empty()) {
auto iter = strong_pixel_map.begin();
DiffractionSpot spot = BuildSpot(iter);
spot.ConvertToImageCoordinates(experiment, module_number);
double d = spot.GetResolution(experiment);
if ((spot.PixelCount() <= settings.max_pix_per_spot)
&& (spot.PixelCount() >= settings.min_pix_per_spot)
&& ((settings.low_resolution_limit < 0) || (d <= settings.low_resolution_limit))
&& ((settings.high_resolution_limit < 0) || (d >= settings.high_resolution_limit)))
spots_map.insert(std::make_pair(-static_cast<float>(d), spot));
&& ((settings.low_resolution_limit <= 0) || (d <= settings.low_resolution_limit))
&& ((settings.high_resolution_limit <= 0) || (d >= settings.high_resolution_limit)))
spots.push_back(spot);
}
for (auto &[x, spot]: spots_map)
spots.push_back(spot);
if (experiment.GetMaxSpotCount() > 0)
spots.resize(std::min<size_t>(spots.size(), experiment.GetMaxSpotCount()));
}
size_t StrongPixelSet::Count() const {
@@ -126,9 +135,7 @@ size_t StrongPixelSet::Common(const StrongPixelSet &set) const {
return ret;
}
void StrongPixelSet::ReadFPGAOutput(const DiffractionExperiment& experiment,
const DeviceOutput &output,
uint16_t module) {
void StrongPixelSet::ReadFPGAOutput(const DeviceOutput &output) {
strong_pixel_count += output.spot_finding_result.strong_pixel_count;
// Too many strong pixels will kill performance in data processing, so protection is needed
@@ -138,13 +145,15 @@ void StrongPixelSet::ReadFPGAOutput(const DiffractionExperiment& experiment,
return;
auto out_ptr = (uint32_t *) output.spot_finding_result.strong_pixel;
for (int i = 0; i < RAW_MODULE_SIZE / (8 * sizeof(out_ptr[0])); i++) {
if (out_ptr[i]) {
for (int j = 0; j < 8 * sizeof(out_ptr[0]); j++) {
if (out_ptr[i] & (1 << j)) {
size_t npixel = i * 8 * sizeof(out_ptr[0])| j;
auto [col, line] = RawToConvertedCoordinate(experiment, module, npixel);
AddStrongPixel(col, line);
for (int line = 0; line < RAW_MODULE_LINES; line++) {
auto line_ptr = out_ptr + line * RAW_MODULE_COLS / (8 * sizeof(out_ptr[0]));
for (int i = 0; i < RAW_MODULE_COLS / (8 * sizeof(line_ptr[0])); i++) {
if (line_ptr[i]) {
for (int j = 0; j < 8 * sizeof(line_ptr[0]); j++) {
if (line_ptr[i] & (1 << j)) {
size_t npixel = i * 8 * sizeof(line_ptr[0]) | j;
AddStrongPixel(npixel, line, output.pixels[line * RAW_MODULE_COLS + i * sizeof(line_ptr[0]) + j]);
}
}
}
}