Skip to content

Commit 8639c9c

Browse files
rigaaalvesan
andauthored
Feature/qcd hook (#35)
* init new branch * update submodules * adding files * fix linting * updating inf_model * adding limited dataset option * adding hh producer * deleting old qcd estimation * test: add 2j cat and shape uncertanties * adding nested dict for up/down shifts * fixing uncertainties propagation * under/overflow fix * Linting. * Remove test versions. --------- Co-authored-by: Ana A <[email protected]>
1 parent 8479b74 commit 8639c9c

File tree

7 files changed

+112
-22
lines changed

7 files changed

+112
-22
lines changed

hbt/config/categories.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,8 @@ def add_categories(config: od.Config) -> None:
2525
add_category(config, name="noniso", id=13, selection="cat_noniso", label=r"$\tau_{h,2} non-isolated$", tags={"noniso"}) # noqa: E501
2626

2727
# kinematic categories
28-
add_category(
29-
config,
30-
name="incl",
31-
id=100,
32-
selection="cat_incl",
33-
label="inclusive",
34-
)
35-
36-
add_category(
37-
config,
38-
name="2j",
39-
id=110,
40-
selection="cat_2j",
41-
label="2 jets",
42-
)
28+
add_category(config, name="incl", id=100, selection="cat_incl", label="inclusive")
29+
add_category(config, name="2j", id=110, selection="cat_2j", label="2 jets")
4330

4431
#
4532
# build groups

hbt/config/hist_hooks.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,36 @@ def qcd_estimation(task, hists):
141141

142142
# ABCD method
143143
# shape: (SHIFT, VAR)
144-
os_iso_qcd = os_noniso_qcd * (int_ss_iso / int_ss_noniso)
144+
os_iso_qcd = os_noniso_qcd * ((int_ss_iso / int_ss_noniso)[:, None])
145145

146146
# combine uncertainties and store values in bare arrays
147147
os_iso_qcd_values = os_iso_qcd()
148148
os_iso_qcd_variances = os_iso_qcd(sn.UP, sn.ALL, unc=True)**2
149149

150+
# define uncertainties
151+
unc_data = os_iso_qcd(sn.UP, ["os_noniso_data", "ss_iso_data", "ss_noniso_data"], unc=True)
152+
unc_mc = os_iso_qcd(sn.UP, ["os_noniso_mc", "ss_iso_mc", "ss_noniso_mc"], unc=True)
153+
unc_data_rel = abs(unc_data / os_iso_qcd_values)
154+
unc_mc_rel = abs(unc_mc / os_iso_qcd_values)
155+
156+
# only keep the MC uncertainty if it is larger than the data uncertainty and larger than 15%
157+
keep_variance_mask = (
158+
np.isfinite(unc_mc_rel) &
159+
(unc_mc_rel > unc_data_rel) &
160+
(unc_mc_rel > 0.15)
161+
)
162+
os_iso_qcd_variances[keep_variance_mask] = unc_mc[keep_variance_mask]**2
163+
os_iso_qcd_variances[~keep_variance_mask] = 0
164+
150165
# retro-actively set values to zero for shifts that had negative integrals
151166
neg_int_mask = int_ss_iso_neg | int_ss_noniso_neg
152167
os_iso_qcd_values[neg_int_mask] = 1e-5
153-
os_iso_qcd_variances[neg_int_mask] = 1e-5
168+
os_iso_qcd_variances[neg_int_mask] = 0
154169

155170
# residual zero filling
156171
zero_mask = os_iso_qcd_values <= 0
157172
os_iso_qcd_values[zero_mask] = 1e-5
158-
os_iso_qcd_variances[zero_mask] = 1e-5
173+
os_iso_qcd_variances[zero_mask] = 0
159174

160175
# insert values into the qcd histogram
161176
cat_axis = qcd_hist.axes["category"]

hbt/inference/inf_model.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
from columnflow.inference import inference_model, ParameterType, ParameterTransformation
2+
3+
4+
@inference_model
5+
def test_unc(self):
6+
self.add_category(
7+
"incl",
8+
config_category="incl",
9+
config_variable="hh_mass",
10+
# fake data
11+
data_from_processes=["TT", "dy"],
12+
mc_stats=True,
13+
)
14+
15+
self.add_category(
16+
"2j",
17+
config_category="2j",
18+
config_variable="jet1_pt",
19+
# fake data
20+
data_from_processes=["TT", "dy"],
21+
mc_stats=True,
22+
)
23+
24+
#
25+
# processes
26+
#
27+
self.add_process(
28+
"dy",
29+
config_process="dy",
30+
)
31+
32+
self.add_process(
33+
"TT",
34+
config_process="tt_sl",
35+
)
36+
37+
self.add_process(
38+
"hh_ggf",
39+
is_signal=True,
40+
config_process="hh_ggf_hbb_htt_kl1_kt1",
41+
)
42+
43+
#
44+
# parameters
45+
#
46+
47+
# groups
48+
self.add_parameter_group("experiment")
49+
self.add_parameter_group("theory")
50+
51+
# lumi
52+
lumi = self.config_inst.x.luminosity
53+
for unc_name in lumi.uncertainties:
54+
self.add_parameter(
55+
unc_name,
56+
type=ParameterType.rate_gauss,
57+
effect=lumi.get(names=unc_name, direction=("down", "up"), factor=True),
58+
)
59+
self.add_parameter_to_group(unc_name, "experiment")
60+
61+
# electron uncertainty
62+
self.add_parameter(
63+
"CMS_eff_e", # this is the name of the uncertainty as it will show in the datacard. Let's use some variant of the official naming # noqa
64+
process="*",
65+
type=ParameterType.shape,
66+
config_shift_source="e", # this is the name of the shift (alias) in the config
67+
)
68+
self.add_parameter_to_group("CMS_eff_e", "experiment")
69+
70+
# a custom asymmetric uncertainty
71+
self.add_parameter(
72+
"QCDscale_ttbar",
73+
process="TT",
74+
type=ParameterType.shape,
75+
transformations=[ParameterTransformation.effect_from_rate],
76+
effect=(0.85, 1.1),
77+
)
78+
self.add_parameter_to_group("QCDscale_ttbar", "experiment")
79+
80+
"""
81+
# tune uncertainty
82+
self.add_parameter(
83+
"tune",
84+
process="TT",
85+
type=ParameterType.shape,
86+
config_shift_source="tune",
87+
)
88+
self.add_parameter_to_group("tune", "experiment")
89+
"""

hbt/production/default.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from hbt.production.tau import tau_weights, trigger_weights
2020
from hbt.util import IF_DATASET_HAS_LHE_WEIGHTS
2121

22-
2322
ak = maybe_import("awkward")
2423

2524

law.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ production_modules: columnflow.production.{categories,normalization,processes},
4747
categorization_modules: hbt.categorization.default
4848
weight_production_modules: columnflow.weight.{empty,all_weights}, hbt.weight.default
4949
ml_modules: hbt.ml.test
50-
inference_modules: hbt.inference.{test,dl,base,derived,grav_model,test_unc}
50+
inference_modules: hbt.inference.{test,dl,base,derived,grav_model,inf_model}
5151

5252
# whether MergeReducedEvents should keep its inputs from ReduceEvents by default
5353
# (otherwise they are removed after merging)

modules/columnflow

0 commit comments

Comments
 (0)