Skip to content

[RF] Default RooFit variables to zero bins instead of 100#22705

Open
guitargeek wants to merge 2 commits into
root-project:masterfrom
guitargeek:zero_bins
Open

[RF] Default RooFit variables to zero bins instead of 100#22705
guitargeek wants to merge 2 commits into
root-project:masterfrom
guitargeek:zero_bins

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

A freshly-constructed RooRealVar (and RooErrorVar) used to have a default binning of 100 bins. Since 100 is also a valid user choice, there was no way to tell whether a variable's bin count was deliberately set or just left at the default. This caused redundant "nbins" fields to be written when serializing workspaces to HS3 JSON.

RooAbsRealLValue::getBins() now returns 0 until a binning is explicitly set, so HS3 can write "nbins" only when getBins() != 0 (previously the heuristic was getBins() != 100, which both missed a deliberate 100 and churned on the default).

The historical default is re-injected, via the new constant RooAbsRealLValue::DefaultNBins (100), wherever code legitimately relied on it:

  • unbinned-dataset plotting (RooAbsRealLValue::frame and overloads)
  • generateBinned / direct RooDataHist construction (materialized on the dataset's own variable clone in RooDataHist::initialize, so the user's variable is untouched)
  • createHistogram (RooAbsRealLValue and RooAbsData)
  • the RooHist "P" draw-option path

So plotting, generating binned data and creating histograms from a default-constructed variable behave exactly as before.

Also fixes a latent bug where RooUniformBinning's default constructor left its members uninitialized, and guards RooUniformBinning::setRange against division by zero for a zero-bin binning. ROOT I/O is unaffected: binnings are restored from the persisted object, so only newly-constructed variables default to zero bins.

🤖 Done with the help of AI.

FYI, @Phmonski, who raised the point that it's not possible to detect whether nbins == 100 was just the default or explicitly set by the user, which is a problem for HS3 serialization.

weightInterpolated() took the y-dimension binning from the caller's
variable instead of the one owned by the RooDataHist. These can differ
(e.g. RooHistPdf passes its own observable clones), and since the bin
indexing relies on _idxMult and centralIdx (expressed in the internal
binning), a mismatch yields out-of-range bins and a wrong (often zero)
weight. Use the internal binning, like calcTreeIndex() and
interpolateDim() already do.
A freshly-constructed RooRealVar (and RooErrorVar) used to have a
default binning of 100 bins. Since 100 is also a valid user choice,
there was no way to tell whether a variable's bin count was deliberately
set or just left at the default. This caused redundant "nbins" fields to
be written when serializing workspaces to HS3 JSON.

RooAbsRealLValue::getBins() now returns 0 until a binning is explicitly
set, so HS3 can write "nbins" only when getBins() != 0 (previously the
heuristic was getBins() != 100, which both missed a deliberate 100 and
churned on the default).

The historical default is re-injected, via the new constant
RooAbsRealLValue::DefaultNBins (100), wherever code legitimately relied
on it:

  - unbinned-dataset plotting (RooAbsRealLValue::frame and overloads)
  - generateBinned / direct RooDataHist construction (materialized on
    the dataset's own variable clone in RooDataHist::initialize, so the
    user's variable is untouched)
  - createHistogram (RooAbsRealLValue and RooAbsData)
  - the RooHist "P" draw-option path

So plotting, generating binned data and creating histograms from a
default-constructed variable behave exactly as before.

Also fixes a latent bug where RooUniformBinning's default constructor
left its members uninitialized, and guards RooUniformBinning::setRange
against division by zero for a zero-bin binning. ROOT I/O is unaffected:
binnings are restored from the persisted object, so only
newly-constructed variables default to zero bins.

🤖 Done with the help of AI.
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.

2 participants