Build Packages / XDS test (JFJoch plugin) (push) Successful in 11m4s
Build Packages / Unit tests (push) Skipped
Build Packages / build:windows:nocuda (push) Successful in 17m46s
Build Packages / build:windows:cuda (push) Successful in 20m20s
Build Packages / build:viewer-tgz:cpu (push) Successful in 15m56s
Build Packages / build:viewer-tgz:cuda (push) Successful in 17m57s
Build Packages / build:rugnux-tgz (x86_64) (push) Successful in 14m10s
Build Packages / build:rugnux:windows (push) Successful in 11m12s
Build Packages / build:rugnux:aarch64 (cross) (push) Successful in 7m14s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 22m13s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 19m17s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 21m21s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 17m26s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 23m56s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 20m48s
Build Packages / build:rpm (rocky8) (push) Successful in 23m43s
Build Packages / build:rpm (rocky9) (push) Successful in 20m38s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 24m57s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 20m58s
Build Packages / XDS test (durin plugin) (push) Successful in 10m43s
Build Packages / Generate python client (push) Successful in 47s
Build Packages / Build documentation (push) Successful in 1m5s
Build Packages / Create release (push) Skipped
Build Packages / XDS test (neggia plugin) (push) Successful in 8m57s
Build Packages / DIALS test (push) Successful in 18m40s
* `rugnux --model` reports CC(model, data) - the correlation of the merged intensities with the placed, scaled model - by resolution shell, on the same shells as CC1/2, with the reflection count and a significance for each. * `rugnux --model` fits the model's scale, anisotropic B and bulk-solvent parameters on the working reflections only, so the R-free it reports is measured against a model no free reflection helped scale. * The bulk-solvent parameters of `rugnux --model` are searched over their physically meaningful range instead of being fitted without bounds, so a model is never scaled with a solvent term that has silently switched itself off. * The rigid-body placement of `rugnux --model` uses the same bounded bulk solvent as the reported fit, so a model is no longer placed against a target carrying a solvent term with no physical meaning. * `rugnux --model` puts the model into the data's own description of the lattice before placing it, so a model whose cell is written on other axes - I-centred where the run indexed C-centred, a different unique axis, a permuted orthorhombic cell - is placed rather than scored where it was read; `MODEL_CHANGE_OF_BASIS=` and `MODEL_SETTING_AS_READ=` report it when it happens. * The rugnux results report opens with a summary - `VERDICT=` (`OK`, `WARNINGS`, `UNUSABLE`, `FAILED`), `VERDICT_TEXT=`, `PATHOLOGY_FLAGS=` with one closed-vocabulary code per condition that warned, and the `WARNING:` lines, which used to close the file - and the sections after it are renumbered 1-5 with no gaps. * `rugnux --developer` writes the full results report - the pipeline-internal keys and the long explanations the default report now leaves out - and `--finalist-ledger` adds the evidence for every space group the search considered, not only the one it adopted. * The results report warns when the merged data carry no usable signal and when too little of reciprocal space was measured inside the fitted resolution, and omits `FITTED_RESOLUTION` where the CC1/2 curve it is fitted on never falls off. * rugnux detects translational pseudo-symmetry and reports it under the `PSEUDO_TRANSLATION` flag as `TNCS_DETECTED=` and the `TNCS_*` keys - a translation the merged data are exactly invariant under is reported as `UNDECLARED_LATTICE_TRANSLATION=` under `LATTICE_TRANSLATION` instead - and a detected pseudo-translation can no longer buy a false screw axis in the space-group search or hide a twin from the L-test (`L_TEST_VS_TNCS=`). * The space-group search determines glide planes from zonal systematic absences, so a non-Sohncke space group such as P 2_1/c or Pbca is named where the run previously stopped at its Sohncke subgroup; `SOHNCKE_SPACE_GROUP=` carries the best Sohncke group beside it on every run that searched, and a centre of symmetry is never claimed. * Where the cell metric carries more rotational symmetry than the Bravais class the indexer named, the extra rotations are put to the intensities and the space-group search is asked again on the metric's own cell - adopted only where the intensities confirm the higher symmetry - so a lattice that is nearly but not exactly hexagonal, or whose reduction landed in a sub-cell, still reaches its true point group. * Systematic-absence calls rest on the evidence rather than on counts: a screw axis whose absent class the data show extinct is no longer refused because a handful of reflections in it read as present, and `SPACE_GROUP_ALTERNATIVES=` no longer drops a candidate that differs only on a zone the sweep never measured. * A reference correlation measured on too few reflections is refused instead of scored zero, so a run given a reference MTZ is no longer reindexed on an operator that mapped almost everything outside the reference's coverage. * A frame counts as indexed from 6 spots on its lattice rather than 9, so a weakly diffracting crystal whose frames cannot carry 9 is no longer refused the lattice it fits; `--min-indexed-spots` overrides it. * `-C` accepts a known cell in any equivalent description - conventional or primitive, centred or not - instead of only the reduced primitive form, so a centred cell given the way it is published no longer makes the run report that it found no lattice. * Each reflection is corrected for the sensor's quantum efficiency at the angle it meets the detector (attenuation lengths from the NIST tables, which also fixes the spot-width parallax term on CdTe) and for the attenuation of the flight path between the sample and its pixel; `--flight-path air|helium|vacuum` declares the medium - default air, since no file states it - and the report says what was assumed and what it was worth. The unmerged MTZ records the factors in new `QE` and `FLIGHT` columns beside `LP`, so raw counts are `I / LP * QE * FLIGHT`, and `_process.h5` in new optional `qe` and `flight` datasets. * Rotation geometry post-refinement fits the crystal and the detector at once, against the observed spot positions and the observed rocking angles together, so the refined distance depends far less on how wrong the file's distance was. * A coarsely sliced sweep integrates correctly: partials are joined into one rocking event by angle rather than by frame count, so two crossings of the Ewald sphere are no longer summed into one full, and at 0.5 degrees per image or coarser the per-frame geometry refinement accepts a spot whose miss the exposure's own rotation accounts for. * `rugnux --mode scale` reports the detector tilt and direct beam of the geometry it re-scaled at, instead of zeros that read as a flat detector, and no longer warns that no image was indexed on a run whose lattice came from its input file. * Every rotation run that determined a space group and merged reports what the mounting cost: `SPINDLE_LOST_UNIQUE_FRACTION=` is the fraction (0-1) of unique reflections the mounting made unmeasurable under the measured point group, also written to the master as `/entry/MX/spindleLostUniqueFraction` and what the mounting warning fires on; `SPINDLE_SYMMETRY_AXIS_ANGLE_DEG=` / `SPINDLE_SYMMETRY_AXIS_ORDER=` describe the mounting in the `--developer` report. * Stills and grid scans carry a per-image `spindle_blind_fraction` - how much of a rotation sweep's blind cone this orientation would make unrecoverable, 0.5 and above calling for a second orientation - through the CBOR stream, HDF5 (`/entry/MX/spindleBlindFraction`), the plot and scan-result APIs, and the viewer and frontend plots; an absent value means the frame could not be assessed and is not a 0. * The results report's `REPORT_VERSION` is 7. Reviewed-on: #77 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
190 lines
14 KiB
C++
190 lines
14 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <optional>
|
|
|
|
// Spot-intensity extraction method used by the Bragg integration engine. ProfileGaussian (default)
|
|
// profile-fits with a measured-width Gaussian (Kabsch-style) - more accurate intensities than the
|
|
// classical uniform BoxSum; validated on anomalous data (stronger S/Cl peaks vs box-sum). BoxSum is
|
|
// the simpler, faster fallback. ProfileEmpirical learns the profile per resolution shell from strong
|
|
// spots - see docs/CPU_DATA_ANALYSIS_INTEGRATION.md (Bragg integration).
|
|
enum class IntegratorMode { BoxSum, ProfileGaussian, ProfileEmpirical };
|
|
|
|
// What the integrator does about a signal region shared with a neighbouring reflection. Off is the
|
|
// historical behaviour: a neighbour's signal is kept out of this reflection's BACKGROUND ring, but
|
|
// nothing keeps it out of the reflection's own SIGNAL region, so on a dense pattern a crowded
|
|
// reflection reads high. Reject is XDS's MINPK (Kabsch, Acta Cryst D66, 133-144 (2010)) - drop the
|
|
// reflection when too little of its expected profile is cleanly its own. Exclude - the default -
|
|
// drops only the shared PIXELS from the fit; a profile fit is the amplitude of a normalised profile,
|
|
// so leaving pixels out renormalises it by construction and the reflection is kept unbiased rather
|
|
// than discarded. A box sum has no profile to renormalise with, so Exclude does nothing there; only
|
|
// Reject acts on it.
|
|
enum class OverlapMode { Off, Reject, Exclude };
|
|
|
|
// What the diffracted beam flies through between the sample and the detector. Air is what a beamline
|
|
// has unless it was built not to have one; helium and vacuum are what long-wavelength stations use,
|
|
// because air absorbs unusably at low energy. It is an explicit choice, not something detected: no
|
|
// field of the NXmx application definition, and no field of any master file rugnux reads, describes
|
|
// the medium in the flight path - see sensor_absorption::FlightPathAttenuation.
|
|
enum class FlightPathMedium { Air, Helium, Vacuum };
|
|
|
|
// The hkl half-width the broker bootstraps when a config carries no bragg_integration block. Matches
|
|
// the max_hkl default in broker/jfjoch_api.yaml, so an omitting client and an omitting config agree.
|
|
constexpr int BRAGG_ONLINE_DEFAULT_MAX_HKL = 100;
|
|
|
|
class BraggIntegrationSettings {
|
|
IntegratorMode integrator_mode = IntegratorMode::ProfileGaussian;
|
|
float r_1 = 4;
|
|
float r_2 = 6;
|
|
// The background ring's precision is set by how many pixels it averages, not by how big the
|
|
// reflection is: the ring mean's error enters the intensity n_inner times over, so var(b)/n_B is
|
|
// a first-order term in sigma. At r3 = 10 the ring holds ~200 px against the r1 disk's ~50, and
|
|
// widening it to 13 roughly doubles that for no cost in signal - the disk is untouched, and the
|
|
// extra pixels sit further from the reflection, not closer.
|
|
float r_3 = 13;
|
|
// How many times the beam's radial streak to push the r2..r3 background ring out by, per
|
|
// reflection. A bandwidth streaks a spot radially by bw_sigma*Rpx, and against a fixed pixel ring
|
|
// that puts the background annulus on the reflection's own tails at high resolution, where it
|
|
// measures signal as background. The ring's radial semi-axes become r2 + this*bw_sigma*Rpx and
|
|
// r3 + this*bw_sigma*Rpx, the tangential ones stay r2 and r3, and the r1 signal disk stays a
|
|
// circle (growing it trips the all-or-nothing n_inner_valid gate). 0 reproduces the fixed
|
|
// circular stencil exactly, and so does any monochromatic beam, where the streak is zero.
|
|
float stencil_k_sigma = 0.0f;
|
|
// Integration/prediction resolution limit. Unset means "as far as the detector reaches", resolved
|
|
// from the geometry where it is used. The predictor independently rejects any reflection that misses
|
|
// the detector, so this is a bound on how far the lattice walk goes rather than a second opinion on
|
|
// what is measurable - a fixed default simply truncated every experiment whose detector reached
|
|
// past it.
|
|
std::optional<float> d_min_limit_A;
|
|
std::optional<float> fixed_profile_radius;
|
|
// Diagnostic: the rocking width the PREDICTION window is opened to, in place of the per-image
|
|
// sigma_M. Prediction and partiality use one number today, so a sigma_M that moves takes the
|
|
// integrated reflection population with it; pinning this holds the population still while the
|
|
// partiality keeps using the measured sigma_M, which separates the two effects.
|
|
std::optional<float> forced_prediction_mosaicity_deg;
|
|
float minimum_sigma_in_regards_to_i = 0.02;
|
|
// The r2..r3 background ring is estimated with ONE of two robust means, never both: a high-side
|
|
// sigma-clip (bkg_clip_nsigma, the default) or a symmetric trimmed mean (bkg_trim_fraction). Setting
|
|
// either through its setter clears the other, so whichever was asked for last is the one in force;
|
|
// with both at 0 the ring is a plain mean.
|
|
//
|
|
// Symmetric trimmed-mean fraction: drop the lowest and highest this fraction of ring pixels before
|
|
// averaging. Robust to the high-side contamination (neighbour-spot wings, tails, zingers) that
|
|
// biases a plain ring mean up, but a symmetric trim is NOT a consistent estimator of the mean of a
|
|
// right-skewed (Poisson) sample - it sits ~0.1 ct/px low at every level, which with ~50 ring pixels
|
|
// adds ~5 counts to every partial. Kept reachable (rugnux --background-trim) for back compatibility;
|
|
// 0.10 was the shipped value.
|
|
float bkg_trim_fraction = 0.0f;
|
|
// High-side-only sigma clip: reject ring pixels above mean + this many sqrt(mean). Rejects the same
|
|
// contamination as the trim - measurably better, in fact - without cutting the low side, so it does
|
|
// not carry the trim's skew bias. Measured empty-aperture pedestal, counts: plain mean -0.03..-0.20,
|
|
// 10% symmetric trim +5.05..+6.34, 4 sigma clip +0.02..+0.54. Whatever is set here is what the
|
|
// engine applies (rugnux --background-clip); the front end picks the default, and rugnux lowers it
|
|
// to 3 sigma for broadband (non-zero bandwidth) data, where longer spots leak further into the ring.
|
|
float bkg_clip_nsigma = 4.0f;
|
|
// Radial background curvature correction. The signal disk and the background annulus are
|
|
// concentric, so for ANY background linear in position their means are equal - a plane fit buys
|
|
// nothing and the leading error is the CURVATURE of the radial background, which the flat annulus
|
|
// mean is structurally blind to. Sitting on an ice ring that reaches +26 counts on a single
|
|
// reflection. When on, a radial background curve is accumulated per image from the annulus pixels
|
|
// that are already read, and each reflection's background is corrected by
|
|
// mean_annulus(B) - mean_disk(B), evaluated as a fixed kernel over radial offset (O(1), no extra
|
|
// pixel reads). Measured empty-aperture bias over 9 bands on 3 crystals: 4.33 -> 0.79 counts mean
|
|
// |bias|, scatter unchanged.
|
|
//
|
|
// Unset means AUTO: apply it per image where that image's peak-excluded ice score says a SMOOTH
|
|
// powder ring is present, and not otherwise. NOT the default - see below. The correction models the
|
|
// background as a function of radius alone, so it helps exactly where that is true and not
|
|
// elsewhere. Measured against a fixed external model, band-versus-decoy-band: on a crystal with
|
|
// pure smooth ice it removes 43% of the ice bands' excess amplitude, with the effect 7x stronger
|
|
// inside the bands than outside; on a crystal whose ice is discrete crystallite SPOTS - no smooth
|
|
// radial ring to model - the excess amplitude instead GREW by half; on clean data it is inert to
|
|
// four decimal places. The ice score's two channels separate those two morphologies, so the
|
|
// correction is gated on the smooth one. Auto only engages where a peak-excluded score exists
|
|
// (adaptive spot finding); the plain profile carries the Bragg peaks and cannot support a
|
|
// threshold, so without it auto stays off.
|
|
//
|
|
// OFF by default. Auto targets correctly - over the rotation battery it fires on ten crystals and
|
|
// every one of them is ice-positive - but it costs 1.35x the wall clock, and on the merge
|
|
// statistics it is the familiar sign-mixed trade rather than a win: high-shell CC1/2 worse on
|
|
// three of the four crystals that move materially. The case for it rests on agreement with an
|
|
// external model, which is the better arbiter but a narrower one, so it stays opt-in until that
|
|
// is settled on its own evidence.
|
|
std::optional<bool> bkg_radial_correction = false;
|
|
// Half-width of the hkl cube the predictor walks: every reflection with |h|,|k|,|l| <= this is
|
|
// tested against the Ewald sphere, and nothing outside it can ever be predicted. An axis is
|
|
// truncated once a/d_min exceeds this, and the GPU cost is the cube (2n+1)^3 of candidates, so
|
|
// neither a small nor a large fixed value is right for every crystal.
|
|
//
|
|
// Unset (the default) means "take it from the refined cell", which is exact: the predictor keeps
|
|
// only |q| <= 1/d_min and h = a.q, so no reflection can have |h| > a/d_min. See MaxHKLForCell.
|
|
// Offline that is what is wanted. ONLINE it is not: the broker bootstraps a concrete value
|
|
// (BRAGG_ONLINE_DEFAULT_MAX_HKL) so per-image cost stays predictable across samples.
|
|
std::optional<int> max_hkl;
|
|
// Overlap treatment and the MINPK threshold: the least fraction of a reflection's expected profile
|
|
// that must be usable for the reflection to be kept. Excluding the shared pixels is the default:
|
|
// over the rotation battery it costs 1.1% of the wall clock (23% on a genuinely crowded crystal,
|
|
// nothing where no two predictions touch) and buys ISa on 15 crystals against 5, cutting the summed
|
|
// shortfall against XDS by a third.
|
|
//
|
|
// As in XDS, one threshold governs both ways a reflection can lose part of its profile. Under
|
|
// OverlapMode::Reject it is the fraction that must be cleanly the reflection's own rather than a
|
|
// neighbour's. In every profile mode it is also the fraction that must be READABLE - not masked,
|
|
// untrusted, in a detector gap or overloaded - because the profile fit renormalises to the pixels
|
|
// it can read (dials calls that valid_foreground_threshold, and defaults it to the same 0.75).
|
|
OverlapMode overlap_mode = OverlapMode::Exclude;
|
|
float overlap_min_peak = 0.75f;
|
|
// What the diffracted beam crosses between the sample and its pixel, which sets the flight-path
|
|
// attenuation correction (sensor_absorption::FlightPathAttenuation). Air by default; the
|
|
// correction is computed from the NIST attenuation coefficient of the medium, the stated
|
|
// sample-to-detector distance and the stated wavelength, and nothing about it is fitted.
|
|
//
|
|
// It is a declared choice rather than a detected one, and that is not a gap waiting to be
|
|
// closed. Nothing in the files says what the medium was, and the implied transmission does not
|
|
// separate the cases either: in this corpus a CONFIRMED helium station sits at 51% implied air
|
|
// transmission and a CONFIRMED air station at 63%, so any rule dividing them would be a
|
|
// threshold fitted between two points rather than a physical criterion. The honest design is an
|
|
// explicit option, a stated default, and the assumption printed in the report.
|
|
FlightPathMedium flight_path = FlightPathMedium::Air;
|
|
|
|
public:
|
|
BraggIntegrationSettings& R1(float input);
|
|
BraggIntegrationSettings& R2(float input);
|
|
BraggIntegrationSettings& R3(float input);
|
|
BraggIntegrationSettings& StencilKSigma(float input);
|
|
BraggIntegrationSettings& DMinLimit_A(std::optional<float> input);
|
|
BraggIntegrationSettings& FixedProfileRadius_recipA(std::optional<float> input);
|
|
BraggIntegrationSettings& ForcedPredictionMosaicity_deg(std::optional<float> input);
|
|
BraggIntegrationSettings& Integrator(IntegratorMode input);
|
|
BraggIntegrationSettings& BackgroundTrimFraction(float input);
|
|
BraggIntegrationSettings& BackgroundClipNSigma(float input);
|
|
BraggIntegrationSettings& BackgroundRadialCorrection(std::optional<bool> input);
|
|
BraggIntegrationSettings& MaxHKL(std::optional<int> input);
|
|
BraggIntegrationSettings& Overlap(OverlapMode input);
|
|
BraggIntegrationSettings& OverlapMinPeak(float input);
|
|
BraggIntegrationSettings& FlightPath(FlightPathMedium input);
|
|
|
|
|
|
[[nodiscard]] IntegratorMode GetIntegrator() const;
|
|
[[nodiscard]] float GetR1() const;
|
|
[[nodiscard]] float GetR2() const;
|
|
[[nodiscard]] float GetR3() const;
|
|
[[nodiscard]] float GetStencilKSigma() const;
|
|
[[nodiscard]] std::optional<float> GetFixedProfileRadius_recipA() const;
|
|
[[nodiscard]] std::optional<float> GetForcedPredictionMosaicity_deg() const;
|
|
[[nodiscard]] std::optional<float> GetDMinLimit_A() const;
|
|
|
|
[[nodiscard]] float GetMinimumSigmaInRegardsToI() const;
|
|
[[nodiscard]] float GetBackgroundTrimFraction() const;
|
|
[[nodiscard]] float GetBackgroundClipNSigma() const;
|
|
// Unset = auto (gate per image on the smooth-ice score); see bkg_radial_correction.
|
|
[[nodiscard]] std::optional<bool> GetBackgroundRadialCorrection() const;
|
|
[[nodiscard]] std::optional<int> GetMaxHKL() const;
|
|
[[nodiscard]] OverlapMode GetOverlap() const;
|
|
[[nodiscard]] float GetOverlapMinPeak() const;
|
|
// See flight_path: air unless the user said otherwise, which no file can say for them.
|
|
[[nodiscard]] FlightPathMedium GetFlightPath() const;
|
|
};
|