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.LeptonAnalyzer.LeptonAnalyzer Class Reference
Inheritance diagram for objects.LeptonAnalyzer.LeptonAnalyzer:

Public Member Functions

def __init__
 
def attachMiniIsolation
 
def beginLoop
 
def declareHandles
 
def isFromB
 
def makeAllElectrons
 
def makeAllMuons
 
def makeLeptons
 
def matchAnyLeptons
 
def matchLeptons
 
def process
 

Public Attributes

 eleEffectiveArea
 Duplicate removal for fast sim (to be checked if still necessary in latest greatest 5.3.X releases) More...
 
 miniIsolationPUCorr
 
 miniIsolationVetoLeptons
 inclusive leptons = all leptons that could be considered somewhere in the analysis, with minimal requirements (used e.g. More...
 
 muEffectiveArea
 
 muscleCorr
 

Static Public Attributes

 class_object = LeptonAnalyzer,
 
string electrons = 'slimmedElectrons'
 
string muons = 'slimmedMuons'
 
string rhoElectron = 'fixedGridRhoFastjetAll'
 
string rhoMuon = 'fixedGridRhoFastjetAll'
 

Detailed Description

Definition at line 20 of file LeptonAnalyzer.py.

Constructor & Destructor Documentation

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

Definition at line 23 of file LeptonAnalyzer.py.

23 
24  def __init__(self, cfg_ana, cfg_comp, looperName ):
25  super(LeptonAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)
26  if self.cfg_ana.doMuScleFitCorrections and self.cfg_ana.doMuScleFitCorrections != "none":
27  if self.cfg_ana.doMuScleFitCorrections not in [ "none", "prompt", "prompt-sync", "rereco", "rereco-sync" ]:
28  raise RuntimeError, 'doMuScleFitCorrections must be one of "none", "prompt", "prompt-sync", "rereco", "rereco-sync"'
29  rereco = ("prompt" not in self.cfg_ana.doMuScleFitCorrections)
30  sync = ("sync" in self.cfg_ana.doMuScleFitCorrections)
31  self.muscleCorr = MuScleFitCorr(cfg_comp.isMC, rereco, sync)
32  if hasattr(self.cfg_ana, "doRochesterCorrections") and self.cfg_ana.doRochesterCorrections:
33  raise RuntimeError, "You can't run both Rochester and MuScleFit corrections!"
34  else:
self.cfg_ana.doMuScleFitCorrections = False

Member Function Documentation

def objects.LeptonAnalyzer.LeptonAnalyzer.attachMiniIsolation (   self,
  mu 
)

Definition at line 347 of file LeptonAnalyzer.py.

References funct.abs(), bookConverter.max, and min().

348  def attachMiniIsolation(self, mu):
349  mu.miniIsoR = 10.0/min(max(mu.pt(), 50),200)
350  # -- version with increasing cone at low pT, gives slightly better performance for tight cuts and low pt leptons
351  # mu.miniIsoR = 10.0/min(max(mu.pt(), 50),200) if mu.pt() > 20 else 4.0/min(max(mu.pt(),10),20)
352  what = "mu" if (abs(mu.pdgId()) == 13) else ("eleB" if mu.isEB() else "eleE")
353  mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {"mu":0.0001,"eleB":0,"eleE":0.015}[what], 0.0);
354  if self.miniIsolationPUCorr == "weights":
355  if what == "mu":
356  mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.01, 0.5);
357  else:
358  mu.miniAbsIsoNeutral = ( self.IsolationComputer.photonAbsIsoWeighted( mu.physObj, mu.miniIsoR, 0.08 if what == "eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone) +
359  self.IsolationComputer.neutralHadAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone) )
360  else:
361  if what == "mu":
362  mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.01, 0.5);
363  else:
364  mu.miniAbsIsoPho = self.IsolationComputer.photonAbsIsoRaw( mu.physObj, mu.miniIsoR, 0.08 if what == "eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone)
365  mu.miniAbsIsoNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
366  mu.miniAbsIsoNeutral = mu.miniAbsIsoPho + mu.miniAbsIsoNHad
367  # -- version relying on PF candidate vetos; apparently less performant, and the isolation computed at RECO level doesn't have them
368  #mu.miniAbsIsoPhoSV = self.IsolationComputer.photonAbsIsoRaw( mu.physObj, mu.miniIsoR, 0.0, 0.0)
369  #mu.miniAbsIsoNHadSV = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.0, 0.0)
370  #mu.miniAbsIsoNeutral = mu.miniAbsIsoPhoSV + mu.miniAbsIsoNHadSV
371  if self.miniIsolationPUCorr == "rhoArea":
372  mu.miniAbsIsoNeutral = max(0.0, mu.miniAbsIsoNeutral - mu.rho * mu.EffectiveArea03 * (mu.miniIsoR/0.3)**2)
373  elif self.miniIsolationPUCorr == "deltaBeta":
374  if what == "mu":
375  mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.01, 0.5);
376  else:
377  mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.015 if what == "eleE" else 0.0, 0.0);
378  mu.miniAbsIsoNeutral = max(0.0, mu.miniAbsIsoNeutral - 0.5*mu.miniAbsIsoPU)
379  elif self.miniIsolationPUCorr != 'raw':
380  raise RuntimeError, "Unsupported miniIsolationCorr name '" + str(self.cfg_ana.miniIsolationCorr) + "'! For now only 'rhoArea', 'deltaBeta', 'raw', 'weights' are supported (and 'weights' is not tested)."
381  mu.miniAbsIso = mu.miniAbsIsoCharged + mu.miniAbsIsoNeutral
382  mu.miniRelIso = mu.miniAbsIso/mu.pt()
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
def objects.LeptonAnalyzer.LeptonAnalyzer.beginLoop (   self,
  setup 
)

Definition at line 87 of file LeptonAnalyzer.py.

87 
88  def beginLoop(self, setup):
89  super(LeptonAnalyzer,self).beginLoop(setup)
90  self.counters.addCounter('events')
91  count = self.counters.counter('events')
92  count.register('all events')
def objects.LeptonAnalyzer.LeptonAnalyzer.declareHandles (   self)

Definition at line 73 of file LeptonAnalyzer.py.

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

73 
74  def declareHandles(self):
75  super(LeptonAnalyzer, self).declareHandles()
76 
77  #leptons
78  self.handles['muons'] = AutoHandle(self.cfg_ana.muons,"std::vector<pat::Muon>")
79  self.handles['electrons'] = AutoHandle(self.cfg_ana.electrons,"std::vector<pat::Electron>")
80 
81  #rho for muons
82  self.handles['rhoMu'] = AutoHandle( self.cfg_ana.rhoMuon, 'double')
83  #rho for electrons
84  self.handles['rhoEle'] = AutoHandle( self.cfg_ana.rhoElectron, 'double')
85 
86  if self.doMiniIsolation:
self.handles['packedCandidates'] = AutoHandle( self.cfg_ana.packedCandidates, 'std::vector<pat::PackedCandidate>')
def objects.LeptonAnalyzer.LeptonAnalyzer.isFromB (   self,
  particle,
  bid = 5,
  done = {} 
)

Definition at line 404 of file LeptonAnalyzer.py.

References funct.abs(), and objects.LeptonAnalyzer.LeptonAnalyzer.isFromB().

Referenced by objects.LeptonAnalyzer.LeptonAnalyzer.isFromB(), and objects.LeptonAnalyzer.LeptonAnalyzer.matchAnyLeptons().

405  def isFromB(self,particle,bid=5, done={}):
406  for i in xrange( particle.numberOfMothers() ):
407  mom = particle.mother(i)
408  momid = abs(mom.pdgId())
409  if momid / 1000 == bid or momid / 100 == bid or momid == bid:
410  return True
411  elif mom.status() == 2 and self.isFromB(mom, done=done):
412  return True
413  return False
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def objects.LeptonAnalyzer.LeptonAnalyzer.makeAllElectrons (   self,
  event 
)
       make a list of all electrons, and apply basic corrections to them

Definition at line 259 of file LeptonAnalyzer.py.

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

260  def makeAllElectrons(self, event):
261  """
262  make a list of all electrons, and apply basic corrections to them
263  """
264  allelectrons = map( Electron, self.handles['electrons'].product() )
265 
266  ## Duplicate removal for fast sim (to be checked if still necessary in latest greatest 5.3.X releases)
267  allelenodup = []
268  for e in allelectrons:
269  dup = False
270  for e2 in allelenodup:
271  if abs(e.pt()-e2.pt()) < 1e-6 and abs(e.eta()-e2.eta()) < 1e-6 and abs(e.phi()-e2.phi()) < 1e-6 and e.charge() == e2.charge():
272  dup = True
273  break
274  if not dup: allelenodup.append(e)
275  allelectrons = allelenodup
276 
277  # fill EA for rho-corrected isolation
278  for ele in allelectrons:
279  ele.rho = float(self.handles['rhoEle'].product()[0])
280  if self.eleEffectiveArea == "Data2012":
281  # https://twiki.cern.ch/twiki/bin/viewauth/CMS/EgammaEARhoCorrection?rev=14
282  SCEta = abs(ele.superCluster().eta())
283  if SCEta < 1.0 : ele.EffectiveArea03 = 0.13 # 0.130;
284  elif SCEta < 1.479: ele.EffectiveArea03 = 0.14 # 0.137;
285  elif SCEta < 2.0 : ele.EffectiveArea03 = 0.07 # 0.067;
286  elif SCEta < 2.2 : ele.EffectiveArea03 = 0.09 # 0.089;
287  elif SCEta < 2.3 : ele.EffectiveArea03 = 0.11 # 0.107;
288  elif SCEta < 2.4 : ele.EffectiveArea03 = 0.11 # 0.110;
289  else : ele.EffectiveArea03 = 0.14 # 0.138;
290  if SCEta < 1.0 : ele.EffectiveArea04 = 0.208;
291  elif SCEta < 1.479: ele.EffectiveArea04 = 0.209;
292  elif SCEta < 2.0 : ele.EffectiveArea04 = 0.115;
293  elif SCEta < 2.2 : ele.EffectiveArea04 = 0.143;
294  elif SCEta < 2.3 : ele.EffectiveArea04 = 0.183;
295  elif SCEta < 2.4 : ele.EffectiveArea04 = 0.194;
296  else : ele.EffectiveArea04 = 0.261;
297  elif self.eleEffectiveArea == "Phys14_25ns_v1":
298  aeta = abs(ele.eta())
299  if aeta < 0.800: ele.EffectiveArea03 = 0.1013
300  elif aeta < 1.300: ele.EffectiveArea03 = 0.0988
301  elif aeta < 2.000: ele.EffectiveArea03 = 0.0572
302  elif aeta < 2.200: ele.EffectiveArea03 = 0.0842
303  else: ele.EffectiveArea03 = 0.1530
304  if aeta < 0.800: ele.EffectiveArea04 = 0.1830
305  elif aeta < 1.300: ele.EffectiveArea04 = 0.1734
306  elif aeta < 2.000: ele.EffectiveArea04 = 0.1077
307  elif aeta < 2.200: ele.EffectiveArea04 = 0.1565
308  else: ele.EffectiveArea04 = 0.2680
309  else: raise RuntimeError, "Unsupported value for ele_effectiveAreas: can only use Data2012 (rho: ?) and Phys14_v1 (rho: fixedGridRhoFastjetAll)"
310 
311  # Electron scale calibrations
312  if self.cfg_ana.doElectronScaleCorrections:
313  for ele in allelectrons:
314  self.electronEnergyCalibrator.correct(ele, event.run)
315 
316  # Attach the vertex
317  for ele in allelectrons:
318  ele.associatedVertex = event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]
319 
320  # Compute relIso with R=0.3 and R=0.4 cones
321  for ele in allelectrons:
322  if self.cfg_ana.ele_isoCorr=="rhoArea" :
323  ele.absIso03 = (ele.chargedHadronIsoR(0.3) + max(ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3)-ele.rho*ele.EffectiveArea03,0))
324  ele.absIso04 = (ele.chargedHadronIsoR(0.4) + max(ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4)-ele.rho*ele.EffectiveArea04,0))
325  elif self.cfg_ana.ele_isoCorr=="deltaBeta" :
326  ele.absIso03 = (ele.chargedHadronIsoR(0.3) + max( ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3) - ele.puChargedHadronIsoR(0.3)/2, 0.0))
327  ele.absIso04 = (ele.chargedHadronIsoR(0.4) + max( ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4) - ele.puChargedHadronIsoR(0.4)/2, 0.0))
328  else :
329  raise RuntimeError, "Unsupported ele_isoCorr name '" + str(self.cfg_ana.ele_isoCorr) + "'! For now only 'rhoArea' and 'deltaBeta' are supported."
330  ele.relIso03 = ele.absIso03/ele.pt()
331  ele.relIso04 = ele.absIso04/ele.pt()
332 
333  # Set tight MVA id
334  for ele in allelectrons:
335  if self.cfg_ana.ele_tightId=="MVA" :
336  ele.tightIdResult = ele.electronID("POG_MVA_ID_Trig_full5x5")
337  elif self.cfg_ana.ele_tightId=="Cuts_2012" :
338  ele.tightIdResult = -1 + 1*ele.electronID("POG_Cuts_ID_2012_Veto_full5x5") + 1*ele.electronID("POG_Cuts_ID_2012_Loose_full5x5") + 1*ele.electronID("POG_Cuts_ID_2012_Medium_full5x5") + 1*ele.electronID("POG_Cuts_ID_2012_Tight_full5x5")
339  else :
340  try:
341  ele.tightIdResult = ele.electronID(self.cfg_ana.ele_tightId)
342  except RuntimeError:
343  raise RuntimeError, "Unsupported ele_tightId name '" + str(self.cfg_ana.ele_tightId) + "'! For now only 'MVA' and 'Cuts_2012' are supported, in addition to what provided in Electron.py."
344 
345 
346  return allelectrons
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
eleEffectiveArea
Duplicate removal for fast sim (to be checked if still necessary in latest greatest 5...
def objects.LeptonAnalyzer.LeptonAnalyzer.makeAllMuons (   self,
  event 
)
       make a list of all muons, and apply basic corrections to them

Definition at line 182 of file LeptonAnalyzer.py.

References core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, and python.multivaluedict.map().

183  def makeAllMuons(self, event):
184  """
185  make a list of all muons, and apply basic corrections to them
186  """
187  # Start from all muons
188  allmuons = map( Muon, self.handles['muons'].product() )
189 
190  # Muon scale and resolution corrections (if enabled)
191  if self.cfg_ana.doMuScleFitCorrections:
192  for mu in allmuons:
193  self.muscleCorr.correct(mu, event.run)
194  elif self.cfg_ana.doRochesterCorrections:
195  for mu in allmuons:
196  corp4 = rochcor.corrected_p4(mu, event.run)
197  mu.setP4( corp4 )
198 
199  # Clean up dulicate muons (note: has no effect unless the muon id is removed)
200  if self.cfg_ana.doSegmentBasedMuonCleaning:
201  isgood = cmgMuonCleanerBySegments.clean( self.handles['muons'].product() )
202  newmu = []
203  for i,mu in enumerate(allmuons):
204  if isgood[i]: newmu.append(mu)
205  allmuons = newmu
206 
207  # Attach EAs for isolation:
208  for mu in allmuons:
209  mu.rho = float(self.handles['rhoMu'].product()[0])
210  if self.muEffectiveArea == "Data2012":
211  if aeta < 1.0 : mu.EffectiveArea03 = 0.382;
212  elif aeta < 1.47 : mu.EffectiveArea03 = 0.317;
213  elif aeta < 2.0 : mu.EffectiveArea03 = 0.242;
214  elif aeta < 2.2 : mu.EffectiveArea03 = 0.326;
215  elif aeta < 2.3 : mu.EffectiveArea03 = 0.462;
216  else : mu.EffectiveArea03 = 0.372;
217  if aeta < 1.0 : mu.EffectiveArea04 = 0.674;
218  elif aeta < 1.47 : mu.EffectiveArea04 = 0.565;
219  elif aeta < 2.0 : mu.EffectiveArea04 = 0.442;
220  elif aeta < 2.2 : mu.EffectiveArea04 = 0.515;
221  elif aeta < 2.3 : mu.EffectiveArea04 = 0.821;
222  else : mu.EffectiveArea04 = 0.660;
223  elif self.muEffectiveArea == "Phys14_25ns_v1":
224  aeta = abs(mu.eta())
225  if aeta < 0.800: mu.EffectiveArea03 = 0.0913
226  elif aeta < 1.300: mu.EffectiveArea03 = 0.0765
227  elif aeta < 2.000: mu.EffectiveArea03 = 0.0546
228  elif aeta < 2.200: mu.EffectiveArea03 = 0.0728
229  else: mu.EffectiveArea03 = 0.1177
230  if aeta < 0.800: mu.EffectiveArea04 = 0.1564
231  elif aeta < 1.300: mu.EffectiveArea04 = 0.1325
232  elif aeta < 2.000: mu.EffectiveArea04 = 0.0913
233  elif aeta < 2.200: mu.EffectiveArea04 = 0.1212
234  else: mu.EffectiveArea04 = 0.2085
235  else: raise RuntimeError, "Unsupported value for mu_effectiveAreas: can only use Data2012 (rho: ?) and Phys14_v1 (rho: fixedGridRhoFastjetAll)"
236  # Attach the vertex to them, for dxy/dz calculation
237  for mu in allmuons:
238  mu.associatedVertex = event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]
239  mu.setTrackForDxyDz(self.cfg_ana.muon_dxydz_track)
240 
241  # Set tight id if specified
242  if hasattr(self.cfg_ana, "mu_tightId"):
243  for mu in allmuons:
244  mu.tightIdResult = mu.muonID(self.cfg_ana.mu_tightId)
245 
246  # Compute relIso in 0.3 and 0.4 cones
247  for mu in allmuons:
248  if self.cfg_ana.mu_isoCorr=="rhoArea" :
249  mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt + max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.rho * mu.EffectiveArea03,0.0))
250  mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt + max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.rho * mu.EffectiveArea04,0.0))
251  elif self.cfg_ana.mu_isoCorr=="deltaBeta" :
252  mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt + max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.pfIsolationR03().sumPUPt/2,0.0))
253  mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt + max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.pfIsolationR04().sumPUPt/2,0.0))
254  else :
255  raise RuntimeError, "Unsupported mu_isoCorr name '" + str(self.cfg_ana.mu_isoCorr) + "'! For now only 'rhoArea' and 'deltaBeta' are supported."
256  mu.relIso03 = mu.absIso03/mu.pt()
257  mu.relIso04 = mu.absIso04/mu.pt()
258  return allmuons
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def objects.LeptonAnalyzer.LeptonAnalyzer.makeLeptons (   self,
  event 
)

Definition at line 98 of file LeptonAnalyzer.py.

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

Referenced by objects.LeptonAnalyzer.LeptonAnalyzer.process().

98 
99  def makeLeptons(self, event):
100  ### inclusive leptons = all leptons that could be considered somewhere in the analysis, with minimal requirements (used e.g. to match to MC)
101  event.inclusiveLeptons = []
102  ### selected leptons = subset of inclusive leptons passing some basic id definition and pt requirement
103  ### other leptons = subset of inclusive leptons failing some basic id definition and pt requirement
104  event.selectedLeptons = []
105  event.selectedMuons = []
106  event.selectedElectrons = []
107  event.otherLeptons = []
108 
109  if self.doMiniIsolation:
110  self.IsolationComputer.setPackedCandidates(self.handles['packedCandidates'].product())
111  if self.miniIsolationVetoLeptons == "any":
112  for lep in self.handles['muons'].product():
113  self.IsolationComputer.addVeto(lep)
114  for lep in self.handles['electrons'].product():
115  self.IsolationComputer.addVeto(lep)
116 
117  #muons
118  allmuons = self.makeAllMuons(event)
119 
120  #electrons
121  allelectrons = self.makeAllElectrons(event)
122 
123  #make inclusive leptons
124  inclusiveMuons = []
125  inclusiveElectrons = []
126  for mu in allmuons:
127  if (mu.track().isNonnull() and mu.muonID(self.cfg_ana.inclusive_muon_id) and
128  mu.pt()>self.cfg_ana.inclusive_muon_pt and abs(mu.eta())<self.cfg_ana.inclusive_muon_eta and
129  abs(mu.dxy())<self.cfg_ana.inclusive_muon_dxy and abs(mu.dz())<self.cfg_ana.inclusive_muon_dz):
130  inclusiveMuons.append(mu)
131  for ele in allelectrons:
132  if ( ele.electronID(self.cfg_ana.inclusive_electron_id) and
133  ele.pt()>self.cfg_ana.inclusive_electron_pt and abs(ele.eta())<self.cfg_ana.inclusive_electron_eta and
134  abs(ele.dxy())<self.cfg_ana.inclusive_electron_dxy and abs(ele.dz())<self.cfg_ana.inclusive_electron_dz and
135  ele.lostInner()<=self.cfg_ana.inclusive_electron_lostHits ):
136  inclusiveElectrons.append(ele)
137  event.inclusiveLeptons = inclusiveMuons + inclusiveElectrons
138 
139  if self.doMiniIsolation:
140  if self.miniIsolationVetoLeptons == "inclusive":
141  for lep in event.inclusiveLeptons:
142  self.IsolationComputer.addVeto(lep)
143  for lep in event.inclusiveLeptons:
144  self.attachMiniIsolation(lep)
145 
146  # make loose leptons (basic selection)
147  for mu in inclusiveMuons:
148  if (mu.muonID(self.cfg_ana.loose_muon_id) and
149  mu.pt() > self.cfg_ana.loose_muon_pt and abs(mu.eta()) < self.cfg_ana.loose_muon_eta and
150  abs(mu.dxy()) < self.cfg_ana.loose_muon_dxy and abs(mu.dz()) < self.cfg_ana.loose_muon_dz and
151  self.muIsoCut(mu)):
152  mu.looseIdSusy = True
153  event.selectedLeptons.append(mu)
154  event.selectedMuons.append(mu)
155  else:
156  mu.looseIdSusy = False
157  event.otherLeptons.append(mu)
158  looseMuons = event.selectedLeptons[:]
159  for ele in inclusiveElectrons:
160  if (ele.electronID(self.cfg_ana.loose_electron_id) and
161  ele.pt()>self.cfg_ana.loose_electron_pt and abs(ele.eta())<self.cfg_ana.loose_electron_eta and
162  abs(ele.dxy()) < self.cfg_ana.loose_electron_dxy and abs(ele.dz())<self.cfg_ana.loose_electron_dz and
163  self.eleIsoCut(ele) and
164  ele.lostInner() <= self.cfg_ana.loose_electron_lostHits and
165  ( True if getattr(self.cfg_ana,'notCleaningElectrons',False) else (bestMatch(ele, looseMuons)[1] > (self.cfg_ana.min_dr_electron_muon**2)) )):
166  event.selectedLeptons.append(ele)
167  event.selectedElectrons.append(ele)
168  ele.looseIdSusy = True
169  else:
170  event.otherLeptons.append(ele)
171  ele.looseIdSusy = False
172 
173  event.otherLeptons.sort(key = lambda l : l.pt(), reverse = True)
174  event.selectedLeptons.sort(key = lambda l : l.pt(), reverse = True)
175  event.selectedMuons.sort(key = lambda l : l.pt(), reverse = True)
176  event.selectedElectrons.sort(key = lambda l : l.pt(), reverse = True)
177  event.inclusiveLeptons.sort(key = lambda l : l.pt(), reverse = True)
178 
179  for lepton in event.selectedLeptons:
180  if hasattr(self,'efficiency'):
181  self.efficiency.attachToObject(lepton)
def bestMatch
Definition: deltar.py:139
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
miniIsolationVetoLeptons
inclusive leptons = all leptons that could be considered somewhere in the analysis, with minimal requirements (used e.g.
def objects.LeptonAnalyzer.LeptonAnalyzer.matchAnyLeptons (   self,
  event 
)

Definition at line 414 of file LeptonAnalyzer.py.

References funct.abs(), objects.LeptonAnalyzer.LeptonAnalyzer.isFromB(), genutils.isPromptLepton(), and deltar.matchObjectCollection3().

Referenced by objects.LeptonAnalyzer.LeptonAnalyzer.process().

415  def matchAnyLeptons(self, event):
416  event.anyLeptons = [ x for x in event.genParticles if x.status() == 1 and abs(x.pdgId()) in [11,13] ]
417  leps = event.inclusiveLeptons if hasattr(event, 'inclusiveLeptons') else event.selectedLeptons
418  match = matchObjectCollection3(leps, event.anyLeptons, deltaRMax = 0.3, filter = lambda x,y : abs(x.pdgId()) == abs(y.pdgId()))
419  for lep in leps:
420  gen = match[lep]
421  lep.mcMatchAny_gp = gen
422  if gen:
423  if self.isFromB(gen): lep.mcMatchAny = 5 # B (inclusive of B->D)
424  elif self.isFromB(gen,bid=4): lep.mcMatchAny = 4 # Charm
425  else: lep.mcMatchAny = 1
426  else:
427  lep.mcMatchAny = 0
428  # fix case where the matching with the only prompt leptons failed, but we still ended up with a prompt match
429  if gen != None and hasattr(lep,'mcMatchId') and lep.mcMatchId == 0:
430  if isPromptLepton(gen, False): lep.mcMatchId = 100
431  elif not hasattr(lep,'mcMatchId'):
432  lep.mcMatchId = 0
433  if not hasattr(lep,'mcMatchTau'): lep.mcMatchTau = 0
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def isPromptLepton
Definition: genutils.py:49
def matchObjectCollection3
Definition: deltar.py:41
def objects.LeptonAnalyzer.LeptonAnalyzer.matchLeptons (   self,
  event 
)

Definition at line 383 of file LeptonAnalyzer.py.

References funct.abs(), deltaR(), deltar.matchObjectCollection3(), bookConverter.max, and min().

Referenced by objects.LeptonAnalyzer.LeptonAnalyzer.process().

384  def matchLeptons(self, event):
385  def plausible(rec,gen):
386  if abs(rec.pdgId()) == 11 and abs(gen.pdgId()) != 11: return False
387  if abs(rec.pdgId()) == 13 and abs(gen.pdgId()) != 13: return False
388  dr = deltaR(rec.eta(),rec.phi(),gen.eta(),gen.phi())
389  if dr < 0.3: return True
390  if rec.pt() < 10 and abs(rec.pdgId()) == 13 and gen.pdgId() != rec.pdgId(): return False
391  if dr < 0.7: return True
392  if min(rec.pt(),gen.pt())/max(rec.pt(),gen.pt()) < 0.3: return False
393  return True
394 
395  leps = event.inclusiveLeptons if self.cfg_ana.match_inclusiveLeptons else event.selectedLeptons
396  match = matchObjectCollection3(leps,
397  event.genleps + event.gentauleps,
398  deltaRMax = 1.2, filter = plausible)
399  for lep in leps:
400  gen = match[lep]
401  lep.mcMatchId = (gen.sourceId if gen != None else 0)
402  lep.mcMatchTau = (gen in event.gentauleps if gen else -99)
403  lep.mcLep=gen
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
def matchObjectCollection3
Definition: deltar.py:41
def objects.LeptonAnalyzer.LeptonAnalyzer.process (   self,
  event 
)

Definition at line 434 of file LeptonAnalyzer.py.

References objects.LeptonAnalyzer.LeptonAnalyzer.makeLeptons(), objects.LeptonAnalyzer.LeptonAnalyzer.matchAnyLeptons(), objects.LeptonAnalyzer.LeptonAnalyzer.matchLeptons(), and core.Analyzer.Analyzer.readCollections().

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().

435  def process(self, event):
436  self.readCollections( event.input )
437  self.counters.counter('events').inc('all events')
438 
439  #call the leptons functions
440  self.makeLeptons(event)
441 
442  if self.cfg_comp.isMC and self.cfg_ana.do_mc_match:
443  self.matchLeptons(event)
444  self.matchAnyLeptons(event)
445 
446  return True
447 
448 #A default config
setattr(LeptonAnalyzer,"defaultConfig",cfg.Analyzer(

Member Data Documentation

objects.LeptonAnalyzer.LeptonAnalyzer.class_object = LeptonAnalyzer,
static

Definition at line 450 of file LeptonAnalyzer.py.

string objects.LeptonAnalyzer.LeptonAnalyzer.electrons = 'slimmedElectrons'
static

Definition at line 453 of file LeptonAnalyzer.py.

objects.LeptonAnalyzer.LeptonAnalyzer.eleEffectiveArea

Duplicate removal for fast sim (to be checked if still necessary in latest greatest 5.3.X releases)

Definition at line 279 of file LeptonAnalyzer.py.

objects.LeptonAnalyzer.LeptonAnalyzer.miniIsolationPUCorr

Definition at line 353 of file LeptonAnalyzer.py.

objects.LeptonAnalyzer.LeptonAnalyzer.miniIsolationVetoLeptons

inclusive leptons = all leptons that could be considered somewhere in the analysis, with minimal requirements (used e.g.

to match to MC) selected leptons = subset of inclusive leptons passing some basic id definition and pt requirement other leptons = subset of inclusive leptons failing some basic id definition and pt requirement

Definition at line 110 of file LeptonAnalyzer.py.

objects.LeptonAnalyzer.LeptonAnalyzer.muEffectiveArea

Definition at line 209 of file LeptonAnalyzer.py.

string objects.LeptonAnalyzer.LeptonAnalyzer.muons = 'slimmedMuons'
static

Definition at line 452 of file LeptonAnalyzer.py.

objects.LeptonAnalyzer.LeptonAnalyzer.muscleCorr

Definition at line 30 of file LeptonAnalyzer.py.

string objects.LeptonAnalyzer.LeptonAnalyzer.rhoElectron = 'fixedGridRhoFastjetAll'
static

Definition at line 455 of file LeptonAnalyzer.py.

string objects.LeptonAnalyzer.LeptonAnalyzer.rhoMuon = 'fixedGridRhoFastjetAll'
static

Definition at line 454 of file LeptonAnalyzer.py.