forked from reanahub/reana-demo-bsm-search
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
histogram.py
42 lines (32 loc) · 981 Bytes
/
histogram.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
import sys
import ROOT
import array
def main():
inputfile = sys.argv[1]
outputfile = sys.argv[2]
name = sys.argv[3]
weight = float(sys.argv[4])
variations = sys.argv[5].split(',')
if len(sys.argv) > 6:
histtemplate = sys.argv[6]
else:
histtemplate = '{name}_{variation}'
assert 'nominal' in variations
fin = ROOT.TFile.Open(inputfile)
ntin = fin.Get('ntuple;1')
fout = ROOT.TFile.Open(outputfile,'RECREATE')
hists = {}
for v in variations:
h = ROOT.TH1F(histtemplate.format(name = name,variation = v),'{}_{}'.format(name,v),50,-5,5)
ROOT.SetOwnership( h, False )
hists[v] = h
for event in ntin:
for v in variations:
wname = 'weight_nominal' if v == 'nominal' else v
hists[v].Fill(event.var,weight*getattr(event,wname) )
for h in hists.values():
h.Sumw2()
h.Write()
fout.Close()
if __name__ == '__main__':
main()