forked from ram1123/nanoAOD_skim
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Helper.py
143 lines (112 loc) · 4.32 KB
/
Helper.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
import ROOT
import yaml
PI=3.14159
def PassTrig(event,cfgFile):
PassTrig = False
with open(cfgFile, 'r') as ymlfile:
cfg = yaml.load(ymlfile)
TriggerList = []
for TriggerName in cfg['Triggers']:
TriggerList.append(eval(TriggerName))
for i in range(len(TriggerList)):
PassTrig = PassTrig | TriggerList[i]
return PassTrig
def goodLooseElectrons2012(electrons, elePtcut):
goodElectrons = []
for x in electrons:
if ((x.pt>elePtcut) & (abs(x.eta)<2.5)):
goodElectrons.append(x)
return goodElectrons
def goodLooseMuons2012(muons, muPtcut):
goodMuons = []
for x in muons:
if ((x.pt>muPtcut) & (abs(x.eta)<2.4) & (x.isPFcand | x.isGlobal | x.isTracker)):
goodMuons.append(x)
return goodMuons
def goodLooseTaus2012(Taus, TauPtcut):
goodTaus = []
for x in Taus:
if ((x.pt>TauPtcut) & (abs(x.eta)<2.3)):
goodTaus.append(x)
return goodTaus
def goodTaus2015(Taus, TauPtcut):
goodTaus = []
for x in Taus:
if ((x.pt>TauPtcut)):
goodTaus.append(x)
return goodTaus
def goodLoosePhotons2015(Photons):
goodPhotons = []
for x in Photons:
goodPhotons.append(x)
return goodPhotons
def goodPhotons2015(Photons,phoPtCut):
goodPhotons = []
for x in Photons:
if x.pt>phoPtCut:
goodPhotons.append(x)
return goodPhotons
def goodMuons2015_noIso_noPf(muons, muPtcut, sip3dcut):
bestMuons = []
for x in muons:
if ((x.pt>muPtcut) & (abs(x.eta)<2.4) & (x.isGlobal | x.isTracker)):
if(x.sip3d < sip3dcut):
if((abs(x.dxy)<0.5)&(abs(x.dz)<1)):
bestMuons.append(x)
return bestMuons
def goodElectrons2015_noIso_noBdt(electrons, elePtcut, sip3dcut):
bestElectrons = []
for x in electrons:
if ((x.pt>elePtcut)):
if(x.sip3d < sip3dcut):
if((abs(x.dxy)<0.5)&(abs(x.dz)<1)):
bestElectrons.append(x)
return bestElectrons
def passTight_BDT_Id(electrons,year = '2018'):
Tight_Id = []
cutVal = 1000
mvaVal = -1
for x in electrons:
if (year == '2018'):
if (x.pt<=10):
if (abs(x.eta) < 0.8): cutVal = 0.9044286167
if ((abs(x.eta) >= 0.8)&(abs(x.eta) <1.479)): cutVal = 0.9094166886
if (abs(x.eta) >= 1.479): cutVal = 0.9443653660
else:
if (abs(x.eta) < 0.8): cutVal = 0.1968600840
if ((abs(x.eta) >= 0.8)&(abs(x.eta) <1.479)): cutVal = 0.0759172100
if (abs(x.eta) >= 1.479): cutVal = -0.5169136775
mvaVal = x.mvaFall17V2Iso_WP90
if (year == '2017'):
if (x.pt<=10):
if (abs(x.eta) < 0.8): cutVal = 0.9128577458
if ((abs(x.eta) >= 0.8)&(abs(x.eta) <1.479)): cutVal = 0.9056792368
if (abs(x.eta) >= 1.479): cutVal = 0.9439440575
else:
if (abs(x.eta) < 0.8): cutVal = 0.1559788054
if ((abs(x.eta) >= 0.8)&(abs(x.eta) <1.479)): cutVal = 0.0273863727
if (abs(x.eta) >= 1.479): cutVal = -0.5532483665
mvaVal = x.mvaFall17V2Iso_WP90
if (year == '2016'):
if (x.pt<=10):
if (abs(x.eta) < 0.8): cutVal = 0.9557993256
if ((abs(x.eta) >= 0.8)&(abs(x.eta) <1.479)): cutVal = 0.9475406570
if (abs(x.eta) >= 1.479): cutVal = 0.9285158721
else:
if (abs(x.eta) < 0.8): cutVal = 0.3272075608
if ((abs(x.eta) >= 0.8)&(abs(x.eta) <1.479)): cutVal = 0.2468345995
if (abs(x.eta) >= 1.479): cutVal = -0.5955762814
mvaVal = x.mvaFall17V2Iso_WP90
if mvaVal > cutVal:
Tight_Id.append(True)
else:
Tight_Id.append(False)
return Tight_Id
def passTight_Id(muons):
Tight_Id = []
for x in muons:
if (x.pt<200):
Tight_Id.append(x.isPFcand)
else:
Tight_Id.append(((x.ptErr/x.pt)<0.3)&(abs(x.dxy)<0.2)&(abs(x.dz)<0.5)&(x.nTrackerLayers>5)|x.isPFcand)
return Tight_Id