6 from ROOT
import TLorentzVector
8 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
9 from PhysicsTools.HeppyCore.framework.event
import Event
10 from PhysicsTools.HeppyCore.statistics.counter
import Counter, Counters
11 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
12 from PhysicsTools.Heppy.physicsobjects.Lepton
import Lepton
13 from PhysicsTools.Heppy.physicsobjects.Tau
import Tau
14 from PhysicsTools.Heppy.physicsobjects.IsoTrack
import IsoTrack
18 import PhysicsTools.HeppyCore.framework.config
as cfg
20 from ROOT
import heppy
27 return math.sqrt(2*x1.pt()*x2.pt()*(1-math.cos(x1.phi()-x2.phi())))
35 for i,lepton
in enumerate(leptons):
36 minDeltaRtemp=
deltaR(lepton.eta(),lepton.phi(),track.eta(),track.phi())
37 if minDeltaRtemp < minDeltaR:
38 minDeltaR = minDeltaRtemp
41 if len(leptons) > 0
and ibest!=-1:
42 nearestLepton.append(leptons[ibest])
48 def __init__(self, cfg_ana, cfg_comp, looperName ):
49 super(IsoTrackAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
60 self.handles[
'met'] = AutoHandle(
'slimmedMETs',
'std::vector<pat::MET>' )
61 self.handles[
'packedCandidates'] = AutoHandle(
'packedPFCandidates',
'std::vector<pat::PackedCandidate>')
64 super(IsoTrackAnalyzer,self).
beginLoop(setup)
65 self.counters.addCounter(
'events')
66 count = self.counters.counter(
'events')
67 count.register(
'all events')
68 count.register(
'has >=1 selected Track')
69 count.register(
'has >=1 selected Iso Track')
76 event.selectedIsoTrack = []
77 event.selectedIsoCleanTrack = []
80 patcands = self.handles[
'packedCandidates'].product()
82 charged = [ p
for p
in patcands
if ( p.charge() != 0
and p.fromPV() > 1 ) ]
84 self.IsoTrackIsolationComputer.setPackedCandidates(patcands, 1, 9999, 9999.)
87 alltrack = map( IsoTrack, charged )
90 for track
in alltrack:
92 if (
abs(track.dz()) > self.cfg_ana.dzMax ):
continue
93 if ( (
abs(track.pdgId())!=11)
and (
abs(track.pdgId())!=13)
and (track.pt() < self.cfg_ana.ptMin) ):
continue
94 if ( track.pt() < self.cfg_ana.ptMinEMU ):
continue
96 foundNonIsoTrack =
False
99 if( (self.cfg_ana.doSecondVeto)
and len(event.selectedLeptons)>0) :
100 if(
deltaR(event.selectedLeptons[0].
eta(), event.selectedLeptons[0].phi(), track.eta(), track.phi()) <0.01) :
continue
101 if ( (
abs(track.pdgId())!=11)
and (
abs(track.pdgId())!=13)
and (track.charge()*event.selectedLeptons[0].
charge()) ):
continue
105 track.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
109 isoSum = self.IsoTrackIsolationComputer.chargedAbsIso(track.physObj, self.cfg_ana.isoDR, 0., self.cfg_ana.ptPartMin)
110 if(
abs(track.pdgId())==211 ): isoSum = isoSum - track.pt()
112 if self.cfg_ana.doRelIsolation:
113 relIso = (isoSum)/track.pt()
114 if ( (
abs(track.pdgId())!=11)
and (
abs(track.pdgId())!=13)
and (relIso > self.cfg_ana.MaxIsoSum) ):
continue
115 elif((relIso > self.cfg_ana.MaxIsoSumEMU)):
continue
117 if(isoSum > (self.cfg_ana.maxAbsIso)):
continue
119 if self.doIsoAnnulus:
120 self.attachIsoAnnulus04(track)
122 track.absIso = isoSum
128 if self.cfg_ana.doRelIsolation
or (track.absIso <
min(0.2*track.pt(), self.cfg_ana.maxAbsIso)):
129 event.selectedIsoTrack.append(track)
131 if self.cfg_ana.doPrune:
132 myMet = self.handles[
'met'].product()[0]
133 mtwIsoTrack =
mtw(track, myMet)
134 if mtwIsoTrack < 100:
135 if abs(track.pdgId()) == 11
or abs(track.pdgId()) == 13:
136 if track.pt()>5
and track.absIso/track.pt()<0.2:
138 myLeptons = [ l
for l
in event.selectedLeptons
if l.pt() > 10 ]
140 if len(nearestSelectedLeptons) > 0:
141 for lep
in nearestSelectedLeptons:
142 if deltaR(lep.eta(), lep.phi(), track.eta(), track.phi()) > 0.01:
143 event.selectedIsoCleanTrack.append(track)
145 event.selectedIsoCleanTrack.append(track)
225 event.selectedIsoTrack.sort(key =
lambda l : l.pt(), reverse =
True)
226 event.selectedIsoCleanTrack.sort(key =
lambda l : l.pt(), reverse =
True)
228 self.counters.counter(
'events').inc(
'all events')
230 if(len(event.selectedIsoTrack)): self.counters.counter(
'events').inc(
'has >=1 selected Iso Track')
234 mu.absIsoAnCharged = self.IsoTrackIsolationComputer.chargedAbsIso (mu.physObj, 0.4, self.cfg_ana.isoDR, 0.0,self.IsoTrackIsolationComputer.selfVetoNone)
235 mu.absIsoAnPho = self.IsoTrackIsolationComputer.photonAbsIsoRaw (mu.physObj, 0.4, self.cfg_ana.isoDR, 0.0,self.IsoTrackIsolationComputer.selfVetoNone)
236 mu.absIsoAnNHad = self.IsoTrackIsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.4, self.cfg_ana.isoDR, 0.0,self.IsoTrackIsolationComputer.selfVetoNone)
237 mu.absIsoAnPU = self.IsoTrackIsolationComputer.puAbsIso (mu.physObj, 0.4, self.cfg_ana.isoDR, 0.0,self.IsoTrackIsolationComputer.selfVetoNone)
238 mu.absIsoAnNeutral =
max(0.0, mu.absIsoAnPho + mu.absIsoAnNHad - 0.5*mu.absIsoAnPU)
240 mu.absIsoAn04 = mu.absIsoAnCharged + mu.absIsoAnNeutral
241 mu.relIsoAn04 = mu.absIsoAn04/mu.pt()
245 matchTau =
matchObjectCollection3(event.selectedIsoTrack, event.gentaus + event.gentauleps + event.genleps, deltaRMax = 0.5)
246 for lep
in event.selectedIsoTrack:
248 lep.mcMatchId = 1
if gen
else 0
252 print 'event to Veto'
253 print '----------------'
255 if len(event.selectedIsoTrack)>0:
256 print 'lenght: ',len(event.selectedIsoTrack)
257 print 'track candidate pt: ',event.selectedIsoTrack[0].
pt()
258 print 'track candidate eta: ',event.selectedIsoTrack[0].
eta()
259 print 'track candidate phi: ',event.selectedIsoTrack[0].phi()
260 print 'track candidate mass: ',event.selectedIsoTrack[0].mass()
261 print 'pdgId candidate : ',event.selectedIsoTrack[0].
pdgId()
262 print 'dz: ',event.selectedIsoTrack[0].dz()
263 print 'iso: ',event.selectedIsoTrack[0].absIso
264 print 'matchId: ',event.selectedIsoTrack[0].mcMatchId
274 print '----------------'
279 if self.cfg_ana.setOff:
282 self.readCollections( event.input )
283 self.makeIsoTrack(event)
285 if len(event.selectedIsoTrack)==0 :
return True
293 if not self.cfg_comp.isMC:
296 if hasattr(event,
'gentaus')
and hasattr(event,
'gentauleps')
and hasattr(event,
'genleps')
and self.cfg_ana.do_mc_match :
297 self.matchIsoTrack(event)
315 setattr(IsoTrackAnalyzer,
"defaultConfig",cfg.Analyzer(
316 class_object=IsoTrackAnalyzer,
319 candidates=
'packedPFCandidates',
320 candidatesTypes=
'std::vector<pat::PackedCandidate>',
330 doRelIsolation =
False,
333 doSecondVeto =
False,
def attachIsoAnnulus04
alltrack = map( IsoTrack, charged )
Abs< T >::type abs(const T &t)
IsoTrackIsolationComputer
double deltaR(double eta1, double eta2, double phi1, double phi2)
def matchObjectCollection3