// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once #include #include #include #include "../../common/Logger.h" #include "../../common/Reflection.h" // MergedReflection #include "../../common/ScalingSettings.h" // ResolutionCutoffMethod // Automatic high-resolution cutoff from the CC1/2 fall-off of the merged half-sets (DIALS-style). // The merge itself, the error model and the per-image _process.h5 are left untouched - only the // written reflections and the reported shell table should be trimmed to the returned d_cut. // // Method (see docs/rugnux_resolution_cutoff_design.md): bin CC1/2 against s = 1/d^2 in fine bins, // fit a logistic CC1/2(s) = 1/(1+exp(k*(s-s0))) to the contiguous-from-low-res fall-off, take the s // where the fit crosses cc_target, then extend by one mean (10-shell) shell width in s ("one shell // too far", generous). d_cut is nullopt when the fit is degenerate (too few bins, flat/non-monotone) // or CC1/2 never falls below cc_target inside the measured range - the caller then keeps the full // range. cc_target in (0,1); merged must carry finite I_half[0]/I_half[1] to contribute. struct ResolutionCutoffResult { std::optional d_cut; // high-resolution limit (A); nullopt => keep the full range std::string note; // human-readable description of the decision (for logging) }; ResolutionCutoffResult ComputeCCHalfLogisticCutoff(const std::vector &merged, double cc_target, Logger &logger); // Resolve the effective high-resolution limit and trim `merged` to it, in one place shared by the // stills merge, the rotation merge and the offline --scale path. A manual limit (manual_limit) wins; // otherwise, unless this is a P1 space-group search merge (for_search), the CCHalfLogistic method // takes the auto CC1/2 cutoff. Reflections beyond the resolved limit are erased from `merged`. // Returns the applied limit (nullopt => the full range was kept). The decision is logged as before. std::optional ApplyResolutionCutoff(std::vector &merged, std::optional manual_limit, ResolutionCutoffMethod method, double cc_target, bool for_search, Logger &logger);