Merge branch 'supercell-rerun-starved' into rc173 (late passes re-run when their background ring is starved)

This commit is contained in:
leonarski_f committed 2026-09-27 21:27:55 +02:00
commit 03309032bd
1 file changed
+26 -12
+26 -12
View File
@@ -2901,8 +2901,14 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) {
// The pass that integrates at the widened radius is now the canonical one, so the measurement
// and the remedy are both here: re-run it at the radius that keeps the data, the same remedy the
// two guards below use and, like them, a pass only on a crystal that was going to be wrong.
if (!cancelled_ && bragg_adaptive_ && bkg_starved_fraction_
&& *bkg_starved_fraction_ > spot_width::BKG_STARVED_MAX_FRACTION) {
// Asked of every pass that can end the run - the two guards below re-run at whatever radius is
// in hand, and a starved refined pass has written nothing (see the superseded flag in
// RunPipeline) - so each is followed by it. After the first re-run the radius is the fixed one
// and this never fires again.
const auto rerun_if_starved = [&](ProcessResult &pass, const std::string decision) {
if (cancelled_ || !bragg_adaptive_ || !bkg_starved_fraction_
|| *bkg_starved_fraction_ <= spot_width::BKG_STARVED_MAX_FRACTION)
return;
logger.Info("Two-pass: at the widened integration radius r1={:.1f} the neighbouring "
"reflections left {:.2f}% of the predicted reflections without a background "
"ring (bound {:.2f}%), so this pass is re-run at r1={:.1f} r2={:.1f} r3={:.2f}",
@@ -2912,18 +2918,19 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) {
bragg_before_adaptive_->GetR3());
const double starved = *bkg_starved_fraction_;
const float wide_r1 = bragg_adaptive_->GetR1();
const int passes = pass2.pass_count + 1;
const int passes = pass.pass_count + 1;
experiment_.ImportBraggIntegrationSettings(*bragg_before_adaptive_);
bragg_adaptive_.reset();
pass2 = RunPipeline(observer, /*write_output=*/true, /*geometry_prepass=*/false);
pass2.post_refine = pass1.post_refine;
pass2.pass_number = passes;
pass2.pass_count = passes;
pass2.pass_decision = fmt::format(
"post-refined geometry adopted, re-run at the fixed integration radius: at r1={:.1f} "
"neighbouring reflections left {:.2f}% of the predicted reflections without a "
"background ring", wide_r1, 100.0 * starved);
}
pass = RunPipeline(observer, /*write_output=*/true, /*geometry_prepass=*/false);
pass.post_refine = pass1.post_refine;
pass.pass_number = passes;
pass.pass_count = passes;
pass.pass_decision = fmt::format(
"{}, re-run at the fixed integration radius: at r1={:.1f} neighbouring reflections "
"left {:.2f}% of the predicted reflections without a background ring", decision, wide_r1,
100.0 * starved);
};
rerun_if_starved(pass2, "post-refined geometry adopted");
// Supercell-collapse guard for the second pass. The de-novo lattice search can be BISTABLE on a
// periodically-modulated dataset: the tiny post-refine geometry move tips it out of the true-cell
@@ -2959,7 +2966,9 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) {
if (prepass_rotation_scale_ && force_rotation_result_->axis)
force_rotation_result_->axis =
ScaleRotation(*force_rotation_result_->axis, *prepass_rotation_scale_);
rerun_if_starved_ = true;
pass2 = RunPipeline(observer, /*write_output=*/true, /*geometry_prepass=*/false);
rerun_if_starved_ = false;
pass2.post_refine = pass1.post_refine;
pass2.pass_number = 3;
pass2.pass_count = 3;
@@ -2967,6 +2976,8 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) {
"post-refined geometry adopted, re-run with pass-1's lattice forced: the de-novo "
"primitive cell volume {:.0f} A^3 was {:.2f}x pass-1's ({:.0f} A^3), a spurious "
"supercell", v2, v2 / v1, v1);
// Still forced: the re-run at the fixed radius is the same pass.
rerun_if_starved(pass2, pass2.pass_decision);
force_rotation_result_.reset();
}
}
@@ -3001,12 +3012,15 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) {
// This pass is the answer whatever it measures - the guard has had its one chance -
// so it must not conclude from its own search merge that it is going to be re-run.
quality_guard_pass1_.reset();
rerun_if_starved_ = true;
auto redo = RunPipeline(observer, /*write_output=*/true, /*geometry_prepass=*/false);
rerun_if_starved_ = false;
redo.post_refine = pass1.post_refine;
redo.pass_number = pass2.pass_count + 1;
redo.pass_count = pass2.pass_count + 1;
redo.pass_decision = fmt::format(
"header geometry re-adopted: the post-refined pass was worse ({})", worse);
rerun_if_starved(redo, redo.pass_decision);
return redo;
}
if (pass2.pass_decision.empty())