forked from andrzejnovak/nanocc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
substitute_hcc.py
46 lines (38 loc) · 1.28 KB
/
substitute_hcc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import argparse
import uproot
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
import uproot3
from coffea import hist
parser = argparse.ArgumentParser()
lumi = {
2016 : 35.5,
2017 : 41.5,
2018 : 59.2,
}
parser.add_argument("-s", '--source', type=str, required=True, help="Source file")
parser.add_argument("-t", '--target', type=str, required=True, help="Target file")
parser.add_argument("-n", '--new', type=str, default=None, help="Name for modified file")
parser.add_argument("--ys", '--yearsource', default=2017, type=int, help="Scale by appropriate lumi")
parser.add_argument("--yt", '--yeartarget', default=2018, type=int, help="Scale by appropriate lumi")
args = parser.parse_args()
if args.new is None:
args.new = args.target.rstrip(".root")+"_mod.root"
print("Running with the following options:")
print(args)
fins = uproot3.open(args.source)
fint = uproot3.open(args.target)
if os.path.exists(args.new):
os.remove(args.new)
fout = uproot3.create(args.new)
for key in fint.keys():
if b'hcc' in key:
src_hist = fins[key]
for i in range(len(src_hist)):
src_hist[i] /= lumi[args.ys]
src_hist[i] *= lumi[args.yt]
fout[key] = src_hist
else:
fout[key] = fint[key]