Skip to content

[RF] Generalize boundary finding for RooHistPdf and RooHistFunc - #21969

Merged
guitargeek merged 4 commits into
root-project:masterfrom
guitargeek:issue-13030
Nov 20, 2026
Merged

guitargeek merged 4 commits into
root-project:masterfrom
guitargeek:issue-13030

Conversation

@guitargeek

@guitargeek guitargeek commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

The interface to return bin boundaries and sampling hints for plotting in RooHistPdf and RooHistFunc doesn't consider that the histogram variable might be a transformation of the variable for which the bin boundaries or plot hints are requested.

This commit improves the situation by implementing an algorithm that assumes that plot variable and histogram variable are linearly related, and numerically figures out the inverse transformation for transforming histogram bins to plot bins if needed.

If the transformation is not linear, the RooHistFunc or RooHistPdf won't be correctly plotted either, but linear transformations are very common, even explicitly via the RooLinearVar, and supporting those is already a good improvement in user experience.

Closes #13030.

The plot from the reproducer in the original issue does now look like this:
repro_13030

@github-actions

github-actions Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

Test Results

    22 files      22 suites   3d 11h 28m 35s ⏱️
 3 941 tests  3 941 ✅ 0 💤 0 ❌
77 257 runs  77 257 ✅ 0 💤 0 ❌

Results for commit 89283a2.

♻️ This comment has been updated with latest results.

@dpiparo dpiparo added this to the 6.40.00 milestone Apr 22, 2026
@guitargeek
guitargeek marked this pull request as draft April 24, 2026 07:47
@dpiparo

dpiparo commented May 14, 2026

Copy link
Copy Markdown
Member

Is this PR making it into 6.40 or should this be shifted to 6.40.02?

@guitargeek guitargeek removed this from the 6.40.00 milestone May 14, 2026
@guitargeek

Copy link
Copy Markdown
Contributor Author

Let's aim for 6.40.02, it's not realistic to have this in 6.40 at this point.

@guitargeek
guitargeek force-pushed the issue-13030 branch 3 times, most recently from ccb30df to 75cff41 Compare August 4, 2026 17:05
@dpiparo dpiparo added this to the 6.40.06 milestone Sep 2, 2026
@dpiparo

dpiparo commented Sep 2, 2026

Copy link
Copy Markdown
Member

Now in the 6.40.06 milestone. It would be nice to have it in by then!

The interface to return bin boundaries and sampling hints for plotting
in RooHistPdf and RooHistFunc doesn't consider that the histogram
variable might be a transformation of the variable for which the bin
boundaries or plot hints are requested.

This commit improves the situation by implementing an algorithm that
assumes that plot variable and histogram variable are linearly related,
and numerically figures out the inverse transformation for transforming
histogram bins to plot bins if needed.

Non-linear transformations are not inverted exactly, but linear
transformations are very common, even explicitly via the `RooLinearVar`,
and supporting those is already a good improvement in user experience.
For a non-linear transformation, a warning is now emitted so the user
knows that the bin boundaries are only approximate. The inverse is
deliberately computed arithmetically rather than via the l-value
`setVal()` interface, because inverting a boundary can land outside the
range of the plot observable, which would throw.

Closes root-project#13030.
Cover RooHistFunc, a transformation with negative slope and
plotSamplingHint() for transformed histogram observables. On master,
RooHistFunc throws for a RooLinearVar observable and plotSamplingHint()
returns no hint for a shifted RooHistPdf.

Assisted-by: claude-code:claude-opus-5-5
To map the bin boundaries, histogramBoundariesInPlotObs() sets the plot
observable to probe the transformation and restored it with setVal().
That throws if an outer integral over a wider range had set the
observable outside its default range. Restore it with assign() instead.

Also fix the binBoundaries() documentation, which named RooCurve as a
user (RooCurve uses plotSamplingHint()), and shorten the comments.

Assisted-by: claude-code:claude-opus-5-5
The RooBinIntegrator took the bin boundaries from the integrand only
when it was created, but RooRealIntegral keeps reusing it when the
parameters change. For a RooHistPdf or RooHistFunc of a shifted
observable, the boundaries move with the shift, so the integral was
only right at the shift of its first evaluation. Afterwards, it could
count an edge bin twice.

Get the boundaries for each integral instead. This costs one
binBoundaries() call per integral, which in the RooFit tests and
tutorials is less than 0.3 % of the run time.

Assisted-by: claude-code:claude-opus-5-5
@guitargeek
guitargeek marked this pull request as ready for review November 20, 2026 14:08
@guitargeek

Copy link
Copy Markdown
Contributor Author

Now in the 6.40.06 milestone. It would be nice to have it in by then!

Sorry for the late reply! I have revived the PR now and the issue is fixed.

@guitargeek guitargeek modified the milestones: 6.40.06, 6.42.00 Nov 20, 2026
@dpiparo

dpiparo commented Nov 20, 2026

Copy link
Copy Markdown
Member

ready for backporting and merging then...

@guitargeek
guitargeek merged commit c107cea into root-project:master Nov 20, 2026
33 of 34 checks passed
@guitargeek
guitargeek deleted the issue-13030 branch November 20, 2026 16:14
@guitargeek

Copy link
Copy Markdown
Contributor Author

/backport to 6.42

@root-project-bot

Copy link
Copy Markdown

Preparing to backport PR #21969 to branch 6.42 requested by guitargeek

@root-project-bot

Copy link
Copy Markdown

This PR has been backported to branch 6.42: #24277

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] Plotting shifted RooHistPdfs doesn't go well

3 participants