CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Static Public Attributes
objects.PhotonAnalyzer.PhotonAnalyzer Class Reference
Inheritance diagram for objects.PhotonAnalyzer.PhotonAnalyzer:

Public Member Functions

def __init__
 
def beginLoop
 
def checkMatch
 
def computeRandomCone
 
def declareHandles
 
def makePhotons
 
def matchPhotons
 
def printInfo
 
def process
 
def randomCone
 

Public Attributes

 etaCentral
 

Static Public Attributes

 do_mc_match = True,
 
 do_randomCone = False,
 
float etaMax = 2.5
 
string gammaID = "PhotonCutBasedIDLoose_CSA14"
 
string photons = 'slimmedPhotons'
 
int ptMin = 20
 

Detailed Description

Definition at line 19 of file PhotonAnalyzer.py.

Constructor & Destructor Documentation

def objects.PhotonAnalyzer.PhotonAnalyzer.__init__ (   self,
  cfg_ana,
  cfg_comp,
  looperName 
)

Definition at line 22 of file PhotonAnalyzer.py.

22 
23  def __init__(self, cfg_ana, cfg_comp, looperName ):
24  super(PhotonAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)
25  self.etaCentral = self.cfg_ana.etaCentral if hasattr(self.cfg_ana, 'etaCentral') else 9999

Member Function Documentation

def objects.PhotonAnalyzer.PhotonAnalyzer.beginLoop (   self,
  setup 
)

Definition at line 39 of file PhotonAnalyzer.py.

39 
40  def beginLoop(self, setup):
41  super(PhotonAnalyzer,self).beginLoop(setup)
42  self.counters.addCounter('events')
43  count = self.counters.counter('events')
44  count.register('all events')
45  count.register('has >=1 gamma at preselection')
46  count.register('has >=1 selected gamma')
def objects.PhotonAnalyzer.PhotonAnalyzer.checkMatch (   self,
  eta,
  phi,
  particles,
  deltar 
)

Definition at line 170 of file PhotonAnalyzer.py.

References deltaR().

Referenced by objects.PhotonAnalyzer.PhotonAnalyzer.computeRandomCone().

171  def checkMatch( self, eta, phi, particles, deltar ):
172 
173  for part in particles:
174  if deltaR(eta, phi, part.eta(), part.phi()) < deltar:
175  return True
176 
177  return False
178 
179 
180 
181 
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
def objects.PhotonAnalyzer.PhotonAnalyzer.computeRandomCone (   self,
  event,
  eta,
  phi,
  deltarmax,
  charged,
  jets,
  photons 
)

Definition at line 182 of file PhotonAnalyzer.py.

References objects.PhotonAnalyzer.PhotonAnalyzer.checkMatch(), and deltaR().

Referenced by objects.PhotonAnalyzer.PhotonAnalyzer.randomCone().

183  def computeRandomCone( self, event, eta, phi, deltarmax, charged, jets, photons ):
184 
185  if self.checkMatch( eta, phi, jets, 2.*deltarmax ):
186  return -1.
187 
188  if self.checkMatch( eta, phi, photons, 2.*deltarmax ):
189  return -1.
190 
191  if self.checkMatch( eta, phi, event.selectedLeptons, deltarmax ):
192  return -1.
193 
194  iso = 0.
195 
196  for part in charged:
197  if deltaR(eta, phi, part.eta(), part.phi()) > deltarmax : continue
198  #if deltaR(eta, phi, part.eta(), part.phi()) < 0.02: continue
199  iso += part.pt()
200 
201  return iso
202 
203 
204 
205 
206 
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
def objects.PhotonAnalyzer.PhotonAnalyzer.declareHandles (   self)

Definition at line 26 of file PhotonAnalyzer.py.

References core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, and core.Analyzer.Analyzer.mchandles.

26 
27  def declareHandles(self):
28  super(PhotonAnalyzer, self).declareHandles()
def objects.PhotonAnalyzer.PhotonAnalyzer.makePhotons (   self,
  event 
)

Definition at line 47 of file PhotonAnalyzer.py.

References funct.abs(), objects.PhotonAnalyzer.PhotonAnalyzer.etaCentral, core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, and python.multivaluedict.map().

Referenced by objects.PhotonAnalyzer.PhotonAnalyzer.process().

47 
48  def makePhotons(self, event):
49  event.allphotons = map( Photon, self.handles['photons'].product() )
50  event.allphotons.sort(key = lambda l : l.pt(), reverse = True)
51 
52  event.selectedPhotons = []
53  event.selectedPhotonsCentral = []
54 
55  foundPhoton = False
56  for gamma in event.allphotons:
57  if gamma.pt() < self.cfg_ana.ptMin: continue
58  if abs(gamma.eta()) > self.cfg_ana.etaMax: continue
59  foundPhoton = True
60 
61  def idWP(gamma,X):
62  """Create an integer equal to 1-2-3 for (loose,medium,tight)"""
63 
64  id=0
65  if gamma.photonID(X%"Loose"):
66  id=1
67  #if gamma.photonID(X%"Medium"):
68  # id=2
69  if gamma.photonID(X%"Tight"):
70  id=3
71  return id
72 
73  gamma.idCutBased = idWP(gamma, "PhotonCutBasedID%s")
74 
75 
76  keepThisPhoton = True
77  if self.cfg_ana.gammaID=="PhotonCutBasedIDLoose_CSA14" :
78  keepThisPhoton = gamma.photonIDCSA14("PhotonCutBasedIDLoose_CSA14")
79  gamma.idCutBased = keepThisPhoton
80  # we're keeing sigmaietaieta sidebands, but the id is false for them:
81 
82  if abs(gamma.eta())< 1.479 and gamma.full5x5_sigmaIetaIeta()>0.010 :
83  gamma.idCutBased = False
84  if abs(gamma.eta())>=1.479 and gamma.full5x5_sigmaIetaIeta()>0.0321 :
85  gamma.idCutBased = False
86  if gamma.hasPixelSeed():
87  keepThisPhoton = False
88  gamma.idCutBased = 0
89  else:
90  # Reading from miniAOD directly
91  # keepThisPhoton = gamma.photonID(self.cfg_ana.gammaID)
92 
93  # implement cut based ID with CMGTools
94  keepThisPhoton = gamma.passPhotonID(self.cfg_ana.gammaID)
95 
96  if keepThisPhoton:
97  event.selectedPhotons.append(gamma)
98 
99  if keepThisPhoton and abs(gamma.eta()) < self.etaCentral:
100  event.selectedPhotonsCentral.append(gamma)
101 
102  event.selectedPhotons.sort(key = lambda l : l.pt(), reverse = True)
103  event.selectedPhotonsCentral.sort(key = lambda l : l.pt(), reverse = True)
104 
105  self.counters.counter('events').inc('all events')
106  if foundPhoton: self.counters.counter('events').inc('has >=1 gamma at preselection')
107  if len(event.selectedPhotons): self.counters.counter('events').inc('has >=1 selected gamma')
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def objects.PhotonAnalyzer.PhotonAnalyzer.matchPhotons (   self,
  event 
)

Definition at line 108 of file PhotonAnalyzer.py.

References funct.abs(), deltaR(), deltar.matchObjectCollection3(), core.Analyzer.Analyzer.mchandles, and benchmark_cfg.pdgId.

Referenced by objects.PhotonAnalyzer.PhotonAnalyzer.process().

109  def matchPhotons(self, event):
110  event.genPhotons = [ x for x in event.genParticles if x.status() == 1 and abs(x.pdgId()) == 22 ]
111  event.genPhotonsWithMom = [ x for x in event.genPhotons if x.numberOfMothers()>0 ]
112  event.genPhotonsWithoutMom = [ x for x in event.genPhotons if x.numberOfMothers()==0 ]
113  event.genPhotonsMatched = [ x for x in event.genPhotonsWithMom if abs(x.mother(0).pdgId())<23 or x.mother(0).pdgId()==2212 ]
114  match = matchObjectCollection3(event.allphotons, event.genPhotonsMatched, deltaRMax = 0.1)
115  matchNoMom = matchObjectCollection3(event.allphotons, event.genPhotonsWithoutMom, deltaRMax = 0.1)
116  packedGenParts = [ p for p in self.mchandles['packedGen'].product() if abs(p.eta()) < 3.1 ]
117  for gamma in event.allphotons:
118  gen = match[gamma]
119  gamma.mcGamma = gen
120  if gen and gen.pt()>=0.5*gamma.pt() and gen.pt()<=2.*gamma.pt():
121  gamma.mcMatchId = 22
122  sumPt03 = 0.;
123  sumPt04 = 0.;
124  for part in packedGenParts:
125  if abs(part.pdgId())==12: continue # exclude neutrinos
126  if abs(part.pdgId())==14: continue
127  if abs(part.pdgId())==16: continue
128  if abs(part.pdgId())==18: continue
129  deltar = deltaR(gen.eta(), gen.phi(), part.eta(), part.phi())
130  if deltar <= 0.3:
131  sumPt03 += part.pt()
132  if deltar <= 0.4:
133  sumPt04 += part.pt()
134  sumPt03 -= gen.pt()
135  sumPt04 -= gen.pt()
136  if sumPt03<0. : sumPt03=0.
137  if sumPt04<0. : sumPt04=0.
138  gamma.genIso03 = sumPt03
139  gamma.genIso04 = sumPt04
140  else:
141  genNoMom = matchNoMom[gamma]
142  if genNoMom:
143  gamma.mcMatchId = 7
144  sumPt03 = 0.;
145  sumPt04 = 0.;
146  for part in packedGenParts:
147  if abs(part.pdgId())==12: continue # exclude neutrinos
148  if abs(part.pdgId())==14: continue
149  if abs(part.pdgId())==16: continue
150  if abs(part.pdgId())==18: continue
151  deltar = deltaR(genNoMom.eta(), genNoMom.phi(), part.eta(), part.phi());
152  if deltar <= 0.3:
153  sumPt03 += part.pt()
154  if deltar <= 0.4:
155  sumPt04 += part.pt()
156  sumPt03 -= genNoMom.pt()
157  sumPt04 -= genNoMom.pt()
158  if sumPt03<0. : sumPt03=0.
159  if sumPt04<0. : sumPt04=0.
160  gamma.genIso03 = sumPt03
161  gamma.genIso04 = sumPt04
162  else:
163  gamma.mcMatchId = 0
164  gamma.genIso03 = -1.
165  gamma.genIso04 = -1.
166 
167 
168 
169 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
def matchObjectCollection3
Definition: deltar.py:41
def objects.PhotonAnalyzer.PhotonAnalyzer.printInfo (   self,
  event 
)

Definition at line 241 of file PhotonAnalyzer.py.

References eta(), phi, and EnergyCorrector.pt.

242  def printInfo(self, event):
243  print '----------------'
244  if len(event.selectedPhotons)>0:
245  print 'lenght: ',len(event.selectedPhotons)
246  print 'gamma candidate pt: ',event.selectedPhotons[0].pt()
247  print 'gamma candidate eta: ',event.selectedPhotons[0].eta()
248  print 'gamma candidate phi: ',event.selectedPhotons[0].phi()
249  print 'gamma candidate mass: ',event.selectedPhotons[0].mass()
250  print 'gamma candidate HoE: ',event.selectedPhotons[0].hOVERe()
251  print 'gamma candidate r9: ',event.selectedPhotons[0].full5x5_r9()
252  print 'gamma candidate sigmaIetaIeta: ',event.selectedPhotons[0].full5x5_sigmaIetaIeta()
253  print 'gamma candidate had iso: ',event.selectedPhotons[0].chargedHadronIso()
254  print 'gamma candidate neu iso: ',event.selectedPhotons[0].neutralHadronIso()
255  print 'gamma candidate gamma iso: ',event.selectedPhotons[0].photonIso()
256  print 'gamma idCutBased',event.selectedPhotons[0].idCutBased
257 
T eta() const
Definition: DDAxes.h:10
def objects.PhotonAnalyzer.PhotonAnalyzer.process (   self,
  event 
)

Definition at line 258 of file PhotonAnalyzer.py.

References objects.PhotonAnalyzer.PhotonAnalyzer.makePhotons(), objects.PhotonAnalyzer.PhotonAnalyzer.matchPhotons(), objects.PhotonAnalyzer.PhotonAnalyzer.randomCone(), and core.Analyzer.Analyzer.readCollections().

Referenced by ConfigBuilder.ConfigBuilder.__init__(), ConfigBuilder.ConfigBuilder.addExtraStream(), ConfigBuilder.ConfigBuilder.anyOf(), ConfigBuilder.ConfigBuilder.completeInputCommand(), ConfigBuilder.ConfigBuilder.doNotInlineEventContent(), ConfigBuilder.ConfigBuilder.PrintAllModules.leave(), ConfigBuilder.ConfigBuilder.prepare(), ConfigBuilder.ConfigBuilder.prepare_ALCA(), ConfigBuilder.ConfigBuilder.prepare_DQM(), ConfigBuilder.ConfigBuilder.prepare_FASTSIM(), ConfigBuilder.ConfigBuilder.prepare_HARVESTING(), ConfigBuilder.ConfigBuilder.prepare_HLT(), ConfigBuilder.ConfigBuilder.prepare_LHE(), ConfigBuilder.ConfigBuilder.prepare_PATFILTER(), ConfigBuilder.ConfigBuilder.prepare_VALIDATION(), ConfigBuilder.ConfigBuilder.renameHLTprocessInSequence(), ConfigBuilder.ConfigBuilder.renameInputTagsInSequence(), and ConfigBuilder.ConfigBuilder.scheduleSequence().

259  def process(self, event):
260  self.readCollections( event.input )
261  self.makePhotons(event)
262 # self.printInfo(event)
263 
264  if self.cfg_ana.do_randomCone:
265  self.randomCone(event)
266 
267  if not self.cfg_comp.isMC:
268  return True
269 
270  if self.cfg_ana.do_mc_match and hasattr(event, 'genParticles'):
271  self.matchPhotons(event)
272 
273 
274  return True
275 
276 
setattr(PhotonAnalyzer,"defaultConfig",cfg.Analyzer(
def objects.PhotonAnalyzer.PhotonAnalyzer.randomCone (   self,
  event 
)

Definition at line 207 of file PhotonAnalyzer.py.

References funct.abs(), objects.PhotonAnalyzer.PhotonAnalyzer.computeRandomCone(), core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, and HTTP.RequestManager.handles.

Referenced by objects.PhotonAnalyzer.PhotonAnalyzer.process().

208  def randomCone( self, event ):
209 
210  patcands = self.handles['packedCandidates'].product()
211  jets = self.handles['jets'].product()
212 
213  charged = [ p for p in patcands if ( p.charge() != 0 and abs(p.pdgId())>20 and abs(p.dz())<=0.1 and p.fromPV()>1 and p.trackHighPurity() ) ]
214  photons10 = [ p for p in patcands if ( p.pdgId() == 22 and p.pt()>10. ) ]
215  jets20 = [ j for j in jets if j.pt() > 20 and abs(j.eta())<2.5 ]
216 
217  for gamma in event.allphotons:
218 
219  etaPhot = gamma.eta()
220  phiPhot = gamma.eta()
221  pi = 3.14159
222  phiRC = phiPhot + 0.5*pi
223  while phiRC>pi:
224  phiRC -= 2.*pi
225 
226 
227  gamma.chHadIsoRC03 = self.computeRandomCone( event, etaPhot, phiRC, 0.3, charged, jets20, photons10 )
228  gamma.chHadIsoRC04 = self.computeRandomCone( event, etaPhot, phiRC, 0.4, charged, jets20, photons10 )
229 
230 
231  #try other side
232  phiRC = phiPhot - 0.5*pi
233  while phiRC<-pi:
234  phiRC += 2.*pi
235 
236  if gamma.chHadIsoRC03<0. : gamma.chHadIsoRC03 = self.computeRandomCone( event, etaPhot, phiRC, 0.3, charged, jets20, photons10 )
237  if gamma.chHadIsoRC04<0. : gamma.chHadIsoRC04 = self.computeRandomCone( event, etaPhot, phiRC, 0.4, charged, jets20, photons10 )
238 
239 
240 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

Member Data Documentation

objects.PhotonAnalyzer.PhotonAnalyzer.do_mc_match = True,
static

Definition at line 282 of file PhotonAnalyzer.py.

objects.PhotonAnalyzer.PhotonAnalyzer.do_randomCone = False,
static

Definition at line 283 of file PhotonAnalyzer.py.

objects.PhotonAnalyzer.PhotonAnalyzer.etaCentral

Definition at line 24 of file PhotonAnalyzer.py.

Referenced by objects.PhotonAnalyzer.PhotonAnalyzer.makePhotons().

float objects.PhotonAnalyzer.PhotonAnalyzer.etaMax = 2.5
static

Definition at line 280 of file PhotonAnalyzer.py.

string objects.PhotonAnalyzer.PhotonAnalyzer.gammaID = "PhotonCutBasedIDLoose_CSA14"
static

Definition at line 281 of file PhotonAnalyzer.py.

string objects.PhotonAnalyzer.PhotonAnalyzer.photons = 'slimmedPhotons'
static

Definition at line 278 of file PhotonAnalyzer.py.

int objects.PhotonAnalyzer.PhotonAnalyzer.ptMin = 20
static

Definition at line 279 of file PhotonAnalyzer.py.