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 declareHandles
 
def makePhotons
 
def matchPhotons
 
def printInfo
 
def process
 

Public Attributes

 etaCentral
 

Static Public Attributes

 do_mc_match = True,
 
float etaMax = 2.5
 
string gammaID = "PhotonCutBasedIDLoose"
 
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 37 of file PhotonAnalyzer.py.

37 
38  def beginLoop(self, setup):
39  super(PhotonAnalyzer,self).beginLoop(setup)
40  self.counters.addCounter('events')
41  count = self.counters.counter('events')
42  count.register('all events')
43  count.register('has >=1 gamma at preselection')
44  count.register('has >=1 selected gamma')
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 45 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().

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

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

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

105  def matchPhotons(self, event):
106  event.genPhotons = [ x for x in event.genParticles if x.status() == 1 and abs(x.pdgId()) == 22 ]
107  event.genPhotonsWithMom = [ x for x in event.genPhotons if x.numberOfMothers()>0 ]
108  event.genPhotonsWithoutMom = [ x for x in event.genPhotons if x.numberOfMothers()==0 ]
109  event.genPhotonsMatched = [ x for x in event.genPhotonsWithMom if abs(x.mother(0).pdgId())<23 or x.mother(0).pdgId()==2212 ]
110  match = matchObjectCollection3(event.allphotons, event.genPhotonsMatched, deltaRMax = 0.1)
111  matchNoMom = matchObjectCollection3(event.allphotons, event.genPhotonsWithoutMom, deltaRMax = 0.1)
112  packedGenParts = [ p for p in self.mchandles['packedGen'].product() if abs(p.eta()) < 3.1 ]
113  for gamma in event.allphotons:
114  gen = match[gamma]
115  if gen and gen.pt()>=0.5*gamma.pt() and gen.pt()<=2.*gamma.pt():
116  gamma.mcMatchId = 22
117  sumPt = 0.;
118  for part in packedGenParts:
119  if abs(part.pdgId())==12: continue # exclude neutrinos
120  if abs(part.pdgId())==14: continue
121  if abs(part.pdgId())==16: continue
122  if abs(part.pdgId())==18: continue
123  if deltaR(gen.eta(), gen.phi(), part.eta(), part.phi()) > 0.4: continue
124  sumPt += part.pt()
125  sumPt -= gen.pt()
126  if sumPt<0. : sumPt=0.
127  gamma.genIso = sumPt
128  else:
129  genNoMom = matchNoMom[gamma]
130  if genNoMom:
131  gamma.mcMatchId = 7
132  sumPt = 0.;
133  for part in packedGenParts:
134  if abs(part.pdgId())==12: continue # exclude neutrinos
135  if abs(part.pdgId())==14: continue
136  if abs(part.pdgId())==16: continue
137  if abs(part.pdgId())==18: continue
138  if deltaR(genNoMom.eta(), genNoMom.phi(), part.eta(), part.phi()) > 0.4: continue
139  sumPt += part.pt()
140  sumPt -= genNoMom.pt()
141  if sumPt<0. : sumPt=0.
142  gamma.genIso = sumPt
143  else:
144  gamma.mcMatchId = 0
145  gamma.genIso = -1.
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:38
def objects.PhotonAnalyzer.PhotonAnalyzer.printInfo (   self,
  event 
)

Definition at line 146 of file PhotonAnalyzer.py.

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

147  def printInfo(self, event):
148  print '----------------'
149  if len(event.selectedPhotons)>0:
150  print 'lenght: ',len(event.selectedPhotons)
151  print 'gamma candidate pt: ',event.selectedPhotons[0].pt()
152  print 'gamma candidate eta: ',event.selectedPhotons[0].eta()
153  print 'gamma candidate phi: ',event.selectedPhotons[0].phi()
154  print 'gamma candidate mass: ',event.selectedPhotons[0].mass()
155  print 'gamma candidate HoE: ',event.selectedPhotons[0].hOVERe()
156  print 'gamma candidate r9: ',event.selectedPhotons[0].full5x5_r9()
157  print 'gamma candidate sigmaIetaIeta: ',event.selectedPhotons[0].full5x5_sigmaIetaIeta()
158  print 'gamma candidate had iso: ',event.selectedPhotons[0].chargedHadronIso()
159  print 'gamma candidate neu iso: ',event.selectedPhotons[0].neutralHadronIso()
160  print 'gamma candidate gamma iso: ',event.selectedPhotons[0].photonIso()
161  print 'gamma idCutBased',event.selectedPhotons[0].idCutBased
162 
T eta() const
Definition: DDAxes.h:10
def objects.PhotonAnalyzer.PhotonAnalyzer.process (   self,
  event 
)

Definition at line 163 of file PhotonAnalyzer.py.

References objects.PhotonAnalyzer.PhotonAnalyzer.makePhotons(), objects.PhotonAnalyzer.PhotonAnalyzer.matchPhotons(), 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_VALIDATION(), ConfigBuilder.ConfigBuilder.renameHLTprocessInSequence(), ConfigBuilder.ConfigBuilder.renameInputTagsInSequence(), and ConfigBuilder.ConfigBuilder.scheduleSequence().

164  def process(self, event):
165  self.readCollections( event.input )
166  self.makePhotons(event)
167 # self.printInfo(event)
168 
169  if not self.cfg_comp.isMC:
170  return True
171 
172  if self.cfg_ana.do_mc_match and hasattr(event, 'genParticles'):
173  self.matchPhotons(event)
174 
175  return True
176 
177 
setattr(PhotonAnalyzer,"defaultConfig",cfg.Analyzer(

Member Data Documentation

objects.PhotonAnalyzer.PhotonAnalyzer.do_mc_match = True,
static

Definition at line 183 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 181 of file PhotonAnalyzer.py.

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

Definition at line 182 of file PhotonAnalyzer.py.

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

Definition at line 179 of file PhotonAnalyzer.py.

int objects.PhotonAnalyzer.PhotonAnalyzer.ptMin = 20
static

Definition at line 180 of file PhotonAnalyzer.py.