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 attachIsoAnnulus04
 
def attachIsolationScan
 
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.attachIsoAnnulus04 (   self,
  mu 
)

Definition at line 418 of file LeptonAnalyzer.py.

References bookConverter.max, and min().

419  def attachIsoAnnulus04(self, mu): # annulus isolation with outer cone of 0.4 and delta beta PU correction
420  mu.miniIsoR = 10.0/min(max(mu.pt(), 50),200)
421  mu.absIsoAnCharged = self.IsolationComputer.chargedAbsIso (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
422  mu.absIsoAnPho = self.IsolationComputer.photonAbsIsoRaw (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
423  mu.absIsoAnNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
424  mu.absIsoAnPU = self.IsolationComputer.puAbsIso (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
425  mu.absIsoAnNeutral = max(0.0, mu.absIsoAnPho + mu.absIsoAnNHad - 0.5*mu.absIsoAnPU)
426 
427  mu.absIsoAn04 = mu.absIsoAnCharged + mu.absIsoAnNeutral
428  mu.relIsoAn04 = mu.absIsoAn04/mu.pt()
429 
T min(T a, T b)
Definition: MathUtil.h:58
def objects.LeptonAnalyzer.LeptonAnalyzer.attachIsolationScan (   self,
  mu 
)

Definition at line 430 of file LeptonAnalyzer.py.

References funct.abs().

431  def attachIsolationScan(self, mu):
432 
433  what = "mu" if (abs(mu.pdgId()) == 13) else ("eleB" if mu.isEB() else "eleE")
434  vetoreg = {"mu":0.0001,"eleB":0,"eleE":0.015}[what]
435 
436  if what=="mu":
437  mu.ScanAbsIsoCharged005 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.05, vetoreg, 0.0)
438  mu.ScanAbsIsoCharged01 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.1, vetoreg, 0.0)
439  mu.ScanAbsIsoCharged02 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.2, vetoreg, 0.0)
440  mu.ScanAbsIsoCharged03 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.3, vetoreg, 0.0)
441  mu.ScanAbsIsoCharged04 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.4, vetoreg, 0.0)
442  else:
443  mu.ScanAbsIsoCharged005 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.05, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
444  mu.ScanAbsIsoCharged01 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.1, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
445  mu.ScanAbsIsoCharged02 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.2, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
446  mu.ScanAbsIsoCharged03 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.3, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
447  mu.ScanAbsIsoCharged04 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.4, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
448 
449  if what=="mu":
450  mu.ScanAbsIsoNeutral005 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.05, 0.01, 0.5)
451  mu.ScanAbsIsoNeutral01 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.1, 0.01, 0.5)
452  mu.ScanAbsIsoNeutral02 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.2, 0.01, 0.5)
453  mu.ScanAbsIsoNeutral03 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.3, 0.01, 0.5)
454  mu.ScanAbsIsoNeutral04 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.4, 0.01, 0.5)
455  else:
456  vetoreg = {"eleB":0.0,"eleE":0.08}[what]
457  mu.ScanAbsIsoNeutral005 = self.IsolationComputer.photonAbsIsoRaw(mu.physObj, 0.05, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)+self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.05, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
458  mu.ScanAbsIsoNeutral01 = self.IsolationComputer.photonAbsIsoRaw(mu.physObj, 0.1, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)+self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.1, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
459  mu.ScanAbsIsoNeutral02 = self.IsolationComputer.photonAbsIsoRaw(mu.physObj, 0.2, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)+self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.2, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
460  mu.ScanAbsIsoNeutral03 = self.IsolationComputer.photonAbsIsoRaw(mu.physObj, 0.3, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)+self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.3, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
461  mu.ScanAbsIsoNeutral04 = self.IsolationComputer.photonAbsIsoRaw(mu.physObj, 0.4, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)+self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.4, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
462 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def objects.LeptonAnalyzer.LeptonAnalyzer.attachMiniIsolation (   self,
  mu 
)

Definition at line 374 of file LeptonAnalyzer.py.

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

375  def attachMiniIsolation(self, mu):
376  mu.miniIsoR = 10.0/min(max(mu.pt(), 50),200)
377  # -- version with increasing cone at low pT, gives slightly better performance for tight cuts and low pt leptons
378  # mu.miniIsoR = 10.0/min(max(mu.pt(), 50),200) if mu.pt() > 20 else 4.0/min(max(mu.pt(),10),20)
379  what = "mu" if (abs(mu.pdgId()) == 13) else ("eleB" if mu.isEB() else "eleE")
380  if what == "mu":
381  mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {"mu":0.0001,"eleB":0,"eleE":0.015}[what], 0.0);
382  else:
383  mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {"mu":0.0001,"eleB":0,"eleE":0.015}[what], 0.0,self.IsolationComputer.selfVetoNone);
385  if self.miniIsolationPUCorr == None: puCorr = self.cfg_ana.mu_isoCorr if what=="mu" else self.cfg_ana.ele_isoCorr
386  else: puCorr = self.miniIsolationPUCorr
387 
388  if puCorr == "weights":
389  if what == "mu":
390  mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.01, 0.5);
391  else:
392  mu.miniAbsIsoNeutral = ( self.IsolationComputer.photonAbsIsoWeighted( mu.physObj, mu.miniIsoR, 0.08 if what == "eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone) +
393  self.IsolationComputer.neutralHadAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone) )
394  else:
395  if what == "mu":
396  mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.01, 0.5);
397  else:
398  mu.miniAbsIsoPho = self.IsolationComputer.photonAbsIsoRaw( mu.physObj, mu.miniIsoR, 0.08 if what == "eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone)
399  mu.miniAbsIsoNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
400  mu.miniAbsIsoNeutral = mu.miniAbsIsoPho + mu.miniAbsIsoNHad
401  # -- version relying on PF candidate vetos; apparently less performant, and the isolation computed at RECO level doesn't have them
402  #mu.miniAbsIsoPhoSV = self.IsolationComputer.photonAbsIsoRaw( mu.physObj, mu.miniIsoR, 0.0, 0.0)
403  #mu.miniAbsIsoNHadSV = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.0, 0.0)
404  #mu.miniAbsIsoNeutral = mu.miniAbsIsoPhoSV + mu.miniAbsIsoNHadSV
405  if puCorr == "rhoArea":
406  mu.miniAbsIsoNeutral = max(0.0, mu.miniAbsIsoNeutral - mu.rho * mu.EffectiveArea03 * (mu.miniIsoR/0.3)**2)
407  elif puCorr == "deltaBeta":
408  if what == "mu":
409  mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.01, 0.5);
410  else:
411  mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.015 if what == "eleE" else 0.0, 0.0,self.IsolationComputer.selfVetoNone);
412  mu.miniAbsIsoNeutral = max(0.0, mu.miniAbsIsoNeutral - 0.5*mu.miniAbsIsoPU)
413  elif self.miniIsolationPUCorr != 'raw':
414  raise RuntimeError("Unsupported miniIsolationCorr name '" + str(self.cfg_ana.miniIsolationCorr) + "'! For now only 'rhoArea', 'deltaBeta', 'raw', 'weights' are supported (and 'weights' is not tested).")
415  mu.miniAbsIso = mu.miniAbsIsoCharged + mu.miniAbsIsoNeutral
416  mu.miniRelIso = mu.miniAbsIso/mu.pt()
417 
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 102 of file LeptonAnalyzer.py.

103  def beginLoop(self, setup):
104  super(LeptonAnalyzer,self).beginLoop(setup)
105  self.counters.addCounter('events')
106  count = self.counters.counter('events')
107  count.register('all events')
def objects.LeptonAnalyzer.LeptonAnalyzer.declareHandles (   self)

Definition at line 88 of file LeptonAnalyzer.py.

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

88 
89  def declareHandles(self):
90  super(LeptonAnalyzer, self).declareHandles()
91 
92  #leptons
93  self.handles['muons'] = AutoHandle(self.cfg_ana.muons,"std::vector<pat::Muon>")
94  self.handles['electrons'] = AutoHandle(self.cfg_ana.electrons,"std::vector<pat::Electron>")
95 
96  #rho for muons
97  self.handles['rhoMu'] = AutoHandle( self.cfg_ana.rhoMuon, 'double')
98  #rho for electrons
99  self.handles['rhoEle'] = AutoHandle( self.cfg_ana.rhoElectron, 'double')
100 
101  if self.doMiniIsolation or self.doIsolationScan:
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 484 of file LeptonAnalyzer.py.

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

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

485  def isFromB(self,particle,bid=5, done={}):
486  for i in xrange( particle.numberOfMothers() ):
487  mom = particle.mother(i)
488  momid = abs(mom.pdgId())
489  if momid / 1000 == bid or momid / 100 == bid or momid == bid:
490  return True
491  elif mom.status() == 2 and self.isFromB(mom, done=done):
492  return True
493  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 283 of file LeptonAnalyzer.py.

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

284  def makeAllElectrons(self, event):
285  """
286  make a list of all electrons, and apply basic corrections to them
287  """
288  allelectrons = map( Electron, self.handles['electrons'].product() )
289 
290  ## Duplicate removal for fast sim (to be checked if still necessary in latest greatest 5.3.X releases)
291  allelenodup = []
292  for e in allelectrons:
293  dup = False
294  for e2 in allelenodup:
295  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():
296  dup = True
297  break
298  if not dup: allelenodup.append(e)
299  allelectrons = allelenodup
300 
301  # fill EA for rho-corrected isolation
302  for ele in allelectrons:
303  ele.rho = float(self.handles['rhoEle'].product()[0])
304  if self.eleEffectiveArea == "Data2012":
305  # https://twiki.cern.ch/twiki/bin/viewauth/CMS/EgammaEARhoCorrection?rev=14
306  SCEta = abs(ele.superCluster().eta())
307  if SCEta < 1.0 : ele.EffectiveArea03 = 0.13 # 0.130;
308  elif SCEta < 1.479: ele.EffectiveArea03 = 0.14 # 0.137;
309  elif SCEta < 2.0 : ele.EffectiveArea03 = 0.07 # 0.067;
310  elif SCEta < 2.2 : ele.EffectiveArea03 = 0.09 # 0.089;
311  elif SCEta < 2.3 : ele.EffectiveArea03 = 0.11 # 0.107;
312  elif SCEta < 2.4 : ele.EffectiveArea03 = 0.11 # 0.110;
313  else : ele.EffectiveArea03 = 0.14 # 0.138;
314  if SCEta < 1.0 : ele.EffectiveArea04 = 0.208;
315  elif SCEta < 1.479: ele.EffectiveArea04 = 0.209;
316  elif SCEta < 2.0 : ele.EffectiveArea04 = 0.115;
317  elif SCEta < 2.2 : ele.EffectiveArea04 = 0.143;
318  elif SCEta < 2.3 : ele.EffectiveArea04 = 0.183;
319  elif SCEta < 2.4 : ele.EffectiveArea04 = 0.194;
320  else : ele.EffectiveArea04 = 0.261;
321  elif self.eleEffectiveArea == "Phys14_25ns_v1":
322  aeta = abs(ele.eta())
323  if aeta < 0.800: ele.EffectiveArea03 = 0.1013
324  elif aeta < 1.300: ele.EffectiveArea03 = 0.0988
325  elif aeta < 2.000: ele.EffectiveArea03 = 0.0572
326  elif aeta < 2.200: ele.EffectiveArea03 = 0.0842
327  else: ele.EffectiveArea03 = 0.1530
328  if aeta < 0.800: ele.EffectiveArea04 = 0.1830
329  elif aeta < 1.300: ele.EffectiveArea04 = 0.1734
330  elif aeta < 2.000: ele.EffectiveArea04 = 0.1077
331  elif aeta < 2.200: ele.EffectiveArea04 = 0.1565
332  else: ele.EffectiveArea04 = 0.2680
333  else: raise RuntimeError("Unsupported value for ele_effectiveAreas: can only use Data2012 (rho: ?) and Phys14_v1 (rho: fixedGridRhoFastjetAll)")
334 
335  # Electron scale calibrations
336  if self.cfg_ana.doElectronScaleCorrections:
337  for ele in allelectrons:
338  self.electronEnergyCalibrator.correct(ele, event.run)
339 
340  # Attach the vertex
341  for ele in allelectrons:
342  ele.associatedVertex = event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]
343 
344  # Compute relIso with R=0.3 and R=0.4 cones
345  for ele in allelectrons:
346  if self.cfg_ana.ele_isoCorr=="rhoArea" :
347  ele.absIso03 = (ele.chargedHadronIsoR(0.3) + max(ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3)-ele.rho*ele.EffectiveArea03,0))
348  ele.absIso04 = (ele.chargedHadronIsoR(0.4) + max(ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4)-ele.rho*ele.EffectiveArea04,0))
349  elif self.cfg_ana.ele_isoCorr=="deltaBeta" :
350  ele.absIso03 = (ele.chargedHadronIsoR(0.3) + max( ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3) - ele.puChargedHadronIsoR(0.3)/2, 0.0))
351  ele.absIso04 = (ele.chargedHadronIsoR(0.4) + max( ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4) - ele.puChargedHadronIsoR(0.4)/2, 0.0))
352  else :
353  raise RuntimeError("Unsupported ele_isoCorr name '" + str(self.cfg_ana.ele_isoCorr) + "'! For now only 'rhoArea' and 'deltaBeta' are supported.")
354  ele.relIso03 = ele.absIso03/ele.pt()
355  ele.relIso04 = ele.absIso04/ele.pt()
356 
357  # Set tight MVA id
358  for ele in allelectrons:
359  if self.cfg_ana.ele_tightId=="MVA" :
360  ele.tightIdResult = ele.electronID("POG_MVA_ID_Trig_full5x5")
361  elif self.cfg_ana.ele_tightId=="Cuts_2012" :
362  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")
363  elif self.cfg_ana.ele_tightId=="Cuts_PHYS14_25ns_v1_ConvVetoDxyDz" :
364  ele.tightIdResult = -1 + 1*ele.electronID("POG_Cuts_ID_PHYS14_25ns_v1_ConvVetoDxyDz_Veto_full5x5") + 1*ele.electronID("POG_Cuts_ID_PHYS14_25ns_v1_ConvVetoDxyDz_Loose_full5x5") + 1*ele.electronID("POG_Cuts_ID_PHYS14_25ns_v1_ConvVetoDxyDz_Medium_full5x5") + 1*ele.electronID("POG_Cuts_ID_PHYS14_25ns_v1_ConvVetoDxyDz_Tight_full5x5")
365 
366  else :
367  try:
368  ele.tightIdResult = ele.electronID(self.cfg_ana.ele_tightId)
369  except RuntimeError:
370  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.")
371 
372 
373  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 206 of file LeptonAnalyzer.py.

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

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

Definition at line 113 of file LeptonAnalyzer.py.

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

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

114  def makeLeptons(self, event):
115  ### inclusive leptons = all leptons that could be considered somewhere in the analysis, with minimal requirements (used e.g. to match to MC)
116  event.inclusiveLeptons = []
117  ### selected leptons = subset of inclusive leptons passing some basic id definition and pt requirement
118  ### other leptons = subset of inclusive leptons failing some basic id definition and pt requirement
119  event.selectedLeptons = []
120  event.selectedMuons = []
121  event.selectedElectrons = []
122  event.otherLeptons = []
123 
124  if self.doMiniIsolation or self.doIsolationScan:
125  self.IsolationComputer.setPackedCandidates(self.handles['packedCandidates'].product())
126  if self.doMiniIsolation:
127  if self.miniIsolationVetoLeptons == "any":
128  for lep in self.handles['muons'].product():
129  self.IsolationComputer.addVetos(lep)
130  for lep in self.handles['electrons'].product():
131  self.IsolationComputer.addVetos(lep)
132 
133  #muons
134  allmuons = self.makeAllMuons(event)
135 
136  #electrons
137  allelectrons = self.makeAllElectrons(event)
138 
139  #make inclusive leptons
140  inclusiveMuons = []
141  inclusiveElectrons = []
142  for mu in allmuons:
143  if (mu.track().isNonnull() and mu.muonID(self.cfg_ana.inclusive_muon_id) and
144  mu.pt()>self.cfg_ana.inclusive_muon_pt and abs(mu.eta())<self.cfg_ana.inclusive_muon_eta and
145  abs(mu.dxy())<self.cfg_ana.inclusive_muon_dxy and abs(mu.dz())<self.cfg_ana.inclusive_muon_dz):
146  inclusiveMuons.append(mu)
147  for ele in allelectrons:
148  if ( ele.electronID(self.cfg_ana.inclusive_electron_id) and
149  ele.pt()>self.cfg_ana.inclusive_electron_pt and abs(ele.eta())<self.cfg_ana.inclusive_electron_eta and
150  abs(ele.dxy())<self.cfg_ana.inclusive_electron_dxy and abs(ele.dz())<self.cfg_ana.inclusive_electron_dz and
151  ele.lostInner()<=self.cfg_ana.inclusive_electron_lostHits ):
152  inclusiveElectrons.append(ele)
153  event.inclusiveLeptons = inclusiveMuons + inclusiveElectrons
154 
155  if self.doMiniIsolation:
156  if self.miniIsolationVetoLeptons == "inclusive":
157  for lep in event.inclusiveLeptons:
158  self.IsolationComputer.addVetos(lep.physObj)
159  for lep in event.inclusiveLeptons:
160  self.attachMiniIsolation(lep)
161 
162  if self.doIsoAnnulus:
163  for lep in event.inclusiveLeptons:
164  self.attachIsoAnnulus04(lep)
165 
166  if self.doIsolationScan:
167  for lep in event.inclusiveLeptons:
168  self.attachIsolationScan(lep)
169 
170  # make loose leptons (basic selection)
171  for mu in inclusiveMuons:
172  if (mu.muonID(self.cfg_ana.loose_muon_id) and
173  mu.pt() > self.cfg_ana.loose_muon_pt and abs(mu.eta()) < self.cfg_ana.loose_muon_eta and
174  abs(mu.dxy()) < self.cfg_ana.loose_muon_dxy and abs(mu.dz()) < self.cfg_ana.loose_muon_dz and
175  self.muIsoCut(mu)):
176  mu.looseIdSusy = True
177  event.selectedLeptons.append(mu)
178  event.selectedMuons.append(mu)
179  else:
180  mu.looseIdSusy = False
181  event.otherLeptons.append(mu)
182  looseMuons = event.selectedLeptons[:]
183  for ele in inclusiveElectrons:
184  if (ele.electronID(self.cfg_ana.loose_electron_id) and
185  ele.pt()>self.cfg_ana.loose_electron_pt and abs(ele.eta())<self.cfg_ana.loose_electron_eta and
186  abs(ele.dxy()) < self.cfg_ana.loose_electron_dxy and abs(ele.dz())<self.cfg_ana.loose_electron_dz and
187  self.eleIsoCut(ele) and
188  ele.lostInner() <= self.cfg_ana.loose_electron_lostHits and
189  ( True if getattr(self.cfg_ana,'notCleaningElectrons',False) else (bestMatch(ele, looseMuons)[1] > (self.cfg_ana.min_dr_electron_muon**2)) )):
190  event.selectedLeptons.append(ele)
191  event.selectedElectrons.append(ele)
192  ele.looseIdSusy = True
193  else:
194  event.otherLeptons.append(ele)
195  ele.looseIdSusy = False
196 
197  event.otherLeptons.sort(key = lambda l : l.pt(), reverse = True)
198  event.selectedLeptons.sort(key = lambda l : l.pt(), reverse = True)
199  event.selectedMuons.sort(key = lambda l : l.pt(), reverse = True)
200  event.selectedElectrons.sort(key = lambda l : l.pt(), reverse = True)
201  event.inclusiveLeptons.sort(key = lambda l : l.pt(), reverse = True)
202 
203  for lepton in event.selectedLeptons:
204  if hasattr(self,'efficiency'):
205  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 494 of file LeptonAnalyzer.py.

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

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

495  def matchAnyLeptons(self, event):
496  event.anyLeptons = [ x for x in event.genParticles if x.status() == 1 and abs(x.pdgId()) in [11,13] ]
497  leps = event.inclusiveLeptons if hasattr(event, 'inclusiveLeptons') else event.selectedLeptons
498  match = matchObjectCollection3(leps, event.anyLeptons, deltaRMax = 0.3, filter = lambda x,y : abs(x.pdgId()) == abs(y.pdgId()))
499  for lep in leps:
500  gen = match[lep]
501  lep.mcMatchAny_gp = gen
502  if gen:
503  if self.isFromB(gen): lep.mcMatchAny = 5 # B (inclusive of B->D)
504  elif self.isFromB(gen,bid=4): lep.mcMatchAny = 4 # Charm
505  else: lep.mcMatchAny = 1
506  else:
507  lep.mcMatchAny = 0
508  # fix case where the matching with the only prompt leptons failed, but we still ended up with a prompt match
509  if gen != None and hasattr(lep,'mcMatchId') and lep.mcMatchId == 0:
510  if isPromptLepton(gen, False): lep.mcMatchId = 100
511  elif not hasattr(lep,'mcMatchId'):
512  lep.mcMatchId = 0
513  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 463 of file LeptonAnalyzer.py.

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

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

464  def matchLeptons(self, event):
465  def plausible(rec,gen):
466  if abs(rec.pdgId()) == 11 and abs(gen.pdgId()) != 11: return False
467  if abs(rec.pdgId()) == 13 and abs(gen.pdgId()) != 13: return False
468  dr = deltaR(rec.eta(),rec.phi(),gen.eta(),gen.phi())
469  if dr < 0.3: return True
470  if rec.pt() < 10 and abs(rec.pdgId()) == 13 and gen.pdgId() != rec.pdgId(): return False
471  if dr < 0.7: return True
472  if min(rec.pt(),gen.pt())/max(rec.pt(),gen.pt()) < 0.3: return False
473  return True
474 
475  leps = event.inclusiveLeptons if self.cfg_ana.match_inclusiveLeptons else event.selectedLeptons
476  match = matchObjectCollection3(leps,
477  event.genleps + event.gentauleps,
478  deltaRMax = 1.2, filter = plausible)
479  for lep in leps:
480  gen = match[lep]
481  lep.mcMatchId = (gen.sourceId if gen != None else 0)
482  lep.mcMatchTau = (gen in event.gentauleps if gen else -99)
483  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 514 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().

515  def process(self, event):
516  self.readCollections( event.input )
517  self.counters.counter('events').inc('all events')
518 
519  #call the leptons functions
520  self.makeLeptons(event)
521 
522  if self.cfg_comp.isMC and self.cfg_ana.do_mc_match:
523  self.matchLeptons(event)
524  self.matchAnyLeptons(event)
525 
526  return True
527 
528 #A default config
setattr(LeptonAnalyzer,"defaultConfig",cfg.Analyzer(

Member Data Documentation

objects.LeptonAnalyzer.LeptonAnalyzer.class_object = LeptonAnalyzer,
static

Definition at line 530 of file LeptonAnalyzer.py.

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

Definition at line 533 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 303 of file LeptonAnalyzer.py.

objects.LeptonAnalyzer.LeptonAnalyzer.miniIsolationPUCorr

Definition at line 384 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 126 of file LeptonAnalyzer.py.

objects.LeptonAnalyzer.LeptonAnalyzer.muEffectiveArea

Definition at line 233 of file LeptonAnalyzer.py.

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

Definition at line 532 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 535 of file LeptonAnalyzer.py.

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

Definition at line 534 of file LeptonAnalyzer.py.