diff --git a/image_analysis/scale_merge/Merge.cpp b/image_analysis/scale_merge/Merge.cpp index 97c2232f2..713daef36 100644 --- a/image_analysis/scale_merge/Merge.cpp +++ b/image_analysis/scale_merge/Merge.cpp @@ -39,21 +39,6 @@ namespace { return static_cast(z & 1ULL); } - // The weight of a reflection in CC1/2 and R_split, as the rotation merge gives it (MergedReflection:: - // cc_weight): the counting precision its two half-sets would have had with every observation at one - // common scale, over the precision they have. An observation scaled up by image_scale_corr = 1/(G p) - // carries that factor squared in counting variance, so a half of n observations has a variance of 1/n - // at a common scale and 1/q, q = sum(1/corr^2), as measured. Nothing intensity-dependent, and no credit - // for multiplicity: only how far the observations were scaled up. Without it the reflections measured a - // handful of times on weak frames or at low partiality - at the beam stop's edge and in the detector's - // corners, a few in a hundred - hold half-set means whose scaled-up noise exceeds the whole signal - // variance of the strongest shell, and the plain Pearson CC1/2 and R_split are theirs. - double HalfSetWeight(const size_t n[2], const double q[2]) { - if (n[0] == 0 || n[1] == 0) - return 1.0; - return (1.0 / n[0] + 1.0 / n[1]) / (1.0 / q[0] + 1.0 / q[1]); - } - // Calls reduce(i, out) for the images in parallel, a block of them at a time, and then consume(i, out) // for each image of the block in image order - the order that every floating-point sum, every // half-set choice and every hash-map insertion of the merge depends on. The result is therefore the @@ -149,7 +134,6 @@ size_t MergeOnTheFly::Contributions(const IntegrationOutcome &outcome, std::vect .w = w, .wI = w * I_corr, .d = r.d, - .inv_corr2 = 1.0f / (r.image_scale_corr * r.image_scale_corr), .on_ice_ring = r.on_ice_ring }); } @@ -218,11 +202,8 @@ void MergeOnTheFly::Accumulate(const std::vector &contributions, i it->second.sum_wI_half[half] += c.wI; it->second.sum_w_half[half] += c.w; it->second.n_half[half]++; - it->second.q_half[half] += c.inv_corr2; it->second.sum_wI_split[prefer] += c.wI; it->second.sum_w_split[prefer] += c.w; - it->second.n_split[prefer]++; - it->second.q_split[prefer] += c.inv_corr2; if (c.on_ice_ring) it->second.on_ice_ring = true; @@ -822,23 +803,16 @@ MergeStatistics MergeOnTheFly::MergeStats(const std::vector &m } } - // The statistics weigh each reflection by HalfSetWeight; the resolution cutoff, which reads - // MergedReflection::cc_weight, does not - on a photon-counting set the weighted fall-off - // moves the cut outwards, past where the plain one finds the data useful to refinement. - const auto it = accumulator.find(generator(m).pack()); - const bool counted = it != accumulator.end(); - const double w_half = counted ? HalfSetWeight(it->second.n_half, it->second.q_half) : 1.0; - const double w_split = counted ? HalfSetWeight(it->second.n_split, it->second.q_split) : 1.0; if (std::isfinite(m.I_half[0]) && std::isfinite(m.I_half[1])) { - acc[s].cc_half.Add(m.I_half[0], m.I_half[1], w_half); - cc_half_overall.Add(m.I_half[0], m.I_half[1], w_half); + acc[s].cc_half.Add(m.I_half[0], m.I_half[1]); + cc_half_overall.Add(m.I_half[0], m.I_half[1]); } if (std::isfinite(m.I_split[0]) && std::isfinite(m.I_split[1])) { for (auto *a: {&acc[s], &split_overall}) { - a->cc_split.Add(m.I_split[0], m.I_split[1], w_split); - a->split_abs_diff += w_split * std::fabs(m.I_split[0] - m.I_split[1]); - a->split_sum += w_split * 0.5 * (m.I_split[0] + m.I_split[1]); + a->cc_split.Add(m.I_split[0], m.I_split[1]); + a->split_abs_diff += std::fabs(m.I_split[0] - m.I_split[1]); + a->split_sum += 0.5 * (m.I_split[0] + m.I_split[1]); a->split_pairs++; } } diff --git a/image_analysis/scale_merge/Merge.h b/image_analysis/scale_merge/Merge.h index 83a625ed2..8f4206ed3 100644 --- a/image_analysis/scale_merge/Merge.h +++ b/image_analysis/scale_merge/Merge.h @@ -253,12 +253,9 @@ struct MergeAccum { double sum_wI_half[2] = {0.0, 0.0}; double sum_w_half[2] = {0.0, 0.0}; size_t n_half[2] = {0, 0}; - double q_half[2] = {0.0, 0.0}; // sum of 1 / image_scale_corr^2 over the half (HalfSetWeight) // The same sums with each frame's observations kept whole in the frame's half (R_split). double sum_wI_split[2] = {0.0, 0.0}; double sum_w_split[2] = {0.0, 0.0}; - size_t n_split[2] = {0, 0}; - double q_split[2] = {0.0, 0.0}; }; // XDS's error-model convention (Diederichs, Acta Cryst. D66 (2010) 733) is sigma^2 = a*(sigma0^2 + @@ -384,7 +381,6 @@ class MergeOnTheFly { uint64_t key; int32_t h, k, l; // the reflection's own index, as the accumulator records it float w, wI, d; - float inv_corr2; // 1 / image_scale_corr^2: how far the observation was scaled up (HalfSetWeight) bool on_ice_ring; }; // The observations of one image that reach the merge; returns how many the outlier test dropped. diff --git a/tests/MergeScaleTest.cpp b/tests/MergeScaleTest.cpp index ff3778481..e9ae92b10 100644 --- a/tests/MergeScaleTest.cpp +++ b/tests/MergeScaleTest.cpp @@ -1269,49 +1269,6 @@ TEST_CASE("MergeOnTheFly_StillsRejectsAGrainAmongPartials") { CHECK(merge.RejectedCount() == 1); } -// A reflection measured twice, on observations scaled up 300-fold (weak frames, low partiality), holds two -// half-set means whose noise dwarfs the spread of every well-measured reflection; CC1/2 and R_split weigh -// it by how far its observations were scaled up, so it does not decide them. -TEST_CASE("MergeOnTheFly_StillsCCHalfNotTakenByScaledUpPairs") { - DiffractionExperiment x; - x.SetSpaceGroup(gemmi::get_spacegroup_by_name("P 1")); - REQUIRE(!x.IsRotationIndexing()); - - std::mt19937 rng(11); - std::normal_distribution gauss(0.0f, 1.0f); - std::vector outcomes(40); - for (size_t i = 0; i < outcomes.size(); ++i) { - for (int h = 1; h <= 60; ++h) { - Reflection r{}; - r.h = h; r.k = 1; r.l = 0; - r.d = 2.0f + 0.01f * static_cast(h); - r.I = 100.0f * static_cast(h % 13 + 1) + 10.0f * gauss(rng); - r.sigma = 10.0f; - r.prescaling_corr = 1.0f; - r.partiality = 1.0f; - r.image_scale_corr = 1.0f; - outcomes[i].reflections.push_back(r); - } - if (i < 2) { - Reflection r{}; - r.h = 1; r.k = 2; r.l = 0; - r.d = 2.3f; - r.I = i == 0 ? 50.0f : -50.0f; - r.sigma = 30.0f; - r.prescaling_corr = 1.0f; - r.partiality = 1.0f; - r.image_scale_corr = 300.0f; - outcomes[i].reflections.push_back(r); - } - } - MergeOnTheFly merge(x); - merge.AddImages(outcomes); - const auto merged = merge.ExportIntensities(); - const auto stats = merge.MergeStats(merged, outcomes); - CHECK(stats.overall.cc_half > 0.99); - CHECK(stats.overall.r_split < 0.05); -} - // The capture term widens the sigma of a partial by (c (1 - p) ): a partial merges at a lower weight // than a full of the same intensity, and not at all differently with c = 0. TEST_CASE("MergeOnTheFly_CaptureTermDownweightsPartials") {