// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once #include #include #include #include "../../common/Coord.h" #include "../../common/CrystalLattice.h" #include "../../common/GoniometerAxis.h" // What a rotation sweep can still gain: the fraction of the unique reflections to d_min that the // sweep [start, end] brought through the Ewald sphere, in this crystal's actual orientation and // point group, and the same fraction for every extension of the sweep up to a full turn. The // counterpart of SpindleCuspLoss for a sweep of finite length: that answers what no length of sweep // can recover (the blind double cone about the spindle), this answers how much of the rest is in. // // A unique reflection is measured when any member of its orbit under the proper rotations of the // point group, with Friedel's inversion, crosses the sphere inside the sweep. The crossing angles are // exact (the two roots of |R(-phi) s + S0| = |S0|), the unique reflections are sampled uniformly // over reciprocal space to d_min (directions on a spiral, radii at the volume quantiles), so the // fractions are geometric and carry no measurement noise: a merge's completeness falls short of // them by what the detector, the integration and the rejections lost. struct SweepCoverageForecast { double measured_fraction = 0; // brought through the sphere by [start, end] double asymptote_fraction = 0; // by any sweep: 1 - SpindleCuspLoss::lost_unique_fraction // fraction_at[k]: by [start, end + k degrees], k = 0..360 std::vector fraction_at; // The least extension, in degrees, that reaches the target fraction; none where no extension does. std::optional DegreesTo(double target_fraction) const; }; // The goniometer angles, in [0, 360), at which the reciprocal point s (the crystal at angle 0) is in // reflecting position: the crystal turned by -phi about the unit spindle u, as GetTransformationAngle(-phi) // turns the lattice, against the incident wavevector s0. Empty when it never is - s inside the blind // cone of its own shell, or along the spindle. std::vector EwaldCrossingAngles_deg(const Coord &s, const Coord &u, const Coord &s0); // lattice: the sweep's lattice at goniometer angle 0, the way ProcessResult::end_message keeps it // (RugnuxFarEnd and the predictor place it on an image with GetTransformationAngle(-angle)). // s0: the incident wavevector, DiffractionGeometry::GetScatteringVector(). Angles in degrees; // end > start, and a sweep of 360 degrees or more measures everything measurable. std::optional ForecastSweepCoverage(const gemmi::SpaceGroup &sg, const CrystalLattice &lattice, const GoniometerAxis &gonio, const Coord &s0, double d_min_A, double start_deg, double end_deg); // The least tilt, in whole degrees, of a second sweep's spindle against the first that leaves at most // `max_lost_fraction` of the reciprocal space to d_min blind to both sweeps - their blind cones apart. // Symmetry is not counted, so this is enough for any point group, and the same in every direction of tilt. double SecondSweepTilt_deg(double wavelength_A, double d_min_A, double max_lost_fraction);