1 from builtins
import range
8 from ROOT
import TLorentzVector, TVectorD
10 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
11 from PhysicsTools.HeppyCore.framework.event
import Event
12 from PhysicsTools.HeppyCore.statistics.counter
import Counter, Counters
13 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
15 import PhysicsTools.HeppyCore.framework.config
as cfg
19 from ROOT.heppy
import Hemisphere
20 from ROOT.heppy
import ReclusterJets
22 from ROOT.heppy
import Davismt2
25 from ROOT.heppy
import mt2w_bisect
26 mt2wSNT = mt2w_bisect.mt2w()
34 def __init__(self, cfg_ana, cfg_comp, looperName ):
35 super(MT2Analyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
41 self.handles[
'genJets'] = AutoHandle(
'slimmedGenJets',
'std::vector<reco::GenJet>')
42 self.handles[
'met'] = AutoHandle( self.cfg_ana.metCollection,
'std::vector<pat::MET>' )
46 self.counters.addCounter(
'pairs')
47 count = self.counters.counter(
'pairs')
48 count.register(
'all events')
55 metVector = array.array(
'd',[0.,metVec.px(), metVec.py()])
56 visaVector = array.array(
'd',[0.,visaVec.px(), visaVec.py()])
57 visbVector = array.array(
'd',[0.,visbVec.px(), visbVec.py()])
59 davismt2.set_momenta(visaVector,visbVector,metVector);
62 return davismt2.get_mt2()
64 def getMT2AKT(self, event, TMPobjects40jc, met , collectionPostFix, postFix):
67 if len(TMPobjects40jc)>=2:
69 objects = ROOT.std.vector(ROOT.reco.Particle.LorentzVector)()
70 for jet
in TMPobjects40jc:
71 objects.push_back(jet.p4())
73 hemisphereViaKt = ReclusterJets(objects, 1.,50.0)
74 groupingViaKt=hemisphereViaKt.getGroupingExclusive(2)
76 if len(groupingViaKt)>=2:
77 setattr(event,
"pseudoViaKtJet1"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector(groupingViaKt[0]) )
78 setattr(event,
"pseudoViaKtJet2"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector(groupingViaKt[1]) )
79 setattr(event,
"mt2ViaAKt"+collectionPostFix+postFix, self.
computeMT2(getattr(event,
'pseudoViaKtJet1'+collectionPostFix+postFix), getattr(event,
'pseudoViaKtJet2'+collectionPostFix+postFix), met) )
80 return self.
computeMT2(getattr(event,
'pseudoViaKtJet1'+collectionPostFix+postFix), getattr(event,
'pseudoViaKtJet2'+collectionPostFix+postFix), met)
82 if not self.cfg_ana.doOnlyDefault:
83 hemisphereViaAKt = ReclusterJets(objects, -1.,50.0)
84 groupingViaAKt=hemisphereViaAKt.getGroupingExclusive(2)
86 if len(groupingViaAKt)>=2:
87 setattr(event,
"pseudoViaAKtJet1"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector(groupingViaAKt[0]) )
88 setattr(event,
"pseudoViaAKtJet2"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector(groupingViaAKt[1]) )
89 setattr(event,
"mt2ViaAKt"+collectionPostFix+postFix, self.
computeMT2(getattr(event,
'pseudoViaAKtJet1'+collectionPostFix+postFix), getattr(event,
'pseudoViaAKtJet2'+collectionPostFix+postFix), met) )
90 return self.
computeMT2(getattr(event,
'pseudoViaAKtJet1'+collectionPostFix+postFix), getattr(event,
'pseudoViaAKtJet2'+collectionPostFix+postFix), met)
92 def getMT2Hemi(self, event, TMPobjects40jc, met, collectionPostFix, postFix):
94 if len(TMPobjects40jc)>=2:
96 pxvec = ROOT.std.vector(float)()
97 pyvec = ROOT.std.vector(float)()
98 pzvec = ROOT.std.vector(float)()
99 Evec = ROOT.std.vector(float)()
100 grouping = ROOT.std.vector(int)()
102 for jet
in TMPobjects40jc:
103 pxvec.push_back(jet.px())
104 pyvec.push_back(jet.py())
105 pzvec.push_back(jet.pz())
106 Evec.push_back(jet.energy())
108 hemisphere = Hemisphere(pxvec, pyvec, pzvec, Evec, 2, 3)
109 grouping=hemisphere.getGrouping()
123 for index
in range(0, len(pxvec)):
124 if(grouping[index]==1):
125 pseudoJet1px += pxvec[index]
126 pseudoJet1py += pyvec[index]
127 pseudoJet1pz += pzvec[index]
128 pseudoJet1energy += Evec[index]
130 if(grouping[index]==2):
131 pseudoJet2px += pxvec[index]
132 pseudoJet2py += pyvec[index]
133 pseudoJet2pz += pzvec[index]
134 pseudoJet2energy += Evec[index]
137 pseudoJet1pt2 = pseudoJet1px*pseudoJet1px + pseudoJet1py*pseudoJet1py
138 pseudoJet2pt2 = pseudoJet2px*pseudoJet2px + pseudoJet2py*pseudoJet2py
140 if pseudoJet1pt2 >= pseudoJet2pt2:
141 setattr(event,
"pseudoJet1"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector( pseudoJet1px, pseudoJet1py, pseudoJet1pz, pseudoJet1energy ))
142 setattr(event,
"pseudoJet2"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector( pseudoJet2px, pseudoJet2py, pseudoJet2pz, pseudoJet2energy ))
143 setattr(event,
"multPseudoJet1"+collectionPostFix+postFix, multPSJ1 )
144 setattr(event,
"multPseudoJet2"+collectionPostFix+postFix, multPSJ2 )
146 setattr(event,
"pseudoJet2"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector( pseudoJet1px, pseudoJet1py, pseudoJet1pz, pseudoJet1energy ))
147 setattr(event,
"pseudoJet1"+collectionPostFix+postFix, ROOT.reco.Particle.LorentzVector( pseudoJet2px, pseudoJet2py, pseudoJet2pz, pseudoJet2energy ))
148 setattr(event,
"multPseudoJet1"+collectionPostFix+postFix, multPSJ2 )
149 setattr(event,
"multPseudoJet2"+collectionPostFix+postFix, multPSJ1 )
151 setattr(event,
"mt2"+collectionPostFix+postFix, self.
computeMT2(getattr(event,
'pseudoJet1'+collectionPostFix+postFix), getattr(event,
'pseudoJet2'+collectionPostFix+postFix), met) )
152 return self.
computeMT2(getattr(event,
'pseudoJet1'+collectionPostFix+postFix), getattr(event,
'pseudoJet2'+collectionPostFix+postFix), met)
159 self.
met = ROOT.pat.MET(self.handles[
'met'].product()[0])
164 objects40jc = [ j
for j
in event.cleanJets
if j.pt() > 40
and abs(j.eta())<2.5 ]
165 objectsXjc = [ j
for j
in event.cleanJets
if j.pt() > self.
jetPt and abs(j.eta())<2.5 ]
167 setattr(event,
"mt2ViaKt"+self.cfg_ana.collectionPostFix+
"had", -999)
168 setattr(event,
"mt2ViaKt"+self.cfg_ana.collectionPostFix+
"_Xj_had", -999)
169 setattr(event,
"pseudoViaKtJet1"+self.cfg_ana.collectionPostFix+
"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
170 setattr(event,
"pseudoViaKtJet2"+self.cfg_ana.collectionPostFix+
"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
171 setattr(event,
"pseudoViaKtJet1"+self.cfg_ana.collectionPostFix+
"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
172 setattr(event,
"pseudoViaKtJet2"+self.cfg_ana.collectionPostFix+
"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
174 setattr(event,
"mt2ViaAKt"+self.cfg_ana.collectionPostFix+
"had", -999)
175 setattr(event,
"mt2ViaAKt"+self.cfg_ana.collectionPostFix+
"_Xj_had", -999)
176 setattr(event,
"pseudoViaAKtJet1"+self.cfg_ana.collectionPostFix+
"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
177 setattr(event,
"pseudoViaAKtJet2"+self.cfg_ana.collectionPostFix+
"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
178 setattr(event,
"pseudoViaAKtJet1"+self.cfg_ana.collectionPostFix+
"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
179 setattr(event,
"pseudoViaAKtJet2"+self.cfg_ana.collectionPostFix+
"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
182 if len(objects40jc)>=2:
184 self.mt2ViaKt_had=self.
getMT2AKT(event, objects40jc, self.
met, self.cfg_ana.collectionPostFix,
"_had")
186 if len(objectsXjc)>=2:
188 self.mt2ViaKt_Xj_had=self.
getMT2AKT(event, objectsXjc, self.
met, self.cfg_ana.collectionPostFix,
"_Xj_had")
193 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_had", -999)
194 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_Xj_had", -999)
196 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
197 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
198 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
199 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"_Xj_had", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
201 if len(objects40jc)>=2:
203 self.mt2_had = self.
getMT2Hemi(event,objects40jc, self.
met, self.cfg_ana.collectionPostFix,
"_had")
205 if len(objectsXjc)>=2:
207 self.mt2_Xj_had = self.
getMT2Hemi(event,objectsXjc, self.
met, self.cfg_ana.collectionPostFix,
"_Xj_had")
211 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_gen", -999)
212 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_Xj_gen", -999)
214 if self.cfg_comp.isMC
and self.met.genMET():
215 allGenJets = [ x
for x
in self.handles[
'genJets'].product() ]
216 objects40jc_Gen = [ j
for j
in allGenJets
if j.pt() > 40
and abs(j.eta())<2.5 ]
217 objectsXjc_Gen = [ j
for j
in allGenJets
if j.pt() > self.jetPt
and abs(j.eta())<2.5 ]
219 if len(objects40jc_Gen)>=2:
220 self.mt2_gen = self.getMT2Hemi(event,objects40jc_Gen, self.met.genMET(), self.cfg_ana.collectionPostFix,
"_gen")
222 if len(objectsXjc_Gen)>=2:
223 self.mt2_Xj_gen = self.getMT2Hemi(event,objectsXjc_Gen, self.met.genMET(), self.cfg_ana.collectionPostFix,
"_Xj_gen")
231 objects10lc = [ l
for l
in event.selectedLeptons
if l.pt() > 10
and abs(l.eta())<2.5 ]
232 if hasattr(event,
'selectedIsoCleanTrack'):
233 objects10lc = [ l
for l
in event.selectedLeptons
if l.pt() > 10
and abs(l.eta())<2.5 ] + [ t
for t
in event.selectedIsoCleanTrack ]
235 objects40j10lc = objects40jc + objects10lc
236 objects40j10lc.sort(key =
lambda obj : obj.pt(), reverse =
True)
238 objectsXj10lc = objectsXjc + objects10lc
239 objectsXj10lc.sort(key =
lambda obj : obj.pt(), reverse =
True)
241 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"", -999)
242 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_Xj", -999)
244 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
245 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
246 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"_Xj", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
247 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"_Xj", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
249 if len(objects40j10lc)>=2:
251 self.mt2 = self.getMT2Hemi(event,objects40j10lc,self.met,self.cfg_ana.collectionPostFix,
"")
253 if len(objectsXj10lc)>=2:
255 self.mt2_Xj = self.getMT2Hemi(event,objectsXj10lc,self.met,self.cfg_ana.collectionPostFix,
"_Xj")
259 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_gamma", -999)
261 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"_gamma", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
262 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"_gamma", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
264 if hasattr(event,
'gamma_met'):
266 gamma_objects40jc = [ j
for j
in event.gamma_cleanJets
if j.pt() > 40
and abs(j.eta())<2.5 ]
268 gamma_objects40j10lc = gamma_objects40jc + objects10lc
270 gamma_objects40j10lc.sort(key =
lambda obj : obj.pt(), reverse =
True)
273 if len(gamma_objects40jc)>=2:
275 self.gamma_mt2 = self.getMT2Hemi(event,gamma_objects40jc,event.gamma_met,self.cfg_ana.collectionPostFix,
"_gamma")
277 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_Xj_gamma", -999)
278 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"_Xj_gamma", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
279 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"_Xj_gamma", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
281 if hasattr(event,
'gamma_met'):
283 gamma_objectsXjc = [ j
for j
in event.gamma_cleanJets
if j.pt() > self.jetPt
and abs(j.eta())<2.5 ]
285 gamma_objectsXj10lc = gamma_objectsXjc + objects10lc
287 gamma_objectsXj10lc.sort(key =
lambda obj : obj.pt(), reverse =
True)
289 if len(gamma_objectsXjc)>=2:
291 self.gamma_mt2_Xj = self.getMT2Hemi(event,gamma_objectsXjc,event.gamma_met,self.cfg_ana.collectionPostFix,
"_Xj_gamma")
297 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_zll", -999)
298 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"_zll", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
299 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"_zll", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
301 if hasattr(event,
'zll_met'):
303 csLeptons = [ l
for l
in event.selectedLeptons
if l.pt() > 10
and abs(l.eta()) < 2.5 ]
305 if len(csLeptons)==2
and len(objects40jc)>=2:
307 self.zll_mt2 = self.getMT2Hemi(event,objects40jc,event.zll_met,self.cfg_ana.collectionPostFix,
"_zll")
309 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_Xj_zll", -999)
310 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"_Xj_zll", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
311 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"_Xj_zll", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
313 if hasattr(event,
'zll_met'):
315 csLeptons = [ l
for l
in event.selectedLeptons
if l.pt() > 10
and abs(l.eta()) < 2.5 ]
317 if len(csLeptons)==2
and len(objectsXjc)>=2:
319 self.zll_mt2_Xj = self.getMT2Hemi(event,objectsXjc,event.zll_met,self.cfg_ana.collectionPostFix,
"_Xj_zll")
350 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_rl", -999)
351 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"_rl", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
352 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"_rl", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
354 if hasattr(event,
'rl_met'):
356 csLeptons = [ l
for l
in event.selectedLeptons
if l.pt() > 10
and abs(l.eta()) < 2.5 ]
358 if len(csLeptons)==1
and len(objects40jc)>=2:
360 self.rl_mt2 = self.getMT2Hemi(event,objects40jc,event.rl_met,self.cfg_ana.collectionPostFix,
"_rl")
362 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_Xj_rl", -999)
363 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"_Xj_rl", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
364 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"_Xj_rl", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
366 if hasattr(event,
'rl_met'):
368 csLeptons = [ l
for l
in event.selectedLeptons
if l.pt() > 10
and abs(l.eta()) < 2.5 ]
370 if len(csLeptons)==1
and len(objectsXjc)>=2:
372 self.rl_mt2_Xj = self.getMT2Hemi(event,objectsXjc,event.rl_met,self.cfg_ana.collectionPostFix,
"_Xj_rl")
377 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_zllmt", -999)
378 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
379 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
381 if hasattr(event,
'zllmt_met'):
383 csLeptons = [ l
for l
in event.selectedLeptons
if l.pt() > 10
and abs(l.eta()) < 2.5 ]
385 if len(csLeptons)==2
and len(objects40jc)>=2:
387 self.zllmt_mt2 = self.getMT2Hemi(event,objects40jc,event.zllmt_met,self.cfg_ana.collectionPostFix,
"_zllmt")
389 setattr(event,
"mt2"+self.cfg_ana.collectionPostFix+
"_Xj_zllmt", -999)
390 setattr(event,
"pseudoJet1"+self.cfg_ana.collectionPostFix+
"_Xj_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
391 setattr(event,
"pseudoJet2"+self.cfg_ana.collectionPostFix+
"_Xj_zllmt", ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 ))
393 if hasattr(event,
'zllmt_met'):
395 csLeptons = [ l
for l
in event.selectedLeptons
if l.pt() > 10
and abs(l.eta()) < 2.5 ]
397 if len(csLeptons)==2
and len(objectsXjc)>=1:
400 if (event.eventId%2):
401 csLeptons_mt.append(csLeptons[1])
403 csLeptons_mt.append(csLeptons[0])
405 self.zllmt_mt2_Xj = self.getMT2Hemi(event,objectsXjc+[l
for l
in csLeptons
if l
not in csLeptons_mt],event.zllmt_met,self.cfg_ana.collectionPostFix,
"_Xj_zllmt")
409 if len(event.bjetsMedium)>=2:
411 event.mt2bb = self.computeMT2(event.bjetsMedium[0], event.bjetsMedium[1], self.met)
412 event.mt2bb_Xj = self.computeMT2(event.bjetsMedium[0], event.bjetsMedium[1], self.met)
414 if len(event.bjetsMedium)==1:
416 objects40jcCSV = [ j
for j
in event.cleanJets
if j.pt() > 40
and abs(j.eta())<2.5
and j.p4()!=event.bjetsMedium[0].p4() ]
417 objects40jcCSV.sort(key =
lambda l : l.btag(
'pfCombinedInclusiveSecondaryVertexV2BJetTags'), reverse =
True)
419 objectsXjcCSV = [ j
for j
in event.cleanJets
if j.pt() > self.jetPt
and abs(j.eta())<2.5
and j.p4()!=event.bjetsMedium[0].p4() ]
420 objectsXjcCSV.sort(key =
lambda l : l.btag(
'pfCombinedInclusiveSecondaryVertexV2BJetTags'), reverse =
True)
422 if len(objects40jcCSV)>0:
423 self.mt2bb = self.computeMT2(event.bjetsMedium[0], objects40jcCSV[0], self.met)
424 setattr(event,
"mt2bb"+self.cfg_ana.collectionPostFix, self.mt2bb)
426 if len(objectsXjcCSV)>0:
427 self.mt2bb_Xj = self.computeMT2(event.bjetsMedium[0], objectsXjcCSV[0], self.met)
428 setattr(event,
"mt2bb_Xj"+self.cfg_ana.collectionPostFix, self.mt2bb_Xj)
433 if not self.cfg_ana.doOnlyDefault:
434 if len(event.selectedLeptons)>=2:
435 self.mt2lep = self.computeMT2(event.selectedLeptons[0], event.selectedLeptons[1], self.met)
436 setattr(event,
"mt2lep"+self.cfg_ana.collectionPostFix, self.mt2lep)
441 self.readCollections( event.input )
447 event.multPseudoJet1_had=0
448 event.multPseudoJet2_had=0
450 event.multPseudoJet1_Xj_had=0
451 event.multPseudoJet2_Xj_had=0
465 setattr(MT2Analyzer,
"defaultConfig", cfg.Analyzer(
466 class_object = MT2Analyzer,
467 metCollection =
"slimmedMETs",
468 collectionPostFix =
"",
469 doOnlyDefault =
True,
const uint16_t range(const Frame &aFrame)
if(conf_.getParameter< bool >("UseStripCablingDB"))
Abs< T >::type abs(const T &t)