diff --git a/rugnux/ResultReport.cpp b/rugnux/ResultReport.cpp index 552b7380f..f2f76ab82 100644 --- a/rugnux/ResultReport.cpp +++ b/rugnux/ResultReport.cpp @@ -204,9 +204,8 @@ namespace { return o.str(); } - // The finest shell whose CC1/2 still reaches the cut's own target. A fitted resolution finer than - // this was read off a curve that never behaved like a fall-off, and asserting it states a - // resolution the shell table on the same page refutes. + // The finest shell whose CC1/2 still reaches the cut's own target: where the table says the signal + // is, for the completeness quoted beside the written range. double FinestSupportedShell(const MergeStatistics &ms, double target) { double finest = 0.0; for (const auto &sh : ms.shells) @@ -215,6 +214,25 @@ namespace { return finest; // 0.0 = no shell reaches the target at all } + // The finest resolution the shell table supports a fitted crossing at. A shell's CC1/2 is an + // average over the shell, so the crossing sits INSIDE the first shell whose average falls below the + // target, between its d_max and its d_min: a fit anywhere down to that shell's d_min is what the + // table shows, and only a fit finer than it is one the table refutes. Comparing against the last + // shell ABOVE the target instead withheld the number on 68 of 100 battery datasets whose fit sat + // 0.01-0.02 A inside the first sub-target shell. 0.0 when no shell reaches the target; the finest + // shell when none falls below it. + double CrossingShellLimit(const MergeStatistics &ms, double target) { + double finest = 0.0; + for (const auto &sh : ms.shells) { + if (!std::isfinite(sh.cc_half)) + continue; + if (sh.cc_half < target) + return finest == 0.0 ? 0.0 : sh.d_min; + finest = sh.d_min; + } + return finest; + } + // Where CC1/2 climbs back above the cut's target after it has already fallen below it. Below the // target a shell carries no signal the cut would keep, so a shell past that point which // correlates again is noise correlating with noise: the curve is not a fall-off, and no single @@ -619,6 +637,7 @@ ReportDocument BuildReportDocument(const std::string &output_prefix, // than the finest shell that still reaches the target asserts a resolution the shell // table on this very page refutes. const double finest_supported = FinestSupportedShell(ms, cc_target); + const double crossing_limit = CrossingShellLimit(ms, cc_target); const double climbs_back = CCHalfClimbsBackAboveTarget(ms, cc_target); std::string fit_suppressed; // Only where there are shells to judge the fit against; with no table there is no @@ -630,15 +649,15 @@ ReportDocument BuildReportDocument(const std::string &output_prefix, " at {:.2f} A, so this curve is not a fall-off and no one resolution can be" " read off it", cc_target, climbs_back); else if (result.resolution_fit_A) { - if (finest_supported == 0.0) + if (crossing_limit == 0.0) fit_suppressed = fmt::format( "CC1/2 never reaches the cut's target of {:.2f} in any shell, so there is" " no fall-off to fit", cc_target); - else if (*result.resolution_fit_A < finest_supported - 1e-6) + else if (*result.resolution_fit_A < crossing_limit - 1e-6) fit_suppressed = fmt::format( - "the fit reads {:.2f} A, finer than the finest shell whose CC1/2 still" - " reaches {:.2f} ({:.2f} A), so the curve it was read off is not a" - " fall-off", *result.resolution_fit_A, cc_target, finest_supported); + "the fit reads {:.2f} A, finer than the shell where CC1/2 falls below" + " {:.2f} ({:.2f} A), so the curve it was read off is not a fall-off", + *result.resolution_fit_A, cc_target, crossing_limit); else fitted_resolution = *result.resolution_fit_A; } diff --git a/tests/ResultReportTest.cpp b/tests/ResultReportTest.cpp index 5bafc0525..9a246edb8 100644 --- a/tests/ResultReportTest.cpp +++ b/tests/ResultReportTest.cpp @@ -628,6 +628,13 @@ TEST_CASE("ResultReport_FittedResolutionSuppressed", "[Diagnostics]") { CHECK(RenderResultReport("p", "in.h5", x, result).find("\nFITTED_RESOLUTION= 0.95\n") != std::string::npos); + // A shell's CC1/2 is its average, so the crossing lies inside the first shell below the target: + // a fit there is what the table shows, not something it refutes. + result.resolution_fit_A = 0.85; + CHECK(RenderResultReport("p", "in.h5", x, result).find("\nFITTED_RESOLUTION= 0.85\n") + != std::string::npos); + result.resolution_fit_A = 0.95; + // CC1/2 that drops through the target and climbs back above it is not a fall-off either, and the // finest shell reaching the target is then noise correlating with noise - so a fit the test above // accepts must still be suppressed, and the user told so in the default report.