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
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)
57 self.handles[
'met'] = AutoHandle(
'slimmedMETs',
'std::vector<pat::MET>' )
58 self.handles[
'packedCandidates'] = AutoHandle(
'packedPFCandidates',
'std::vector<pat::PackedCandidate>')
61 super(IsoTrackAnalyzer,self).
beginLoop(setup)
62 self.counters.addCounter(
'events')
63 count = self.counters.counter(
'events')
64 count.register(
'all events')
65 count.register(
'has >=1 selected Track')
66 count.register(
'has >=1 selected Iso Track')
75 event.selectedIsoTrack = []
76 event.selectedIsoCleanTrack = []
79 patcands = self.handles[
'packedCandidates'].product()
81 charged = [ p
for p
in patcands
if ( p.charge() != 0
and abs(p.dz())<=self.cfg_ana.dzMax ) ]
83 self.IsoTrackIsolationComputer.setPackedCandidates(patcands, -1, 0.1,
True)
85 alltrack =
map( IsoTrack, charged )
88 for track
in alltrack:
90 if ( (
abs(track.pdgId())!=11)
and (
abs(track.pdgId())!=13)
and (track.pt() < self.cfg_ana.ptMin) ):
continue
91 if ( track.pt() < self.cfg_ana.ptMinEMU ):
continue
93 foundNonIsoTrack =
False
96 if( (self.cfg_ana.doSecondVeto)
and len(event.selectedLeptons)>0) :
97 if(
deltaR(event.selectedLeptons[0].
eta(), event.selectedLeptons[0].
phi(), track.eta(), track.phi()) <0.01) :
continue
98 if ( (
abs(track.pdgId())!=11)
and (
abs(track.pdgId())!=13)
and (track.charge()*event.selectedLeptons[0].charge()) ):
continue
102 track.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
106 isoSum = self.IsoTrackIsolationComputer.chargedAbsIso(track.physObj, self.cfg_ana.isoDR, 0., self.cfg_ana.ptPartMin)
108 if(isoSum > (self.cfg_ana.maxAbsIso + track.pt())):
continue
112 track.absIso = isoSum - track.pt()
118 if(track.absIso <
min(0.2*track.pt(), self.cfg_ana.maxAbsIso)):
119 event.selectedIsoTrack.append(track)
121 if self.cfg_ana.doPrune:
122 myMet = self.handles[
'met'].product()[0]
123 mtwIsoTrack =
mtw(track, myMet)
124 if mtwIsoTrack < 100:
125 if abs(track.pdgId()) == 11
or abs(track.pdgId()) == 13:
126 if track.pt()>5
and track.absIso/track.pt()<0.2:
128 myLeptons = [ l
for l
in event.selectedLeptons
if l.pt() > 10 ]
130 if len(nearestSelectedLeptons) > 0:
131 for lep
in nearestSelectedLeptons:
132 if deltaR(lep.eta(), lep.phi(), track.eta(), track.phi()) > 0.1:
133 event.selectedIsoCleanTrack.append(track)
135 event.selectedIsoCleanTrack.append(track)
215 event.selectedIsoTrack.sort(key =
lambda l : l.pt(), reverse =
True)
216 event.selectedIsoCleanTrack.sort(key =
lambda l : l.pt(), reverse =
True)
218 self.counters.counter(
'events').inc(
'all events')
220 if(len(event.selectedIsoTrack)): self.counters.counter(
'events').inc(
'has >=1 selected Iso Track')
223 matchTau =
matchObjectCollection3(event.selectedIsoTrack, event.gentaus + event.gentauleps + event.genleps, deltaRMax = 0.5)
224 for lep
in event.selectedIsoTrack:
226 lep.mcMatchId = 1
if gen
else 0
229 print 'event to Veto'
230 print '----------------'
232 if len(event.selectedIsoTrack)>0:
233 print 'lenght: ',len(event.selectedIsoTrack)
234 print 'track candidate pt: ',event.selectedIsoTrack[0].
pt()
235 print 'track candidate eta: ',event.selectedIsoTrack[0].
eta()
236 print 'track candidate phi: ',event.selectedIsoTrack[0].
phi()
237 print 'track candidate mass: ',event.selectedIsoTrack[0].mass()
238 print 'pdgId candidate : ',event.selectedIsoTrack[0].
pdgId()
239 print 'dz: ',event.selectedIsoTrack[0].dz()
240 print 'iso: ',event.selectedIsoTrack[0].absIso
241 print 'matchId: ',event.selectedIsoTrack[0].mcMatchId
251 print '----------------'
256 if self.cfg_ana.setOff:
259 self.readCollections( event.input )
260 self.makeIsoTrack(event)
262 if len(event.selectedIsoTrack)==0 :
return True
270 if not self.cfg_comp.isMC:
273 if hasattr(event,
'gentaus')
and hasattr(event,
'gentauleps')
and hasattr(event,
'genleps') :
274 self.matchIsoTrack(event)
292 setattr(IsoTrackAnalyzer,
"defaultConfig",cfg.Analyzer(
293 class_object=IsoTrackAnalyzer,
296 candidates=
'packedPFCandidates',
297 candidatesTypes=
'std::vector<pat::PackedCandidate>',
309 doSecondVeto =
False,
def matchIsoTrack
alltrack = map( IsoTrack, charged )
Abs< T >::type abs(const T &t)
IsoTrackIsolationComputer
double deltaR(double eta1, double eta2, double phi1, double phi2)
if(conf.exists("allCellsPositionCalc"))
def matchObjectCollection3