Skip to content

[RF] Let RooGenericPdf/RooFormulaVar declare a piecewise-flat binning#22708

Merged
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:flat_binning
Jul 16, 2026
Merged

[RF] Let RooGenericPdf/RooFormulaVar declare a piecewise-flat binning#22708
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:flat_binning

Conversation

@guitargeek

@guitargeek guitargeek commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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.

@guitargeek guitargeek self-assigned this Jun 25, 2026
@guitargeek
guitargeek requested a review from hageboeck as a code owner June 25, 2026 17:53
@guitargeek guitargeek added new feature in:RooFit experiment Affects an experiment / reported by its software & computimng experts labels Jun 25, 2026
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 15h 14m 19s ⏱️
 3 875 tests  3 869 ✅   0 💤 6 ❌
78 804 runs  78 691 ✅ 107 💤 6 ❌

For more details on these failures, see this check.

Results for commit 8d9620e.

♻️ This comment has been updated with latest results.

Comment thread roofit/roofitcore/src/RooGenericPdf.cxx
Comment thread roofit/roofitcore/test/testGenericPdf.cxx
Comment thread roofit/roofitcore/inc/RooGenericPdf.h Outdated
@guitargeek
guitargeek force-pushed the flat_binning branch 5 times, most recently from f66ab36 to 3bcf799 Compare July 16, 2026 12:28
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.
@will-cern

Copy link
Copy Markdown
Contributor

thanks, looks good!

@guitargeek
guitargeek merged commit 9ea4ec6 into root-project:master Jul 16, 2026
30 of 32 checks passed
@guitargeek
guitargeek deleted the flat_binning branch July 16, 2026 17:18
@guitargeek

Copy link
Copy Markdown
Contributor Author

/backport to 6.40

@root-project-bot

Copy link
Copy Markdown

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

@root-project-bot

Copy link
Copy Markdown

Something went wrong when assigning the PR or setting labels @guitargeek please see the logs

@root-project-bot

Copy link
Copy Markdown

This PR has been backported to branch 6.40: #22838

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

Labels

AI-Assisted experiment Affects an experiment / reported by its software & computimng experts in:RooFit new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants