← Back to Pull requests

[RF][HS3] Identical factors and likelihoods that combine several documents (HS3 #161) #24250

Closed
unknown closed this pull request without merging on Nov 21, 2026 13:36 UTC
View on GitHub
unknown unknown commented on Nov 19, 2026 13:23 UTC
Author

This PR implements the ROOT side of HS3 PR #161 ("Define identity and composition of factors"), which is merged. It builds on #24201.

HS3 #161 defines when two factors are the same and how distributions compose:

  • A combined_dist and an array_dist use union composition: they stand for a set of factors, in which identical factors are contained once, however many times and under whatever names they occur.

  • Two factors of such a set that are not identical must not share a variate.

  • The likelihood is the plain product of its terms: union composition applies within a listed distribution, not across terms.

  • Distributions that share factors, such as the models of a combination with common constraint terms, are joined in a combined_dist, which may contain combined distributions itself, and listed as one term.
  • The main use case is the combination of models from several documents, e.g. two HistFactory models written by RooFit that share a systematic or the luminosity. The constraint terms of each document are collected in its own array distribution, so the arrays of both documents contain identical components for the shared parameters, which have to count once.

    Identical components of array distributions

  • Import: a component of an array distribution over an observable that another array has already created is reused if it is identical: same type, and same fields after applying the defaults, with numbers compared as numbers. RooFit then has one object, and RooAbsPdf::getAllConstraints() finds it once. A component that is not identical is an error.

  • Distinct-variates check: each term of a likelihood is the union of its parts (components of combined distributions, recursively, and of array distributions), in which identical parts count once. A variate that two terms share is an error, also for identical parts. Components of a combined distribution whose sub-data set is missing or empty contribute nothing and are left out. The axes of identical factors may occur in several sub-data sets of the paired combined data set. The error says how to join such distributions.

  • Export: a component of several arrays is written in each of them. An external constraint that is a component of an array is written as the array, which requires all of the array's components to be external constraints.
  • One flat RooSimultaneous and one data set per likelihood

    A ModelConfig has one pdf. Without the name of that pdf in RooFit's metadata (misc.ROOT_internal), the importer took the pdf named simPdf if there was one. That silently dropped the other terms of the likelihood.

    Now the model of a likelihood becomes one RooSimultaneous <analysis>_simPdf:

  • The terms are its channels. Terms that are combined distributions are flattened, recursively, also where a component is a combined distribution itself.

  • Its index has the columns of all combined distributions. A channel has the label "" in a column that doesn't apply to it (HS3 #161 allows relabelling).

  • The column <analysis>_categoryIndex, labelled with the names of the terms, is added if a term is not a combined distribution, or if the channels can't be told apart by their labels. Several columns are a RooSuperCategory.

  • Arrays as channels: RooFit finds a constraint term that several channels contain once, but array distributions that are channels of their own (as RooFit writes them with exportConstraintData, see #24201) would each be evaluated on their data. Array channels of one component type, each with one data entry, are therefore merged into one array with the union of their components, and their entries into one entry. Differing observed values of a shared variate are an error.

  • Data: the data sets of the terms are merged into one data set <analysis>_data with these columns. Combined data sets may now have combined data sets as components.

  • Export: the likelihood is written with one combined distribution and one combined data set. The replaced distributions are marked as helpers, which the export only writes if something else uses them. Skipping helpers is weakly transitive: what only skipped helpers use, e.g. the arrays that were merged, is not written either; a skipped array dissolves into its components, which are then written on their own.

  • Metadata: a pdf named in RooFit's metadata, as in files of ROOT before HS3 0.3, is still used.
  • Changes to code that came with #24201

  • On import, #24201 puts constraint terms back into the channels of a combined distribution, taking the candidates from the other terms of the likelihood. Only terms that can be a constraint term are candidates now: not a combined distribution, and paired with no data, a value given in-line, point data or an unbinned data set of one entry.

  • Its checks of the constraints of HistFactory modifiers descend into nested combined distributions, and a nested combined distribution is not wrapped with constraints like other channels that are no products.

  • Violations of these checks and of distinct variates are reported together.
  • Tests

  • ArrayDistIdenticalComponents: a model and two arrays over x1…x4 and x3…x6, as components of one combined distribution, give the likelihood of the model and one array over x1…x6; RooFit merges the two array channels. The round trip is stable after the first export. The two arrays as auxiliary distributions of the likelihood are rejected (two terms with shared variates), as are a component with another width and identical components with different observed values.

  • MergedHistFactoryDocumentsWithArrayConstraints: two documents written by RooFit with exportConstraintData, with a shared systematic and luminosity, joined in a combined distribution whose components are their combined distributions. Both documents use the same column in one variant and each their own column in the other. The flattened model has one array per type, and its likelihood matches that of a single HistFactory model of both channels. The export has one likelihood with one combined distribution, and the round trip is stable after the first export. The two models as two terms of a likelihood are rejected, as is a combination in which the luminosity uncertainties differ.

  • LikelihoodOfCombinedAndPlainTerms: a combined and a plain distribution in one likelihood.

  • The round trip of the 283 HS3 documents on HEPData still works.
  • Open question

    Without RooFit's metadata, constraint terms that are written as data (exportConstraintData) are channels of the RooSimultaneous rather than external constraints. How RooFit should treat global observables and external constraints in the future is asked in #24251.

    🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: guitargeek Review duration: 2893m
    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 #24250"
    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%