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.Photon
import Photon
22 def __init__(self, cfg_ana, cfg_comp, looperName ):
23 super(PhotonAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
24 self.
etaCentral = self.cfg_ana.etaCentral
if hasattr(self.cfg_ana,
'etaCentral')
else 9999
34 self.handles[
'photons'] = AutoHandle( self.cfg_ana.photons,
'std::vector<pat::Photon>')
35 self.mchandles[
'packedGen'] = AutoHandle(
'packedGenParticles',
'std::vector<pat::PackedGenParticle>' )
38 super(PhotonAnalyzer,self).
beginLoop(setup)
39 self.counters.addCounter(
'events')
40 count = self.counters.counter(
'events')
41 count.register(
'all events')
42 count.register(
'has >=1 gamma at preselection')
43 count.register(
'has >=1 selected gamma')
46 event.allphotons =
map( Photon, self.handles[
'photons'].product() )
47 event.allphotons.sort(key =
lambda l : l.pt(), reverse =
True)
49 event.selectedPhotons = []
50 event.selectedPhotonsCentral = []
53 for gamma
in event.allphotons:
54 if gamma.pt() < self.cfg_ana.ptMin:
continue
55 if abs(gamma.eta()) > self.cfg_ana.etaMax:
continue
59 """Create an integer equal to 1-2-3 for (loose,medium,tight)"""
62 if gamma.photonID(X%
"Loose"):
66 if gamma.photonID(X%
"Tight"):
70 gamma.idCutBased = idWP(gamma,
"PhotonCutBasedID%s")
74 if self.cfg_ana.gammaID==
"PhotonCutBasedIDLoose_CSA14" :
75 keepThisPhoton = gamma.photonIDCSA14(
"PhotonCutBasedIDLoose_CSA14")
76 gamma.idCutBased = keepThisPhoton
79 if abs(gamma.eta())< 1.479
and gamma.full5x5_sigmaIetaIeta()>0.010 :
80 gamma.idCutBased =
False
81 if abs(gamma.eta())>=1.479
and gamma.full5x5_sigmaIetaIeta()>0.0321 :
82 gamma.idCutBased =
False
84 keepThisPhoton = gamma.photonID(self.cfg_ana.gammaID)
86 if gamma.hasPixelSeed():
87 keepThisPhoton =
False
92 event.selectedPhotons.append(gamma)
95 event.selectedPhotonsCentral.append(gamma)
97 event.selectedPhotons.sort(key =
lambda l : l.pt(), reverse =
True)
98 event.selectedPhotonsCentral.sort(key =
lambda l : l.pt(), reverse =
True)
100 self.counters.counter(
'events').inc(
'all events')
101 if foundPhoton: self.counters.counter(
'events').inc(
'has >=1 gamma at preselection')
102 if len(event.selectedPhotons): self.counters.counter(
'events').inc(
'has >=1 selected gamma')
105 event.genPhotons = [ x
for x
in event.genParticles
if x.status() == 1
and abs(x.pdgId()) == 22 ]
106 event.genPhotonsWithMom = [ x
for x
in event.genPhotons
if x.numberOfMothers()>0 ]
107 event.genPhotonsWithoutMom = [ x
for x
in event.genPhotons
if x.numberOfMothers()==0 ]
108 event.genPhotonsMatched = [ x
for x
in event.genPhotonsWithMom
if abs(x.mother(0).
pdgId())<23
or x.mother(0).
pdgId()==2212 ]
111 packedGenParts = [ p
for p
in self.mchandles[
'packedGen'].product()
if abs(p.eta()) < 3.1 ]
112 for gamma
in event.allphotons:
114 if gen
and gen.pt()>=0.5*gamma.pt()
and gen.pt()<=2.*gamma.pt():
117 for part
in packedGenParts:
118 if abs(part.pdgId())==12:
continue
119 if abs(part.pdgId())==14:
continue
120 if abs(part.pdgId())==16:
continue
121 if abs(part.pdgId())==18:
continue
122 if deltaR(gen.eta(), gen.phi(), part.eta(), part.phi()) > 0.4:
continue
125 if sumPt<0. : sumPt=0.
128 genNoMom = matchNoMom[gamma]
132 for part
in packedGenParts:
133 if abs(part.pdgId())==12:
continue
134 if abs(part.pdgId())==14:
continue
135 if abs(part.pdgId())==16:
continue
136 if abs(part.pdgId())==18:
continue
137 if deltaR(genNoMom.eta(), genNoMom.phi(), part.eta(), part.phi()) > 0.4:
continue
139 sumPt -= genNoMom.pt()
140 if sumPt<0. : sumPt=0.
147 print '----------------'
148 if len(event.selectedPhotons)>0:
149 print 'lenght: ',len(event.selectedPhotons)
150 print 'gamma candidate pt: ',event.selectedPhotons[0].
pt()
151 print 'gamma candidate eta: ',event.selectedPhotons[0].
eta()
152 print 'gamma candidate phi: ',event.selectedPhotons[0].
phi()
153 print 'gamma candidate mass: ',event.selectedPhotons[0].mass()
154 print 'gamma candidate HoE: ',event.selectedPhotons[0].hOVERe()
155 print 'gamma candidate r9: ',event.selectedPhotons[0].full5x5_r9()
156 print 'gamma candidate sigmaIetaIeta: ',event.selectedPhotons[0].full5x5_sigmaIetaIeta()
157 print 'gamma candidate had iso: ',event.selectedPhotons[0].chargedHadronIso()
158 print 'gamma candidate neu iso: ',event.selectedPhotons[0].neutralHadronIso()
159 print 'gamma candidate gamma iso: ',event.selectedPhotons[0].photonIso()
160 print 'gamma idCutBased',event.selectedPhotons[0].idCutBased
164 self.readCollections( event.input )
168 if not self.cfg_comp.isMC:
171 if self.cfg_ana.do_mc_match
and hasattr(event,
'genParticles'):
177 setattr(PhotonAnalyzer,
"defaultConfig",cfg.Analyzer(
178 class_object=PhotonAnalyzer,
179 photons=
'slimmedPhotons',
182 gammaID =
"PhotonCutBasedIDLoose",
Abs< T >::type abs(const T &t)
double deltaR(double eta1, double eta2, double phi1, double phi2)
def matchObjectCollection3