Skip to content

[RF] Zero out negative bins in RooHistPdf for consistent normalization - #23103

Open
guitargeek wants to merge 1 commit into
root-project:masterfrom
guitargeek:histpdf-clamp-negative-bins
Open

[RF] Zero out negative bins in RooHistPdf for consistent normalization#23103
guitargeek wants to merge 1 commit into
root-project:masterfrom
guitargeek:histpdf-clamp-negative-bins

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

A RooHistPdf clamps negative bin contents to zero when evaluating, but its normalization integral was based on the plain sum of the bin weights, including the negative ones. A histogram with negative bins therefore yielded a pdf that did not integrate to unity, silently biasing in particular the yields of extended fits: even an Asimov fit with a model identical to the generating pdf did not close.

Now, if the input histogram contains bins with negative content, these are set to zero in an internally-owned clone of the histogram that is used instead, with a warning. This makes the pdf value and its normalization consistent, restoring exact closure. The input histogram is not modified, and bin errors are preserved.

The RooHistPdf constructed by RooAbsCachedPdf implementations like RooFFTConvPdf is unaffected, because the cache histogram is still empty at construction time and only filled (in place) afterwards.

Fixes ROOT-10825.

🤖 Done with the help of AI

Comment thread roofit/roofitcore/src/RooHistPdf.cxx Outdated
for (std::size_t i = 0; i < nBins; ++i) {
if (dh->weight(i) < 0.) {
// Keep the bin error, which still quantifies the statistical
// uncertainty of the original bin content estimate.

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.

While I agree on this statement, I don't fully get why we need to preserve this uncertainty: can an example be made of a case where this quantity is needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Very good question! As far as I remember, there is no place in RooFit where we need to get the weight error for a RooHistPdf.

However, there is a public interface of the RooHistPdf to get the underlying RooDataHist, so in principle users could rely on the uncertainties being present in the RooDataHist. I could think of a usecase: if you'd like to get out the original statistical uncertainty of an MC template, for example to reason if the sub-zero value could be a statistical fluctuation. A bit of a constructed example though. In any case, I'll add a comment!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added 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 a lot for the clarification. The example is maybe a niche one, but it's a use case.

A RooHistPdf clamps negative bin contents to zero when evaluating, but
its normalization integral was based on the plain sum of the bin
weights, including the negative ones. A histogram with negative bins
therefore yielded a pdf that did not integrate to unity, silently
biasing in particular the yields of extended fits: even an Asimov fit
with a model identical to the generating pdf did not close.

Now, if the input histogram contains bins with negative content, these
are set to zero in an internally-owned clone of the histogram that is
used instead, with a warning. This makes the pdf value and its
normalization consistent, restoring exact closure. The input histogram
is not modified, and bin errors are preserved.

The RooHistPdf constructed by RooAbsCachedPdf implementations like
RooFFTConvPdf is unaffected, because the cache histogram is still empty
at construction time and only filled (in place) afterwards.

Fixes ROOT-10825.

🤖 Done with the help of AI
@guitargeek
guitargeek force-pushed the histpdf-clamp-negative-bins branch from d2d9854 to 773da6b Compare August 19, 2026 11:57
@github-actions

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 16h 32m 35s ⏱️
 3 860 tests  3 858 ✅ 0 💤 2 ❌
78 638 runs  78 633 ✅ 2 💤 3 ❌

For more details on these failures, see this check.

Results for commit 773da6b.

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.

2 participants