Every dense map that needs geometry now evaluates each image pixel at its place on the detector plane (DetectorModules), so it is right for a stacked panel layout and picks up refined module placements: - AzimuthalIntegrationMapping: bins, resolution, solid-angle/polarisation corrections built per pixel through the table; a pixel on no panel is left as a masked one. The geometry cache key now includes the panel table, so a mapping built after the stills module placement is rebuilt rather than served from the cache. ResolutionMaskBits follows (it is a lookup). - ROIMap / ExportROIMap: azimuthal ROIs on the plane (box and circle ROIs stay in image pixels). - ROIIntegration CPU+GPU: the weighted sums are taken per ROI and panel in image pixels and placed on the plane at the end (exact; the affine commutes with a weighted mean). - HotPixelFinder: ring/sector keys and the zeta of the persistence rule on the plane. - Background beam-centre walk CPU+GPU: pixels binned at their plane position; host and device share BackgroundPlanePoint so they stay bit-identical. New common/PanelRows.h: ForEachPixelInRows, ForEachPixel cut to a band of rows in index order, for the row-parallel builders. An empty table takes the old arithmetic in the old order: rotation sets and every single-panel input are unchanged. [PanelLayout] AzintMapping and ResolutionMask enabled (+ azimuthal ROI map and ROI centroid on the plane); new BeamCenterFromBackground_BinsOnThePlane and ROIIntegrationGPU_MatchesCPU_Panels. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
66 lines
2.4 KiB
C++
66 lines
2.4 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "ROIIntegration.h"
|
|
#include "../../common/DiffractionExperiment.h"
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
ROIIntegration::ROIIntegration(const DiffractionExperiment &experiment)
|
|
: roi_map(experiment.ExportROIMap()),
|
|
width(experiment.GetXPixelsNumConv()),
|
|
npixel(roi_map.size()),
|
|
roi_count(experiment.ROI().size()),
|
|
roi_name(roi_count),
|
|
roi_sum(roi_count),
|
|
roi_sum2(roi_count),
|
|
roi_pixels(roi_count),
|
|
roi_x_weighted(roi_count),
|
|
roi_y_weighted(roi_count),
|
|
roi_max(roi_count),
|
|
modules(experiment.GetModules()),
|
|
panel_slots(std::max<size_t>(modules.size(), 1)),
|
|
roi_panel_v(roi_count * panel_slots),
|
|
roi_panel_x(roi_count * panel_slots),
|
|
roi_panel_y(roi_count * panel_slots) {
|
|
for (const auto &[name, id] : experiment.ROI().GetROINameMap())
|
|
roi_name[id] = name;
|
|
}
|
|
|
|
void ROIIntegration::PlaceWeighted() {
|
|
for (uint16_t r = 0; r < roi_count; r++) {
|
|
if (modules.empty()) {
|
|
roi_x_weighted[r] = roi_panel_x[r];
|
|
roi_y_weighted[r] = roi_panel_y[r];
|
|
continue;
|
|
}
|
|
// Sum over panels of v * (o + (x - x0) f + (y - y0) s).
|
|
double x = 0, y = 0;
|
|
for (size_t p = 0; p < modules.size(); p++) {
|
|
const auto &m = modules[p];
|
|
const size_t k = r * panel_slots + p;
|
|
const auto v = static_cast<double>(roi_panel_v[k]);
|
|
const auto u = static_cast<double>(roi_panel_x[k] - m.x0 * roi_panel_v[k]);
|
|
const auto w = static_cast<double>(roi_panel_y[k] - m.y0 * roi_panel_v[k]);
|
|
x += m.ox * v + m.fx * u + m.sx * w;
|
|
y += m.oy * v + m.fy * u + m.sy * w;
|
|
}
|
|
roi_x_weighted[r] = std::llround(x);
|
|
roi_y_weighted[r] = std::llround(y);
|
|
}
|
|
}
|
|
|
|
void ROIIntegration::Export(std::map<std::string, ROIMessage> &out) const {
|
|
for (uint16_t r = 0; r < roi_count; r++)
|
|
out[roi_name[r]] = ROIMessage{
|
|
.sum = roi_sum[r],
|
|
.sum_square = roi_sum2[r],
|
|
.max_count = roi_max[r],
|
|
.pixels = roi_pixels[r],
|
|
.pixels_masked = 0,
|
|
.x_weighted = roi_x_weighted[r],
|
|
.y_weighted = roi_y_weighted[r],
|
|
};
|
|
}
|