pyhs3.from_hifa¶
- pyhs3.from_hifa(spec, *, modifier_settings=None)[source]¶
Convert a pyhf workspace (HistFactory JSON) to an HS3 workspace.
The input is a workspace following pyhf’s
schemas/1.0.0/workspace.json, with any patches already applied (apyhf.Workspaceworks, since it is adict). The result goes through all ofWorkspace’s validation.Every pyhf modifier type is supported:
normfactor,normsys,histosys,shapefactor,shapesys,staterrorandlumi.Names of the generated HS3 objects
pyhf
HS3
channel
cwithnbinshistfactory_distmodel_cwith axisobs_x_c(min=0,max=n,nbins=n)observation of channel
cbinneddataobsData_con axisobs_x_cmeasurement
mlikelihood, analysis,
product_domainand parameter point, all namedmscalar modifier
xparameter
x(noalpha_prefix)per-bin modifier
xparameters
x_bin_0,x_bin_1, … (pyhf’sx[i], which ROOT rejects as a name)lumiin measurementmgaussian_distlumi_constraint_m, in likelihoodm’saux_distributionsA
shapefactororshapesysnumbers the bins of its own channel. Astaterrornumbers them as pyhf does: over the channels using its name, sorted by channel name, sox_bin_iis pyhf’sx[i]. Its parameters stay per channel.Each likelihood pairs every channel’s distribution with its data, in the input’s channel order. An observation whose name matches no channel is ignored, as pyhf ignores it, and logged at debug level: a patch that removes a channel can leave its observation behind. Each analysis has
initand its one domain set tom, andparameters_of_interestset to the measurement’spoi, copied as given even when no modifier uses it. Parameter pointmand domainmlist every parameter of the model, sorted by pyhf name, with per-bin parameters in bin order.Parameter defaults (pyhf’s), which the measurement config’s
inits,boundsandfixedoverride; a fixed parameter isconst:modifier
init
bounds
constraint
normfactor1
[0, 10]
none
normsys,histosys0
[-5, 5]
Gauss(aux 0, width 1)shapefactor1
[0, 10]
none
shapesys1
[1e-10, 10]
Poisson, tau = (nu/delta)^2staterror1
[1e-10, 10]
Gauss, width sqrt(sum delta^2) / sum nuluminone
none
Gauss, configauxdataandsigmasFor a per-bin parameter,
initsandboundshold one entry per bin andfixedapplies to every bin. Config entries naming a parameter the model does not use are ignored, as pyhf ignores them.Per-bin modifiers. A
shapefactormaps to HS3shapefactor, and biniis shared wherever its name appears, as in pyhf. Ashapesysmaps to HS3shapesyswithconstraint: Poissonand its absolute uncertainties asvals. Astaterrormaps to Barlow-Beeston lite: an HS3staterrorwithconstraint: Gausson each sample carrying it, whose uncertainties go in that sample’sdata.errors; samples without it get noerrors. pyhs3’s lite mode holds one staterror group per channel: the group on more than one sample if there is one, else the first to appear. Any other group in the channel sits on a single sample and maps to ashapesyswithconstraint: Gaussandvals= abs(delta), which gives the same width delta / nu.A
shapesysbin with no positive yield or no positive uncertainty, and astaterrorbin with no positive summed yield or a combined uncertainty of 0, has no constraint term in pyhs3. pyhf fixes such a bin, so its parameter isconstat its initial value (1 unlessinitssays otherwise).lumi. pyhf requires
inits,bounds,auxdataandsigmas(one value each) forlumiin every measurement.lumimaps to anormfactoron parameterlumiplus, per measurementm, agaussian_distwithx= auxdata,mean=lumiandsigma= sigmas. A fixedlumiisconstand keeps its constraint, which pyhf still evaluates at the fixed value.Interpolation. Each
normsysandhistosysmodifier records its code indata.interpolation. The defaults are pyhs3’s (and ROOT’s):code4fornormsysandcode4pforhistosys.modifier_settingsoverrides them per modifier type, in pyhf’s shape, e.g.{"normsys": {"interpcode": "code1"}}; a type it leaves out keeps pyhs3’s default. Accepted codes arecode1andcode4fornormsys, andcode0,code2andcode4pforhistosys.- Parameters:
- Return type:
- Returns:
The HS3 workspace.
- Raises:
pydantic_core.ValidationError – If
specdoes not follow pyhf’s schema, ormodifier_settingsnames an unknown modifier type, key or code.ValueError – For duplicate channel, observation, measurement or config-parameter names; a channel without an observation; bin counts that disagree within a channel, including a
histosys,shapesysorstaterror’s data; one name used by modifier types with different pyhf defaults, such asnormfactorwithnormsysorshapefactor,shapesyswithstaterror, andlumiwith any other type; ashapefactoron channels with different bin counts; ashapesysname used on more than one sample or channel, whose constraint pyhs3 would emit once per use; twostaterrorgroups in one channel that each sit on more than one sample; a sample carrying astaterrorin only some of the channels using its name, which pyhf rejects; configinitsorboundswhose length is not the parameter’s number of bins (1 for a scalar); configfixed: falseon a per-bin parameter with a bin that has no constraint term, which pyhf would free under a dummy constraint; configauxdata,sigmasorfactorsa modifier type does not use (all three onnormfactorandshapefactor,factorsonnormsys,histosysandstaterror,sigmasonshapesys); and configauxdata,sigmasorfactorsother than the values pyhf derives, within a relative tolerance of 1e-9, which HS3 v0.2 cannot express:[0]and[1]fornormsys/histosys, tau (1 for a bin with no constraint term) forshapesys, and auxdata 1 and the width (1 for a bin with no constraint term) forstaterror; alumiwhose config lacksinits,bounds,auxdataorsigmas, sets more than one value for any of them, setsfactors, or sets a non-positivesigmas.
Examples
>>> import pyhs3 >>> spec = { ... "channels": [ ... { ... "name": "SR", ... "samples": [ ... { ... "name": "signal", ... "data": [5.0, 10.0], ... "modifiers": [ ... {"name": "mu", "type": "normfactor", "data": None} ... ], ... }, ... { ... "name": "background", ... "data": [50.0, 60.0], ... "modifiers": [ ... { ... "name": "bkg_norm", ... "type": "normsys", ... "data": {"hi": 1.1, "lo": 0.9}, ... } ... ], ... }, ... ], ... } ... ], ... "observations": [{"name": "SR", "data": [53.0, 65.0]}], ... "measurements": [ ... {"name": "meas", "config": {"poi": "mu", "parameters": []}} ... ], ... "version": "1.0.0", ... } >>> ws = pyhs3.from_hifa(spec) >>> [p.name for p in ws.parameter_points["meas"]] ['bkg_norm', 'mu'] >>> ws.domains["meas"]["mu"] (0.0, 10.0)