forked from LPC-DM/decaf
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathids.py
347 lines (307 loc) · 9.6 KB
/
ids.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import awkward
import uproot
import numpy as np
from coffea.util import save
def Mask(pt):
# Just a complicated way to initialize a jagged array with the needed shape
# to True
return ~(pt == np.nan)
######
## Electron
## Electron_cutBased Int_t cut-based ID Fall17 V2
## (0:fail, 1:veto, 2:loose, 3:medium, 4:tight)
## https://twiki.cern.ch/twiki/bin/view/CMS/CutBasedElectronIdentificationRun2
######
def isLooseElectron(pt, eta, dxy, dz, loose_id, year):
mask = Mask(pt)
if year == "2016":
mask = (
(pt > 10)
& (abs(eta) < 1.4442)
& (abs(dxy) < 0.05)
& (abs(dz) < 0.1)
& (loose_id >= 2)
) | (
(pt > 10)
& (abs(eta) > 1.5660)
& (abs(eta) < 2.5)
& (abs(dxy) < 0.1)
& (abs(dz) < 0.2)
& (loose_id >= 2)
)
elif year == "2017":
mask = (
(pt > 10)
& (abs(eta) < 1.4442)
& (abs(dxy) < 0.05)
& (abs(dz) < 0.1)
& (loose_id >= 2)
) | (
(pt > 10)
& (abs(eta) > 1.5660)
& (abs(eta) < 2.5)
& (abs(dxy) < 0.1)
& (abs(dz) < 0.2)
& (loose_id >= 2)
)
elif year == "2018":
mask = (
(pt > 10)
& (abs(eta) < 1.4442)
& (abs(dxy) < 0.05)
& (abs(dz) < 0.1)
& (loose_id >= 2)
) | (
(pt > 10)
& (abs(eta) > 1.5660)
& (abs(eta) < 2.5)
& (abs(dxy) < 0.1)
& (abs(dz) < 0.2)
& (loose_id >= 2)
)
return mask
def isTightElectron(pt, eta, dxy, dz, tight_id, year):
# 2017/18 pT thresholds adjusted to match monojet, using dedicated ID SFs
mask = Mask(pt)
if year == "2016": # Trigger: HLT_Ele27_WPTight_Gsf_v
mask = (
(pt > 40)
& (abs(eta) < 1.4442)
& (abs(dxy) < 0.05)
& (abs(dz) < 0.1)
& (tight_id == 4)
) | (
(pt > 40)
& (abs(eta) > 1.5660)
& (abs(eta) < 2.5)
& (abs(dxy) < 0.1)
& (abs(dz) < 0.2)
& (tight_id == 4)
)
elif year == "2017": # Trigger: HLT_Ele35_WPTight_Gsf_v
mask = (
(pt > 40)
& (abs(eta) < 1.4442)
& (abs(dxy) < 0.05)
& (abs(dz) < 0.1)
& (tight_id == 4)
) | (
(pt > 40)
& (abs(eta) > 1.5660)
& (abs(eta) < 2.5)
& (abs(dxy) < 0.1)
& (abs(dz) < 0.2)
& (tight_id == 4)
)
elif year == "2018": # Trigger: HLT_Ele32_WPTight_Gsf_v
mask = (
(pt > 40)
& (abs(eta) < 1.4442)
& (abs(dxy) < 0.05)
& (abs(dz) < 0.1)
& (tight_id == 4)
) | (
(pt > 40)
& (abs(eta) > 1.5660)
& (abs(eta) < 2.5)
& (abs(dxy) < 0.1)
& (abs(dz) < 0.2)
& (tight_id == 4)
)
return mask
#######
## Muon
## Muon ID WPs:
## https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideMuonIdRun2#Muon_selectors_Since_9_4_X
## Muon isolation WPs:
## https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideMuonSelection#Muon_Isolation
#######
def isLooseMuon(pt, eta, iso, loose_id, year):
# dxy and dz cuts are missing from med_id; loose isolation is 0.25
mask = Mask(pt)
if year == "2016":
mask = (pt > 20) & (abs(eta) < 2.4) & loose_id & (iso < 0.25)
elif year == "2017":
mask = (pt > 20) & (abs(eta) < 2.4) & loose_id & (iso < 0.25)
elif year == "2018":
mask = (pt > 15) & (abs(eta) < 2.4) & loose_id & (iso < 0.25)
return mask
def isTightMuon(pt, eta, iso, tight_id, year):
# dxy and dz cuts are baked on tight_id; tight isolation is 0.15
mask = Mask(pt)
if year == "2016":
mask = (pt > 30) & (abs(eta) < 2.4) & tight_id & (iso < 0.15)
elif year == "2017":
mask = (pt > 30) & (abs(eta) < 2.4) & tight_id & (iso < 0.15)
elif year == "2018":
mask = (pt > 30) & (abs(eta) < 2.4) & tight_id & (iso < 0.15)
return mask
def isSoftMuon(pt, eta, iso, tight_id, year):
# dxy and dz cuts are baked on tight_id; tight isolation is 0.15
mask = Mask(pt)
if year == "2016":
mask = (pt > 5) & (abs(eta) < 2.4) & tight_id & (iso > 0.15)
elif year == "2017":
mask = (pt > 5) & (abs(eta) < 2.4) & tight_id & (iso > 0.15)
elif year == "2018":
mask = (pt > 5) & (abs(eta) < 2.4) & tight_id & (iso > 0.15)
return mask
######
## Tau
## https://twiki.cern.ch/twiki/bin/viewauth/CMS/TauIDRecommendationForRun2
## The decayModeFindingNewDMs: recommended for use with DeepTauv2p1, where decay
## modes 5 and 6 should be explicitly rejected.
##
## Tau_idDeepTau2017v2p1VSe ID working points (bitmask):
## 1 = VVVLoose, 2 = VVLoose, 4 = VLoose, 8 = Loose,
## 16 = Medium, 32 = Tight, 64 = VTight, 128 = VVTight
##
## Tau_idDeepTau2017v2p1VSjet ID working points (bitmask):
## 1 = VVVLoose, 2 = VVLoose, 4 = VLoose, 8 = Loose,
## 16 = Medium, 32 = Tight, 64 = VTight, 128 = VVTight
##
## Tau_idDeepTau2017v2p1VSmu ID working points (bitmask):
## 1 = VLoose, 2 = Loose, 4 = Medium, 8 = Tight
######
def isLooseTau(pt, eta, decayMode, decayModeDMs, ide, idj, idm, year):
mask = Mask(pt)
if year == "2016":
mask = (
(pt > 20)
& (abs(eta) < 2.3)
& ~(decayMode == 5)
& ~(decayMode == 6)
& decayModeDMs
& ((ide & 16) == 16)
& ((idj & 4) == 4)
& ((idm & 2) == 2)
)
elif year == "2017":
mask = (
(pt > 20)
& (abs(eta) < 2.3)
& ~(decayMode == 5)
& ~(decayMode == 6)
& decayModeDMs
& ((ide & 16) == 16)
& ((idj & 4) == 4)
& ((idm & 2) == 2)
)
elif year == "2018":
mask = (
(pt > 20)
& (abs(eta) < 2.3)
& ~(decayMode == 5)
& ~(decayMode == 6)
& decayModeDMs
& ((ide & 16) == 16)
& ((idj & 4) == 4)
& ((idm & 2) == 2)
)
return mask
######
## Photon
## https://twiki.cern.ch/twiki/bin/view/CMS/CutBasedPhotonIdentificationRun2
## Photon_cutBased Int_t cut-based ID bitmap, Fall17V2,
## (0:fail, 1:loose, 2:medium, 3:tight)
## Note: Photon IDs are integers, not bit masks
######
def isLoosePhoton(pt, eta, loose_id, year):
mask = Mask(pt)
if year == "2016":
mask = (
(pt > 20)
& ~(abs(eta) > 1.4442)
& (abs(eta) < 1.5660)
& (abs(eta) < 2.5)
& (loose_id >= 1)
)
elif year == "2017":
mask = (
(pt > 20)
& ~(abs(eta) > 1.4442)
& (abs(eta) < 1.5660)
& (abs(eta) < 2.5)
& (loose_id >= 1)
)
elif year == "2018":
mask = (
(pt > 20)
& ~(abs(eta) > 1.4442)
& (abs(eta) < 1.5660)
& (abs(eta) < 2.5)
& (loose_id >= 1)
)
return mask
def isTightPhoton(pt, tight_id, year):
# isScEtaEB is used (barrel only), so no eta requirement
# 2017/18 pT requirement adjusted to match monojet, using dedicated ID SFs
# Tight photon use medium ID, as in monojet
mask = Mask(pt)
if year == "2016":
mask = (pt > 200) & (tight_id == 3)
elif year == "2017":
mask = (pt > 230) & (tight_id == 3)
elif year == "2018":
mask = (pt > 230) & (tight_id == 3)
return mask
######
## Fatjet
## https://twiki.cern.ch/twiki/bin/view/CMS/JetID13TeVUL
## Tight working point including lepton veto (TightLepVeto)
######
def isGoodFatJet(pt, eta, jet_id, nhf, chf):
mask = (
(pt > 160) & (abs(eta) < 2.4) & ((jet_id & 6) == 6) & (nhf < 0.8) & (chf > 0.1)
)
return mask
######
## Jet
## https://twiki.cern.ch/twiki/bin/view/CMS/JetID13TeVUL
## Tight working point including lepton veto (TightLepVeto)
##
## For Jet ID flags, bit1 is Loose (always false in 2017 since it does not
## exist), bit2 is Tight, bit3 is TightLepVeto. The POG recommendation is to
## use Tight Jet ID as the standard Jet ID.
######
## PileupJetID
## https://twiki.cern.ch/twiki/bin/view/CMS/PileupJetIDUL
## Using Loose Pileup ID
##
## Note: There is a bug in 2016 UL in which bit values for Loose and Tight Jet
## Pileup IDs are accidentally flipped relative to 2017 UL and 2018 UL.
##
## For 2016 UL,
## Jet_puId = (passtightID*4 + passmediumID*2 + passlooseID*1).
##
## For 2017 UL and 2018 UL,
## Jet_puId = (passlooseID*4 + passmediumID*2 + passtightID*1).
######
def isGoodJet(pt, eta, jet_id, pu_id, year):
mask = (pt > 30) & (abs(eta) < 2.4) & ((jet_id & 6) == 6)
if year == "2016":
mask = ((pt >= 50) & mask) | ((pt < 50) & mask & ((pu_id & 1) == 1))
elif year == "2017":
mask = ((pt >= 50) & mask) | ((pt < 50) & mask & ((pu_id & 4) == 4))
elif year == "2018":
mask = ((pt >= 50) & mask) | ((pt < 50) & mask & ((pu_id & 4) == 4))
return mask
######
## HEM
######
def isHEMJet(pt, eta, phi):
mask = (pt > 30) & (eta > -3.0) & (eta < -1.3) & (phi > -1.57) & (phi < -0.87)
return mask
ids = {}
ids["isLooseElectron"] = isLooseElectron
ids["isTightElectron"] = isTightElectron
ids["isLooseMuon"] = isLooseMuon
ids["isTightMuon"] = isTightMuon
ids["isSoftMuon"] = isSoftMuon
ids["isLooseTau"] = isLooseTau
ids["isLoosePhoton"] = isLoosePhoton
ids["isTightPhoton"] = isTightPhoton
ids["isGoodJet"] = isGoodJet
ids["isGoodFatJet"] = isGoodFatJet
ids["isHEMJet"] = isHEMJet
save(ids, "data/test_ids.coffea")