[RF] Let RooGenericPdf/RooFormulaVar declare a piecewise-flat binning#22708
Merged
Conversation
Test Results 23 files 23 suites 3d 15h 14m 19s ⏱️ For more details on these failures, see this check. Results for commit 8d9620e. ♻️ This comment has been updated with latest results. |
will-cern
reviewed
Jun 26, 2026
will-cern
reviewed
Jun 26, 2026
will-cern
reviewed
Jun 26, 2026
guitargeek
force-pushed
the
flat_binning
branch
5 times, most recently
from
July 16, 2026 12:28
f66ab36 to
3bcf799
Compare
A RooGenericPdf or RooFormulaVar that is constant within bins of an
observable (a step function) was always integrated with the generic
adaptive numeric integrator, which is needlessly expensive: for a flat
distribution the integral is just the sum of each bin's value times its
width.
Add RooGenericPdf::setBinning() and RooFormulaVar::setBinning(),
which take a RooAbsBinning for an observable and declare the function to be
flat within those bins. Once set:
* isBinnedDistribution() reports the observable as binned, so
RooRealIntegral selects the fast RooBinIntegrator;
* binBoundaries() and plotSamplingHint() expose the bins so that
integration covers exactly the range and plotting draws crisp steps.
A binning can be registered for several observables (e.g. for a
multi-dimensional flat distribution). By default the function is sampled
inside each bin to verify that it really is flat, and the binning is
rejected with an error otherwise; pass checkFlatness=false to skip this.
The binnings are stored in a std::map keyed by the observable's index in
the internal variable list, so they survive renaming of a variable or a
server redirection, and a RooUniformBinning keeps the storage compact even
for many bins. Lookups resolve the observable by name, so a same-named
stand-in (e.g. one read back separately from a file) is accepted too.
The shared flatness check and bin-boundary helpers live in RooHelpers.
The persistent schema version of both classes is bumped to 2.
dpiparo
approved these changes
Jul 16, 2026
Contributor
|
thanks, looks good! |
Contributor
Author
|
/backport to 6.40 |
|
Preparing to backport PR #22708 to branch 6.40 requested by guitargeek |
|
Something went wrong when assigning the PR or setting labels @guitargeek please see the logs |
|
This PR has been backported to branch 6.40: #22838 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A RooGenericPdf or RooFormulaVar that is constant within bins of an
observable (a step function) was always integrated with the generic
adaptive numeric integrator, which is needlessly expensive: for a flat
distribution the integral is just the sum of each bin's value times its
width.
Add RooGenericPdf::setBinning() and RooFormulaVar::setBinning(),
which take a RooAbsBinning for an observable and declare the function to be
flat within those bins. Once set:
RooRealIntegral selects the fast RooBinIntegrator;
integration covers exactly the range and plotting draws crisp steps.
A binning can be registered for several observables (e.g. for a
multi-dimensional flat distribution). By default the function is sampled
inside each bin to verify that it really is flat, and the binning is
rejected with an error otherwise; pass checkFlatness=false to skip this.
The binnings are stored in a std::map keyed by the observable's index in
the internal variable list, so they survive renaming of a variable or a
server redirection, and a RooUniformBinning keeps the storage compact even
for many bins. Lookups resolve the observable by name, so a same-named
stand-in (e.g. one read back separately from a file) is accepted too.
The shared flatness check and bin-boundary helpers live in RooHelpers.
The persistent schema version of both classes is bumped to 2.