Combines the stills reader and module work (stills-readers, stills-modgeom, stills-euxfel) onto rc178 with the owner's decisions for this release: - Inputs are files, never a directory; several files of one format are one dataset (the multi-input CLI of the previous commit), so every reader takes an explicit list: JFJochXFELReader::ReadFiles, ReadCXI, ReadPanelTable and JFJochXTCReader::ReadFiles take std::vector<std::string>; ListFiles and xtc::CollectStreams are gone, CanRead* accept a regular file only. - One HDF5 frame reader (JFJochCrystFELReader -> JFJochXFELReader) parameterised by what the file holds: per-shot groups or a 3D stack, a /metadata panel table (posx/posy/angle, pixel size, nominal camera length, pixel mask: as SACLA writes), a Cheetah CXI single panel (square frame; a tiled slab is refused with a message). At most 8 files open; every file checked against the first. Signed 32-bit decode, per-frame 3D masks, panels at their own coffset (from the EuXFEL work). - Frames stored one chunk each are read the way the NXmx reader reads its images: only the chunk's place is asked of HDF5 under its lock (H5Dget_chunk_info_by_coord), the bytes are read through HDF5ImageSource::RawFile (positional, no lock) and decoded outside it - deflate(+shuffle) by zlib, bitshuffle/LZ4 (and zstd, plain LZ4) by CompressedImage's decoders. Bitshuffle/LZ4 used to go through HDF5's filter under the global lock, one frame at a time. - LCLS-I XTC (Rayonix): wavelength from the beam record, pixel size from the Rayonix model and binning, only --detector-distance needed; damaged/compressed frames skipped, a truncated last event dropped; std::ifstream, no POSIX calls: builds with MSVC. No DIALS .expt support at all. - CrystFEL .geom: module geometry only (panel ranges, fs/ss, corners, pixel size, coffset, data path) and optionally the camera length; everything else is ignored with a note in the log. - --mask-good / --mask-bad <file>:<dataset>: a mask array in another HDF5 file, in the frames' stored layout (what a .geom's mask_file used to give). - Gain measured on the background for panel-table and CXI input that states none (--gain overrides). - Detector modules from explicit geometry only (DetectorModules: the reader's panels, an NXmx file with one NXdetector_module per module, or --module-geometry); never from the image. Spots and predictions are mapped through the modules, the image is not re-assembled. - Module refinement in the stills bundle adjustment (Ceres; per-module shift and in-plane turn, gauge on mean shift/turn/scale and on the two tilt-like patterns when the tilt is refined; adopted only where it predicts held-out frames better). Applied for a foreign multi-panel detector (panel table, .geom panels); for a JUNGFRAU measured and reported only. Written to <prefix>_modules.h5 (NXmx NXdetector_module groups), read back with --module-geometry. - A panel-table file's camera length is nominal: with a reference cell it is refined from the cell. - Broker and writer output unchanged: masters keep the single NXdetector_module group, the start message carries no module list. Tests: [CrystFELGeometry], JFJochXFELReader_*, JFJochXTCReader, [JFJochMultiReader], [CellPopulation], SaturationCeiling_*, [DetectorModules], RefineGlobalGeometry_ModulePlacement, [reindex], Sublattice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
76 lines
3.5 KiB
C++
76 lines
3.5 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "ModuleShift.h"
|
|
|
|
class DetectorGeometry;
|
|
|
|
// One detector module: where its pixels are in the image rugnux reads, and where they really are on the
|
|
// detector plane. The plane is the one DiffractionGeometry describes (beam centre, distance, tilt), in its
|
|
// pixel units, so a module placed exactly as the image has it maps every pixel onto itself.
|
|
//
|
|
// Image pixel (x, y) of the module, x0 <= x < x0 + width, y0 <= y < y0 + height, lies on the plane at
|
|
// (ox, oy) + (x - x0) (fx, fy) + (y - y0) (sx, sy)
|
|
// - the NXdetector_module description (data_origin, data_size, module_offset, fast_pixel_direction,
|
|
// slow_pixel_direction) taken in the plane. A pixel's centre is at its index, as everywhere in the image.
|
|
struct DetectorModule {
|
|
int64_t x0 = 0, y0 = 0, width = 0, height = 0;
|
|
double ox = 0, oy = 0;
|
|
double fx = 1, fy = 0;
|
|
double sx = 0, sy = 1;
|
|
|
|
// The module where the image has it: every pixel maps onto itself.
|
|
static DetectorModule AsImaged(int64_t x0, int64_t y0, int64_t width, int64_t height);
|
|
|
|
[[nodiscard]] bool ContainsImagePixel(double x, double y) const;
|
|
[[nodiscard]] std::pair<double, double> ImageToPlane(double x, double y) const;
|
|
[[nodiscard]] std::pair<double, double> PlaneToImage(double px, double py) const;
|
|
// Plane position of the module's centre.
|
|
[[nodiscard]] std::pair<double, double> PlaneCentre() const;
|
|
// Moved by a refinement's rigid step, which is expressed on the plane (ModuleShift: turn about
|
|
// (x0, y0) of the shift, then shift).
|
|
void Apply(const ModuleShift &shift);
|
|
};
|
|
|
|
// The modules of one detector. Empty means the image is one flat detector: every mapping is the identity.
|
|
class DetectorModules {
|
|
std::vector<DetectorModule> modules;
|
|
public:
|
|
DetectorModules() = default;
|
|
explicit DetectorModules(std::vector<DetectorModule> modules);
|
|
|
|
[[nodiscard]] bool empty() const;
|
|
[[nodiscard]] size_t size() const;
|
|
[[nodiscard]] const DetectorModule &operator[](size_t i) const;
|
|
[[nodiscard]] const std::vector<DetectorModule> &Get() const;
|
|
|
|
// True where some module is placed other than as imaged.
|
|
[[nodiscard]] bool Moved() const;
|
|
|
|
// Module of an image pixel, or -1 (a gap, or outside every module).
|
|
[[nodiscard]] int64_t ModuleOfImagePixel(double x, double y) const;
|
|
// Module whose placed footprint holds a plane point, or -1.
|
|
[[nodiscard]] int64_t ModuleOfPlanePoint(double px, double py) const;
|
|
|
|
// Image -> plane; a point on no module is left as it is.
|
|
[[nodiscard]] std::pair<double, double> ImageToPlane(double x, double y) const;
|
|
// Plane -> image; a point on no placed module is left as it is.
|
|
[[nodiscard]] std::pair<double, double> PlaneToImage(double px, double py) const;
|
|
|
|
// Each module moved by the shift whose centre is nearest its own plane centre (and within it).
|
|
void Apply(const std::vector<ModuleShift> &shifts);
|
|
// The modules as refinement starting points: their plane centres, no move.
|
|
[[nodiscard]] std::vector<ModuleShift> Centres() const;
|
|
};
|
|
|
|
// The modules of a modular (JUNGFRAU) detector where its assembled image puts them: one box per module,
|
|
// CONVERTED_MODULE_COLS x CONVERTED_MODULE_LINES turned the way the geometry turns it, placed as imaged.
|
|
// Empty for a detector of one module.
|
|
DetectorModules ModulesAsImaged(const DetectorGeometry &geom);
|