Skip to content

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

Merged
guitargeek merged 1 commit into
root-project:v6-40-00-patchesfrom
root-project-bot:BP_6.40_pull_22708
Jul 16, 2026
Merged

[6.40] [RF] Let RooGenericPdf/RooFormulaVar declare a piecewise-flat binning#22838
guitargeek merged 1 commit into
root-project:v6-40-00-patchesfrom
root-project-bot:BP_6.40_pull_22708

Conversation

@root-project-bot

Copy link
Copy Markdown

Backport of #22708, requested by @guitargeek.

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.

(cherry picked from commit 9ea4ec6)
@guitargeek
guitargeek merged commit 0a25f80 into root-project:v6-40-00-patches Jul 16, 2026
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants