[RF][HS3] Don't rely on object names in the HistFactory export #24026
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
guitargeek
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
custommodifiers, which the XML-based HistFactory doesn't support), and still have the structure of a HistFactory model. Their channels should be written ashistfactory_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_distimplies 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 withbinWidthin its name was dropped. A normfactor called e.g.signal_binWidth_scalesilently disappeared from the model, and a renamedRooBinWidthFunctionwas written as acustommodifier, 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 kbecame the factors1 + 0.2andk, 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 like2e-1are not binary operators). |FormulaWithTopLevelSumIsNotSplit(fails without the fix) || Identify bin width factors by their structure | A
RooBinWidthFunctionthat divides by the bin width is identified by its type. The constant inverse bin width of HistFactory before ROOT 6.26 (a constantRooRealVarbinWidth_<observables>_<i>in the coefficients of theRooRealSumPdf, valuenumBins/(max-min)) is identified by its structure: aRooConstVaror constantRooRealVarthat is not floating in any snapshot, whose only clients are theRooRealSumPdfor 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 containbinWidth, a warning says that it was identified. Identified factors are not written as model parameters either.RooJSONFactoryWSTool::config().identifyLegacyBinWidthFactors = falseswitches 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 secondFlexibleInterpVarwith a new constrained parameter added, and in one channel theRooBinWidthFunctionreplaced 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 calledsignal_binWidth_scale). Checks: both channels arehistfactory_distwith 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| Ahistfactory_distis a product of Poisson distributions of the bin counts, which is what RooFit's binned likelihood (BinnedLikelihoodattribute of theRooRealSumPdf) computes; binned generation (GenerateBinned) generates bin counts. HistFactory enables both by default, but the importer didn't: they only came back frommisc, keyed by the name of theRooRealSumPdf, so they were lost for renamed channels. The importer now enables both for everyhistfactory_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 ofHS3ExportDoesNotDependOnNames|Remaining name dependencies
Found while reading the exporter, not changed here:
ParamHistFuncis taken asstaterrorif its name starts withmc_stat_, otherwise asshapefactor. A renamed staterror is therefore written as ashapefactorper 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.nom_are not exported as model parameters. Renamed global observables are exported as parameters in addition; harmless._tausuffix only as fallback.model_,L_x_,_shapesetc.; cosmetic.On the import side, HistFactory objects are created with the usual names, so the
miscattributes of a renamedRooRealSumPdfare 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:
Tests run (Linux, Ubuntu 26.04, GCC 15.2, RelWithDebInfo,
-Droofit=ON -Dtesting=ON):testRooFitHS3111 → 113 (2 new),testJSONInterface1,testHistFactory69 → 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 (newconfig()fields, includes), and pass there as well (on #24005:testRooFitHS3128, on #24013: 127;testHistFactory72 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