Distance check: pre-passes only where the integration can see the move; otherwise pass 2 holds it
The distance pre-passes (d07080766 and after) ratified every move pass 1 committed or asked for by
re-integrating the pre-pass frames along it: 330 pre-passes on 198 of the battery's 264 rotation sets,
999 s - a sixth of the arm's wall and most of the release's +31 %. On 130 of those sets the move was a
tenth of a percent or so (median 0.10 %), the pre-pass realised a held-out residual within 10 % of the
header's on 73 of the 88 it refused, and the merge came out identical to a run that never asked.
Whether a pre-pass can measure anything pass 1 did not is asked first, from the geometry. Pass 2
re-indexes at the moved distance, so the cell scale compensates the move to first order; what is left
displaces a reflection at Bragg angle theta by eps r (1/(cos^2 theta cos 2theta) - 1) along the radius -
a quarter of eps r at 2theta = 30 deg, twice eps r at 65 deg. Where that displacement at the furthest
spots pass 1 found (spot_resolution_estimate_A) exceeds the width of the spots measured there (the
pre-scan's footprint), the move is ratified by the pre-passes exactly as before: on a small-molecule
sweep at 0.65 A a 0.36 % move displaces the edge by 9 px against spots 4 px wide, and committed without
the pre-passes it cost a third of ISa (59 -> 36, SHELXL R1 0.031 -> 0.044); on a cubic salt a 0.76 %
move displaces it by 19 px against 6.5 and cost R1 0.042 -> 0.114.
Where the displacement stays within the spot, no pre-pass is run: pass 2 integrates at the committed
distance holding it as its own hypothesis (header_distance_mm_), and decides late, right after its own
integration. The header stands and the refined passes run again there (distance_refused_, tried on a
copy of the run first so the refusal restarts them, the metric-symmetry arms included) on either of two
findings:
- pass 2 did not index pass 1's lattice, orientation included, the cell scaled with the distance
(LatticeMismatch >= 0.1) - the same test that ends the pre-pass walk on a pre-pass on another lattice.
Measured: a cubic crystal re-indexed at the commit on a lattice whose indices are half-integers of
pass 1's; the rotation-scale walk beside pass 2 then adopted a scale on whose probe pass 1's lattice
came back, and the joint merge found the sweep not isomorphous with the others (ratio 0.83, sweep
left out). Where that walk has adopted a scale at the commit, it is run again at the header; the
sweep then joins as it did before (ratio 0.998).
- the data integrated at the commit ask for q >= 3/4 of the move again: the two asks imply a fixed point
move/(1-q) past the header, beyond the four moves the pre-pass walk reaches. Measured: the asks that
held fell at q <= 0.36 on every set tried, the drifting ones at 0.83-1.08 (ten sweeps of one crystal);
with the refusal at q >= 1 only one of six drifting sweeps was refused and the joint merge went from
R_meas 0.27 to 0.33, at 3/4 all six are and it stays at 0.27.
Holding the header outright against every move the integration cannot see was tried and refused: a
monoclinic crystal whose header is 0.56 % long reads the move at 1.45 px against spots 1.6 px wide, and
at the header its second pass loses the axis-harmonic pair the doubled cell is decided on and fails.
On the battery's rotation arms the rule keeps the pre-passes on 68 of the 198 checked sets (every
small-molecule and high-resolution set among them; 357 s of the 999 s) and drops them on 130 (642 s).
Measured on 35 rotation sets plus 16 multi-sweep and extra sets, back to back against the same base:
wall 1565 -> 1035 s on the 35 (-34 %, with the two commits before), every small-molecule result
identical (ISa, R_meas, SHELXL R1), no verdict or space-group change, protein merges within noise.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVeDQrPqZ52Tp6rzzZGxf3
This commit is contained in:
1 parent
df3a5939f0
commit
691b2b88e2
3 files changed
+173
-9
No files matched your search
@@ -399,6 +399,8 @@ The refinement above (§7.2) runs per image against that image's spots. For rota
|
||||
**Whether the data determine the distance at all is asked, not assumed.** At a detector far enough away that no reflection reaches more than a few degrees of $2\theta$, a longer distance and a larger cell move every spot the same way to first order — the difference is of order $\sin^2\theta$ of the spot's own position, about 0.4 px rms per per cent of distance over a 2M detector at 820 mm against 2–3 px at the distances a crystal is usually collected at. The joint fit then finds a distance/cell pair that fits its own spot positions a little better than the header, commits it, and the pass re-integrated there finds the next pair: a walk along the degenerate direction that the realised residual never ratifies (measured on such a sweep: a header at 820 mm walked to 846 mm with the cell 3.3 % too large, the realised held-out residual flat at every round). So the same fit is asked once more with the distance **held at the header**, every other block as free as before — the nested hypothesis "the header distance is right" — and the two are compared on the one residual family that can tell them apart: the **excitation** residual. It never involves the detector, so it is blind to the distance itself; what it sees is the cell scale, and a held fit at a wrong header distance is forced into a wrong cell scale by the spot positions, which the rocking angles then refuse (measured: a header 1.4 % long leaves the held fit's excitation residual seventeen times the free fit's). Where freeing the distance lowers the held-out excitation residual below the held fit's by more than that residual's own standard error, the free fit is committed exactly as before; where it does not, the held fit is — header distance, refined beam, cell, orientation and axis — and the report says so (`POSTREFINE_DISTANCE_HELD`). The positional residual is deliberately not consulted for this: it is the family whose in-fit gain along the degenerate direction re-integration erases, and pooled with the excitation family it either drowns a decisive excitation gain in its own noise (a 54 % excitation gain read as 9 % pooled against a 9 % noise) or lends the degenerate direction a gain that is not there. Nothing is tuned here: the only input is the standard error of the residual itself, the same noise the geometry walk's rounds have to beat. The wavelength is never refined on a single crystal for the same reason in its exact form: it scales the spot positions and the rocking angles identically to the cell, so no sweep can tell the two apart at any $2\theta$.
|
||||
3. **Pass 2** re-indexes de novo and re-integrates at the committed geometry. Only the **detector distance and beam centre** carry over: the refined cell, orientation and axis are what make the distance identifiable, but pass 2 re-indexes from scratch, so they are not propagated. Where the re-index finds a **different** lattice — the two compared on their Niggli-reduced primitive edges, within 2 %, so a symmetric setting is never told apart from its own primitive cell — pass 1's lattice is scored at the refined geometry as a hypothesis of its own, and integrated when it indexes more validation frames; the same lattice found again is kept as the re-index refined it. The run likewise falls back to pass 1's lattice where the re-index indexes too few frames, and integrates it at the refined geometry — and the cell is then **scaled to the distance it will be used at**, since a real-space cell is measured against the distance its spots were seen at, and carrying it across a distance change otherwise scales the whole cell by the ratio of the two. The orientation is untouched.
|
||||
|
||||
A distance pass 1 freed is a hypothesis, not a decision: the paired test above is sensitive enough to free it along the degenerate direction too, where every distance integrated asks for as much again. Whether re-integration can ratify it is asked first, from the geometry: pass 2 re-indexes, so the cell scale compensates the move to first order, and what is left displaces a reflection at Bragg angle $\theta$ by $\epsilon\, r\,(1/(\cos^2\theta\cos 2\theta) - 1)$ along the radius — a quarter of $\epsilon r$ at $2\theta = 30°$, twice $\epsilon r$ at 65°. Where that displacement at the furthest spots pass 1 found exceeds the width of the spots measured there (the pre-scan's footprint), the move is **ratified by pre-passes** along it, each integrating the pre-pass frames at a distance and asking the same paired test of it; the first distance whose data hold it is the fixed point, a sign change brackets one, and the run adopts the shortest move whose realised held-out residual beats the header's beyond the noise of the two — a move every distance asks for again does not bracket a fixed point, and the header stands. Where the displacement stays within the spot, a pre-pass could only re-measure what pass 1 measured, so none is run: pass 2 **holds the committed distance** as its own hypothesis and asks the paired test of it on the whole sweep. Integrated there, the data hold it (the fixed point), or ask for a further move: the two asks — pass 1's from the header, pass 2's from the commit — imply a fixed point $\text{move}/(1-q)$ past the header, $q$ the second ask over the first, and it is held to the reach of the pre-pass walk, four moves ($q \le 3/4$): within it the walk below takes the step; beyond it the ask is about as much again from wherever it is integrated, the data do not pin the distance, the header stands, and the refined passes are run again at the header with the distance decided (`POSTREFINE_DISTANCE_HELD`). The header stands in the same way where pass 2 at the commit did not index pass 1's lattice, orientation included and the cell scaled with the distance — the test that ends the pre-pass walk on a pre-pass that indexed another lattice — and where the rotation-scale walk beside pass 2 had already adopted a scale at the commit, that walk is run again at the header.
|
||||
|
||||
Pass 2 measures the post-refinement again, and where it still moves the geometry the run **walks**: it re-indexes and re-integrates at what the fit asks for, and repeats. A round is kept only for what it *realises*, not for what the fit predicts, and it can realise a gain in two ways, either of which has to beat its own noise: a lower held-out residual (the standard errors of the two means combined), or a larger share of the validation spots on the lattice beyond chance (the binomial noise of the two shares, z = 3.29). The residual alone misses exactly the errors that cost resolution: it is dominated by the low-resolution reflections, where a distance and the cell scale that compensates it move every spot alike, and its centroids are taken inside a disc centred on the prediction, so they follow the prediction part of the way; the high-resolution validation spots are the first to leave the lattice (measured: 0.6 % of distance read 0.74 of the residual's noise and 70.4 % against 58.1 % of the validation spots, and cost 0.07 Å of resolution). A move of a trust-region step or more starts the walk outright. A smaller one is first tried as two indexing probes on the validation frames — at the fit's geometry and at the one in hand, each stopping once the lattice is scored — and pays for a re-integrated round only where the fit's geometry scores higher. The run keeps the best round it reached.
|
||||
|
||||
The space group is determined **after** pass 2, on the geometry the run refined, and pass 1 does not search at all: a decision taken on the worse of the two passes and then carried forward is a constraint on the better one, and would have to be reconciled with what pass 2 later found. The guard that chooses which pass is written compares each pass's **first** merge — $P1$ on both sides, full resolution range, before the correction surfaces — which both passes produce anyway, so it never compares statistics computed in two different space groups. Where pass 1 integrated only part of the sweep, pass 2 is judged on a merge of its own integration of the same frames, made the same way, since a merge of more frames holds more reflections and more signal whatever the geometry. What it compares there is the **signal each pass measured**: the count of unique reflections merged at $I/\sigma \ge 2$, less the count at $I/\sigma \le -2$. An empty reflection is as likely to land in either tail, so the second count is the merge's own measure of how much of the first is noise — which is what makes two passes on different lattices comparable: a pass on an $n$-fold supercell merges $n$ times the reflections, most of them empty, and their noise alone once out-counted the crystal's own lattice. Self-consistency cannot do this job — against an external arbiter the signal count named the more accurate geometry on 23 of 27 arm-dataset pairs where $R_\mathrm{meas}$, $CC_{1/2}$ and ISa managed 13, a coin flip — and that merge's own $CC_{1/2}$ least of all, being pooled over the whole range, uncut and uncorrected, so the shells with no signal in them dominate it and they are exactly the shells a geometry move disturbs (it reads 0.13 on a crystal whose data merge at 0.995). The refined pass is sent back only where it merges more unique reflections than its cell can hold, where it measured decisively less signal (10 %, and only where it covers no more of reciprocal space either — a wider integration disk pulls weak reflections in and dilutes the strong fraction without measuring less; between two lattices the reflection count of the smaller is scaled by the integer index of one in the other), or where it lost the axial rows the systematic absences are read off. One index-time veto remains and is keyed to pass 1's **lattice** rather than its group: a centred pass-1 lattice against a primitive pass-2 one. A pass sent back is pass 1 as it was judged — its whole indexing result is reused, not indexed again de novo at the header geometry, which is a hypothesis nobody had judged.
|
||||
|
||||
+12
-7
@@ -1359,6 +1359,10 @@ class Rugnux {
|
||||
// fit's ask and residual and the lattice integrated on, nothing of a merge, so neither the scaling
|
||||
// engine nor a merge is made.
|
||||
bool distance_probe_ = false;
|
||||
// Set by RefinedPasses where pass 2, integrated at the distance pass 1 committed, finds the data asking
|
||||
// for as much again or indexes another lattice than pass 1's: the committed distance is refused and
|
||||
// RunAllPasses runs the refined passes again at the header, with the distance decided.
|
||||
bool distance_refused_ = false;
|
||||
// The indexing result the last full pass integrated on, which the doubled-cell hypothesis doubles.
|
||||
std::optional<RotationIndexerResult> last_rotation_result_;
|
||||
// Keep the merged reflections on the result (ProcessResult::merged_reflections).
|
||||
@@ -1707,11 +1711,11 @@ class Rugnux {
|
||||
}
|
||||
// The same, of another experiment beside the run's settings.
|
||||
[[nodiscard]] std::vector<double> ExperimentKey(const DiffractionExperiment &x, bool rotation_angles = true) const;
|
||||
// The file's detector distance, from before the first pass of the rotation two-pass: a pass whose
|
||||
// distance is still this one asks the post-refinement to test "the header distance is right"
|
||||
// (PostRefineSettings::distance_at_header); a pass that has walked off it does not.
|
||||
// The distance a pass holds as its hypothesis and asks the post-refinement to test "this distance is
|
||||
// right" at (PostRefineSettings::distance_at_header): the file's for pass 1, the distance pass 1
|
||||
// committed for pass 2 (RunAllPasses); a pass that has walked off it does not ask.
|
||||
double header_distance_mm_ = std::numeric_limits<double>::quiet_NaN();
|
||||
// The distance check refused a move pass 1 committed: the passes after it hold the header distance
|
||||
// Pass 2 refused the distance pass 1 committed: the passes after it hold the header distance
|
||||
// (PostRefineSettings::distance_decided).
|
||||
bool header_distance_decided_ = false;
|
||||
|
||||
@@ -1980,9 +1984,10 @@ class Rugnux {
|
||||
RotationScaleOutcome scale_walk; // where the walk has ended before they start
|
||||
int distance_passes = 0; // the pre-passes the fixed-point distance ran (FixedPointDistance)
|
||||
};
|
||||
// The detector distance as the fixed point of the integration, where pass 1 held the header but its
|
||||
// free fit asked for a move of a step or more (see RunAllPasses). Returns the geometry to start the
|
||||
// refined passes from, or nothing where the header stands; `passes` counts the pre-passes it ran.
|
||||
// The detector distance as the fixed point of the integration, where pass 1 committed or asked for a
|
||||
// move the integration can see (see RunAllPasses). Returns the geometry to start the refined passes
|
||||
// from, or nothing where the header stands or the move is left to pass 2; `passes` counts the
|
||||
// pre-passes it ran.
|
||||
std::optional<std::array<float, 5>> FixedPointDistance(RugnuxObserver *observer, const ProcessResult &pass1,
|
||||
const DiffractionExperiment &first_pass_start,
|
||||
int &passes);
|
||||
|
||||
+159
-2
@@ -416,6 +416,7 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) {
|
||||
const int64_t max_spot_count_snapshot = experiment_.GetDatasetSettings().GetMaxSpotCount();
|
||||
header_distance_mm_ = experiment_.GetDetectorDistance_mm();
|
||||
header_distance_decided_ = false;
|
||||
distance_refused_ = false;
|
||||
distance_probe_ = false;
|
||||
prepass_detector_geometry_.reset();
|
||||
prepass_rotation_scale_.reset();
|
||||
@@ -680,6 +681,19 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) {
|
||||
experiment_.GetDetectorDistance_mm(),
|
||||
experiment_.GetPoniRot1_rad(),
|
||||
experiment_.GetPoniRot2_rad()};
|
||||
// The distance pass 1 committed (prepass_detector_geometry_) is a hypothesis, not a decision. The
|
||||
// paired test that frees it is sensitive enough to free it along the direction the data do not
|
||||
// determine - the distance and the cell scale trading against each other - where every distance
|
||||
// integrated asks for as much again. A move the integration can see is ratified by pre-passes
|
||||
// along it (FixedPointDistance), which decide the distance before pass 2. A move it cannot see
|
||||
// is not: pass 2 integrates at the committed distance and HOLDS it as its own hypothesis
|
||||
// (header_distance_mm_), so its post-refinement asks of that distance what pass 1 asked of the
|
||||
// header's. Integrated there, the data hold it (the fixed point), ask for a move toward a fixed
|
||||
// point within the pre-pass walk's reach (which the geometry walk takes), or ask for about as much
|
||||
// again - then the data do not pin the distance, the refined passes are thrown away and run again
|
||||
// at the header, with the distance decided (RefinedPasses, distance_refused_). On the battery the
|
||||
// pre-passes on such moves cost a tenth of the wall for a decision pass 2 reaches on its own on
|
||||
// all but the drifting crystals, which now cost one pass more instead of up to five pre-passes.
|
||||
int distance_passes = 0;
|
||||
if (const auto g = FixedPointDistance(observer, pass1, experiment_before_first_pass, distance_passes)) {
|
||||
prepass_detector_geometry_ = g;
|
||||
@@ -694,7 +708,32 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) {
|
||||
const auto &g = *prepass_detector_geometry_;
|
||||
experiment_.BeamX_pxl(g[0]).BeamY_pxl(g[1]).DetectorDistance_mm(g[2])
|
||||
.PoniRot1_rad(g[3]).PoniRot2_rad(g[4]);
|
||||
if (g[2] != header_geometry[2] && distance_passes == 0)
|
||||
header_distance_mm_ = g[2];
|
||||
}
|
||||
// Where pass 2 refuses the committed distance: the geometry a fit with the distance held at the
|
||||
// header would have left - its beam where the held fit converged, the geometry the run started
|
||||
// from where it did not - and the distance decided, so no later pass asks again.
|
||||
const auto hold_header_distance = [&] {
|
||||
std::array<float, 5> g = header_geometry;
|
||||
const PostRefineResult &held = *pass1.post_refine;
|
||||
if (std::isfinite(held.beam_x_held_px) && std::isfinite(held.beam_y_held_px)) {
|
||||
g[0] = static_cast<float>(held.beam_x_held_px);
|
||||
g[1] = static_cast<float>(held.beam_y_held_px);
|
||||
g[3] = pass1.end_message.refined_poni_rot1.value_or(g[3]);
|
||||
g[4] = pass1.end_message.refined_poni_rot2.value_or(g[4]);
|
||||
}
|
||||
experiment_.BeamX_pxl(g[0]).BeamY_pxl(g[1]).DetectorDistance_mm(g[2]).PoniRot1_rad(g[3]).PoniRot2_rad(g[4]);
|
||||
prepass_detector_geometry_ = g;
|
||||
header_distance_mm_ = g[2];
|
||||
header_distance_decided_ = true;
|
||||
pass1.post_refine->distance_after_mm = g[2];
|
||||
pass1.post_refine->beam_x_after_px = g[0];
|
||||
pass1.post_refine->beam_y_after_px = g[1];
|
||||
pass1.post_refine->distance_held = true;
|
||||
step("Distance check");
|
||||
note("the header distance stands: pass 2 at the committed distance did not bear it out");
|
||||
};
|
||||
RefinedPassStart start{gonio_snapshot, header_geometry, {}, distance_passes};
|
||||
|
||||
// The goniometer rotation scale: the angles in the file are the commanded ones, so a stage that
|
||||
@@ -722,8 +761,14 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) {
|
||||
// PostRefine.cpp): there the walk moves off them and refits as a rule, which calls the output
|
||||
// pass off and throws it away, so the walk runs first, on its own, and the refined passes
|
||||
// after it. Either way the run ends where the sequential walk leaves it.
|
||||
// Where the output pass refuses the distance pass 1 committed after the walk beside it has
|
||||
// adopted a scale, that scale was scored at the commit: the header is held and the walk is run
|
||||
// again there, as it would have run had the commit been refused before it (once - at the header
|
||||
// there is no commit left to refuse).
|
||||
constexpr double ROTATION_SCALE_STEP = 0.01;
|
||||
if (!cancelled_ && !config_.fast_live && gonio_snapshot && pass1.post_refine && !config_.rotation_scale) {
|
||||
for (bool walk_again = true; walk_again && !cancelled_ && !config_.fast_live && gonio_snapshot
|
||||
&& pass1.post_refine && !config_.rotation_scale;) {
|
||||
walk_again = false;
|
||||
const auto check = std::make_shared<RotationScaleCheck>();
|
||||
RotationScaleWalk walk;
|
||||
if (std::fabs(pass1.post_refine->rotation_scale - 1.0) >= ROTATION_SCALE_STEP) {
|
||||
@@ -749,10 +794,21 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) {
|
||||
check->Set(check->output_indexed);
|
||||
check->Set(check->output_ended);
|
||||
walk = walk_done.get();
|
||||
if (output->distance_refused_ && check->overturns) {
|
||||
hold_header_distance();
|
||||
walk_again = true;
|
||||
continue;
|
||||
}
|
||||
if (!check->overturns) {
|
||||
if (output_error)
|
||||
std::rethrow_exception(output_error);
|
||||
return output->DoubledCellHypothesis(observer, std::move(*result));
|
||||
if (!output->distance_refused_)
|
||||
return output->DoubledCellHypothesis(observer, std::move(*result));
|
||||
// The committed distance refused: the refined passes run again on the run itself, at
|
||||
// the header, after the walk the copy's passes ran beside.
|
||||
start.scale_walk = {check->passes, check->text};
|
||||
hold_header_distance();
|
||||
return DoubledCellHypothesis(observer, *RefinedPasses(observer, std::move(pass1), start));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -771,6 +827,16 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) {
|
||||
walk.scale > 1.0f ? "further" : "less far");
|
||||
}
|
||||
}
|
||||
// A committed distance is tried on a copy of the run, so that a refusal starts the refined passes
|
||||
// again from where they start - the metric-symmetry arms included, which a pass at a distance the
|
||||
// data do not pin decided at that distance.
|
||||
if (!cancelled_ && header_distance_mm_ != header_geometry[2]) {
|
||||
const auto trial = std::make_shared<Rugnux>(*this);
|
||||
std::optional<ProcessResult> result = trial->RefinedPasses(observer, pass1, start);
|
||||
if (!trial->distance_refused_)
|
||||
return trial->DoubledCellHypothesis(observer, std::move(*result));
|
||||
hold_header_distance();
|
||||
}
|
||||
return DoubledCellHypothesis(observer, *RefinedPasses(observer, std::move(pass1), start));
|
||||
}
|
||||
return RunPipeline(observer, /*write_output=*/true, /*geometry_prepass=*/false);
|
||||
@@ -814,6 +880,51 @@ std::optional<std::array<float, 5>> Rugnux::FixedPointDistance(RugnuxObserver *o
|
||||
if (!std::isfinite(move) || (!moved && std::fabs(move) < POSTREFINE_STEP_BOUND * d0))
|
||||
return std::nullopt;
|
||||
Logger logger("Rugnux");
|
||||
// Whether re-integrating at the moved distance can measure anything pass 1 did not. Pass 2 re-indexes
|
||||
// there, so the cell scale compensates the move to first order; what is left displaces a reflection at
|
||||
// Bragg angle theta by eps r (1 / (cos^2 theta cos 2theta) - 1) along the radius, r its distance from
|
||||
// the direct beam and eps the relative move - 0.24 eps r at 2theta = 30 deg, 2 eps r at 65 deg. Where
|
||||
// that displacement, at the furthest reflections the data hold, stays within the width of the spots
|
||||
// measured there (the pre-scan's footprint), the integration disc, the profile and the centroids all
|
||||
// move within the spot, and a pre-pass can only realise the residual pass 1 realised: on the battery
|
||||
// 73 of 88 such pre-passes read a residual within 10 % of the header's and the header stood, with the
|
||||
// merge then identical to a run that never asked. So such a move is not ratified here; pass 2
|
||||
// integrates at it holding it as its hypothesis (RunAllPasses). A move the spots can see is ratified
|
||||
// below as before: on a small-molecule sweep at 0.65 A a 0.4 % move displaces the edge by 9 px
|
||||
// against spots 4 px wide, and committed unratified it cost a third of ISa.
|
||||
if (prescan_footprint_ && !prescan_footprint_->empty()) {
|
||||
const DiffractionGeometry &geom = experiment_.GetDiffractionGeometry();
|
||||
const auto [dbx, dby] = geom.GetDirectBeam_pxl();
|
||||
const PlaneBox box = experiment_.GetModules().PlaneBounds(experiment_.GetXPixelsNum(),
|
||||
experiment_.GetYPixelsNum());
|
||||
const double fx = std::fabs(dbx - box.x0) > std::fabs(box.x1 - dbx) ? box.x0 : box.x1;
|
||||
const double fy = std::fabs(dby - box.y0) > std::fabs(box.y1 - dby) ? box.y0 : box.y1;
|
||||
const double r_far = std::hypot(fx - dbx, fy - dby);
|
||||
const double two_theta_far = geom.TwoTheta_rad(static_cast<float>(fx), static_cast<float>(fy));
|
||||
// The data's own edge, where the spots pass 1 found stop short of the detector's.
|
||||
const double lambda = experiment_.GetWavelength_A();
|
||||
double two_theta = two_theta_far;
|
||||
if (pass1.spot_resolution_estimate_A && *pass1.spot_resolution_estimate_A > 0.0f)
|
||||
two_theta = std::min(two_theta_far,
|
||||
2.0 * std::asin(std::min(1.0, lambda / (2.0 * *pass1.spot_resolution_estimate_A))));
|
||||
const double r_edge = r_far * std::tan(two_theta) / std::tan(two_theta_far);
|
||||
const double theta = two_theta / 2.0;
|
||||
const double displacement = std::fabs(move) / d0 * r_edge
|
||||
* (1.0 / (std::cos(theta) * std::cos(theta) * std::cos(two_theta)) - 1.0);
|
||||
const SpotFootprint &fp = *prescan_footprint_;
|
||||
const size_t bin = std::min(fp.sigma_rad.size() - 1,
|
||||
static_cast<size_t>(std::max(0.0, r_edge / fp.bin_px)));
|
||||
const double spot_width = std::max(fp.sigma_rad[bin], fp.sigma_tan[bin]);
|
||||
logger.Info("Distance check: the move {:.3f} -> {:.3f} mm displaces the furthest reflections ({:.1f} deg "
|
||||
"2theta, {:.0f} px from the direct beam) by {:.2f} px once the cell scale compensates it, "
|
||||
"against spots {:.1f} px wide there - {}", d0, d0 + move, two_theta * 180.0 / PI, r_edge,
|
||||
displacement, spot_width,
|
||||
displacement > spot_width ? "the integration can see the move, so it is ratified by pre-passes"
|
||||
: "within the spot, so pass 2 integrates at the committed distance "
|
||||
"and holds it as its hypothesis");
|
||||
if (!(displacement > spot_width))
|
||||
return std::nullopt;
|
||||
}
|
||||
if (observer)
|
||||
observer->OnStep("Distance check");
|
||||
|
||||
@@ -1446,6 +1557,52 @@ std::optional<ProcessResult> Rugnux::RefinedPasses(RugnuxObserver *observer, Pro
|
||||
rerun_if_starved_ = !config_.fast_live;
|
||||
const DiffractionExperiment before_pass2 = experiment_;
|
||||
auto pass2 = RunPipeline(observer, /*write_output=*/true, /*geometry_prepass=*/false);
|
||||
// The distance pass 1 committed was a hypothesis this pass integrated at and held as its own (see
|
||||
// RunAllPasses). Integrated there, the data hold it, or ask for a move. Two asks are now in hand - pass
|
||||
// 1's from the header, this pass's from the commit - and where the ask shrinks step by step the fixed
|
||||
// point they imply lies move / (1 - q) past the header, q the second ask over the first. The pre-pass
|
||||
// walk that ratifies a visible move reaches four moves and brackets a fixed point only within them; a
|
||||
// move the integration cannot see is held to the same reach: q <= 3/4, the fixed point within four
|
||||
// moves, is a step toward it, which the geometry walk below takes; beyond that the ask is as much again
|
||||
// from wherever it is integrated - the direction the data do not determine, the distance and the cell
|
||||
// scale trading against each other, where only the ask's significance wanders (measured: ten sweeps
|
||||
// of one crystal each asking for 0.9-0.99 of their move again at every distance, and 0.77 on a
|
||||
// far-detector crystal at 5 deg 2theta). Then the data do not pin the distance and the header stands:
|
||||
// the run is told so (distance_refused_) and runs the refined passes again there, with the distance
|
||||
// decided. So it does where this pass did not index pass 1's lattice, orientation included, the cell
|
||||
// scaled with the distance (LatticeMismatch) - the test that ends the pre-pass walk on a pre-pass that
|
||||
// indexed another lattice: its ask is that lattice's and says nothing of the distance pass 1 committed
|
||||
// (measured: a cubic crystal re-indexed at the commit on a lattice whose indices are half-integers of
|
||||
// pass 1's, after which the rotation-scale walk at the commit moved to a scale on whose probe pass 1's
|
||||
// lattice came back, and the joint merge found the sweep no longer isomorphous with the others). The
|
||||
// test is asked even of a pass the rotation-scale walk has called off, once it has indexed.
|
||||
if (!config_.fast_live && pass1.post_refine && before_pass2.GetDetectorDistance_mm() == header_distance_mm_
|
||||
&& header_distance_mm_ != header_geometry[2]) {
|
||||
const double d0 = header_geometry[2];
|
||||
const double d1 = header_distance_mm_;
|
||||
const double mismatch = LatticeMismatch(pass1, pass2, d0 / d1);
|
||||
const bool another_lattice = std::isfinite(mismatch) && mismatch >= 0.1;
|
||||
double asked = NAN;
|
||||
if (pass2.post_refine)
|
||||
asked = std::isfinite(pass2.post_refine->distance_free_mm) ? pass2.post_refine->distance_free_mm
|
||||
: pass2.post_refine->distance_after_mm;
|
||||
const double q = (asked - d1) / (d1 - d0);
|
||||
const bool drift = std::isfinite(q) && q >= 0.75;
|
||||
logger.Info("Distance check: header {:.3f} mm, pass 1 committed {:.3f} mm; integrated there the data ask for "
|
||||
"{:.3f} mm, {:.2f} of the move again{}, on {} (indices {:.3f} from whole) - {}", d0, d1, asked, q,
|
||||
pass2.post_refine && pass2.post_refine->rocking_holds_distance
|
||||
? " (the rocking angles hold the committed distance)" : "",
|
||||
another_lattice ? "another lattice than pass 1's" : "pass 1's lattice", mismatch,
|
||||
another_lattice ? "the commit is not borne out: the header stands and the refined passes run "
|
||||
"again there"
|
||||
: drift ? "a fixed point beyond four moves, so the data do not pin the distance: the header "
|
||||
"stands and the refined passes run again there"
|
||||
: "the committed distance stands");
|
||||
if (another_lattice || drift) {
|
||||
distance_refused_ = true;
|
||||
return pass2;
|
||||
}
|
||||
}
|
||||
if (radius_recheck_) {
|
||||
// The radius decided on the pre-pass frames within its noise, re-checked on the whole sweep.
|
||||
const bool elsewhere = widened_crowding_
|
||||
|
||||
Reference in new issue
Block a user