forked from cms-analysis/flashggFinalFit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstage1helpers.py
163 lines (141 loc) · 5.11 KB
/
stage1helpers.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#various helpers for the stage 1 results scripts
import numpy as np
def prettyCat( cat ):
cat = cat.replace('RECO','')
cat = cat.replace('PTH_0_60','Low')
cat = cat.replace('PTH_60_120','Medium')
cat = cat.replace('PTH_120_200','High')
cat = cat.replace('PTH_GT200','BSM')
cat = cat.replace('GE2J','2J')
cat = cat.replace('VBFTOPO','VBF')
cat = cat.replace('JET3VETO','2J-like')
cat = cat.replace('JET3','3J-like')
cat = cat.replace('REST','Rest')
cat = cat.replace('WHLEP','WH Leptonic')
cat = cat.replace('ZHLEP','ZH Leptonic')
cat = cat.replace('VHLEPLOOSE','VH Leptonic Loose')
cat = cat.replace('VHMET','VH MET')
cat = cat.replace('VHHAD','VH Hadronic')
cat = cat.replace('TTH_LEP','ttH Leptonic')
cat = cat.replace('TTH_HAD','ttH Hadronic')
cat = cat.replace('Tag0','Tag 0')
cat = cat.replace('Tag1','Tag 1')
cat = cat.replace('Tag2','Tag 2')
cat = cat.replace('_',' ')
return cat
class YieldInfo():
'''Take care of all the different signal shape+yield and background yield for summary table'''
def __init__(self, procs, cats):
self.procs = procs
self.cats = cats
self.sigYields = {}
self.bkgYields = {}
self.sigYields['Total'] = 0.
self.bkgYields['Total'] = 0.
for cat in cats:
self.sigYields[cat] = 0.
self.bkgYields[cat] = 0.
for proc in procs:
abbrev = self.getProcAbbrev(proc)
stage0 = self.getProcStage0(proc)
self.sigYields[(proc,cat)] = 0.
self.sigYields[(abbrev,cat)] = 0.
self.sigYields[(stage0,cat)] = 0.
for proc in procs:
abbrev = self.getProcAbbrev(proc)
stage0 = self.getProcStage0(proc)
self.sigYields[proc] = 0.
self.sigYields[abbrev] = 0.
self.sigYields[stage0] = 0.
self.effSigmas = {}
self.fwhms = {}
def addSigYield(self, key, val):
self.sigYields[key] += val
def addBkgYield(self, key, val):
self.bkgYields[key] += val
def getSigYield(self, key):
return self.sigYields[key]
def getBkgYield(self, key):
return self.bkgYields[key]
def setEffSigma(self, key, val):
self.effSigmas[key] = val
def setFWHM(self, key, val):
self.fwhms[key] = val
def getEffSigma(self, key):
return self.effSigmas[key]
def getFWHM(self, key):
return self.fwhms[key]
def getPurity(self, cat):
s = 0.68 * self.getSigYield(cat)
b = 2. * self.getEffSigma(cat) * self.getBkgYield(cat)
return s/(s+b)
def getTotPurity(self):
s = 0.68 * self.getSigYield('Total')
b = 2. * self.getTotEffSigma() * self.getBkgYield('Total')
return s/(s+b)
def getAMS(self, cat, breg = 3.):
s = 0.68 * self.getSigYield(cat)
b = 2. * self.getEffSigma(cat) * self.getBkgYield(cat)
b += breg
val = (s + b)*np.log(1. + (s/b))
val = 2*(val - s)
val = np.sqrt(val)
return val
def getTotAMS(self, breg = 3.):
s = 0.68 * self.getSigYield('Total')
b = 2. * self.getTotEffSigma() * self.getBkgYield('Total')
b += breg
val = (s + b)*np.log(1. + (s/b))
val = 2*(val - s)
val = np.sqrt(val)
return val
def getTotEffSigma(self):
theSum = 0.
sumW = 0.
for cat in self.cats:
theSum += self.getEffSigma(cat) * self.getSigYield(cat)
sumW += self.getSigYield(cat)
return theSum / sumW
def getTotFWHM(self):
theSum = 0.
sumW = 0.
for cat in self.cats:
theSum += self.getFWHM(cat) * self.getSigYield(cat)
sumW += self.getSigYield(cat)
return theSum / sumW
def getProcAbbrev(self, theProc):
if 'ZH2HQQ' in theProc: return 'zh'
elif 'QQ2HLL' in theProc: return 'zh'
elif 'WH2HQQ' in theProc: return 'wh'
elif 'QQ2HLNU' in theProc: return 'wh'
elif 'TTH' in theProc: return 'tth'
elif 'GG2H' in theProc: return 'ggh'
elif 'VBF' in theProc: return 'vbf'
elif 'BBH' in theProc: return 'bbh'
elif 'GGZH' in theProc: return 'ggzh'
elif 'THQ' in theProc: return 'th'
elif 'THW' in theProc: return 'th'
else:
print 'Oh dear, didn not get a prefix for proc %s'%theProc
raise Exception
def getAbbrevList(self):
return ['ggh', 'vbf', 'tth', 'th', 'bbh', 'wh', 'zh']
def getProcStage0(self, theProc):
if 'ZH2HQQ' in theProc: return 'ZH2HQQ'
elif 'QQ2HLL' in theProc: return 'QQ2HLL'
elif 'WH2HQQ' in theProc: return 'WH2HQQ'
elif 'QQ2HLNU' in theProc: return 'QQ2HLNU'
elif 'TTH' in theProc: return 'TTH'
elif 'GG2H' in theProc: return 'GG2H'
elif 'VBF' in theProc: return 'VBF'
elif 'BBH' in theProc: return 'BBH'
elif 'GGZH' in theProc: return 'GGZH'
elif 'THQ' in theProc: return 'THQ'
elif 'THW' in theProc: return 'THW'
else:
print 'Oh dear, didn not get a Stage 0 name for proc %s'%theProc
raise Exception
def getStage0list(self):
return ['GG2H', 'VBF', 'TTH', 'testTHQ', 'testTHW', 'testBBH', 'GGZH', 'QQ2HLNU', 'WH2HQQ', 'QQ2HLL', 'ZH2HQQ']
def getStage0dict(self):
return {'GG2H':'ggH', 'VBF':'VBF', 'TTH':'ttH', 'testTHQ':'tHq', 'testTHW':'tHW', 'testBBH':'bbH', 'GGZH':'ggZH', 'QQ2HLNU':'WH lep', 'WH2HQQ':'WH had', 'QQ2HLL':'ZH lep', 'ZH2HQQ':'ZH had'}