← Back to Pull requests

[RF][HS3] Don't rely on object names in the HistFactory export #24026

Closed
unknown closed this pull request without merging on Nov 11, 2026 07:24 UTC
View on GitHub
unknown unknown commented on Nov 06, 2026 09:46 UTC
Author

[!IMPORTANT]

Rebased onto master after the merge of #23840: the 4 commits of this PR are all that is new.

This Pull request:

Makes the HistFactory exporter of the HS3 I/O independent of the names of the objects in the workspace. Many workspaces were made with old or custom versions of HistFactory, or modified after their creation (e.g. with custom modifiers, which the XML-based HistFactory doesn't support), and still have the structure of a HistFactory model. Their channels should be written as histfactory_dist, not split into primitives, and the model must stay the same.

A new test renames everything in a HistFactory model and changes its modifiers (see below). It found two bugs:

1. Bin width. histfactory_dist implies the division by the bin width, so the exporter doesn't write it as a modifier. It recognised it by the name: every factor of a sample with binWidth in its name was dropped. A normfactor called e.g. signal_binWidth_scale silently disappeared from the model, and a renamed RooBinWidthFunction was written as a custom modifier, so that the import divided by the bin width twice.
2. Formulae with a sum. The exporter decomposes RooFormulaVars that are products into their factors. It split an expression at every top-level , also if the expression is a sum at the top level: 1 + 0.2 k became the factors 1 + 0.2 and k, i.e. 1.2 * k. This doesn't depend on names; the test just happened to use such a formula.

Changes or fixes:

| Commit | Change | Test |
|---|---|---|
| Don't split a sum with a product into factors | A binary + or - at the top level means that the expression is not a product (signs and exponents like 2e-1 are not binary operators). | FormulaWithTopLevelSumIsNotSplit (fails without the fix) |
| Identify bin width factors by their structure | A RooBinWidthFunction that divides by the bin width is identified by its type. The constant inverse bin width of HistFactory before ROOT 6.26 (a constant RooRealVar binWidth_<observables>_<i> in the coefficients of the RooRealSumPdf, value numBins/(max-min)) is identified by its structure: a RooConstVar or constant RooRealVar that is not floating in any snapshot, whose only clients are the RooRealSumPdf or products of the channel, and whose value is the inverse of the volume of the first bin, or of the average bin volume, of one of the histograms of the channel. If its name doesn't contain binWidth, a warning says that it was identified. Identified factors are not written as model parameters either. RooJSONFactoryWSTool::config().identifyLegacyBinWidthFactors = false switches this off; such constants are then written as normfactors. | HS3LegacyBinWidthFactor (ROOT 6.16 reference workspace: original and renamed factors, a factor floating in a snapshot, the switch) |
| Test that the export doesn't depend on names | New test HS3ExportDoesNotDependOnNames: a two-channel HistFactory model (normfactor, normsys, histosys, shapesys, staterror, shapefactor, lumi; bins of width π/10, which is not exactly representable), changed (a custom modifier added, a normsys removed, a constraint swapped for a narrower Gaussian, a second FlexibleInterpVar with a new constrained parameter added, and in one channel the RooBinWidthFunction replaced by the constant inverse bin width of HistFactory before ROOT 6.26, with 7 significant digits as HistFactory wrote it), and every object renamed except the observables, the channel category and the constants (names reversed, so that no prefix or suffix of the HistFactory naming scheme survives; the POI is called signal_binWidth_scale). Checks: both channels are histfactory_dist with the expected modifiers (the renamed legacy bin width is identified by its value, with a warning), the likelihood is the same after the round trip at several parameter points, and the document is stable from the second export on. Without the two fixes, the POI is dropped and the custom modifier is split into wrong factors. | |
| Enable the binned likelihood for imported histfactory_dist | A histfactory_dist is a product of Poisson distributions of the bin counts, which is what RooFit's binned likelihood (BinnedLikelihood attribute of the RooRealSumPdf) computes; binned generation (GenerateBinned) generates bin counts. HistFactory enables both by default, but the importer didn't: they only came back from misc, keyed by the name of the RooRealSumPdf, so they were lost for renamed channels. The importer now enables both for every histfactory_dist. The binned likelihood differs from the event-wise one only by a constant (checked with both evaluation backends, for binned and unbinned data), so only absolute NLL values change, and only for workspaces that didn't have the attribute. | HistFactoryImportEnablesBinnedLikelihood, and the renamed model of HS3ExportDoesNotDependOnNames |

Remaining name dependencies

Found while reading the exporter, not changed here:

  • staterror: a ParamHistFunc is taken as staterror if its name starts with mc_stat_, otherwise as shapefactor. A renamed staterror is therefore written as a shapefactor per sample, with the same parameters and constraints: a valid description of the same likelihood, but without the staterror semantics. Telling them apart by structure (gammas shared by all samples of a channel, constraints derived from the sample errors) is possible but not obviously unambiguous.

  • Global observables: parameters whose name starts with nom_ are not exported as model parameters. Renamed global observables are exported as parameters in addition; harmless.

  • Poisson τ: the τ of a Poisson gamma constraint is found as the constant factor of its mean, with a _tau suffix only as fallback.

  • Channel and sample names are derived by stripping model_, L_x_, _shapes etc.; cosmetic.
  • On the import side, HistFactory objects are created with the usual names, so the misc attributes of a renamed RooRealSumPdf are lost in the first round trip (the binned likelihood is enabled anyway, see the last commit); from the second export on, the document is stable.

    Checklist:

  • tested changes locally

  • updated the docs (if necessary)
  • Tests run (Linux, Ubuntu 26.04, GCC 15.2, RelWithDebInfo, -Droofit=ON -Dtesting=ON): testRooFitHS3 111 → 113 (2 new), testJSONInterface 1, testHistFactory 69 → 71 (2 new), all passing; each commit built and tested on its own. clang-format clean. The commits also apply on top of #24005 and of #24013 with trivial conflicts (new config() fields, includes), and pass there as well (on #24005: testRooFitHS3 128, on #24013: 127; testHistFactory 72 on both). The round-trip tests of the ROOT 6.16 reference workspace in #24005 and #24013 compared absolute NLL values, which change when the binned likelihood is enabled; they now compare the likelihood up to a constant.

    AI assistance: Claude Code (claude-opus-5-5) implemented the changes, the tests and this description under review of the author, following the author's design for the structural identification of the bin width factor. The commits carry Assisted-by: claude-code:claude-opus-5-5.

    🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: guitargeek Review duration: 7057m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #24026"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%