// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once #include "HKLKey.h" #include "Merge.h" #include "../../common/DiffractionExperiment.h" #include "../IntegrationOutcome.h" #include #include struct ScaleOnTheFlyResult { double G = 1.0; double cc = NAN; size_t cc_n = 0; }; // Per-image reference scaling with the FIXED partiality model: each reflection's stored partiality is // used as-is (it is 1 for stills and the zeta/erf rocking-curve value already set at prediction for // rotation data). No partiality recompute, no mosaicity or wedge refinement: the fit is linear in G, a // robust 1-D IRLS. Rotation self-scaling/merging offline uses the dedicated RotationScaleMerge path. class ScaleOnTheFly { constexpr static size_t MIN_REFLECTIONS = 20; const ScalingSettings s; const HKLKeyGenerator hkl_key_generator; std::map reference_data; bool Accept(const Reflection &r) const; public: ScaleOnTheFly(const DiffractionExperiment &x, const std::vector &ref); void Scale(IntegrationOutcome &integration_outcome) const; void Scale(std::vector &integration_outcome, size_t nthreads = 0) const; // Leave an image unscaled when its fitted scale collapsed far below the run median (see the .cpp). // Called by the multi-image Scale, which is where the run median exists; public so a caller that // scales images one at a time can apply it once it has them all. static void RejectCollapsedScales(std::vector &integration); };