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
22 return math.sqrt(2*x1.pt()*x2.pt()*(1-math.cos(x1.phi()-x2.phi())))
30 for i,lepton
in enumerate(leptons):
31 minDeltaRtemp=
deltaR(lepton.eta(),lepton.phi(),track.eta(),track.phi())
32 if minDeltaRtemp < minDeltaR:
33 minDeltaR = minDeltaRtemp
36 if len(leptons) > 0
and ibest!=-1:
37 nearestLepton.append(leptons[ibest])
43 def __init__(self, cfg_ana, cfg_comp, looperName ):
44 super(IsoTrackAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
51 self.handles[
'cmgCand'] = AutoHandle(self.cfg_ana.candidates,self.cfg_ana.candidatesTypes)
52 self.handles[
'met'] = AutoHandle(
'slimmedMETs',
'std::vector<pat::MET>' )
55 super(IsoTrackAnalyzer,self).
beginLoop(setup)
56 self.counters.addCounter(
'events')
57 count = self.counters.counter(
'events')
58 count.register(
'all events')
59 count.register(
'has >=1 selected Track')
60 count.register(
'has >=1 selected Iso Track')
69 event.selectedIsoTrack = []
70 event.selectedIsoCleanTrack = []
73 pfcands = self.handles[
'cmgCand'].product()
75 charged = [ p
for p
in pfcands
if ( p.charge() != 0
and abs(p.dz())<=self.cfg_ana.dzMax ) ]
77 alltrack =
map( IsoTrack, charged )
80 for track
in alltrack:
82 foundNonIsoTrack =
False
85 if ( (
abs(track.pdgId())!=11)
and (
abs(track.pdgId())!=13)
and (track.pt() < self.cfg_ana.ptMin) ):
continue
86 if ( track.pt() < self.cfg_ana.ptMinEMU ):
continue
90 if( (self.cfg_ana.doSecondVeto)
and len(event.selectedLeptons)>0) :
91 if(
deltaR(event.selectedLeptons[0].
eta(), event.selectedLeptons[0].
phi(), track.eta(), track.phi()) <0.01) :
continue
92 if ( (
abs(track.pdgId())!=11)
and (
abs(track.pdgId())!=13)
and (track.charge()*event.selectedLeptons[0].charge()) ):
continue
95 track.associatedVertex = event.goodVertices[0]
99 othertracks = [ p
for p
in charged
if(
deltaR(p.eta(), p.phi(), track.eta(), track.phi()) < self.cfg_ana.isoDR
and p.pt()>self.cfg_ana.ptPartMin ) ]
103 for part
in othertracks:
110 if(isoSum > (self.cfg_ana.maxAbsIso + track.pt())):
111 foundNonIsoTrack =
True
114 if foundNonIsoTrack:
continue
129 track.absIso = isoSum - track.pt()
135 if(track.absIso <
min(0.2*track.pt(), self.cfg_ana.maxAbsIso)):
136 event.selectedIsoTrack.append(track)
138 if self.cfg_ana.doPrune:
139 myMet = self.handles[
'met'].product()[0]
140 mtwIsoTrack =
mtw(track, myMet)
141 if mtwIsoTrack < 100:
142 if abs(track.pdgId()) == 11
or abs(track.pdgId()) == 13:
143 if track.pt()>5
and track.absIso/track.pt()<0.2:
145 myLeptons = [ l
for l
in event.selectedLeptons
if l.pt() > 10 ]
147 if len(nearestSelectedLeptons) > 0:
148 for lep
in nearestSelectedLeptons:
149 if deltaR(lep.eta(), lep.phi(), track.eta(), track.phi()) > 0.1:
150 event.selectedIsoCleanTrack.append(track)
152 event.selectedIsoCleanTrack.append(track)
154 event.selectedIsoTrack.sort(key =
lambda l : l.pt(), reverse =
True)
155 event.selectedIsoCleanTrack.sort(key =
lambda l : l.pt(), reverse =
True)
157 self.counters.counter(
'events').inc(
'all events')
159 if(len(event.selectedIsoTrack)): self.counters.counter(
'events').inc(
'has >=1 selected Iso Track')
162 matchTau =
matchObjectCollection3(event.selectedIsoTrack, event.gentaus + event.gentauleps + event.genleps, deltaRMax = 0.5)
163 for lep
in event.selectedIsoTrack:
165 lep.mcMatchId = 1
if gen
else 0
168 print 'event to Veto'
169 print '----------------'
171 if len(event.selectedIsoTrack)>0:
172 print 'lenght: ',len(event.selectedIsoTrack)
173 print 'track candidate pt: ',event.selectedIsoTrack[0].
pt()
174 print 'track candidate eta: ',event.selectedIsoTrack[0].
eta()
175 print 'track candidate phi: ',event.selectedIsoTrack[0].
phi()
176 print 'track candidate mass: ',event.selectedIsoTrack[0].mass()
177 print 'pdgId candidate : ',event.selectedIsoTrack[0].
pdgId()
178 print 'dz: ',event.selectedIsoTrack[0].dz()
179 print 'iso: ',event.selectedIsoTrack[0].absIso
180 print 'matchId: ',event.selectedIsoTrack[0].mcMatchId
190 print '----------------'
195 if self.cfg_ana.setOff:
198 self.readCollections( event.input )
199 self.makeIsoTrack(event)
201 if len(event.selectedIsoTrack)==0 :
return True
209 if not self.cfg_comp.isMC:
212 if hasattr(event,
'gentaus')
and hasattr(event,
'gentauleps')
and hasattr(event,
'genleps') :
213 self.matchIsoTrack(event)
231 setattr(IsoTrackAnalyzer,
"defaultConfig",cfg.Analyzer(
232 class_object=IsoTrackAnalyzer,
235 candidates=
'packedPFCandidates',
236 candidatesTypes=
'std::vector<pat::PackedCandidate>',
248 doSecondVeto =
False,
Abs< T >::type abs(const T &t)
double deltaR(double eta1, double eta2, double phi1, double phi2)
if(conf.exists("allCellsPositionCalc"))
def matchObjectCollection3