Skip to content

Commit a9f2508

Browse files
adeiorioAgostino De Iorio
andauthored
feat: Autorebin option in make_template script (#133)
* fixing pt range of fixed WP histos * Updated unfo for JECs in Summer23BPix campaing * feat: add autorebin option and new cross section entry for TBbartoLplusNuBbar process * fix: correct formatting * fix: correct formatting in cross section entry for TBbartoLplusNuBbar process --------- Co-authored-by: Agostino De Iorio <[email protected]>
1 parent 6e6a994 commit a9f2508

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

scripts/make_template.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from coffea.util import load
2+
import numpy as np
23
import uproot, sys, os, argparse, hist
34
from BTVNanoCommissioning.helpers.xs_scaler import collate, scaleSumW
5+
from BTVNanoCommissioning.utils.plot_utils import (
6+
rebin_hist,
7+
)
48
import numpy as np
59

610
parser = argparse.ArgumentParser(description="Make templates from coffea files")
@@ -44,6 +48,11 @@
4448
default=None,
4549
help="Specify mergemap as dict, '{merge1:[dataset1,dataset2]...}' Also works with the json file with dict",
4650
)
51+
parser.add_argument(
52+
"--autorebin",
53+
default=None,
54+
help="Rebin the plotting variables, input `int` or `list`. int: merge N bins. list of number: rebin edges(non-uniform bin is possible)",
55+
)
4756

4857

4958
def create_template(inputs, variable, mergemap, axis, lumi, output):
@@ -54,7 +63,29 @@ def create_template(inputs, variable, mergemap, axis, lumi, output):
5463
hall = merge_all["all"][variable][axis]
5564

5665
fout = uproot.recreate(f"{variable}_{output}")
66+
subtract = False
67+
if "osss" in axis.keys():
68+
if "sum" in str(axis["osss"]):
69+
subtract = True
70+
axis.pop("osss")
5771
for data in collated.keys():
72+
if subtract:
73+
collated[data][variable] = (
74+
collated[data][variable][{"osss": 0}]
75+
+ collated[data][variable][{"osss": 1}] * -1
76+
)
77+
if arg.autorebin is not None:
78+
if arg.autorebin.isdigit():
79+
rebin = int(arg.autorebin)
80+
else:
81+
rebin = np.array([float(i) for i in arg.autorebin.split(",")])
82+
fout[data.replace("-", "_")] = rebin_hist(
83+
collated[data][variable][axis],
84+
collated[data][variable].axes[-1].name,
85+
rebin,
86+
)
87+
else:
88+
fout[data.replace("-", "_")] = collated[data][variable][axis]
5889
if variable not in collated[data].keys():
5990
raise f"{variable} not in {data}"
6091
elif np.sum(collated[data][variable].values()) == 0:
@@ -90,6 +121,7 @@ def create_template(inputs, variable, mergemap, axis, lumi, output):
90121
for d in inputs[f].keys():
91122
flists.append(d)
92123
mergemap = {d: d for d in flists}
124+
93125
axis = json.loads(arg.axis)
94126
# modify axis to hist methods
95127
for a in axis:

src/BTVNanoCommissioning/helpers/xsection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@
152152
"energy": "13.6",
153153
"comment": "from TOP-22-012 with PDG 2023 value",
154154
},
155+
{
156+
"process_name": "TBbartoLplusNuBbar-s-channel-4FS_TuneCP5_13p6TeV_amcatnlo-pythia8",
157+
"cross_section": "2.278",
158+
"energy": "13.6",
159+
"comment": "from XSDB",
160+
},
155161
{
156162
"process_name": "TTTo2L2Nu_CP5_13p6TeV_powheg-pythia8",
157163
"cross_section": "96.9",

0 commit comments

Comments
 (0)