diff --git a/rugnux/Rugnux.cpp b/rugnux/Rugnux.cpp index 17ac8a819..f5a5a3ef1 100644 --- a/rugnux/Rugnux.cpp +++ b/rugnux/Rugnux.cpp @@ -3334,10 +3334,42 @@ ProcessResult Rugnux::RunPipeline(RugnuxObserver *observer, bool write_output, b // the run died; with the ladder's lean seed the measured centre indexes 60/60, and // the run then indexes every frame of the sweep and merges to the deposited // resolution. So ask the ladder here too, before giving the centre up. + // + // The depth is asked at BOTH centres, and the centre moves only if it is the + // centre that paid. A lean rung at the measured centre scored against the whole + // spot list at the file's changes two things at once, and the count cannot say + // which of them the gain came from - the same reason a trial centre is scored on + // its own spots at all. Measured on one crystal: the measured centre's ladder + // reached 40/60 on a FIVE-fold axis harmonic while the file's own centre reached + // 49/60 on the deposited cell, and the run moved the centre, shipped the + // supercell, and skipped the beam-centre walk that would have found the crystal's + // own. An exact tie keeps the file's centre: nothing then says the centre is wrong. bool lean = false; + bool deeper_at_home = false; if (!measured_indexes) { - if (auto l = first_pass_ladder(alt.score, 1, majority + 1)) { - alt = *l; + const FirstPassState before = committed; + restore_beam_center(header_x, header_y); + const auto home = first_pass_ladder(best.score, 1, majority + 1); + const FirstPassState home_state = committed; + committed = before; + apply_state(committed); + try_beam_center(measured_x, measured_y); + const auto away = first_pass_ladder(alt.score, 1, majority + 1); + if (home && (!away || home->score >= away->score)) { + committed = home_state; + restore_beam_center(header_x, header_y); + apply_state(committed); + best = *home; + deeper_at_home = true; + logger.Warning("Beam centre check: reading less of each frame takes the " + "file's centre to {}/{} validation frames against {}/{} at " + "the measured centre {:.2f} px away - it is how deep this " + "run was reading and not the centre, so the centre stays", + home->score, static_cast(validation.size()), + away ? away->score : 0, + static_cast(validation.size()), moved); + } else if (away) { + alt = *away; measured_indexes = true; lean = true; } @@ -3361,7 +3393,7 @@ ProcessResult Rugnux::RunPipeline(RugnuxObserver *observer, bool write_output, b static_cast(validation.size()), measured_x, measured_y, alt.score, static_cast(validation.size())); best = alt; - } else { + } else if (!deeper_at_home) { // Nothing worked. Put the file's centre back, so the ladder below searches // around the value the run started with rather than around a fit that has just // been tested and found no better - and so a run that fails for some other