CMS 3D CMS Logo

runTauDisplay.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from __future__ import absolute_import
3 from builtins import range
4 import ROOT, os, math, sys
5 import numpy as num
6 from DataFormats.FWLite import Events, Handle
7 from .DeltaR import *
8 
9 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
10 from PhysicsTools.Heppy.physicsobjects.Muon import Muon
11 from PhysicsTools.Heppy.physicsobjects.Electron import Electron
12 from PhysicsTools.Heppy.physicsobjects.Tau import Tau
13 from PhysicsTools.Heppy.physicsutils.TauDecayModes import tauDecayModes
14 
15 
16 ROOT.gROOT.SetBatch(True)
17 
18 #RelVal = '7_6_0_pre7'
19 #RelVal = '7_6_0'
20 #RelVal = '7_6_1'
21 #RelVal = '7_6_1_v2'
22 RelVal = '7_6_1_v3'
23 
24 tag = 'v11'
25 if RelVal=='7_6_0_pre7':
26  tag = 'v5'
27 
28 tauH = Handle('vector<pat::Tau>')
29 vertexH = Handle('std::vector<reco::Vertex>')
30 genParticlesH = Handle ('std::vector<reco::GenParticle>')
31 jetH = Handle('vector<pat::Jet>')
32 
33 filelist = []
34 argvs = sys.argv
35 argc = len(argvs)
36 
37 if argc != 2:
38  print('Please specify the runtype : python3 runTauDisplay.py <ZTT, ZEE, ZMM, QCD>')
39  sys.exit(0)
40 
41 runtype = argvs[1]
42 
43 print('You selected', runtype)
44 
45 
46 
47 #def isFinal(p):
48 # return not (p.numberOfDaughters() == 1 and p.daughter(0).pdgId() == p.pdgId())
49 
50 
51 def returnRough(dm):
52  if dm in [0]:
53  return 0
54  elif dm in [1,2]:
55  return 1
56  elif dm in [5,6]:
57  return 2
58  elif dm in [10]:
59  return 3
60  elif dm in [11]:
61  return 4
62  else:
63  return -1
64 
65 
66 def finalDaughters(gen, daughters=None):
67  if daughters is None:
68  daughters = []
69  for i in range(gen.numberOfDaughters()):
70  daughter = gen.daughter(i)
71  if daughter.numberOfDaughters() == 0:
72  daughters.append(daughter)
73  else:
74  finalDaughters(daughter, daughters)
75 
76  return daughters
77 
78 
79 def visibleP4(gen):
80  final_ds = finalDaughters(gen)
81 
82  p4 = sum((d.p4() for d in final_ds if abs(d.pdgId()) not in [12, 14, 16]), ROOT.math.XYZTLorentzVectorD())
83 
84  return p4
85 
86 
87 
88 
89 
90 for ii in range(1, 4):
91 
92  if runtype == 'ZEE' and RelVal.find('7_6_1')!=-1: pass
93  else:
94  if ii==3 : continue
95 
96  filename = ''
97 
98  if runtype == 'ZTT':
99  filename = 'root://eoscms//eos/cms/store/cmst3/user/ytakahas/TauPOG/ZTT_CMSSW_' + RelVal + '_RelValZTT_13_MINIAODSIM_76X_mcRun2_asymptotic_' + tag + '-v1_' + str(ii) + '.root'
100  elif runtype == 'ZEE':
101  filename = 'root://eoscms//eos/cms/store/cmst3/user/ytakahas/TauPOG/ZEE_CMSSW_' + RelVal + '_RelValZEE_13_MINIAODSIM_76X_mcRun2_asymptotic_' + tag + '-v1_' + str(ii) + '.root'
102  elif runtype == 'ZMM':
103  filename = 'root://eoscms//eos/cms/store/cmst3/user/ytakahas/TauPOG/ZMM_CMSSW_' + RelVal + '_RelValZMM_13_MINIAODSIM_76X_mcRun2_asymptotic_' + tag + '-v1_' + str(ii) + '.root'
104  elif runtype == 'QCD':
105  filename = 'root://eoscms//eos/cms/store/cmst3/user/ytakahas/TauPOG/QCD_CMSSW_' + RelVal + '_QCD_FlatPt_15_3000HS_13_MINIAODSIM_76X_mcRun2_asymptotic_v11-v1_' + str(ii) + '.root'
106 
107  print(filename)
108  filelist.append(filename)
109 
110 events = Events(filelist)
111 print(len(filelist), 'files will be analyzed')
112 
113 
114 outputname = 'Myroot_' + RelVal + '_' + runtype + '.root'
115 file = ROOT.TFile(outputname, 'recreate')
116 
117 h_ngen = ROOT.TH1F("h_ngen", "h_ngen",10,0,10)
118 
119 tau_tree = ROOT.TTree('per_tau','per_tau')
120 
121 tau_eventid = num.zeros(1, dtype=int)
122 tau_id = num.zeros(1, dtype=int)
123 tau_dm = num.zeros(1, dtype=int)
124 tau_dm_rough = num.zeros(1, dtype=int)
125 tau_pt = num.zeros(1, dtype=float)
126 tau_eta = num.zeros(1, dtype=float)
127 tau_phi = num.zeros(1, dtype=float)
128 tau_mass = num.zeros(1, dtype=float)
129 tau_gendm = num.zeros(1, dtype=int)
130 tau_gendm_rough = num.zeros(1, dtype=int)
131 tau_genpt = num.zeros(1, dtype=float)
132 tau_geneta = num.zeros(1, dtype=float)
133 tau_genphi = num.zeros(1, dtype=float)
134 tau_vertex = num.zeros(1, dtype=int)
135 
136 tau_againstMuonLoose3 = num.zeros(1, dtype=int)
137 tau_againstMuonTight3 = num.zeros(1, dtype=int)
138 
139 tau_againstElectronVLooseMVA5 = num.zeros(1, dtype=int)
140 tau_againstElectronLooseMVA5 = num.zeros(1, dtype=int)
141 tau_againstElectronMediumMVA5 = num.zeros(1, dtype=int)
142 tau_againstElectronTightMVA5 = num.zeros(1, dtype=int)
143 tau_againstElectronVTightMVA5 = num.zeros(1, dtype=int)
144 tau_againstElectronMVA5raw = num.zeros(1, dtype=float)
145 tau_byIsolationMVA3oldDMwLTraw = num.zeros(1, dtype=float)
146 tau_byLooseIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
147 tau_byMediumIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
148 tau_byTightIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
149 tau_byVLooseIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
150 tau_byVTightIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
151 tau_byVVTightIsolationMVA3oldDMwLT = num.zeros(1, dtype=int)
152 
153 
154 tau_byCombinedIsolationDeltaBetaCorrRaw3Hits = num.zeros(1, dtype=float)
155 tau_byLooseCombinedIsolationDeltaBetaCorr3Hits = num.zeros(1, dtype=int)
156 tau_byMediumCombinedIsolationDeltaBetaCorr3Hits = num.zeros(1, dtype=int)
157 tau_byTightCombinedIsolationDeltaBetaCorr3Hits = num.zeros(1, dtype=int)
158 tau_chargedIsoPtSum = num.zeros(1, dtype=float)
159 tau_neutralIsoPtSum = num.zeros(1, dtype=float)
160 tau_puCorrPtSum = num.zeros(1, dtype=float)
161 tau_byLoosePileupWeightedIsolation3Hits = num.zeros(1, dtype=int)
162 tau_byMediumPileupWeightedIsolation3Hits = num.zeros(1, dtype=int)
163 tau_byTightPileupWeightedIsolation3Hits = num.zeros(1, dtype=int)
164 tau_byPileupWeightedIsolationRaw3Hits = num.zeros(1, dtype=float)
165 tau_neutralIsoPtSumWeight = num.zeros(1, dtype=float)
166 tau_footprintCorrection = num.zeros(1, dtype=float)
167 tau_photonPtSumOutsideSignalCone = num.zeros(1, dtype=float)
168 tau_decayModeFindingOldDMs = num.zeros(1, dtype=int)
169 tau_decayModeFindingNewDMs = num.zeros(1, dtype=int)
170 
171 
172 tau_againstElectronVLooseMVA6 = num.zeros(1, dtype=int)
173 tau_againstElectronLooseMVA6 = num.zeros(1, dtype=int)
174 tau_againstElectronMediumMVA6 = num.zeros(1, dtype=int)
175 tau_againstElectronTightMVA6 = num.zeros(1, dtype=int)
176 tau_againstElectronVTightMVA6 = num.zeros(1, dtype=int)
177 tau_againstElectronMVA6raw = num.zeros(1, dtype=float)
178 
179 #'byIsolationMVArun2v1DBdR03oldDMwLTraw'
180 tau_byIsolationMVArun2v1DBoldDMwLTraw = num.zeros(1, dtype=float)
181 tau_byVLooseIsolationMVArun2v1DBoldDMwLT = num.zeros(1, dtype=int)
182 tau_byLooseIsolationMVArun2v1DBoldDMwLT = num.zeros(1, dtype=int)
183 tau_byMediumIsolationMVArun2v1DBoldDMwLT = num.zeros(1, dtype=int)
184 tau_byTightIsolationMVArun2v1DBoldDMwLT = num.zeros(1, dtype=int)
185 tau_byVTightIsolationMVArun2v1DBoldDMwLT = num.zeros(1, dtype=int)
186 tau_byVVTightIsolationMVArun2v1DBoldDMwLT = num.zeros(1, dtype=int)
187 
188 #byIsolationMVArun2v1PWdR03oldDMwLTraw'
189 #'byLooseCombinedIsolationDeltaBetaCorr3HitsdR03'
190 #'byLooseIsolationMVArun2v1DBdR03oldDMwLT'
191 #'byLooseIsolationMVArun2v1PWdR03oldDMwLT'
192 #'byMediumCombinedIsolationDeltaBetaCorr3HitsdR03'
193 #'byMediumIsolationMVArun2v1DBdR03oldDMwLT'
194 #'byMediumIsolationMVArun2v1PWdR03oldDMwLT'
195 #'byTightCombinedIsolationDeltaBetaCorr3HitsdR03'
196 #'byTightIsolationMVArun2v1DBdR03oldDMwLT'
197 #'byTightIsolationMVArun2v1PWdR03oldDMwLT'
198 tau_byIsolationMVArun2v1PWoldDMwLTraw = num.zeros(1, dtype=float)
199 tau_byLooseIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
200 tau_byMediumIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
201 tau_byTightIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
202 tau_byVLooseIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
203 tau_byVTightIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
204 tau_byVVTightIsolationMVArun2v1PWoldDMwLT = num.zeros(1, dtype=int)
205 
206 #'byVLooseIsolationMVArun2v1DBdR03oldDMwLT'
207 #'byVLooseIsolationMVArun2v1PWdR03oldDMwLT'
208 #'byVTightIsolationMVArun2v1DBdR03oldDMwLT'
209 #'byVTightIsolationMVArun2v1PWdR03oldDMwLT'
210 #'byVVTightIsolationMVArun2v1DBdR03oldDMwLT'
211 #'byVVTightIsolationMVArun2v1PWdR03oldDMwLT'
212 
213 
214 
215 tau_tree.Branch('tau_id', tau_id, 'tau_id/I')
216 tau_tree.Branch('tau_vertex', tau_vertex, 'tau_vertex/I')
217 tau_tree.Branch('tau_eventid', tau_eventid, 'tau_eventid/I')
218 tau_tree.Branch('tau_dm', tau_dm, 'tau_dm/I')
219 tau_tree.Branch('tau_dm_rough', tau_dm_rough, 'tau_dm_rough/I')
220 tau_tree.Branch('tau_pt', tau_pt, 'tau_pt/D')
221 tau_tree.Branch('tau_eta', tau_eta, 'tau_eta/D')
222 tau_tree.Branch('tau_phi', tau_phi, 'tau_phi/D')
223 tau_tree.Branch('tau_mass', tau_mass, 'tau_mass/D')
224 tau_tree.Branch('tau_gendm', tau_gendm, 'tau_gendm/I')
225 tau_tree.Branch('tau_gendm_rough', tau_gendm_rough, 'tau_gendm_rough/I')
226 tau_tree.Branch('tau_genpt', tau_genpt, 'tau_genpt/D')
227 tau_tree.Branch('tau_geneta', tau_geneta, 'tau_geneta/D')
228 tau_tree.Branch('tau_genphi', tau_genphi, 'tau_genphi/D')
229 
230 tau_tree.Branch('tau_againstMuonLoose3', tau_againstMuonLoose3, 'tau_againstMuonLoose3/I')
231 tau_tree.Branch('tau_againstMuonTight3', tau_againstMuonTight3, 'tau_againstMuonTight3/I')
232 
233 tau_tree.Branch('tau_againstElectronVLooseMVA5', tau_againstElectronVLooseMVA5, 'tau_againstElectronVLooseMVA5/I')
234 tau_tree.Branch('tau_againstElectronLooseMVA5', tau_againstElectronLooseMVA5, 'tau_againstElectronLooseMVA5/I')
235 tau_tree.Branch('tau_againstElectronMediumMVA5', tau_againstElectronMediumMVA5, 'tau_againstElectronMediumMVA5/I')
236 tau_tree.Branch('tau_againstElectronTightMVA5', tau_againstElectronTightMVA5, 'tau_againstElectronTightMVA5/I')
237 tau_tree.Branch('tau_againstElectronVTightMVA5', tau_againstElectronVTightMVA5, 'tau_againstElectronVTightMVA5/I')
238 tau_tree.Branch('tau_againstElectronMVA5raw', tau_againstElectronMVA5raw, 'tau_againstElectronMVA5raw/D')
239 
240 tau_tree.Branch('tau_againstElectronVLooseMVA6', tau_againstElectronVLooseMVA6, 'tau_againstElectronVLooseMVA6/I')
241 tau_tree.Branch('tau_againstElectronLooseMVA6', tau_againstElectronLooseMVA6, 'tau_againstElectronLooseMVA6/I')
242 tau_tree.Branch('tau_againstElectronMediumMVA6', tau_againstElectronMediumMVA6, 'tau_againstElectronMediumMVA6/I')
243 tau_tree.Branch('tau_againstElectronTightMVA6', tau_againstElectronTightMVA6, 'tau_againstElectronTightMVA6/I')
244 tau_tree.Branch('tau_againstElectronVTightMVA6', tau_againstElectronVTightMVA6, 'tau_againstElectronVTightMVA6/I')
245 tau_tree.Branch('tau_againstElectronMVA6raw', tau_againstElectronMVA6raw, 'tau_againstElectronMVA6raw/D')
246 
247 
248 tau_tree.Branch('tau_byCombinedIsolationDeltaBetaCorrRaw3Hits', tau_byCombinedIsolationDeltaBetaCorrRaw3Hits, 'tau_byCombinedIsolationDeltaBetaCorrRaw3Hits/D')
249 tau_tree.Branch('tau_byLooseCombinedIsolationDeltaBetaCorr3Hits', tau_byLooseCombinedIsolationDeltaBetaCorr3Hits, 'tau_byLooseCombinedIsolationDeltaBetaCorr3Hits/I')
250 tau_tree.Branch('tau_byMediumCombinedIsolationDeltaBetaCorr3Hits', tau_byMediumCombinedIsolationDeltaBetaCorr3Hits, 'tau_byMediumCombinedIsolationDeltaBetaCorr3Hits/I')
251 tau_tree.Branch('tau_byTightCombinedIsolationDeltaBetaCorr3Hits', tau_byTightCombinedIsolationDeltaBetaCorr3Hits, 'tau_byTightCombinedIsolationDeltaBetaCorr3Hits/I')
252 tau_tree.Branch('tau_chargedIsoPtSum', tau_chargedIsoPtSum, 'tau_chargedIsoPtSum/D')
253 tau_tree.Branch('tau_neutralIsoPtSum', tau_neutralIsoPtSum, 'tau_neutralIsoPtSum/D')
254 tau_tree.Branch('tau_puCorrPtSum', tau_puCorrPtSum, 'tau_puCorrPtSum/D')
255 tau_tree.Branch('tau_byLoosePileupWeightedIsolation3Hits', tau_byLoosePileupWeightedIsolation3Hits, 'tau_byLoosePileupWeightedIsolation3Hits/I')
256 tau_tree.Branch('tau_byMediumPileupWeightedIsolation3Hits', tau_byMediumPileupWeightedIsolation3Hits, 'tau_byMediumPileupWeightedIsolation3Hits/I')
257 tau_tree.Branch('tau_byTightPileupWeightedIsolation3Hits', tau_byTightPileupWeightedIsolation3Hits, 'tau_byTightPileupWeightedIsolation3Hits/I')
258 tau_tree.Branch('tau_byPileupWeightedIsolationRaw3Hits', tau_byPileupWeightedIsolationRaw3Hits, 'tau_byPileupWeightedIsolationRaw3Hits/D')
259 tau_tree.Branch('tau_neutralIsoPtSumWeight', tau_neutralIsoPtSumWeight, 'tau_neutralIsoPtSumWeight/D')
260 tau_tree.Branch('tau_footprintCorrection', tau_footprintCorrection, 'tau_footprintCorrection/D')
261 tau_tree.Branch('tau_photonPtSumOutsideSignalCone', tau_photonPtSumOutsideSignalCone, 'tau_photonPtSumOutsideSignalCone/D')
262 tau_tree.Branch('tau_decayModeFindingOldDMs', tau_decayModeFindingOldDMs, 'tau_decayModeFindingOldDMs/I')
263 tau_tree.Branch('tau_decayModeFindingNewDMs', tau_decayModeFindingNewDMs, 'tau_decayModeFindingNewDMs/I')
264 
265 tau_tree.Branch('tau_byIsolationMVA3oldDMwLTraw', tau_byIsolationMVA3oldDMwLTraw, 'tau_byIsolationMVA3oldDMwLTraw/D')
266 tau_tree.Branch('tau_byLooseIsolationMVA3oldDMwLT', tau_byLooseIsolationMVA3oldDMwLT, 'tau_byLooseIsolationMVA3oldDMwLT/I')
267 tau_tree.Branch('tau_byMediumIsolationMVA3oldDMwLT', tau_byMediumIsolationMVA3oldDMwLT, 'tau_byMediumIsolationMVA3oldDMwLT/I')
268 tau_tree.Branch('tau_byTightIsolationMVA3oldDMwLT', tau_byTightIsolationMVA3oldDMwLT, 'tau_byTightIsolationMVA3oldDMwLT/I')
269 tau_tree.Branch('tau_byVLooseIsolationMVA3oldDMwLT', tau_byVLooseIsolationMVA3oldDMwLT, 'tau_byVLooseIsolationMVA3oldDMwLT/I')
270 tau_tree.Branch('tau_byVTightIsolationMVA3oldDMwLT', tau_byVTightIsolationMVA3oldDMwLT, 'tau_byVTightIsolationMVA3oldDMwLT/I')
271 tau_tree.Branch('tau_byVVTightIsolationMVA3oldDMwLT', tau_byVVTightIsolationMVA3oldDMwLT, 'tau_byVVTightIsolationMVA3oldDMwLT/I')
272 
273 
274 tau_tree.Branch('tau_byIsolationMVArun2v1DBoldDMwLTraw', tau_byIsolationMVArun2v1DBoldDMwLTraw, 'tau_byIsolationMVArun2v1DBoldDMwLTraw/D')
275 tau_tree.Branch('tau_byLooseIsolationMVArun2v1DBoldDMwLT', tau_byLooseIsolationMVArun2v1DBoldDMwLT, 'tau_byLooseIsolationMVArun2v1DBoldDMwLT/I')
276 tau_tree.Branch('tau_byMediumIsolationMVArun2v1DBoldDMwLT', tau_byMediumIsolationMVArun2v1DBoldDMwLT, 'tau_byMediumIsolationMVArun2v1DBoldDMwLT/I')
277 tau_tree.Branch('tau_byTightIsolationMVArun2v1DBoldDMwLT', tau_byTightIsolationMVArun2v1DBoldDMwLT, 'tau_byTightIsolationMVArun2v1DBoldDMwLT/I')
278 tau_tree.Branch('tau_byVLooseIsolationMVArun2v1DBoldDMwLT', tau_byVLooseIsolationMVArun2v1DBoldDMwLT, 'tau_byVLooseIsolationMVArun2v1DBoldDMwLT/I')
279 tau_tree.Branch('tau_byVTightIsolationMVArun2v1DBoldDMwLT', tau_byVTightIsolationMVArun2v1DBoldDMwLT, 'tau_byVTightIsolationMVArun2v1DBoldDMwLT/I')
280 tau_tree.Branch('tau_byVVTightIsolationMVArun2v1DBoldDMwLT', tau_byVVTightIsolationMVArun2v1DBoldDMwLT, 'tau_byVVTightIsolationMVArun2v1DBoldDMwLT/I')
281 
282 tau_tree.Branch('tau_byIsolationMVArun2v1PWoldDMwLTraw', tau_byIsolationMVArun2v1PWoldDMwLTraw, 'tau_byIsolationMVArun2v1PWoldDMwLTraw/D')
283 tau_tree.Branch('tau_byLooseIsolationMVArun2v1PWoldDMwLT', tau_byLooseIsolationMVArun2v1PWoldDMwLT, 'tau_byLooseIsolationMVArun2v1PWoldDMwLT/I')
284 tau_tree.Branch('tau_byMediumIsolationMVArun2v1PWoldDMwLT', tau_byMediumIsolationMVArun2v1PWoldDMwLT, 'tau_byMediumIsolationMVArun2v1PWoldDMwLT/I')
285 tau_tree.Branch('tau_byTightIsolationMVArun2v1PWoldDMwLT', tau_byTightIsolationMVArun2v1PWoldDMwLT, 'tau_byTightIsolationMVArun2v1PWoldDMwLT/I')
286 tau_tree.Branch('tau_byVLooseIsolationMVArun2v1PWoldDMwLT', tau_byVLooseIsolationMVArun2v1PWoldDMwLT, 'tau_byVLooseIsolationMVArun2v1PWoldDMwLT/I')
287 tau_tree.Branch('tau_byVTightIsolationMVArun2v1PWoldDMwLT', tau_byVTightIsolationMVArun2v1PWoldDMwLT, 'tau_byVTightIsolationMVArun2v1PWoldDMwLT/I')
288 tau_tree.Branch('tau_byVVTightIsolationMVArun2v1PWoldDMwLT', tau_byVVTightIsolationMVArun2v1PWoldDMwLT, 'tau_byVVTightIsolationMVArun2v1PWoldDMwLT/I')
289 
290 
291 
292 
293 evtid = 0
294 
295 for event in events:
296 
297  evtid += 1
298  eid = event.eventAuxiliary().id().event()
299 
300  if evtid%1000 == 0:
301  print('Event ', evtid, 'processed')
302 
303  event.getByLabel("slimmedTaus", tauH)
304  event.getByLabel("offlineSlimmedPrimaryVertices", vertexH)
305  event.getByLabel('prunedGenParticles',genParticlesH)
306  event.getByLabel("slimmedJets", jetH)
307 
308  taus = tauH.product()
309  vertices = vertexH.product()
310  genParticles = genParticlesH.product()
311  jets = [jet for jet in jetH.product() if jet.pt() > 20 and abs(jet.eta()) < 2.3]
312 
313  genTaus = [p for p in genParticles if abs(p.pdgId()) == 15 and p.status()==2]
314  genElectrons = [p for p in genParticles if abs(p.pdgId()) == 11 and p.status()==1 and p.pt() > 20 and abs(p.eta())<2.3]
315  genMuons = [p for p in genParticles if abs(p.pdgId()) == 13 and p.status()==1 and p.pt() > 20 and abs(p.eta())<2.3]
316 
317  for tau in taus:
318 
319  _genparticle_ = []
320 
321  for igen in genTaus:
322 
323  visP4 = visibleP4(igen)
324 
325  gen_dm = tauDecayModes.genDecayModeInt([d for d in finalDaughters(igen) if abs(d.pdgId()) not in [12, 14, 16]])
326 
327  igen.decaymode = gen_dm
328  igen.vis = visP4
329 
330  if abs(visP4.eta()) > 2.3: continue
331  if visP4.pt() < 20: continue
332 
333  dr = deltaR(tau.eta(), tau.phi(), visP4.eta(), visP4.phi())
334 
335  if dr < 0.5:
336  _genparticle_.append(igen)
337 
338 
339 
340  if runtype=='ZTT':
341  h_ngen.Fill(len(genTaus))
342  if len(_genparticle_) != 1: continue
343 
344  bmjet, _dr_ = bestMatch(tau, jets)
345  if runtype=='QCD':
346  h_ngen.Fill(len(jets))
347  if bmjet == None: continue
348 
349  bme, _dr_ = bestMatch(tau, genElectrons)
350  if runtype=='ZEE':
351  h_ngen.Fill(len(genElectrons))
352  if bme == None: continue
353 
354  bmm, _dr_ = bestMatch(tau, genMuons)
355  if runtype=='ZMM':
356  h_ngen.Fill(len(genMuons))
357  if bmm == None: continue
358 
359 
360  tau_id[0] = evtid
361  tau_eventid[0] = eid
362  tau_dm[0] = tau.decayMode()
363  tau_dm_rough[0] = returnRough(tau.decayMode())
364  tau_pt[0] = tau.pt()
365  tau_eta[0] = tau.eta()
366  tau_phi[0] = tau.phi()
367  tau_mass[0] = tau.mass()
368  tau_vertex[0] = len(vertices)
369 
370  tau_againstMuonLoose3[0] = tau.tauID('againstMuonLoose3')
371  tau_againstMuonTight3[0] = tau.tauID('againstMuonTight3')
372 
373  tau_againstElectronVLooseMVA5[0] = tau.tauID('againstElectronVLooseMVA5')
374  tau_againstElectronLooseMVA5[0] = tau.tauID('againstElectronLooseMVA5')
375  tau_againstElectronMediumMVA5[0] = tau.tauID('againstElectronMediumMVA5')
376  tau_againstElectronTightMVA5[0] = tau.tauID('againstElectronTightMVA5')
377  tau_againstElectronVTightMVA5[0] = tau.tauID('againstElectronVTightMVA5')
378  tau_againstElectronMVA5raw[0] = tau.tauID('againstElectronMVA5raw')
379 
380  tau_byCombinedIsolationDeltaBetaCorrRaw3Hits[0] = tau.tauID('byCombinedIsolationDeltaBetaCorrRaw3Hits')
381  tau_byLooseCombinedIsolationDeltaBetaCorr3Hits[0] = tau.tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits')
382  tau_byMediumCombinedIsolationDeltaBetaCorr3Hits[0] = tau.tauID('byMediumCombinedIsolationDeltaBetaCorr3Hits')
383  tau_byTightCombinedIsolationDeltaBetaCorr3Hits[0] = tau.tauID('byTightCombinedIsolationDeltaBetaCorr3Hits')
384  tau_chargedIsoPtSum[0] = tau.tauID('chargedIsoPtSum')
385  tau_neutralIsoPtSum[0] = tau.tauID('neutralIsoPtSum')
386  tau_puCorrPtSum[0] = tau.tauID('puCorrPtSum')
387  tau_byLoosePileupWeightedIsolation3Hits[0] = tau.tauID('byLoosePileupWeightedIsolation3Hits')
388  tau_byMediumPileupWeightedIsolation3Hits[0] = tau.tauID('byMediumPileupWeightedIsolation3Hits')
389  tau_byTightPileupWeightedIsolation3Hits[0] = tau.tauID('byTightPileupWeightedIsolation3Hits')
390  tau_byPileupWeightedIsolationRaw3Hits[0] = tau.tauID('byPileupWeightedIsolationRaw3Hits')
391  tau_neutralIsoPtSumWeight[0] = tau.tauID('neutralIsoPtSumWeight')
392  tau_footprintCorrection[0] = tau.tauID('footprintCorrection')
393  tau_photonPtSumOutsideSignalCone[0] = tau.tauID('photonPtSumOutsideSignalCone')
394  tau_decayModeFindingOldDMs[0] = tau.tauID('decayModeFinding')
395  tau_decayModeFindingNewDMs[0] = tau.tauID('decayModeFindingNewDMs')
396 
397  tau_byIsolationMVA3oldDMwLTraw[0] = tau.tauID('byIsolationMVA3oldDMwLTraw')
398  tau_byLooseIsolationMVA3oldDMwLT[0] = tau.tauID('byLooseIsolationMVA3oldDMwLT')
399  tau_byMediumIsolationMVA3oldDMwLT[0] = tau.tauID('byMediumIsolationMVA3oldDMwLT')
400  tau_byTightIsolationMVA3oldDMwLT[0] = tau.tauID('byTightIsolationMVA3oldDMwLT')
401  tau_byVLooseIsolationMVA3oldDMwLT[0] = tau.tauID('byVLooseIsolationMVA3oldDMwLT')
402  tau_byVTightIsolationMVA3oldDMwLT[0] = tau.tauID('byVTightIsolationMVA3oldDMwLT')
403  tau_byVVTightIsolationMVA3oldDMwLT[0] = tau.tauID('byVVTightIsolationMVA3oldDMwLT')
404 
405  if RelVal.find('7_6_1')!=-1:
406  tau_againstElectronVLooseMVA6[0] = tau.tauID('againstElectronVLooseMVA6')
407  tau_againstElectronLooseMVA6[0] = tau.tauID('againstElectronLooseMVA6')
408  tau_againstElectronMediumMVA6[0] = tau.tauID('againstElectronMediumMVA6')
409  tau_againstElectronTightMVA6[0] = tau.tauID('againstElectronTightMVA6')
410  tau_againstElectronVTightMVA6[0] = tau.tauID('againstElectronVTightMVA6')
411  tau_againstElectronMVA6raw[0] = tau.tauID('againstElectronMVA6raw')
412 
413  tau_byIsolationMVArun2v1DBoldDMwLTraw[0] = tau.tauID('byIsolationMVArun2v1DBoldDMwLTraw')
414  tau_byLooseIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byLooseIsolationMVArun2v1DBoldDMwLT')
415  tau_byMediumIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byMediumIsolationMVArun2v1DBoldDMwLT')
416  tau_byTightIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byTightIsolationMVArun2v1DBoldDMwLT')
417  tau_byVLooseIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byVLooseIsolationMVArun2v1DBoldDMwLT')
418  tau_byVTightIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byVTightIsolationMVArun2v1DBoldDMwLT')
419  tau_byVVTightIsolationMVArun2v1DBoldDMwLT[0] = tau.tauID('byVVTightIsolationMVArun2v1DBoldDMwLT')
420 
421  tau_byIsolationMVArun2v1PWoldDMwLTraw[0] = tau.tauID('byIsolationMVArun2v1PWoldDMwLTraw')
422  tau_byLooseIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byLooseIsolationMVArun2v1PWoldDMwLT')
423  tau_byMediumIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byMediumIsolationMVArun2v1PWoldDMwLT')
424  tau_byTightIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byTightIsolationMVArun2v1PWoldDMwLT')
425  tau_byVLooseIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byVLooseIsolationMVArun2v1PWoldDMwLT')
426  tau_byVTightIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byVTightIsolationMVArun2v1PWoldDMwLT')
427  tau_byVVTightIsolationMVArun2v1PWoldDMwLT[0] = tau.tauID('byVVTightIsolationMVArun2v1PWoldDMwLT')
428 
429 
430  if runtype == 'ZTT':
431  gp = _genparticle_[0]
432  tau_gendm[0] = gp.decaymode
433  tau_gendm_rough[0] = returnRough(gp.decaymode)
434  tau_genpt[0] = gp.vis.pt()
435  tau_geneta[0] = gp.vis.eta()
436  tau_genphi[0] = gp.vis.phi()
437  elif runtype == 'QCD':
438  tau_gendm[0] = -1
439  tau_genpt[0] = bmjet.pt()
440  tau_geneta[0] = bmjet.eta()
441  tau_genphi[0] = bmjet.phi()
442  elif runtype == 'ZEE':
443  tau_gendm[0] = -1
444  tau_genpt[0] = bme.pt()
445  tau_geneta[0] = bme.eta()
446  tau_genphi[0] = bme.phi()
447  elif runtype == 'ZMM':
448  tau_gendm[0] = -1
449  tau_genpt[0] = bmm.pt()
450  tau_geneta[0] = bmm.eta()
451  tau_genphi[0] = bmm.phi()
452 
453  tau_tree.Fill()
454 
455 
456 
457 print(evtid, 'events are processed !')
458 
459 file.Write()
460 file.Close()
461 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def visibleP4(gen)
def finalDaughters(gen, daughters=None)
def bestMatch(object, matchCollection)
Definition: deltar.py:138
def returnRough(dm)
#define str(s)
Definition: event.py:1