Rugnux: bin merged reflections by the cell the completeness denominator uses

A merged reflection's d came from whichever frame first observed it, while the possible
reflections per shell are enumerated from the reference cell, so reflections near a shell edge
fell on the other side from their possible twin and shells read 100.1-100.9 % complete (17 of
210 battery sets). The group's d is now computed from the reference cell before the export, and
the per-hand table reads the group's d instead of an observation's.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D1G8gJVAy6gp1K5Dz3NE5C
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-09-26 13:43:59 +02:00
1 parent 02bc0b7e0e
commit 6b061880d8
1 file changed
+13 -1
@@ -4505,6 +4505,18 @@ RotationScaleMerge::Result RotationScaleMerge::MergeAndStats(int n_groups, bool
if (o.on_ice) a.on_ice = true;
if (!std::isfinite(a.d) && std::isfinite(o.d) && o.d > 0.0f) a.d = o.d;
}
// A merged reflection's d from the cell the completeness denominator is enumerated with, not
// from whichever frame first observed it: a per-frame cell puts a reflection near a shell edge
// on the other side of it from its possible twin, and a shell then reads above 100 %.
if (reference_cell) {
const CrystalLattice latt(*reference_cell);
for (int g = 0; g < n_groups; ++g) {
if (!std::isfinite(acc[g].d)) continue;
const double q = (group_h[g] * latt.Astar() + group_k[g] * latt.Bstar()
+ group_l[g] * latt.Cstar()).Length();
if (q > 1e-6) acc[g].d = static_cast<float>(1.0 / q);
}
}
// ---- Export merged reflections. ----
for (int g = 0; g < n_groups; ++g) {
const auto &a = acc[g];
@@ -4940,7 +4952,7 @@ RotationScaleMerge::Result RotationScaleMerge::MergeAndStats(int n_groups, bool
if (!(sigma_corr > 0.0f) || !std::isfinite(sigma_corr)) continue;
const double w = 1.0 / (static_cast<double>(sigma_corr) * sigma_corr);
AnomAcc &a = anom[cell >> 1];
a.d = o.d;
a.d = acc[o.group].d;
a.swI[cell & 1][anom_half[i]] += w * static_cast<double>(I_corr);
a.sw[cell & 1][anom_half[i]] += w;
a.nh[cell & 1][anom_half[i]]++;