Files
Jungfraujoch/common/DiffractionSpot.h
T
leonarski_fandClaude Opus 5.5 fd798cd665 Panel layout stage 3: per-panel spot finding (CPU+GPU, CCL) and raster algorithms on the plane raster
Spot finding works panel by panel, as the FPGA path does per JUNGFRAU module. PanelBoxes (common/) gives
one box per DetectorModule; an empty table gives one box, the whole image, so every clamp reduces to the
old image bounds in the same evaluation order (rotation sets, EIGER, CCDs, our JUNGFRAU unchanged).
- ImageSpotFinder::SetPanels: the CPU local-box pass (dense, count-threshold and the DetectAt/candidate
  path of the adaptive finder) slides its windows inside each panel box; host CCL labels panel by panel;
  pixels on no panel are folded into the resolution mask.
- GPU: analyze_pixel tiles each panel (warps numbered panel after panel), analyze_candidates and
  union_neighbours clip to the pixel's panel, the device spot carries its panel; the GPU list is put in
  panel order so it equals the host's.
- DiffractionSpot carries its panel; SpotAnalyze maps by ImageToPlane(panel, ...) (d_A on the plane).
- ImagePreprocessorBuffer::GatherTiles (CPU+GPU) clips each square to the panel of its centre.
- MXAnalysisWithoutFPGA and the pre-scan workers hand the module table to finders and buffers.

Raster algorithms: new common/AssembleToPlane.h (PlaneRasterOf, AssembleToPlane nearest-pixel gather with
gaps, GatherFromPlane back to stored pixels; empty table = copy). With panels, ShadowFinder::GetMask runs on
the projection assembled to the plane raster and gathers the mask back per stored pixel (CPU route);
FindBeamCenterFFT scores the assembled projection and reports plane coordinates; the detector diagnostic
JPEG shows the assembled plane. Without panels all three take their old path.

Harness: PanelLayout_SpotsNeverCrossPanels enabled (count threshold and SNR on the edge scene), new
PanelLayout_SpotFinderParity (CPU vs GPU, local box and adaptive, on the stacked layout),
PanelLayout_AssembleToPlane, PanelLayout_ShadowFinder, PanelLayout_BeamCenterFFT,
PanelLayout_DetectorDiagnostic (stacked vs assembled image cut to the raster).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
2026-10-21 10:29:07 +02:00

43 lines
2.1 KiB
C++

// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "Coord.h"
#include "DiffractionExperiment.h"
#include "DiffractionGeometry.h"
#include "SpotToSave.h"
// Definition of Bragg spot
class DiffractionSpot {
// Photon-weighted position sums, sum(col * photons) and sum(line * photons). Integers, not a
// centroid: column, line and the per-pixel count are all integral, so the sums are exact and
// every implementation that builds them - host, GPU, whatever the build lets the compiler
// contract - arrives at the same bits. In float they did not: gcc fuses the multiply-add under
// -march=x86-64-v3 and not at the baseline, which left the last bit of the centroid a property
// of the build flags rather than of the data.
int64_t x = 0;
int64_t y = 0;
int64_t pixel_count = 0;
int64_t photons = 0; // total photon count
int64_t max_photons = INT64_MIN; // maximum number of counts per pixel in the spot
int64_t panel = -1; // the panel (DetectorModules index) the spot was found on; -1 = no panel table
public:
DiffractionSpot() = default;
DiffractionSpot(uint32_t col, uint32_t line, int64_t photons);
// From already-summed quantities, i.e. the members as AddPixel leaves them, NOT a centroid.
// Used by the GPU spot extractor, which computes those sums on the device.
DiffractionSpot(int64_t x_sum, int64_t y_sum, int64_t pixel_count, int64_t photons, int64_t max_photons,
int64_t panel = -1);
DiffractionSpot& operator+=(const DiffractionSpot& spot);
int64_t PixelCount() const;
int64_t Count() const;
int64_t MaxCount() const;
Coord RawCoord() const;
int64_t Panel() const;
void Panel(int64_t panel);
void ConvertToImageCoordinates(const DiffractionExperiment& experiment, uint16_t module_number);
std::optional<SpotToSave> Export(const DiffractionGeometry &geometry, int64_t image_num = 0) const;
void AddPixel(uint32_t col, uint32_t line, int64_t photons);
};