Skip to content

[RF] Fix RooExtendPdf yield/shape in ranged extended fits - #22989

Merged
guitargeek merged 2 commits into
root-project:masterfrom
guitargeek:issue-22959
Aug 4, 2026
Merged

guitargeek merged 2 commits into
root-project:masterfrom
guitargeek:issue-22959

Conversation

@guitargeek

@guitargeek guitargeek commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

RooExtendPdf is self-normalized, so it delegates both the shape normalization and the extended-term fraction to the wrapped pdf. In a fit over a sub-range, the fit machinery sets the normalization range only on the outer RooExtendPdf; it was never propagated to the wrapped pdf. As a result the wrapped pdf stayed normalized over the full range, which collapsed the fitted yield N to the number of events in the fit range (instead of reinterpreting it to the range requested in the constructor) and biased the shape parameters.

This regressed with the multi-range fit rework in https://github.com/root-project/root/commit fa10523 (v6.28), and is visible in the rf204b_extendedLikelihood_rangedFit tutorial, where the RooExtendPdf fit disagreed with the equivalent RooAddPdf fit.

Propagate the normalization range to the wrapped pdf during graph compilation, mirroring what RooAddPdf does for its components. This is gated on likelihood mode: for a binned chi2 the per-bin predictions must stay normalized over the full range so that the chi2 remains additive across sub-ranges.

Closes #22959.

🤖 Done with the help of AI.

A second commit fixes up minor issues with the comments in the related tutorial.

Note that this doesn't fix the old "legacy" NLL evaluation backend, but this is on its way out anyway.

RooExtendPdf is self-normalized, so it delegates both the shape
normalization and the extended-term fraction to the wrapped pdf. In a
fit over a sub-range, the fit machinery sets the normalization range
only on the outer RooExtendPdf; it was never propagated to the wrapped
pdf. As a result the wrapped pdf stayed normalized over the full range,
which collapsed the fitted yield N to the number of events in the fit
range (instead of reinterpreting it to the range requested in the
constructor) and biased the shape parameters.

This regressed with the multi-range fit rework in fa10523 (v6.28),
and is visible in the rf204b_extendedLikelihood_rangedFit tutorial,
where the RooExtendPdf fit disagreed with the equivalent RooAddPdf fit.

Propagate the normalization range to the wrapped pdf during graph
compilation, mirroring what RooAddPdf does for its components. This is
gated on likelihood mode: for a binned chi2 the per-bin predictions must
stay normalized over the full range so that the chi2 remains additive
across sub-ranges.

Closes root-project#22959.

🤖 Done with the help of AI.
The inline documentation of rf204b_extendedLikelihood_rangedFit had a
frac = integral(Fit range) / integral(Full range) definition that is
the reciprocal of what RooExtendPdf::expectedEvents() actually
computes, and text saying the expected event count is divided by it.
This went unnoticed because the ranged extended fit this tutorial
demonstrates was broken since fa10523 and only fixed by the
preceding commit, so the described numbers were never actually
verified against real output.

Also update the quoted RooAddPdf INFO log line, which was still from
the pre-BatchMode RooAbsOptTestStatistic code path and no longer
matches what fitTo() prints.

Applies to both the C++ and Python versions of the tutorial.
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 19h 38m 45s ⏱️
 3 856 tests  3 856 ✅ 0 💤 0 ❌
78 544 runs  78 544 ✅ 0 💤 0 ❌

Results for commit 1a753a8.

@dpiparo dpiparo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this subtle issue.

@guitargeek
guitargeek merged commit ffeb75c into root-project:master Aug 4, 2026
35 of 42 checks passed
@guitargeek
guitargeek deleted the issue-22959 branch August 4, 2026 06:26
@guitargeek

Copy link
Copy Markdown
Contributor Author

/backport to 6.40

@root-project-bot

Copy link
Copy Markdown

Preparing to backport PR #22989 to branch 6.40 requested by guitargeek

@root-project-bot

Copy link
Copy Markdown

This PR has been backported to branch 6.40: #23000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RF] Bug with RooExtendPdf produces inconsistency in rf204b_extendedLikelihood_rangedFit.C between before 6.26 and after 6.28

3 participants