Skip to content

[HS3] Preserve explicit binnings for RooGenericPdf and RooFormulaVa#22842

Open
Phmonski wants to merge 1 commit into
root-project:masterfrom
Phmonski:feat/hs3-generic-binning
Open

[HS3] Preserve explicit binnings for RooGenericPdf and RooFormulaVa#22842
Phmonski wants to merge 1 commit into
root-project:masterfrom
Phmonski:feat/hs3-generic-binning

Conversation

@Phmonski

Copy link
Copy Markdown
Contributor

Motivation

Following the introduction of explicitly binned RooGenericPdf and RooFormulaVar objects in #22708, their declared binning information was not preserved by HS3 serialization.

Only the formula expression was exported, so an HS3 round trip lost the binning registered through setBinning(). The imported object consequently no longer reported itself as a binned distribution and could not use the intended binned integration path.

Changes

This PR adds optional inline axes key to HS3 generic formulas.

Uniform binnings are represented as:

"axes": [
  {
    "name": "x",
    "min": 0.0,
    "max": 10.0,
    "nbins": 5
  }
]

Non-uniform binnings use explicit edges:

"axes": [
  {
    "name": "x",
    "edges": [0.0, 1.0, 1.5, 3.0]
  }
]

The implementation:

  • Adds a read-only getBinning() accessor to RooGenericPdf and RooFormulaVar.
  • Returns only binnings explicitly registered through setBinning().
  • Refactors binBoundaries() and plotSamplingHint() to use this accessor.
  • Exports axes only when an explicit formula binning exists.
  • Preserves uniform binnings compactly and non-uniform binnings with their complete edge arrays.
  • Imports the axes into a temporary formula object before adding it to the workspace.
  • Calls setBinning(..., false) during import because serialized binnings are treated as trusted declarations, avoiding potentially expensive flatness sampling.
  • Keeps RooFormulaVar export type as generic while continuing to import both generic and generic_function.
  • Reuses a shared internal axis writer for ordinary observable axes and generic-formula axes.

No persistent members or class versions are changed.
JSONFactories_HistFactory.cxx and a few unrelated test lines contain formatting-only changes.

Validation

Imported axes are checked for:

  • A valid sequence and map structure.
  • Unique axis names.
  • A matching direct RooAbsRealLValue dependency.
  • Positive integral nbins.
  • Finite, ordered uniform bounds.
  • At least two strictly increasing explicit edges.
  • No mixing of uniform and explicit-edge representations.

Tests cover:

  • Uniform RooGenericPdf round trips.
  • Uniform RooFormulaVar round trips.
  • Both supported function type aliases.
  • Multiple binned observables.
  • Exact non-uniform boundaries, including boundaries outside the observable's current range.
  • Accessor lookup through same-named observables.
  • Binning removal.
  • Rejection of malformed axes.
  • Generic formulas without explicit binnings remaining unchanged.

The complete GenericPdf test suite and testRooFitHS3 pass.

@cburgard @will-cern

@github-actions

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 15h 30m 48s ⏱️
 3 874 tests  3 874 ✅ 0 💤 0 ❌
78 808 runs  78 808 ✅ 0 💤 0 ❌

Results for commit c63e052.

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