CMS 3D CMS Logo

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