Decorrelate uncertainty for each bin #453
-
Hello, I would like to ask if there is any way to implement systematics with decorrelated among bins? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi, this is called a "shapesys" modifier in HistFactory and is supported by The good news is that you can take an existing workspace and update it to decorrelate uncertainties in this manner. Here is an example snippet operating on a workspace called name_to_decorrelate = "Modeling"
for channel in spec["channels"]:
for sample in channel["samples"]:
if sample["name"] != "Background":
continue # veto samples as needed
# find the normsys and histosys modifiers
normsys = next(
(
mod
for mod in sample["modifiers"]
if mod["name"] == name_to_decorrelate and mod["type"] == "normsys"
),
None,
)
histosys = next(
(
mod
for mod in sample["modifiers"]
if mod["name"] == name_to_decorrelate and mod["type"] == "histosys"
),
None,
)
if normsys:
norm_up, norm_down = normsys["data"]["hi"], normsys["data"]["lo"]
sample["modifiers"].remove(normsys) # delete the existing modifier
else:
norm_up, norm_down = 1.0, 1.0
if histosys:
# shapesys effect is symmetric, so symmetrize
shapesys_up = np.asarray(histosys["data"]["hi_data"]) * norm_up
shapesys_down = np.asarray(histosys["data"]["lo_data"]) * norm_down
shapesys_data = np.abs(shapesys_up - shapesys_down) / 2
sample["modifiers"].remove(histosys) # delete the existing modifier
else:
shapesys_data = np.asarray(sample["data"]) * abs(norm_up - norm_down) / 2
shapesys_modifier = {
"data": shapesys_data.tolist(),
"name": f"{name_to_decorrelate}_{channel['name']}_decorrelated_per_bin",
"type": "shapesys",
}
sample["modifiers"].append(shapesys_modifier) I have not tested this in a lot of detail but it seems to be doing the right thing. The idea is the following: define which modifiers you want to change (by name, veto samples as needed, can also veto channels if needed). Then find the modifiers that need to change: this assumes you have a |
Beta Was this translation helpful? Give feedback.
Hi, this is called a "shapesys" modifier in HistFactory and is supported by
pyhf
but not currently implemented incabinetry
as a config option. A part of the reason for that is that nobody had requested this modifier and its use is somewhat rare in my own experience. I created #454 to track this. The implementation should not be too difficult, there is currently just a somewhat long list of other things to also address (contributions here are certainly welcome).The good news is that you can take an existing workspace and update it to decorrelate uncertainties in this manner. Here is an example snippet operating on a workspace called
spec
: