forked from mflechl/ProductionFromNano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getStitchingWeights.py
56 lines (44 loc) · 1.4 KB
/
getStitchingWeights.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
44
45
46
47
48
49
50
51
52
53
54
55
56
import json
def main():
with open("stitchConfig.json","r") as FSO:
stitch_info = json.load(FSO)
with open("tagMapping.json","r") as FSO:
tag_map = json.load(FSO)
for mergename in stitch_info:
if stitch_info[mergename]["stitching"]:
xsecs = [0]*5
nevents = [0]*5
for sample in stitch_info[mergename]["samples"]:
if "DYJetsToLL_M_10to50_" in sample or "EWK" in sample : continue # low-mass DY and EWK contributions are not relevant for the stiching weight
print sample
nj = getJets(sample)
xsecs[nj] = tag_map[sample]["xsec"]
nevents[nj] = tag_map[sample]["nevents"]
weights = calcStitchingWeights( stitch_info[mergename]["NNLO_xsec"], xsecs, nevents )
print mergename
print showWeightstring(weights)
def showWeightstring(weights):
wstr = "("
for i in xrange(5):
if i == 0:
wstr += "(NUP == {0})*{1}".format(i,weights[i])
else:
wstr += " + (NUP == {0})*{1}".format(i,weights[i])
return wstr + ")"
def getJets(sample):
idx = 0
for i,j in enumerate(["","1","2","3","4"]):
if j+"Jets" in sample:
idx = i
return idx
def calcStitchingWeights(nnlo_xsec, xsecs, nevents):
corr = (1000*nnlo_xsec) / xsecs[0]
weights = [0]*5
for i in xrange(len(xsecs)):
if i == 0:
weights[i] = corr / ( nevents[i] / xsecs[i] )
else:
weights[i] = corr / ( ( nevents[0] / xsecs[0] ) + ( nevents[i] / xsecs[i] ) )
return weights
if __name__ == '__main__':
main()