1 from __future__
import print_function
7 from ROOT
import TLorentzVector
9 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
10 from PhysicsTools.HeppyCore.framework.event
import Event
11 from PhysicsTools.HeppyCore.statistics.counter
import Counter, Counters
12 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
13 from PhysicsTools.Heppy.physicsobjects.Lepton
import Lepton
14 from PhysicsTools.Heppy.physicsobjects.Tau
import Tau
15 from PhysicsTools.Heppy.physicsobjects.IsoTrack
import IsoTrack
19 import PhysicsTools.HeppyCore.framework.config
as cfg
21 from ROOT
import heppy
28 return math.sqrt(2*x1.pt()*x2.pt()*(1-math.cos(x1.phi()-x2.phi())))
36 for i,lepton
in enumerate(leptons):
37 minDeltaRtemp=
deltaR(lepton.eta(),lepton.phi(),track.eta(),track.phi())
38 if minDeltaRtemp < minDeltaR:
39 minDeltaR = minDeltaRtemp
42 if len(leptons) > 0
and ibest!=-1:
43 nearestLepton.append(leptons[ibest])
49 def __init__(self, cfg_ana, cfg_comp, looperName ):
50 super(IsoTrackAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
61 self.handles[
'met'] = AutoHandle(
'slimmedMETs',
'std::vector<pat::MET>' )
62 self.handles[
'packedCandidates'] = AutoHandle(
'packedPFCandidates',
'std::vector<pat::PackedCandidate>')
65 super(IsoTrackAnalyzer,self).
beginLoop(setup)
66 self.counters.addCounter(
'events')
67 count = self.counters.
counter(
'events')
68 count.register(
'all events')
69 count.register(
'has >=1 selected Track')
70 count.register(
'has >=1 selected Iso Track')
77 event.selectedIsoTrack = []
78 event.selectedIsoCleanTrack = []
81 patcands = self.handles[
'packedCandidates'].product()
83 charged = [ p
for p
in patcands
if ( p.charge() != 0
and p.fromPV() > 1 ) ]
88 alltrack =
map( IsoTrack, charged )
91 for track
in alltrack:
93 if (
abs(track.dz()) > self.cfg_ana.dzMax ):
continue 94 if ( (
abs(track.pdgId())!=11)
and (
abs(track.pdgId())!=13)
and (track.pt() < self.cfg_ana.ptMin) ):
continue 95 if ( track.pt() < self.cfg_ana.ptMinEMU ):
continue 97 foundNonIsoTrack =
False 100 if( (self.cfg_ana.doSecondVeto)
and len(event.selectedLeptons)>0) :
101 if(
deltaR(event.selectedLeptons[0].
eta(), event.selectedLeptons[0].phi(), track.eta(), track.phi()) <0.01) :
continue 102 if ( (
abs(track.pdgId())!=11)
and (
abs(track.pdgId())!=13)
and (track.charge()*event.selectedLeptons[0].
charge()) ):
continue 106 track.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
110 isoSum = self.IsoTrackIsolationComputer.chargedAbsIso(track.physObj, self.cfg_ana.isoDR, 0., self.cfg_ana.ptPartMin)
111 if(
abs(track.pdgId())==211 ): isoSum = isoSum - track.pt()
113 if self.cfg_ana.doRelIsolation:
114 relIso = (isoSum)/track.pt()
115 if ( (
abs(track.pdgId())!=11)
and (
abs(track.pdgId())!=13)
and (relIso > self.cfg_ana.MaxIsoSum) ):
continue 116 elif((relIso > self.cfg_ana.MaxIsoSumEMU)):
continue 118 if(isoSum > (self.cfg_ana.maxAbsIso)):
continue 120 if self.doIsoAnnulus:
121 self.attachIsoAnnulus04(track)
123 track.absIso = isoSum
129 if self.cfg_ana.doRelIsolation
or (track.absIso <
min(0.2*track.pt(), self.cfg_ana.maxAbsIso)):
130 event.selectedIsoTrack.append(track)
132 if self.cfg_ana.doPrune:
133 myMet = self.handles[
'met'].product()[0]
134 mtwIsoTrack =
mtw(track, myMet)
135 if mtwIsoTrack < 100:
136 if abs(track.pdgId()) == 11
or abs(track.pdgId()) == 13:
137 if track.pt()>5
and track.absIso/track.pt()<0.2:
139 myLeptons = [ l
for l
in event.selectedLeptons
if l.pt() > 10 ]
141 if len(nearestSelectedLeptons) > 0:
142 for lep
in nearestSelectedLeptons:
143 if deltaR(lep.eta(), lep.phi(), track.eta(), track.phi()) > 0.01:
144 event.selectedIsoCleanTrack.append(track)
146 event.selectedIsoCleanTrack.append(track)
226 event.selectedIsoTrack.sort(key =
lambda l : l.pt(), reverse =
True)
227 event.selectedIsoCleanTrack.sort(key =
lambda l : l.pt(), reverse =
True)
229 self.counters.
counter(
'events').inc(
'all events')
231 if(len(event.selectedIsoTrack)): self.counters.
counter(
'events').inc(
'has >=1 selected Iso Track')
235 mu.absIsoAnCharged = self.IsoTrackIsolationComputer.chargedAbsIso (mu.physObj, 0.4, self.cfg_ana.isoDR, 0.0,self.IsoTrackIsolationComputer.selfVetoNone)
236 mu.absIsoAnPho = self.IsoTrackIsolationComputer.photonAbsIsoRaw (mu.physObj, 0.4, self.cfg_ana.isoDR, 0.0,self.IsoTrackIsolationComputer.selfVetoNone)
237 mu.absIsoAnNHad = self.IsoTrackIsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.4, self.cfg_ana.isoDR, 0.0,self.IsoTrackIsolationComputer.selfVetoNone)
238 mu.absIsoAnPU = self.IsoTrackIsolationComputer.puAbsIso (mu.physObj, 0.4, self.cfg_ana.isoDR, 0.0,self.IsoTrackIsolationComputer.selfVetoNone)
239 mu.absIsoAnNeutral =
max(0.0, mu.absIsoAnPho + mu.absIsoAnNHad - 0.5*mu.absIsoAnPU)
241 mu.absIsoAn04 = mu.absIsoAnCharged + mu.absIsoAnNeutral
242 mu.relIsoAn04 = mu.absIsoAn04/mu.pt()
246 matchTau =
matchObjectCollection3(event.selectedIsoTrack, event.gentaus + event.gentauleps + event.genleps, deltaRMax = 0.5)
247 for lep
in event.selectedIsoTrack:
249 lep.mcMatchId = 1
if gen
else 0
253 print(
'event to Veto')
254 print(
'----------------')
256 if len(event.selectedIsoTrack)>0:
257 print(
'lenght: ',len(event.selectedIsoTrack))
258 print(
'track candidate pt: ',event.selectedIsoTrack[0].
pt())
259 print(
'track candidate eta: ',event.selectedIsoTrack[0].
eta())
260 print(
'track candidate phi: ',event.selectedIsoTrack[0].phi())
261 print(
'track candidate mass: ',event.selectedIsoTrack[0].
mass())
262 print(
'pdgId candidate : ',event.selectedIsoTrack[0].
pdgId())
263 print(
'dz: ',event.selectedIsoTrack[0].
dz())
264 print(
'iso: ',event.selectedIsoTrack[0].absIso)
265 print(
'matchId: ',event.selectedIsoTrack[0].mcMatchId)
275 print(
'----------------')
280 if self.cfg_ana.setOff:
283 self.readCollections( event.input )
284 self.makeIsoTrack(event)
286 if len(event.selectedIsoTrack)==0 :
return True 294 if not self.cfg_comp.isMC:
297 if hasattr(event,
'gentaus')
and hasattr(event,
'gentauleps')
and hasattr(event,
'genleps')
and self.cfg_ana.do_mc_match :
298 self.matchIsoTrack(event)
316 setattr(IsoTrackAnalyzer,
"defaultConfig",cfg.Analyzer(
317 class_object=IsoTrackAnalyzer,
320 candidates=
'packedPFCandidates',
321 candidatesTypes=
'std::vector<pat::PackedCandidate>',
331 doRelIsolation =
False,
334 doSecondVeto =
False,
def attachIsoAnnulus04(self, mu)
def beginLoop(self, setup)
def makeNearestLeptons(leptons, track, event)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Abs< T >::type abs(const T &t)
IsoTrackIsolationComputer
def makeIsoTrack(self, event)
def matchIsoTrack(self, event)
def __init__(self, cfg_ana, cfg_comp, looperName)
def matchObjectCollection3
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
def printInfo(self, event)