CMS 3D CMS Logo

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

Public Member Functions

def beginLoop
 
def bestDiLepton
 
def buildDiLeptons
 
def buildLeptons
 
def buildOtherLeptons
 
def declareHandles
 
def leptonAccept
 
def process
 
def selectionSequence
 
def shiftEnergyScale
 
def testDeltaR
 
def testLeg1
 
def testLeg1ID
 
def testLeg1Iso
 
def testLeg2
 
def testLeg2ID
 
def testLeg2Iso
 
def testLegKine
 
def testMass
 
def thirdLeptonVeto
 
def trigMatched
 

Static Public Attributes

 DiObjectClass = DiObject
 
 LeptonClass = Lepton
 
 OtherLeptonClass = Lepton
 

Detailed Description

Generic analyzer for Di-Leptons.
See ZMuMuAnalyzer for a concrete case.

Example configuration, and list of parameters:
#O means optional

ana = cfg.Analyzer(
  'DiLeptonAnalyzer',
  scaleShift1 = eScaleShift,  #O shift factor for leg 1 energy scale
  scaleShift2 = tauScaleShift,#O same for leg 2
  pt1 = 20,   # pt, eta, iso cuts for leg 1
  eta1 = 2.3,
  iso1 = None,
  pt2 = 20,   # same for leg 2
  eta2 = 2.1,
  iso2 = 0.1,
  m_min = 10,    # mass range
  m_max = 99999,
  dR_min = 0.5,  #O min delta R between the two legs
  triggerMap = pathsAndFilters, #O, necessary for trigger matching
  verbose = False               #from base Analyzer class
  )

COLIN: need to specify what is needed in the event.
COLIN: need to make delta R non optional.
COLIN: make the dR_min parameter non optional

Definition at line 10 of file DiLeptonAnalyzer.py.

Member Function Documentation

def DiLeptonAnalyzer.DiLeptonAnalyzer.beginLoop (   self,
  setup 
)

Definition at line 49 of file DiLeptonAnalyzer.py.

References analyzer.Analyzer.cfg_ana.

49 
50  def beginLoop(self, setup):
51  super(DiLeptonAnalyzer,self).beginLoop(setup)
52  self.counters.addCounter('DiLepton')
53  count = self.counters.counter('DiLepton')
54  count.register('all events')
55  count.register('> 0 di-lepton')
56  # count.register('di-lepton cut string ok')
57  count.register('lepton accept')
58  count.register('third lepton veto')
59  count.register('leg1 offline cuts passed')
60  count.register('leg1 trig matched')
61  count.register('leg2 offline cuts passed')
62  count.register('leg2 trig matched')
63  count.register('{min:3.1f} < m < {max:3.1f}'.format( min = self.cfg_ana.m_min,
64  max = self.cfg_ana.m_max ))
65  if hasattr(self.cfg_ana, 'dR_min'):
66  count.register('dR > {min:3.1f}'.format( min = self.cfg_ana.dR_min))
67 
68  count.register('exactly 1 di-lepton')
69 
def DiLeptonAnalyzer.DiLeptonAnalyzer.bestDiLepton (   self,
  diLeptons 
)
Returns the best diLepton (the one with highest pt1 + pt2).

Definition at line 293 of file DiLeptonAnalyzer.py.

References bookConverter.max.

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.selectionSequence().

294  def bestDiLepton(self, diLeptons):
295  '''Returns the best diLepton (the one with highest pt1 + pt2).'''
296  return max( diLeptons, key=operator.methodcaller( 'sumPt' ) )
297 
def DiLeptonAnalyzer.DiLeptonAnalyzer.buildDiLeptons (   self,
  cmgDiLeptons,
  event 
)
Creates python DiLeptons from the di-leptons read from the disk.
to be overloaded if needed.

Definition at line 70 of file DiLeptonAnalyzer.py.

References python.multivaluedict.map().

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.process().

70 
71  def buildDiLeptons(self, cmgDiLeptons, event):
72  '''Creates python DiLeptons from the di-leptons read from the disk.
73  to be overloaded if needed.'''
74  return map( self.__class__.DiObjectClass, cmgDiLeptons )
75 
def DiLeptonAnalyzer.DiLeptonAnalyzer.buildLeptons (   self,
  cmgLeptons,
  event 
)
Creates python Leptons from the leptons read from the disk.
to be overloaded if needed.

Definition at line 76 of file DiLeptonAnalyzer.py.

References python.multivaluedict.map().

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.process().

76 
77  def buildLeptons(self, cmgLeptons, event):
78  '''Creates python Leptons from the leptons read from the disk.
79  to be overloaded if needed.'''
80  return map( self.__class__.LeptonClass, cmgLeptons )
81 
def DiLeptonAnalyzer.DiLeptonAnalyzer.buildOtherLeptons (   self,
  cmgLeptons,
  event 
)
Creates python Leptons from the leptons read from the disk.
to be overloaded if needed.

Definition at line 82 of file DiLeptonAnalyzer.py.

References python.multivaluedict.map().

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.process().

82 
83  def buildOtherLeptons(self, cmgLeptons, event):
84  '''Creates python Leptons from the leptons read from the disk.
85  to be overloaded if needed.'''
86  return map( self.__class__.LeptonClass, cmgLeptons )
87 
88 
def DiLeptonAnalyzer.DiLeptonAnalyzer.declareHandles (   self)

Definition at line 215 of file DiLeptonAnalyzer.py.

216  def declareHandles(self):
217  super(DiLeptonAnalyzer, self).declareHandles()
218  # self.handles['cmgTriggerObjectSel'] = AutoHandle(
219  # 'cmgTriggerObjectSel',
220  # 'std::vector<cmg::TriggerObject>'
221  # )
def DiLeptonAnalyzer.DiLeptonAnalyzer.leptonAccept (   self,
  leptons 
)
Should implement a default version running on event.leptons.

Definition at line 222 of file DiLeptonAnalyzer.py.

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.selectionSequence().

223  def leptonAccept(self, leptons):
224  '''Should implement a default version running on event.leptons.'''
225  return True
226 
def DiLeptonAnalyzer.DiLeptonAnalyzer.process (   self,
  iEvent,
  event 
)

Definition at line 89 of file DiLeptonAnalyzer.py.

References DiLeptonAnalyzer.DiLeptonAnalyzer.buildDiLeptons(), DiLeptonAnalyzer.DiLeptonAnalyzer.buildLeptons(), DiLeptonAnalyzer.DiLeptonAnalyzer.buildOtherLeptons(), core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, core.Analyzer.Analyzer.readCollections(), DiLeptonAnalyzer.DiLeptonAnalyzer.selectionSequence(), and DiLeptonAnalyzer.DiLeptonAnalyzer.shiftEnergyScale().

Referenced by ConfigBuilder.ConfigBuilder.addExtraStream(), ConfigBuilder.ConfigBuilder.completeInputCommand(), ConfigBuilder.ConfigBuilder.doNotInlineEventContent(), ConfigBuilder.ConfigBuilder.PrintAllModules.leave(), 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().

89 
90  def process(self, iEvent, event):
91  self.readCollections( iEvent )
92  event.diLeptons = self.buildDiLeptons( self.handles['diLeptons'].product(), event )
93  event.leptons = self.buildLeptons( self.handles['leptons'].product(), event )
94  event.otherLeptons = self.buildOtherLeptons( self.handles['otherLeptons'].product(), event )
95  self.shiftEnergyScale(event)
96  return self.selectionSequence(event, fillCounter=True,
97  leg1IsoCut=self.cfg_ana.iso1,
98  leg2IsoCut=self.cfg_ana.iso2)
99 
def DiLeptonAnalyzer.DiLeptonAnalyzer.selectionSequence (   self,
  event,
  fillCounter,
  leg1IsoCut = None,
  leg2IsoCut = None 
)

Definition at line 115 of file DiLeptonAnalyzer.py.

References DiLeptonAnalyzer.DiLeptonAnalyzer.bestDiLepton(), analyzer.Analyzer.cfg_ana, DiLeptonAnalyzer.DiLeptonAnalyzer.leptonAccept(), DiLeptonAnalyzer.DiLeptonAnalyzer.testDeltaR(), DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg1(), DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg2(), DiLeptonAnalyzer.DiLeptonAnalyzer.testMass(), DiLeptonAnalyzer.DiLeptonAnalyzer.thirdLeptonVeto(), and DiLeptonAnalyzer.DiLeptonAnalyzer.trigMatched().

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.process().

116  def selectionSequence(self, event, fillCounter, leg1IsoCut=None, leg2IsoCut=None):
117 
118  if fillCounter: self.counters.counter('DiLepton').inc('all events')
119  # if not self.triggerList.triggerPassed(event.triggerObject):
120  # return False
121  # self.counters.counter('DiLepton').inc('trigger passed ')
122 
123  # if event.eventId == 155035:
124  # import pdb; pdb.set_trace()
125 
126  # import pdb; pdb.set_trace()
127  if len(event.diLeptons) == 0:
128  return False
129  if fillCounter: self.counters.counter('DiLepton').inc('> 0 di-lepton')
130 
131  # import pdb; pdb.set_trace()
132  # testing di-lepton itself
133  selDiLeptons = event.diLeptons
134  # selDiLeptons = self.selectDiLeptons( selDiLeptons )
135 
136  event.leptonAccept = False
137  if self.leptonAccept( event.leptons ):
138  if fillCounter: self.counters.counter('DiLepton').inc('lepton accept')
139  event.leptonAccept = True
140 
141  event.thirdLeptonVeto = False
142  if self.thirdLeptonVeto(event.leptons, event.otherLeptons):
143  if fillCounter: self.counters.counter('DiLepton').inc('third lepton veto')
144  event.thirdLeptonVeto = True
145 
146  # testing leg1
147  selDiLeptons = [ diL for diL in selDiLeptons if \
148  self.testLeg1( diL.leg1(), leg1IsoCut ) ]
149  if len(selDiLeptons) == 0:
150  return False
151  else:
152  if fillCounter: self.counters.counter('DiLepton').inc('leg1 offline cuts passed')
153 
154  if len(self.cfg_comp.triggers)>0:
155  # trigger matching leg1
156  selDiLeptons = [diL for diL in selDiLeptons if \
157  self.trigMatched(event, diL.leg1(), 'leg1')]
158  if len(selDiLeptons) == 0:
159  return False
160  else:
161  if fillCounter: self.counters.counter('DiLepton').inc('leg1 trig matched')
162 
163  # testing leg2
164  selDiLeptons = [ diL for diL in selDiLeptons if \
165  self.testLeg2( diL.leg2(), leg2IsoCut ) ]
166  if len(selDiLeptons) == 0:
167  return False
168  else:
169  if fillCounter: self.counters.counter('DiLepton').inc('leg2 offline cuts passed')
170 
171  if len(self.cfg_comp.triggers)>0:
172  # trigger matching leg2
173  selDiLeptons = [diL for diL in selDiLeptons if \
174  self.trigMatched(event, diL.leg2(), 'leg2')]
175  if len(selDiLeptons) == 0:
176  return False
177  else:
178  if fillCounter: self.counters.counter('DiLepton').inc('leg2 trig matched')
179 
180  # mass cut
181  selDiLeptons = [ diL for diL in selDiLeptons if \
182  self.testMass(diL) ]
183  if len(selDiLeptons)==0:
184  return False
185  else:
186  if fillCounter: self.counters.counter('DiLepton').inc(
187  '{min:3.1f} < m < {max:3.1f}'.format( min = self.cfg_ana.m_min,
188  max = self.cfg_ana.m_max )
189  )
190 
191  # delta R cut
192  if hasattr(self.cfg_ana, 'dR_min'):
193  selDiLeptons = [ diL for diL in selDiLeptons if \
194  self.testDeltaR(diL) ]
195  if len(selDiLeptons)==0:
196  return False
197  else:
198  if fillCounter: self.counters.counter('DiLepton').inc(
199  'dR > {min:3.1f}'.format( min = self.cfg_ana.dR_min )
200  )
201 
202  # exactly one?
203  if len(selDiLeptons)==0:
204  return False
205  elif len(selDiLeptons)==1:
206  if fillCounter: self.counters.counter('DiLepton').inc('exactly 1 di-lepton')
207 
208  event.diLepton = self.bestDiLepton( selDiLeptons )
209  event.leg1 = event.diLepton.leg1()
210  event.leg2 = event.diLepton.leg2()
211  event.selectedLeptons = [event.leg1, event.leg2]
212 
213  return True
214 
def DiLeptonAnalyzer.DiLeptonAnalyzer.shiftEnergyScale (   self,
  event 
)

Definition at line 100 of file DiLeptonAnalyzer.py.

References analyzer.Analyzer.cfg_ana, and python.multivaluedict.map().

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.process().

101  def shiftEnergyScale(self, event):
102  scaleShift1 = None
103  scaleShift2 = None
104  if hasattr( self.cfg_ana, 'scaleShift1'):
105  scaleShift1 = self.cfg_ana.scaleShift1
106  if hasattr( self.cfg_ana, 'scaleShift2'):
107  scaleShift2 = self.cfg_ana.scaleShift2
108  if scaleShift1:
109  # import pdb; pdb.set_trace()
110  map( lambda x: x.leg1().scaleEnergy(scaleShift1), event.diLeptons )
111  if scaleShift2:
112  map( lambda x: x.leg2().scaleEnergy(scaleShift2), event.diLeptons )
113  map( lambda x: x.scaleEnergy(scaleShift2), event.leptons )
114 
def DiLeptonAnalyzer.DiLeptonAnalyzer.testDeltaR (   self,
  diLepton 
)
returns True if the two diLepton.leg1() and .leg2() have a delta R larger than the dR_min parameter.

Definition at line 286 of file DiLeptonAnalyzer.py.

References deltaR(), and eta.

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.selectionSequence().

287  def testDeltaR(self, diLepton):
288  '''returns True if the two diLepton.leg1() and .leg2() have a delta R larger than the dR_min parameter.'''
289  dR = deltaR( diLepton.leg1().eta(), diLepton.leg1().phi(),
290  diLepton.leg2().eta(), diLepton.leg2().phi())
291  return dR > self.cfg_ana.dR_min
292 
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
def DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg1 (   self,
  leg,
  isocut = None 
)
returns testLeg1ID && testLeg1Iso && testLegKine for leg1

Definition at line 232 of file DiLeptonAnalyzer.py.

References ZMuMuAnalyzer.ZMuMuAnalyzer.testLeg1ID, DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg1ID(), ZMuMuAnalyzer.ZMuMuAnalyzer.testLeg1Iso, DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg1Iso(), and DiLeptonAnalyzer.DiLeptonAnalyzer.testLegKine().

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.selectionSequence().

233  def testLeg1(self, leg, isocut=None):
234  '''returns testLeg1ID && testLeg1Iso && testLegKine for leg1'''
235  return self.testLeg1ID(leg) and \
236  self.testLeg1Iso(leg, isocut) and \
237  self.testLegKine(leg, self.cfg_ana.pt1, self.cfg_ana.eta1)
238 
def DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg1ID (   self,
  leg 
)
Always return true by default, overload in your subclass

Definition at line 252 of file DiLeptonAnalyzer.py.

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg1().

253  def testLeg1ID(self, leg):
254  '''Always return true by default, overload in your subclass'''
255  return True
256 
def DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg1Iso (   self,
  leg,
  isocut 
)
If isocut is None, the iso value is taken from the iso1 parameter.
Checks the standard dbeta corrected isolation.

Definition at line 257 of file DiLeptonAnalyzer.py.

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg1().

258  def testLeg1Iso(self, leg, isocut):
259  '''If isocut is None, the iso value is taken from the iso1 parameter.
260  Checks the standard dbeta corrected isolation.
261  '''
262  if isocut is None:
263  isocut = self.cfg_ana.iso1
264  return leg.relIso(0.5) < isocut
265 
def DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg2 (   self,
  leg,
  isocut = None 
)
returns testLeg2ID && testLeg2Iso && testLegKine for leg2

Definition at line 239 of file DiLeptonAnalyzer.py.

References ZMuMuAnalyzer.ZMuMuAnalyzer.testLeg2ID, DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg2ID(), ZMuMuAnalyzer.ZMuMuAnalyzer.testLeg2Iso, DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg2Iso(), and DiLeptonAnalyzer.DiLeptonAnalyzer.testLegKine().

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.selectionSequence().

240  def testLeg2(self, leg, isocut=None):
241  '''returns testLeg2ID && testLeg2Iso && testLegKine for leg2'''
242  return self.testLeg2ID(leg) and \
243  self.testLeg2Iso(leg, isocut) and \
244  self.testLegKine(leg, self.cfg_ana.pt2, self.cfg_ana.eta2)
245 
def DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg2ID (   self,
  leg 
)
Always return true by default, overload in your subclass

Definition at line 266 of file DiLeptonAnalyzer.py.

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg2().

267  def testLeg2ID(self, leg):
268  '''Always return true by default, overload in your subclass'''
269  return True
270 
def DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg2Iso (   self,
  leg,
  isocut 
)
If isocut is None, the iso value is taken from the iso2 parameter.
Checks the standard dbeta corrected isolation.

Definition at line 271 of file DiLeptonAnalyzer.py.

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg2().

272  def testLeg2Iso(self, leg, isocut):
273  '''If isocut is None, the iso value is taken from the iso2 parameter.
274  Checks the standard dbeta corrected isolation.
275  '''
276  if isocut is None:
277  isocut = self.cfg_ana.iso2
278  return leg.relIso(0.5) < isocut
279 
def DiLeptonAnalyzer.DiLeptonAnalyzer.testLegKine (   self,
  leg,
  ptcut,
  etacut 
)
Tests pt and eta.

Definition at line 246 of file DiLeptonAnalyzer.py.

References funct.abs().

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg1(), and DiLeptonAnalyzer.DiLeptonAnalyzer.testLeg2().

247  def testLegKine(self, leg, ptcut, etacut ):
248  '''Tests pt and eta.'''
249  return leg.pt() > ptcut and \
250  abs(leg.eta()) < etacut
251 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def DiLeptonAnalyzer.DiLeptonAnalyzer.testMass (   self,
  diLepton 
)
returns True if the mass of the dilepton is between the m_min and m_max parameters

Definition at line 280 of file DiLeptonAnalyzer.py.

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.selectionSequence().

281  def testMass(self, diLepton):
282  '''returns True if the mass of the dilepton is between the m_min and m_max parameters'''
283  mass = diLepton.mass()
284  return self.cfg_ana.m_min < mass and mass < self.cfg_ana.m_max
285 
def DiLeptonAnalyzer.DiLeptonAnalyzer.thirdLeptonVeto (   self,
  leptons,
  otherLeptons,
  isoCut = 0.3 
)
Should implement a default version running on event.leptons.

Definition at line 227 of file DiLeptonAnalyzer.py.

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.selectionSequence().

228  def thirdLeptonVeto(self, leptons, otherLeptons, isoCut = 0.3) :
229  '''Should implement a default version running on event.leptons.'''
230  return True
231 
def DiLeptonAnalyzer.DiLeptonAnalyzer.trigMatched (   self,
  event,
  leg,
  legName 
)
Returns true if the leg is matched to a trigger object as defined in the
triggerMap parameter

Definition at line 298 of file DiLeptonAnalyzer.py.

References analyzer.Analyzer.cfg_ana.

Referenced by DiLeptonAnalyzer.DiLeptonAnalyzer.selectionSequence().

299  def trigMatched(self, event, leg, legName):
300  '''Returns true if the leg is matched to a trigger object as defined in the
301  triggerMap parameter'''
302  if not hasattr( self.cfg_ana, 'triggerMap'):
303  return True
304  path = event.hltPath
305  triggerObjects = event.triggerObjects
306  filters = self.cfg_ana.triggerMap[ path ]
307  filter = None
308  if legName == 'leg1':
309  filter = filters[0]
310  elif legName == 'leg2':
311  filter = filters[1]
312  else:
313  raise ValueError( 'legName should be leg1 or leg2, not {leg}'.format(
314  leg=legName ) )
315 
316  # JAN: Need a hack for the embedded samples: No trigger matching in that case
317  if filter == '':
318  return True
319 
320  # the dR2Max value is 0.3^2
321  pdgIds = None
322  if len(filter) == 2:
323  filter, pdgIds = filter[0], filter[1]
324  return triggerMatched(leg, triggerObjects, path, filter,
325  # dR2Max=0.089999,
326  dR2Max=0.25,
327  pdgIds=pdgIds )

Member Data Documentation

DiLeptonAnalyzer.DiLeptonAnalyzer.DiObjectClass = DiObject
static

Definition at line 45 of file DiLeptonAnalyzer.py.

DiLeptonAnalyzer.DiLeptonAnalyzer.LeptonClass = Lepton
static

Definition at line 46 of file DiLeptonAnalyzer.py.

DiLeptonAnalyzer.DiLeptonAnalyzer.OtherLeptonClass = Lepton
static

Definition at line 47 of file DiLeptonAnalyzer.py.