Fitting independent templates #1406
-
Hi all, prompted by @matthewfeickert who I bothered originally :) I was wondering if I could use pyhf to find a best fit in setup where all templates are free floating. Here's what the problem could look like with code in "details". I suppose the place to start is the 2bin example, but the models seem to be built around the signal/background setup. import hist
import numpy as np
import mplhep as hep
import matplotlib.pyplot as plt
templates = []
hall = hist.Hist(hist.axis.Regular(50, 0, 10))
for i in [3, 5, 7]:
h = hist.Hist(
hist.axis.Regular(50, 0, 10),
)
h.fill(np.random.normal(i, 1, 10000))
templates.append(h)
hall.fill(np.random.normal(i, 1, round(10000*np.random.uniform(0.7, 1.3))))
hep.set_style("CMS")
hep.histplot(templates, stack=True, histtype='fill',label=["A", "B", "C"])
hep.histplot(hall, histtype='errorbar', color='black', capsize=2, yerr=True, label='Total')
plt.legend() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can assign free-floating "modifiers": [
{
"data": null,
"name": "normalization_A",
"type": "normfactor"
}
] Sample |
Beta Was this translation helpful? Give feedback.
You can assign free-floating
normfactor
modifiers to all the three templates. This example can be converted into a workspace with one channel and three samplesA
,B
,C
. Each sample can have its own modifier, example for sampleA
:Sample
B
would have anormfactor
modifier with name"normalization_B"
(or similar), similarly forC
. If you only want to obtain the best-fitting model, it is irrelevant which of thenormfactor
modifiers you declare to be your parameter of interest in the model.