Skip to content

[RF][HS3] Array distributions and HistFactory constraint terms (HS3 #109, #124, #152; depends on #24005) - #24013

Merged
guitargeek merged 13 commits into
root-project:masterfrom
cburgard:hs3-array-dist
Nov 17, 2026
Merged

guitargeek merged 13 commits into
root-project:masterfrom
cburgard:hs3-array-dist

Conversation

@cburgard

@cburgard cburgard commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Important

Depends on #24005 (#24001, below it, is merged). This branch is stacked on it: please review only the last 13 commits. It was moved onto #24005 so that it uses the check for distinct variates of #24005 (section 8 there) instead of a second implementation. HS3 PRs #109, #124 and #152 (implemented by the last commit) are merged. It will be rebased when the PR below it is merged. The last four commits follow the review (sections 7 to 10).

Rebased onto master after 36821748060 ("Import and export through a typed representation of HS3 documents"). Where the commits conflicted with it, they were re-implemented on the typed HS3Document (parser, validator, writer) instead of the removed code; the messages of these commits say how ("Ported onto the typed HS3 document: …"). Master now lists the constraint terms of HistFactory channels that no modifier names in aux_distributions itself, so that part was dropped here; this PR adds the terms that modifiers name (e.g. the arrays) after the external constraints. The test FormulaNormSysConstraint (added in #23996) is adapted: the constraint is now written into the array distribution of its type, and its name after the round trip depends on that grouping, so the test checks that the parameter is still constrained by a Gaussian. Likewise, HistFactoryShapeFactor (added in #23840) expects the constrained gamma to name the array distribution. Since then also rebased onto the removal of the legacy evaluation backend from master, which leaves 44 instead of 60 tests in testHistFactory, and the [after HS3 #…] tags were dropped from the commit subjects, since the HS3 PRs are merged.

This Pull request:

Implements array_dist from HS3 PR #109 in RooFit's HS3 import and export, and uses it for the constraint terms of HistFactory models, which are also listed in the likelihood from now on.

An array_dist is a product of one-dimensional distributions of one type (component_type), each over its own observable x, with the parameters given per component or in default_parameters. It is the form that is to replace barlow_beeston_lite_poisson_constraint_dist as the recommended staterror constraint of #124 (the HistFactory appendix still recommends BB-lite after #109 and #124; switching the recommendation and deprecating BB-lite is left to a later HS3 PR), and the form of the HS3 appendix on auxiliary measurements (one array of constraint terms paired with one data set of observed values).

RooFit gets no dedicated class for it: an array is split into one pdf per component, and a tagged RooProdPdf records the grouping. A vectorized implementation is left for later.

Changes or fixes:

1. Import of array_dist

What How
Components One pdf per component through the importer of the component type (RooPoisson, RooGaussian, RooLognormal), with default_parameters filled in where a component omits a parameter. Numbers and names may be mixed. Named after the observable: <x>_constraint.
The array A RooProdPdf named after the array, with the attribute hs3_array_dist, so that the array is written back as array_dist.
Supported types poisson_dist, poisson_continuous_dist (section 6), gaussian_dist, lognormal_dist; anything else is an explicit error.
Validation Errors for duplicate or numeric observables, x in default_parameters, empty components, and parameters that depend on an observable of the array (directly or through a function).

An array that no HistFactory modifier references, paired with a one-entry unbinned data set in a likelihood (the appendix form), gives the expected likelihood: one term per component.

2. Export of array_dist

A tagged RooProdPdf (imported, or built by hand) is written as array_dist: one component per factor with the fields of the standalone distribution, a field with the same value in every component once in default_parameters. The observable of a component has to be named, and no two components may share it. The tag is not written as an attribute; it is restored from the type on import.

New: RooJSONFactoryWSTool::exportAsArrayComponent(). The components are registered while the objects that use them are exported, and the arrays are written after all other objects, so that the position of an array in the document does not depend on when its components were registered (the HistFactory channels are exported before the arrays they reference, and a re-export must give the same document).

HistFactory builds its Gaussian constraints with the parameter as x and the global observable as mean, a long-known oddity. The HistFactory exporter records for every constraint which side is the observable (the one that does not depend on the modifier parameter, also for constant parameters such as Lumi), and Gaussians are written with the observable as x (the Gaussian is symmetric in the two), both as array components and as standalone gaussian_dist. Re-imported workspaces therefore have the usual orientation, and the data pairing of section 4 refers to the observable. Gaussians with a number as mean keep the parameter as x, there is nothing to swap with.

3. HistFactory import

A modifier may name an array_dist in constraints. The importer picks the component that depends on the parameter (directly or through a function, e.g. the product of a gamma and its τ) out of the array; no or several matching components is an error. A constraint shared by several channels is one object in all of them, so it is counted once, as with individually named constraints. Components of an array that no parameter uses are reported with a warning at the end of the import, since by the standard the whole array enters the likelihood.

4. HistFactory export

What How
Grouping One array_dist per constraint type and top-level pdf: <toplevel>_poisson_continuous_constraints, <toplevel>_gaussian_constraints, <toplevel>_lognormal_constraints. The modifiers name the array for each constrained parameter ("constraints": ["simPdf_poisson_continuous_constraints", "simPdf_poisson_continuous_constraints"]). A constraint shared by several channels is one component. A constraint that already belongs to an array (imported document) stays in that array.
Order Channels, samples and modifiers in the order they are written; the gammas of staterror and shapesys in bin order.
Not grouped Constraints that cannot be components: a number as observable (as in rf515_hfJSON.json), a RooLognormal with the transformed parametrization. Constraints that an object other than a HistFactory channel or an array uses, e.g. a product_dist in another channel, since that object refers to the constraint by its own name. They are written on their own as before. The decision depends only on the workspace, not on the order of the export; an object that still refers to an array component by its own name makes the export fail instead of leaving a dangling reference.
Likelihood The constraint terms of the channels of a model are listed in its likelihood: by default in aux_distributions (observed values as constant parameters, the global observables), or with config().exportConstraintData = true in distributions, each paired with a generated data set <term>_data (unbinned, one axis per observable, one entry) for terms whose observables are global observables of the ModelConfig. Constraint terms not attached to any modifier parameter are listed as well, as on master.
Opt-out config().exportArrayDist = false: no array_dist is written at all. HistFactory constraints are named individually as before, a tagged product is a plain product_dist.

On import, a term listed in the likelihood that is a constraint of one of the listed HistFactory distributions is not added again (as external constraint or as a channel); its data set sets the observed values, keeps them constant, puts them into the global observables of the ModelConfig, and is not imported into the workspace.

The normfactor export now finds the constraint of a parameter like the other modifiers, independently of which side of a Gaussian the parameter is. For all modifiers, the constraint of a parameter is looked for first among the constraint terms of the channel (the factors of its product besides the RooRealSumPdf), and only then among the clients of the parameter. Before, any RooPoisson, RooGaussian or RooLognormal depending on the parameter could be taken, e.g. a Gaussian with the parameter as mean in another channel, depending on the order of the clients (a bug that is also on master).

5. Distinct variates

The terms of a likelihood must have distinct variates. The check, the deduplication of constraints that are both a factor of a channel and a term of the likelihood, and the override config().allowExportSharedVariates are in #24005 (section 8 there), shared with the components of a combined_dist. The last commit here adds the variates of an array_dist, the x of its components, so that a term that shares an observable with an array is rejected like any other. The case reported in the review, a constraint shared by a HistFactory channel and a product_dist, is such a shared variate: as an HS3 0.3 document it is rejected, and from a RooFit model it is written with the constraint once.

6. Discrete and continuous Poisson distributions (HS3 #152)

HS3 PR #152 (merged) splits the Poisson distribution into the discrete poisson_dist and the poisson_continuous_dist, which ROOT distinguished so far by its own key integer on poisson_dist. The staterror and shapesys constraints of HistFactory are continuous Poisson distributions, so this is needed for the arrays above.

Export A RooPoisson with noRounding is written as poisson_continuous_dist, otherwise as poisson_dist; the key integer is no longer written, on its own or in an array_dist.
Import poisson_continuous_dist is a RooPoisson with noRounding. In documents before HS3 0.3, "integer": false on a poisson_dist is still the continuous form, "integer": true or no key the discrete form, as #152 recommends. From HS3 0.3 on, and on poisson_continuous_dist, the key integer is an error.
array_dist The component type decides between the two. The default "integer": false that made poisson_dist components continuous is dropped.

rf515_hfJSON.json uses poisson_continuous_dist.

7. One source for the constraint terms of the likelihood

#24005 (section 12 there) writes the constraints that RooFit finds in the channels (RooAbsPdf::getAllConstraints()) as terms of the likelihood. The constraint terms of HistFactory channels are now listed with the same logic: the constraints that RooFit finds in a channel, under the names under which they are written (the array_dist that holds a constraint, or the name of the constraint). One mechanism decides which constraints the likelihood lists, for HistFactory channels as for ordinary products, so a constraint shared by a HistFactory channel and a product_dist (section 5) is no special case either.

The HistFactory exporter still records the constraint terms that it writes for a channel (those that the modifiers name and those that no modifier names). This list is now a cross-check: if it differs from what RooFit finds, a constraint would be missing from the likelihood or be in it without being written, and the export fails with an error that names both lists. The terms are listed in the order of that list, which comes from the document, so round trips stay stable. Without observables (a ModelConfig whose observables are not set), RooFit can't tell constraints from other pdfs; then the list of the HistFactory exporter is used, as before.

The documents written for HistFactory models are unchanged: all existing tests pass without changes, so RooFit finds exactly the constraints that the HistFactory exporter writes in all of them.

8. Fix: a constraint that a ModelConfig names is not collected into an array

A constraint of a HistFactory modifier that is also an external constraint of a ModelConfig was collected into an array, but the likelihood still listed it under its own name in aux_distributions. The export succeeded with a reference to a distribution that was not written, and the document could not be read back (reported in the review). A ModelConfig that has the constraint as an external constraint refers to it by name, like an ordinary product, so the constraint is now written on its own (section 4, "Not grouped"). Test: HistFactoryConstraintAlsoExternal (export with arrays, no dangling reference, same NLL after the round trip).

9. exportConstraintData for all constraint terms

With config().exportConstraintData, a constraint term of the likelihood is written in distributions, paired with a data set of one entry that holds the observed values (section 4). With section 7, this also applies to the constraints of ordinary products, but the import only recognised such a term if it was part of a HistFactory channel: otherwise the term was missing from the likelihood after the import, and its data set was imported as an ordinary data set. On import, a term of the likelihood that is not part of the pdf of the ModelConfig (if the document names it, and it is a term of the likelihood) and is paired with a data set of one entry is now an external constraint of the ModelConfig; as for HistFactory constraints, the data set sets the observed values (constant global observables) and is not imported. The external constraints of a ModelConfig are now written like the other constraint terms, also paired with data with the option; before, they were always listed in aux_distributions. So the likelihood is written in the same way after a round trip, in which the constraints of products become external constraints. Test: ConstraintDataOfProductConstraints (with and without the option: same NLL, external constraint, global observable, no extra data set, same likelihood after the round trip, stable document).

10. Fix: constraint terms of renamed HistFactory channels

With renameCombinedObservables of #24005, the components of a RooSimultaneous are written as renamed clones. The constraint terms of section 7 were looked for in the original components, and the terms that the HistFactory exporter records were looked up under the original names, so a renamed HistFactory channel was treated as an ordinary product and its constraints were listed under their own names. With arrays, such a constraint is written as an array component, not on its own, so the likelihood referred to a distribution that is not written, and the document could not be read back (reported in the review). Both now use the channels as they are written. Test: ArrayConstraintTermsOfRenamedChannels (with and without arrays: the same constraint terms as without renaming, no dangling reference, same NLL after the round trip).

Behaviour changes users may notice

  • RooFit's HistFactory export changes for every constrained modifier: constraints names one array per type instead of one distribution per parameter, the arrays stand at the end of distributions, and the likelihood lists them in aux_distributions. Consumers of these documents need array_dist (HS3 0.3). config().exportArrayDist = false restores the previous form of the constraints.
  • After an HS3 round trip, the constraint pdfs of a HistFactory workspace are named after their observable (nom_gamma_stat_channel1_bin_0_constraint, nom_alpha_syst1_constraint) instead of ..._constraint/...Constraint after the parameter, Gaussian constraints of normsys/histosys/normfactor parameters have the global observable as x (in every export mode), and the workspace holds one top-level tagged RooProdPdf per array. The likelihood is unchanged (tested).
  • Documents written before this change, and documents without array_dist, import as before (the rules for shared variates are those of [RF][HS3] Combined data sets and combined distributions (HS3 #119) #24005).
  • With config().exportConstraintData, the external constraints of a ModelConfig and the constraints of ordinary products are paired with data like the HistFactory constraints (section 9).
  • A continuous RooPoisson (noRounding) is written as poisson_continuous_dist instead of poisson_dist with "integer": false, and HS3 0.3 documents with the key integer are rejected.

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

Tests run (Linux, Ubuntu 26.04, GCC 15.2, RelWithDebInfo, -Droofit=ON -Dtesting=ON): testRooFitHS3 141 → 157 tests (16 new), testHistFactory 44, all passing; each commit was built and tested on its own before the last rebases, after them the head of each PR of the stack and the new commits on their own. clang-format clean.

New tests: ArrayDistImport, ArrayDistImportErrors, ArrayDistExport, ArrayDistExportOfTaggedProduct, ArrayDistLikelihood, HistFactoryArrayDistConstraints (two channels with a shared normsys, staterror and shapesys, written with individual constraints and with arrays: same constraint terms, same NLL), HistFactoryArrayDistConstraintErrors, HistFactoryArrayDistExport (structure and order of the written arrays, NLL unchanged by the round trip, second and third export identical, opt-out), HistFactoryConstraintTermsInLikelihood (both routes, with and without arrays), HistFactoryConstraintSharedWithOtherPdf (a constraint shared between a HistFactory channel and a product_dist, reported in the review: rejected as HS3 0.3; as version 0.2 written with the constraint once, in both traversal orders, with and without arrays; re-import, stable document, same NLL), ArrayDistVariatesInLikelihood (a term sharing an observable with an array is rejected), HistFactoryConstraintAlsoExternal (section 8), ConstraintDataOfProductConstraints (section 9), ArrayConstraintTermsOfRenamedChannels (section 10), TutorialRF515RoundTrip, PoissonContinuous (export of both forms, round trip, the integer key of documents before HS3 0.3, errors), and HS3ClosureLoop (now also: the constraints of the HistFactory models are written as arrays, and the Gaussians have the global observable as x, in the array, on their own and after the import).

The two-channel HistFactory fixture of the new tests gives the channels their own observables. Updated to the grouped form: HistFactoryConstraintKeyMigration, HistFactoryLegacyConstraintTypeInConstraintKey, HistFactoryStatErrorConstraint, HistFactoryConstraintsByName.

AI assistance: Claude Code implemented the changes, the tests and this description under review of the author: claude-fable-5-1 the first 5 commits, claude-opus-5-5 the 3 commits that follow the review report on shared constraints, the commit for HS3 #152, the rebase onto #24005, and the 4 commits that follow the later review reports (sections 7 to 10). The commits carry the corresponding Assisted-by trailers. The port onto the typed HS3 document of 3682174 was done by claude-opus-5-5 as well.

🤖 Generated with Claude Code

@Phmonski

Phmonski commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

I found an HS3 export/reimport failure when a Gaussian constraint is shared between a HistFactory channel and an ordinary RooProdPdf channel. Could we cover this case before merging?

With exportArrayDist = true (the default), the HistFactory exporter groups the shared constraint into <root>_gaussian_constraints, but the ordinary product still writes the constraint's original name in factors. The standalone distribution is omitted, leaving a dangling reference. Immediate reimport fails:

object 'model_other' is missing dependency 'shared_constraint' of type 'RooAbsPdf'

Setting RooJSONFactoryWSTool::config().exportArrayDist = false makes the same example round-trip successfully. The observables are distinct, so no observable-renaming option or collision allowance is involved.

The failure is order-dependent: when the HistFactory channel is visited first, it groups the constraint before the ordinary product references it. Renaming the channels so the ordinary product is visited first makes the constraint stay standalone and the round trip succeeds even with arrays enabled.

The source path appears to be:

  • 0fcae621633 introduces automatic grouping of HistFactory constraints through exportConstraint().
  • exportAsArrayComponent() records the original component name in _exportedObjectNames, although no standalone object with that name is written. Later exportObject() calls therefore skip that object.
  • The ordinary product's fallback exporter still writes the original factor names; it does not resolve them through the array-component registry.

In my larger mixed Higgs workspace this affects 13 distinct constraint names, including lumi_Pdf, ATLAS_JES_Pdf and ATLAS_E_EFF_Pdf.

Tested with ROOT 6.43.01 in a local integration containing this PR at a91db49ab7e and the combined-distribution changes from #24005. The attribution above is from source/history inspection; I have not rebuilt every historical revision or the isolated PR branch.

Could we add a regression test with a constraint shared between a HistFactory channel and an ordinary product, exercising both traversal orders, arrays enabled/disabled, successful reimport, and NLL agreement including the shared nuisance parameter?

@cburgard

Self-contained PyROOT reproducer
"""Shared constraint in HistFactory and ordinary product channels."""
import json
from pathlib import Path
import tempfile
import ROOT

ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.ERROR)
document = {
    'metadata': {'hs3_version': '0.3'},
    'distributions': [
        {'name': 'model_hf', 'type': 'histfactory_dist',
         'default_interpolation': {'type': 'mult', 'in': 'poly6', 'out': 'exp'},
         'axes': [{'name': 'x_hf', 'min': 0., 'max': 1., 'nbins': 1}],
         'samples': [{'name': 'signal', 'data': {'contents': [10.]},
                      'modifiers': [
                          {'type': 'normfactor', 'parameters': ['mu']},
                          {'name': 'shared', 'type': 'normsys', 'parameters': ['theta'],
                           'data': {'lo': .9, 'hi': 1.1}, 'constraints': ['shared_constraint']}]}]},
        {'name': 'shape', 'type': 'gaussian_dist', 'x': 'x_other', 'mean': 'theta', 'sigma': 1.},
        {'name': 'model_other', 'type': 'product_dist', 'factors': ['shape', 'shared_constraint']},
        {'name': 'shared_constraint', 'type': 'gaussian_dist',
         'x': 'theta', 'mean': 'theta_obs', 'sigma': 1.}],
    'domains': [{'name': 'default_domain', 'type': 'product_domain', 'axes': [
        {'name': 'x_hf', 'min': 0., 'max': 1., 'nbins': 1},
        {'name': 'x_other', 'min': -5., 'max': 5.},
        {'name': 'theta', 'min': -5., 'max': 5.},
        {'name': 'mu', 'min': 0., 'max': 5.}]}],
    'parameter_points': [{'name': 'default_values', 'parameters': [
        {'name': 'theta', 'value': 0.}, {'name': 'theta_obs', 'value': 0., 'const': True},
        {'name': 'mu', 'value': 1.}]}],
    'data': [
        {'name': 'data_hf', 'type': 'binned',
         'axes': [{'name': 'x_hf', 'min': 0., 'max': 1., 'nbins': 1}], 'contents': [10.]},
        {'name': 'data_other', 'type': 'unbinned',
         'axes': [{'name': 'x_other', 'min': -5., 'max': 5.}], 'entries': [[.2]]}],
    'likelihoods': [{'name': 'lh', 'distributions': ['model_hf', 'model_other'],
                     'data': ['data_hf', 'data_other']}],
    'analyses': [{'name': 'analysis', 'likelihood': 'lh', 'domains': ['default_domain'],
                  'parameters_of_interest': ['mu']}]}

workspace = ROOT.RooWorkspace('input')
assert ROOT.RooJSONFactoryWSTool(workspace).importJSONfromString(json.dumps(document))
config = ROOT.RooJSONFactoryWSTool.config()
# Distinct observables: no collision allowance or renaming option is needed.
for arrays in [True, False]:
    config.exportArrayDist = arrays
    text = str(ROOT.RooJSONFactoryWSTool(workspace).exportJSONtoString())
    exported = json.loads(text)
    definitions = {obj['name']: obj for obj in exported['distributions']}
    missing = {factor for obj in definitions.values() if obj['type'] == 'product_dist'
               for factor in obj['factors'] if factor not in definitions}
    (Path(tempfile.gettempdir()) / f'hs3_shared_constraint_arrays_{arrays}.json').write_text(text)
    print('exportArrayDist:', arrays, 'dangling factors:', sorted(missing), flush=True)
    roundtrip = ROOT.RooWorkspace(f'roundtrip_{arrays}')
    try:
        ok = ROOT.RooJSONFactoryWSTool(roundtrip).importJSONfromString(text)
        print('REIMPORT:', ok, flush=True)
    except Exception as error:
        print('REIMPORT FAILED:', error, flush=True)

Expected diagnostic output on the affected build:

exportArrayDist: True dangling factors: ['shared_constraint']
REIMPORT FAILED: ... object 'model_other' is missing dependency 'shared_constraint' ...
exportArrayDist: False dangling factors: []
REIMPORT: True

To exercise the opposite traversal order, replace model_hf with z_model_hf and model_other with a_model_other throughout the script. In that ordering, both modes currently reimport successfully.

cburgard added a commit to cburgard/root that referenced this pull request Nov 10, 2026
…ther pdfs on their own

With config().exportArrayDist (the default), the constraints of the
HistFactory modifier parameters are collected into array distributions.
A constraint that an ordinary pdf also uses, e.g. a product in another
channel, was collected as well if the HistFactory channel was visited
first. Its name was then recorded as exported, although nothing of that
name was written, and the product referred to a missing distribution:
the document could not be read back. If the product was visited first,
the constraint was written on its own. Reported in root-project#24013.

Whether a constraint is collected now depends only on the workspace: it
is written on its own if an object other than a HistFactory channel or
an array distribution uses it. As a safety net, the export fails if an
object refers to an array component by its own name.

Test: HistFactoryConstraintSharedWithOtherPdf, a HistFactory channel and
a product sharing a Gaussian constraint, in both orders, with and
without arrays: the shared constraint is written on its own, the other
one is still collected, the document reads back, is stable, and has the
same NLL. A component of a tagged array product that another product
uses fails the export in both orders.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cburgard

Copy link
Copy Markdown
Contributor Author

Thanks a lot for this report, @Phmonski! The analysis was spot on and the self-contained reproducer made it easy to follow. Your example led to two fixes, both now on this PR:

  1. ef4ce37 "Write constraints shared with other pdfs on their own". This is the bug you found. Whether a HistFactory constraint is collected into an array now depends only on the workspace, not on the traversal order. It is collected only if every object of the workspace that uses it is a HistFactory channel or an array distribution. Otherwise it is written on its own, because objects like your product_dist refer to it by its own name. As a safety net, the export now fails with an error, instead of writing a dangling reference, if an object still refers to an array component by its own name.
  2. d4bd1f0 "HistFactory export: look for constraints among the channel's terms". Your hint about the opposite traversal order uncovered a second, older bug (on master too). The exporter took the first Gaussian, Poisson or log-normal among all clients of a modifier parameter as its constraint. In your example that could be shape (mean theta) instead of shared_constraint, depending on the order of the clients, which changes on re-import. The constraint is now looked for first among the constraint terms of the channel itself.

The regression test you asked for is HistFactoryConstraintSharedWithOtherPdf. It is your example, plus a second HistFactory parameter whose constraint is not shared. For both traversal orders, with arrays enabled and disabled, it checks that:

  • the shared constraint is written on its own and named both by the modifier and by the product;
  • the unshared constraint is still collected into the array;
  • the document re-imports, and a second export gives the same document;
  • the NLL agrees after the round trip, at a point that moves the shared nuisance parameter.

It also checks that a component of a tagged array product that another product uses makes the export fail in both orders. Your PyROOT reproducer now reports no dangling factors and re-imports in all four cases. The PR description is updated accordingly.

@cburgard

Copy link
Copy Markdown
Contributor Author

A follow-up, @Phmonski: with a third commit, 86927d5 "The terms of a likelihood have distinct variates", your example document is now rejected on import as invalid HS3 0.3. Its global observable is a variate of two likelihood terms: model_other contains shared_constraint as a factor, and the normsys modifier of model_hf makes the same distribution a constraint term of the likelihood. The import error names the variate and the two terms. Older documents (before 0.3) are read with a warning.

On export, a constraint that is both a factor of a channel's product and a term of the likelihood (a HistFactory constraint, as in your workspace, or an external constraint of the ModelConfig) is removed from the product, so it is written once, as a term of the likelihood. RooFit counts it once anyway, so the NLL doesn't change. Your mixed workspace should therefore still export, with the products of the ordinary channels written without the shared constraints, unless it has other shared variates (see below). The test runs your example as a version 0.2 document, for both traversal orders, with arrays enabled and disabled.

Other shared variates, e.g. two channels with the same observable name, now make the export fail. RooJSONFactoryWSTool::config().allowExportSharedVariates = true writes the document anyway, with a warning, so that it can be fixed in the JSON before it is read back.

cburgard added a commit to cburgard/root that referenced this pull request Nov 10, 2026
…ther pdfs on their own

With config().exportArrayDist (the default), the constraints of the
HistFactory modifier parameters are collected into array distributions.
A constraint that an ordinary pdf also uses, e.g. a product in another
channel, was collected as well if the HistFactory channel was visited
first. Its name was then recorded as exported, although nothing of that
name was written, and the product referred to a missing distribution:
the document could not be read back. If the product was visited first,
the constraint was written on its own. Reported in root-project#24013.

Whether a constraint is collected now depends only on the workspace: it
is written on its own if an object other than a HistFactory channel or
an array distribution uses it. As a safety net, the export fails if an
object refers to an array component by its own name.

Test: HistFactoryConstraintSharedWithOtherPdf, a HistFactory channel and
a product sharing a Gaussian constraint. As HS3 0.3 the document is
rejected, since the constraint enters twice (see "Distinct variates of
likelihood terms and combined components"). As version 0.2 it is read
with a warning, like a RooFit model; in both orders, with and without
arrays, the export writes the shared constraint once, on its own (the
product keeps its other factor), still collects the other constraint,
and reads back without warning, with the same NLL, stable from the
second export on. A component of a tagged array product that another
product uses fails the export in both orders.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cburgard cburgard changed the title [RF][HS3] Array distributions and HistFactory constraint terms (HS3 #109, #124; depends on #24001) [RF][HS3] Array distributions and HistFactory constraint terms (HS3 #109, #124; depends on #24005) Nov 10, 2026
@cburgard

Copy link
Copy Markdown
Contributor Author

One more note on the follow-up above, @Phmonski: the check of 86927d5 now lives in #24005, as "Distinct variates of likelihood terms and combined components" (8322532). One function covers both explicitly listed likelihood terms and the components of a combined_dist, which have the same rule since HS3 #119. This PR is now stacked on #24005, and its last commit, 31d94e4 "Variates of array distributions", adds the observables of array_dist components to that check. The behaviour described above is unchanged.

The rebase changed the commit hashes in my earlier comments: d4bd1f0 is now f13c5ef, and ef4ce37 is now 1b51266.

cburgard added a commit to cburgard/root that referenced this pull request Nov 10, 2026
…ther pdfs on their own

With config().exportArrayDist (the default), the constraints of the
HistFactory modifier parameters are collected into array distributions.
A constraint that an ordinary pdf also uses, e.g. a product in another
channel, was collected as well if the HistFactory channel was visited
first. Its name was then recorded as exported, although nothing of that
name was written, and the product referred to a missing distribution:
the document could not be read back. If the product was visited first,
the constraint was written on its own. Reported in root-project#24013.

Whether a constraint is collected now depends only on the workspace: it
is written on its own if an object other than a HistFactory channel or
an array distribution uses it. As a safety net, the export fails if an
object refers to an array component by its own name.

Test: HistFactoryConstraintSharedWithOtherPdf, a HistFactory channel and
a product sharing a Gaussian constraint. As HS3 0.3 the document is
rejected, since the constraint enters twice (see "Distinct variates of
likelihood terms and combined components"). As version 0.2 it is read
with a warning, like a RooFit model; in both orders, with and without
arrays, the export writes the shared constraint once, on its own (the
product keeps its other factor), still collects the other constraint,
and reads back without warning, with the same NLL, stable from the
second export on. A component of a tagged array product that another
product uses fails the export in both orders.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cburgard added a commit to cburgard/root that referenced this pull request Nov 11, 2026
…ther pdfs on their own

With config().exportArrayDist (the default), the constraints of the
HistFactory modifier parameters are collected into array distributions.
A constraint that an ordinary pdf also uses, e.g. a product in another
channel, was collected as well if the HistFactory channel was visited
first. Its name was then recorded as exported, although nothing of that
name was written, and the product referred to a missing distribution:
the document could not be read back. If the product was visited first,
the constraint was written on its own. Reported in root-project#24013.

Whether a constraint is collected now depends only on the workspace: it
is written on its own if an object other than a HistFactory channel or
an array distribution uses it. As a safety net, the export fails if an
object refers to an array component by its own name.

Test: HistFactoryConstraintSharedWithOtherPdf, a HistFactory channel and
a product sharing a Gaussian constraint. As HS3 0.3 the document is
rejected, since the constraint enters twice (see "Distinct variates of
likelihood terms and combined components"). As version 0.2 it is read
with a warning, like a RooFit model; in both orders, with and without
arrays, the export writes the shared constraint once, on its own (the
product keeps its other factor), still collects the other constraint,
and reads back without warning, with the same NLL, stable from the
second export on. A component of a tagged array product that another
product uses fails the export in both orders.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cburgard added a commit to cburgard/root that referenced this pull request Nov 11, 2026
…ther pdfs on their own

With config().exportArrayDist (the default), the constraints of the
HistFactory modifier parameters are collected into array distributions.
A constraint that an ordinary pdf also uses, e.g. a product in another
channel, was collected as well if the HistFactory channel was visited
first. Its name was then recorded as exported, although nothing of that
name was written, and the product referred to a missing distribution:
the document could not be read back. If the product was visited first,
the constraint was written on its own. Reported in root-project#24013.

Whether a constraint is collected now depends only on the workspace: it
is written on its own if an object other than a HistFactory channel or
an array distribution uses it. As a safety net, the export fails if an
object refers to an array component by its own name.

Test: HistFactoryConstraintSharedWithOtherPdf, a HistFactory channel and
a product sharing a Gaussian constraint. As HS3 0.3 the document is
rejected, since the constraint enters twice (see "Distinct variates of
likelihood terms and combined components"). As version 0.2 it is read
with a warning, like a RooFit model; in both orders, with and without
arrays, the export writes the shared constraint once, on its own (the
product keeps its other factor), still collects the other constraint,
and reads back without warning, with the same NLL, stable from the
second export on. A component of a tagged array product that another
product uses fails the export in both orders.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cburgard added a commit to cburgard/root that referenced this pull request Nov 11, 2026
…ther pdfs on their own

With config().exportArrayDist (the default), the constraints of the
HistFactory modifier parameters are collected into array distributions.
A constraint that an ordinary pdf also uses, e.g. a product in another
channel, was collected as well if the HistFactory channel was visited
first. Its name was then recorded as exported, although nothing of that
name was written, and the product referred to a missing distribution:
the document could not be read back. If the product was visited first,
the constraint was written on its own. Reported in root-project#24013.

Whether a constraint is collected now depends only on the workspace: it
is written on its own if an object other than a HistFactory channel or
an array distribution uses it. As a safety net, the export fails if an
object refers to an array component by its own name.

Test: HistFactoryConstraintSharedWithOtherPdf, a HistFactory channel and
a product sharing a Gaussian constraint. As HS3 0.3 the document is
rejected, since the constraint enters twice (see "Distinct variates of
likelihood terms and combined components"). As version 0.2 it is read
with a warning, like a RooFit model; in both orders, with and without
arrays, the export writes the shared constraint once, on its own (the
product keeps its other factor), still collects the other constraint,
and reads back without warning, with the same NLL, stable from the
second export on. A component of a tagged array product that another
product uses fails the export in both orders.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cburgard cburgard changed the title [RF][HS3] Array distributions and HistFactory constraint terms (HS3 #109, #124; depends on #24005) [RF][HS3] Array distributions and HistFactory constraint terms (HS3 #109, #124, #152; depends on #24005) Nov 12, 2026
cburgard added a commit to cburgard/root that referenced this pull request Nov 12, 2026
…ther pdfs on their own

With config().exportArrayDist (the default), the constraints of the
HistFactory modifier parameters are collected into array distributions.
A constraint that an ordinary pdf also uses, e.g. a product in another
channel, was collected as well if the HistFactory channel was visited
first. Its name was then recorded as exported, although nothing of that
name was written, and the product referred to a missing distribution:
the document could not be read back. If the product was visited first,
the constraint was written on its own. Reported in root-project#24013.

Whether a constraint is collected now depends only on the workspace: it
is written on its own if an object other than a HistFactory channel or
an array distribution uses it. As a safety net, the export fails if an
object refers to an array component by its own name.

Test: HistFactoryConstraintSharedWithOtherPdf, a HistFactory channel and
a product sharing a Gaussian constraint. As HS3 0.3 the document is
rejected, since the constraint enters twice (see "Distinct variates of
likelihood terms and combined components"). As version 0.2 it is read
with a warning, like a RooFit model; in both orders, with and without
arrays, the export writes the shared constraint once, on its own (the
product keeps its other factor), still collects the other constraint,
and reads back without warning, with the same NLL, stable from the
second export on. A component of a tagged array product that another
product uses fails the export in both orders.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cburgard

Copy link
Copy Markdown
Contributor Author

@Phmonski thanks, your hypothesis was right: with renameCombinedObservables, the channels are written as renamed clones, but the constraint terms were looked for in the original components, and the terms recorded by the HistFactory exporter were looked up under the original names. So the renamed HistFactory channel was treated as an ordinary product, and with arrays its constraint was listed under a name that is not written. Both now use the channels as they are written.

The fix is in two commits: "Look for constraint terms in the channels as they are written" in #24005 (without arrays the document was valid, but the renamed HistFactory channel was treated like a product there as well), and "Constraint terms of renamed HistFactory channels" here. Your example now passes in all three configurations. The tests ConstraintTermsOfRenamedChannels (#24005) and ArrayConstraintTermsOfRenamedChannels (here) follow it and also check that the likelihood has the same aux_distributions with and without renaming, with and without arrays, and the same NLL after the round trip.

cburgard added a commit to cburgard/root that referenced this pull request Nov 16, 2026
With config().exportArrayDist (the default), the constraints of the
HistFactory modifier parameters are collected into array distributions.
A constraint that an ordinary pdf also uses, e.g. a product in another
channel, was collected as well if the HistFactory channel was visited
first. Its name was then recorded as exported, although nothing of that
name was written, and the product referred to a missing distribution:
the document could not be read back. If the product was visited first,
the constraint was written on its own. Reported in root-project#24013.

Whether a constraint is collected now depends only on the workspace: it
is written on its own if an object other than a HistFactory channel or
an array distribution uses it. As a safety net, the export fails if an
object refers to an array component by its own name.

Test: HistFactoryConstraintSharedWithOtherPdf, a HistFactory channel and
a product sharing a Gaussian constraint. As HS3 0.3 the document is
rejected, since the constraint enters twice (see "Distinct variates of
likelihood terms and combined components"). As version 0.2 it is read
with a warning, like a RooFit model; in both orders, with and without
arrays, the export writes the shared constraint once, on its own (the
product keeps its other factor), still collects the other constraint,
and reads back without warning, with the same NLL, stable from the
second export on. A component of a tagged array product that another
product uses fails the export in both orders.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cburgard added a commit to cburgard/root that referenced this pull request Nov 16, 2026
A constraint of a HistFactory modifier that is also an external
constraint of a ModelConfig was collected into an array distribution,
but the likelihood still listed it under its own name in
"aux_distributions". The export succeeded with a reference to a
distribution that was not written, and the document could not be read
back. A ModelConfig that has the constraint as an external constraint
refers to it by name, like an ordinary product, so the constraint is
now written on its own.

Reported by Phmonski in root-project#24013 (comment).

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cburgard added a commit to cburgard/root that referenced this pull request Nov 16, 2026
With config().renameCombinedObservables, the components of a
RooSimultaneous are written as renamed clones. The constraint terms of
the likelihood were looked for in the original components, and the
terms that the HistFactory exporter records were looked up under their
names. A renamed HistFactory channel was therefore treated as an
ordinary product, and its constraints were listed under their own
names: with arrays, a constraint that is written as a component of an
array was listed although it is not written, and the document could not
be read back. Both now use the channels as they are written.

Reported by Phmonski in root-project#24013 (comment).

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cburgard and others added 13 commits November 16, 2026 23:09
HS3 PR root-project#109 adds `array_dist`: a product of one-dimensional distributions
of one type (`component_type`), each over its own observable `x`, with the
parameters given per component or in `default_parameters`.

RooFit has no dedicated class for it. The importer builds one pdf per
component through the importer of the component type (RooPoisson,
RooGaussian, RooLognormal), named `<x>_constraint` after its observable,
and a RooProdPdf named after the array that holds the components together
and carries the attribute `hs3_array_dist`, so that the array can be
written back as `array_dist` later.

Other component types are rejected with an explicit error, as are
duplicate or numeric observables, `x` in `default_parameters`, and
parameters that depend on an observable of the array (directly or through
a function). A `poisson_dist` component without RooFit's `integer` flag
uses the continued Poisson distribution.

Tests: ArrayDistImport (each type, default parameters, numbers and names,
values), ArrayDistImportErrors.

Assisted-by: claude-code:claude-fable-5-1
A RooProdPdf with the attribute `hs3_array_dist` (as created by the
import of an `array_dist`, or set by hand) is written as `array_dist`:
one component per factor with the fields of the standalone distribution
(RooPoisson, RooGaussian, RooLognormal in the standard parametrization),
and a field with the same value in every component once in
`default_parameters`. The observable of a component has to be named,
and no two components may share it.

The components are registered with the new
RooJSONFactoryWSTool::exportAsArrayComponent(), which keeps them from
being written on their own, and the arrays are written after all other
objects, followed by the servers of their components. This way the
position of the arrays in the document does not depend on when their
components were registered, which the HistFactory export will rely on
(its channels are exported before the arrays they reference). The tag
itself is not written as an attribute, it is restored from the type.

The new option RooJSONFactoryWSTool::config().exportArrayDist (default
true) switches the arrays off: a tagged product is then an ordinary
product_dist with standalone components.

Tests: ArrayDistExport (round trip of imported arrays, default
parameters), ArrayDistExportOfTaggedProduct (hand-built array, opt-out,
write errors), ArrayDistLikelihood (array paired with a one-entry
unbinned data set as in the HS3 appendix).

Ported onto the typed HS3 document: the names of the exported objects
and the registered array components are kept in the export state instead
of being passed around, and the arrays are recorded as generic objects of
the exported document.

Assisted-by: claude-code:claude-fable-5-1
Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A HistFactory modifier may name an `array_dist` as the constraint of a
parameter (HS3 root-project#124 names constraints per parameter, root-project#109 adds the
arrays). The importer then picks the component that depends on the
parameter, directly or through a function, out of the array: that is the
term that enters the likelihood for this parameter, and the whole array
enters once through the components of all of its parameters. A constraint
shared by several channels is one object in all of them, as with
individually named constraints. No component or several components
depending on the parameter is an error.

The constraints of shapesys and staterror modifiers are resolved per
gamma after the gammas exist, in the bin order of "constraints".

Components of an array that no parameter uses are reported with a warning
at the end of the import, since by the standard the whole array enters the
likelihood.

Tests: HistFactoryArrayDistConstraints (two channels with a shared normsys,
staterror and shapesys, written with individual constraints and with
arrays: same constraint terms and same NLL),
HistFactoryArrayDistConstraintErrors.

Ported onto the typed HS3 document: the constraints of the typed
modifiers (ConstraintPdf) and of the gammas (GammaConstraintPdfs, paired
with the gammas in bin order in createPHF()) are resolved with the
parameter, and the error messages get the modifier as context.

Assisted-by: claude-code:claude-fable-5-1
Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The HistFactory exporter collects the constraint distributions of its
modifiers (RooPoisson, RooGaussian, RooLognormal) into one `array_dist`
per type and top-level pdf, named `<toplevel>_poisson_constraints`,
`<toplevel>_gaussian_constraints` and `<toplevel>_lognormal_constraints`,
and the modifiers name that array in "constraints" for each constrained
parameter. This is the form HS3 root-project#124 will recommend for staterror after
array, so it enters the likelihood once, as with individually named
constraints. A constraint that already belongs to an array distribution
(an imported document) stays in that array, which keeps the grouping of
the document. The components follow the order of the channels, samples
and modifiers, with the gammas of staterror and shapesys in bin order.
Constraints that cannot be components (a literal number as observable,
as in the rf515 tutorial, or a RooLognormal with the transformed
parametrization) are written on their own as before.

With RooJSONFactoryWSTool::config().exportArrayDist = false, every
constraint is written on its own and named individually, as before.

Tests: HistFactoryArrayDistExport (structure of the written document,
order of the components, likelihood unchanged by the round trip, second
and third export identical, opt-out), TutorialRF515RoundTrip, and
HS3ClosureLoop, which now also checks that the constraints of the
HistFactory models are written as arrays and none on its own. Updated to the grouped form:
HistFactoryConstraintKeyMigration, HistFactoryLegacyConstraintTypeInConstraintKey,
HistFactoryStatErrorConstraint, HistFactoryConstraintsByName.

Ported onto the typed HS3 document: the constraints that the typed
modifiers name (the constraint terms of the channel, see
nameChannelConstraints()) are exported by exportNamedConstraints(), which
replaces their names in the HistFactoryDist by the names under which they
are written. The root of the export recursion is kept in the export
state.

Assisted-by: claude-code:claude-fable-5-1
Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lihood

So far the constraint terms of HistFactory modifiers entered the
likelihood only implicitly, through the `histfactory_dist`. They are now
listed in the likelihood as well, so that the likelihood section states
the full likelihood:

- by default in "aux_distributions", with the observed values of their
  observables as constant parameters (global observables), after the
  external constraints of the ModelConfig;
- with RooJSONFactoryWSTool::config().exportConstraintData = true in
  "distributions", each paired with a generated data set "<term>_data"
  (unbinned, one axis per observable, one entry with the observed
  values), the form of the HS3 appendix on auxiliary measurements. Only
  terms whose observables are global observables of the ModelConfig are
  paired; the others stay in "aux_distributions". Ranges without a bound
  are written with the largest representable value.

HistFactory builds its Gaussian constraints with the parameter as x and
the global observable as mean. The exporter records, for every
constraint of a modifier parameter, which side is the observable (the
one that does not depend on the parameter, also for constant parameters
like Lumi), and Gaussians are written with the observable as x, both as
array components and as standalone gaussian_dist, so that the data
pairing refers to the observable and re-imported workspaces have the
usual orientation. The normfactor export finds constraints among the
clients of the parameter, independently of the orientation.

On import, a term listed in "aux_distributions" or in "distributions"
that is a constraint of one of the listed HistFactory distributions is
not added again (as external constraint or as a channel). Its data set
sets the observed values, keeps them constant, puts them into the global
observables of the ModelConfig, and is not imported.

Tests: HistFactoryConstraintTermsInLikelihood (both routes, with and
without arrays: structure, transported observed value, likelihood,
stability), the data route in TutorialRF515RoundTrip, the orientation of
the Gaussians in HS3ClosureLoop (in the array, on their own and after
the import).

Ported onto the typed HS3 document: master already lists the
constraint terms that no modifier names (misc.ROOT_internal
histfactory_constraints) in "aux_distributions", and doesn't add them
again on import. This commit adds the terms that the modifiers name (as
written, e.g. the arrays), after the external constraints, and the data
route. The import recognizes all of them through the components of the
listed distributions. The data sets of the data route are typed unbinned
data. The orientation of the Gaussians is recorded while the typed
modifiers are renamed to the written terms.

Assisted-by: claude-code:claude-fable-5-1
Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s terms

The HistFactory exporter found the constraint of a modifier parameter by
searching the clients of the parameter, recursively, for the first
RooPoisson, RooGaussian or RooLognormal. Any such pdf that depends on the
parameter could be taken: e.g. a Gaussian with the parameter as mean in
another channel. Which one was taken depended on the order of the
clients, which differs between a workspace and its re-import.

The constraint is now looked for first among the constraint terms of the
channel, the factors of its product other than the RooRealSumPdf. Only if
none of them depends on the parameter are the clients searched as before,
e.g. for a channel without product.

Ported onto the typed HS3 document: on master, a constraint that is not
a term of the channel is dropped by nameChannelConstraints(), so taking
a pdf of another channel made the parameter appear unconstrained.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With config().exportArrayDist (the default), the constraints of the
HistFactory modifier parameters are collected into array distributions.
A constraint that an ordinary pdf also uses, e.g. a product in another
channel, was collected as well if the HistFactory channel was visited
first. Its name was then recorded as exported, although nothing of that
name was written, and the product referred to a missing distribution:
the document could not be read back. If the product was visited first,
the constraint was written on its own. Reported in root-project#24013.

Whether a constraint is collected now depends only on the workspace: it
is written on its own if an object other than a HistFactory channel or
an array distribution uses it. As a safety net, the export fails if an
object refers to an array component by its own name.

Test: HistFactoryConstraintSharedWithOtherPdf, a HistFactory channel and
a product sharing a Gaussian constraint. As HS3 0.3 the document is
rejected, since the constraint enters twice (see "Distinct variates of
likelihood terms and combined components"). As version 0.2 it is read
with a warning, like a RooFit model; in both orders, with and without
arrays, the export writes the shared constraint once, on its own (the
product keeps its other factor), still collects the other constraint,
and reads back without warning, with the same NLL, stable from the
second export on. A component of a tagged array product that another
product uses fails the export in both orders.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The check for shared variates of the terms of a likelihood (see the
commit "Distinct variates of likelihood terms and combined components")
now knows the variates of an array_dist: the "x" of its components. A
term that shares an observable with an array is rejected like any other
shared variate.

Test: ArrayDistVariatesInLikelihood, an array and a Gaussian over the
same observable in "aux_distributions".

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HS3 PR root-project#152 splits the Poisson distribution into the discrete
"poisson_dist" and the "poisson_continuous_dist". These are a RooPoisson
without and with noRounding, which ROOT distinguished so far by its own
key "integer" on "poisson_dist".

- Export: a RooPoisson with noRounding is written as
  "poisson_continuous_dist", otherwise as "poisson_dist", and without the
  key "integer", also as a component of an array_dist.
- Import: "poisson_continuous_dist" is a RooPoisson with noRounding. For
  documents before HS3 0.3, "integer": false on a "poisson_dist" still
  denotes the continuous form, and "integer": true or no key the discrete
  form, as root-project#152 recommends. From HS3 0.3 on, and on
  "poisson_continuous_dist", the key "integer" is an error.
- array_dist supports the component type "poisson_continuous_dist". The
  default "integer": false that made a "poisson_dist" component the
  continuous form is dropped: the component type decides.
- The HistFactory constraint terms (staterror, shapesys) are continuous
  Poisson distributions, so their array is now
  "<toplevel>_poisson_continuous_constraints".
- rf515_hfJSON.json uses "poisson_continuous_dist".

Test: PoissonContinuous (export of both forms, round trip, the "integer"
key of documents before HS3 0.3, and the errors).

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The constraint terms that the likelihood lists are now the constraints
that RooFit finds in the channels of the model
(RooAbsPdf::getAllConstraints()), for HistFactory channels as for
ordinary products, under the names under which they are written: the
array distribution that holds a constraint of a HistFactory channel,
or the name of the constraint.

The HistFactory exporter still records the constraint terms that it
writes for a channel (the constraints that the modifiers name and those
that no modifier names). This list is now a cross-check: if it differs
from what RooFit finds, a constraint would be missing from the
likelihood or be in it without being written, so the export fails. The
terms are listed in the order of that list, which comes from the
document and doesn't depend on how the workspace was built, so round
trips are stable.

Without observables (e.g. a ModelConfig without data), RooFit can't
tell constraints from other pdfs; then only the terms that the
HistFactory channels write are listed, as before.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A constraint of a HistFactory modifier that is also an external
constraint of a ModelConfig was collected into an array distribution,
but the likelihood still listed it under its own name in
"aux_distributions". The export succeeded with a reference to a
distribution that was not written, and the document could not be read
back. A ModelConfig that has the constraint as an external constraint
refers to it by name, like an ordinary product, so the constraint is
now written on its own.

Reported by Phmonski in root-project#24013 (comment).

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With config().exportConstraintData, a constraint term of the likelihood
is written in "distributions", paired with a data set of one entry that
holds the observed values. Since the constraint terms of the likelihood
come from RooFit (previous commits), this also applies to the
constraints of ordinary products. On import, such a term was only
recognised if it was part of a HistFactory channel: otherwise it was
neither part of the pdf of the ModelConfig nor an external constraint,
so it was missing from the likelihood, and its data set was imported as
an ordinary data set.

On import, a term of the likelihood that is not part of the pdf of the
ModelConfig (if the document names it, and it is a term of the
likelihood) and that is paired with a data set of one entry is now an
external constraint of the ModelConfig. As for the constraints of
HistFactory channels, the data set sets the observed values, which are
constant global observables, and is not imported.

The external constraints of a ModelConfig are now written like the
other constraint terms, also paired with data with
config().exportConstraintData; they were always listed in
"aux_distributions". So the likelihood is written in the same way after
a round trip, in which the constraints become external constraints.

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With config().renameCombinedObservables, the components of a
RooSimultaneous are written as renamed clones. The constraint terms of
the likelihood were looked for in the original components, and the
terms that the HistFactory exporter records were looked up under their
names. A renamed HistFactory channel was therefore treated as an
ordinary product, and its constraints were listed under their own
names: with arrays, a constraint that is written as a component of an
array was listed although it is not written, and the document could not
be read back. Both now use the channels as they are written.

Reported by Phmonski in root-project#24013 (comment).

Assisted-by: claude-code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Test Results

    22 files      22 suites   3d 11h 28m 57s ⏱️
 3 881 tests  3 881 ✅ 0 💤 0 ❌
75 994 runs  75 994 ✅ 0 💤 0 ❌

Results for commit e8a333b.

@silverweed
silverweed removed their request for review November 17, 2026 08:05
@guitargeek
guitargeek merged commit b893acf into root-project:master Nov 17, 2026
34 checks passed
@guitargeek
guitargeek deleted the hs3-array-dist branch November 17, 2026 08:56
guitargeek pushed a commit that referenced this pull request Nov 18, 2026
Follow HS3 PR 109 [1]: an "array_dist" is imported as one pdf per
component (Poisson, Gaussian or lognormal), grouped by a RooProdPdf
with the attribute "hs3_array_dist", which is written back as an
array_dist.

The HistFactory export groups the constraints into one array per
constraint type (<toplevel>_gaussian_constraints, ...), which the
modifiers name. The import picks the component that depends on the
modifier parameter. With config().exportArrayDist = false, the
constraints are written on their own as before. Constraints that
another object refers to by name, like a product_dist or the external
constraints of a ModelConfig, are always written on their own.
HistFactory's Gaussian constraints are written with the global
observable as "x".

The likelihood now also lists the constraints that the modifiers name,
found like the constraints of other products. With the new
config().exportConstraintData, constraint terms are listed in
"distributions" instead of "aux_distributions", each paired with a
one-entry data set of its observed values. On import, that data set
sets the global observables and is not imported itself.

Follow HS3 PR 152 [2]: a RooPoisson with noRounding is written as
"poisson_continuous_dist". It used to be a "poisson_dist" with
"integer": false, which is still read in documents before HS3 0.3.

Also fixed: the HistFactory export could take a pdf of another channel
as the constraint of a parameter.

Reading the HistFactory documents that RooFit writes now needs
array_dist (HS3 0.3). After a round trip, the constraints are named
after their global observable.

16 new tests in testRooFitHS3.

[1] https://github.com/hep-statistics-serialization-standard/hep-statistics-serialization-stand
ard/pull/109
[2] https://github.com/hep-statistics-serialization-standard/hep-statistics-serialization-stand
ard/pull/152

Assisted-by: claude-code:claude-fable-5-1
(cherry picked from commit b893acf)
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.

3 participants