Files
Jungfraujoch/common/AnalysisSettings.cpp
T
leonarski_fandClaude Opus 5 98132d0f83 analysis: every analysis method carries its own settings, and a raster's indexing is one of them
AnalysisSettings had begun collecting per-method parameters - the calibrant was already in
it, and the grid thresholds were about to be. That makes the structure every method reads
grow whenever any one method gains a knob, and it puts a field in front of readers for whom
it means nothing. So: AnalysisSettings keeps what all methods share, which for now is the
mode, and each method gets a class of its own bound the same way.

GridScanAnalysisSettings holds the protein-score threshold, the minimum cells per crystal,
the decisive single-cell score, the maximum crystals reported and the indexing switch.
CalibrationSettings holds the calibrant and the ring source. Both sit on
DiffractionExperiment outside the per-run dataset member, both have an Import/Get pair, and
both have their own endpoint - /config/grid_scan_analysis and /config/calibration - which is
how every other settings group in this API is already reached.

Grid indexing is no longer fixed in the stages table. It was turned off there on cost
grounds, and that reasoning does not hold: a raster runs at up to 100 Hz, which the FFT
indexer keeps up with, and a fixed-target serial experiment with a known cell wants ffbidx on
every cell, where a raster that indexes is most of the measurement. So it is a setting, and
DEFAULTS ON. It is additive rather than a change of answer - blobs are still found on the
protein score, so indexing alters nothing about which cells are called crystals and only adds
what was found in them, including the per-cell lattice count, which is the cheapest
multi-lattice or cracked-crystal signal there is.

That makes indexing the one stage a mode does not decide. AnalysisModeStages still carries a
value for it, but only as the setting's default, and DiffractionExperiment::GetAnalysisStages
- which is what every gate reads - substitutes the configured one. The table row is marked so
nobody reads it as the mode's answer.

The calibration knobs stay coupled to the mode but the rule now lives with them:
CalibrationSettings::ApplyToAzimuthalIntegration moves azimuthal integration onto the CPU and
supplies sectors where fewer than four were asked for, carrying the reason with it - the FPGA
integration core holds 2048 bins in total, so 32 sectors leave 64 q bins, which cannot locate
a ring. Stated there because it will otherwise read as an FPGA defect to be fixed back onto
that path, and it is not one: the core is sized for a detector at full rate, and a calibration
exposure is a few images at a few Hz. Both imports apply it, so the order the mode and the
calibration settings are set in does not matter.

CalibrationMethod moves from image_analysis/geom_refinement/PowderCalibration.h into
common/CalibrationSettings.h, which that header now includes. One enum, so the setting and the
code consuming it are not two vocabularies; every existing user sees it unchanged.

The grid thresholds have one home and it is this class. The raster work owns AnalyzeGridScan's
parameter surface and carries PROTEIN_SCORE_THRESHOLD_DEFAULT / MIN_BLOB_CELLS_DEFAULT beside
that header today; the header here states the signature that replaces them, so the two do not
become competing defaults. The beam size deliberately stays a separate argument to
AnalyzeGridScan: it is measured, not configured.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFEJG6WBQv8th4UJFNe53N
2026-09-08 07:27:41 +02:00

99 lines
4.1 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "AnalysisSettings.h"
#include "GridScanAnalysisSettings.h"
// The mode-to-analysis table. One place, one row per mode, and every gate in the pipeline reads it -
// so what a mode does can be read off here instead of being reconstructed from `if (mode == ...)`
// scattered through the engines.
//
// spots index bragg merge score azint
// None - - - - - -
// MXRotation x x x x x x
// MXStills x x x x x x
// Azint - - - - - x
// Grid x * - - x x * = default; a setting
// PowderCalibration x - - - - x
//
// Two rows want a word.
//
// PowderCalibration keeps spot finding. The geometry is fitted either to the ring arcs of the summed
// (q x azimuth) profile or to the POOLED SPOTS (rugnux --calibration rings|spots), and the second of
// those is a spot finder run - so the mode must not decide this; whoever picks the source does.
//
// Grid indexes by default, but that entry is not the mode's to fix: it is
// GridScanAnalysisSettings::indexing, and what stands here is only what that setting defaults to. A
// raster runs at up to 100 Hz, which the FFT indexer keeps up with, and a fixed-target serial
// experiment with a known cell wants ffbidx on every cell - so whether a raster indexes is a property
// of the experiment, not of rasters. DiffractionExperiment::GetAnalysisStages substitutes the
// configured value.
//
// The switch has no default: adding a mode must be a compile error here rather than a silent
// fall-through to whatever the last row happened to be.
AnalysisStages AnalysisModeStages(AnalysisMode mode) {
switch (mode) {
case AnalysisMode::None:
return {false, false, false, false, false, false};
case AnalysisMode::MXRotation:
case AnalysisMode::MXStills:
return {true, true, true, true, true, true};
case AnalysisMode::Azint:
return {false, false, false, false, false, true};
case AnalysisMode::Grid:
return {true, GridScanAnalysisSettings().IsIndexing(), false, false, true, true};
case AnalysisMode::PowderCalibration:
return {true, false, false, false, false, true};
}
return {false, false, false, false, false, false};
}
bool AnalysisModeIsMX(AnalysisMode mode) {
switch (mode) {
case AnalysisMode::MXRotation:
case AnalysisMode::MXStills:
return true;
case AnalysisMode::None:
case AnalysisMode::Azint:
case AnalysisMode::Grid:
case AnalysisMode::PowderCalibration:
return false;
}
return false;
}
std::string AnalysisModeName(AnalysisMode mode) {
switch (mode) {
case AnalysisMode::None: return "none";
case AnalysisMode::MXRotation: return "mx_rotation";
case AnalysisMode::MXStills: return "mx_stills";
case AnalysisMode::Azint: return "azint";
case AnalysisMode::Grid: return "grid";
case AnalysisMode::PowderCalibration: return "powder_calibration";
}
return "none";
}
std::optional<AnalysisMode> AnalysisModeFromName(std::string_view name) {
if (name == "none") return AnalysisMode::None;
if (name == "mx_rotation") return AnalysisMode::MXRotation;
if (name == "mx_stills") return AnalysisMode::MXStills;
if (name == "azint") return AnalysisMode::Azint;
if (name == "grid") return AnalysisMode::Grid;
if (name == "powder_calibration") return AnalysisMode::PowderCalibration;
return {};
}
AnalysisSettings &AnalysisSettings::Mode(AnalysisMode input) {
mode = input;
return *this;
}
AnalysisMode AnalysisSettings::GetMode() const {
return mode;
}
bool AnalysisSettings::IsMX() const {
return AnalysisModeIsMX(mode);
}