Skip to content

Commit

Permalink
support models with custom modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-held committed Sep 20, 2023
1 parent 2af877c commit 0f7da05
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/cabinetry/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ class ModelPrediction(NamedTuple):


def model_and_data(
spec: Dict[str, Any], *, asimov: bool = False, include_auxdata: bool = True
spec: Dict[str, Any],
*,
asimov: bool = False,
include_auxdata: bool = True,
validate: bool = True,
poi_name: Optional[str] = None,
modifier_set: Optional[Dict[str, Tuple]] = None,
) -> Tuple[pyhf.pdf.Model, List[float]]:
"""Returns model and data for a ``pyhf`` workspace specification.
Expand All @@ -50,18 +56,27 @@ def model_and_data(
asimov (bool, optional): whether to return the Asimov dataset, defaults to False
include_auxdata (bool, optional): whether to also return auxdata, defaults to
True
validate (bool, optional): whether to validate the workspace and model against
the respective JSON schema, defaults to True
poi_name (Optional[str], optional): name of POI to set for model, defaults to
None (then use POI as given in measurement specification)
modifier_set (Optional[Dict[str, Tuple]], optional): additional custom modifiers
to support, defaults to None (no custom modifiers)
Returns:
Tuple[pyhf.pdf.Model, List[float]]:
- a HistFactory-style model in ``pyhf`` format
- the data (plus auxdata if requested) for the model
"""
workspace = pyhf.Workspace(spec)
workspace = pyhf.Workspace(spec, validate=validate)
model = workspace.model(
validate=validate,
poi_name=poi_name,
modifier_set=modifier_set,
modifier_settings={
"normsys": {"interpcode": "code4"},
"histosys": {"interpcode": "code4p"},
}
},
) # use HistFactory InterpCode=4 (default in pyhf since v0.6.0)
if not asimov:
data = workspace.data(model, include_auxdata=include_auxdata)
Expand Down

0 comments on commit 0f7da05

Please sign in to comment.