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 449 of file LeptonAnalyzer.py.

References bookConverter.max, and min().

450  def attachIsoAnnulus04(self, mu): # annulus isolation with outer cone of 0.4 and delta beta PU correction
451  mu.miniIsoR = 10.0/min(max(mu.pt(), 50),200)
452  mu.absIsoAnCharged = self.IsolationComputer.chargedAbsIso (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
453  mu.absIsoAnPho = self.IsolationComputer.photonAbsIsoRaw (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
454  mu.absIsoAnNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
455  mu.absIsoAnPU = self.IsolationComputer.puAbsIso (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
456  mu.absIsoAnNeutral = max(0.0, mu.absIsoAnPho + mu.absIsoAnNHad - 0.5*mu.absIsoAnPU)
457 
458  mu.absIsoAn04 = mu.absIsoAnCharged + mu.absIsoAnNeutral
459  mu.relIsoAn04 = mu.absIsoAn04/mu.pt()
460 
T min(T a, T b)
Definition: MathUtil.h:58
def objects.LeptonAnalyzer.LeptonAnalyzer.attachIsolationScan (   self,
  mu 
)

Definition at line 461 of file LeptonAnalyzer.py.

References funct.abs().

462  def attachIsolationScan(self, mu):
463 
464  what = "mu" if (abs(mu.pdgId()) == 13) else ("eleB" if mu.isEB() else "eleE")
465  vetoreg = {"mu":0.0001,"eleB":0,"eleE":0.015}[what]
466 
467  if what=="mu":
468  mu.ScanAbsIsoCharged005 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.05, vetoreg, 0.0)
469  mu.ScanAbsIsoCharged01 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.1, vetoreg, 0.0)
470  mu.ScanAbsIsoCharged02 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.2, vetoreg, 0.0)
471  mu.ScanAbsIsoCharged03 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.3, vetoreg, 0.0)
472  mu.ScanAbsIsoCharged04 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.4, vetoreg, 0.0)
473  else:
474  mu.ScanAbsIsoCharged005 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.05, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
475  mu.ScanAbsIsoCharged01 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.1, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
476  mu.ScanAbsIsoCharged02 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.2, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
477  mu.ScanAbsIsoCharged03 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.3, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
478  mu.ScanAbsIsoCharged04 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.4, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
479 
480  if what=="mu":
481  mu.ScanAbsIsoNeutral005 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.05, 0.01, 0.5)
482  mu.ScanAbsIsoNeutral01 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.1, 0.01, 0.5)
483  mu.ScanAbsIsoNeutral02 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.2, 0.01, 0.5)
484  mu.ScanAbsIsoNeutral03 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.3, 0.01, 0.5)
485  mu.ScanAbsIsoNeutral04 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.4, 0.01, 0.5)
486  else:
487  vetoreg = {"eleB":0.0,"eleE":0.08}[what]
488  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)
489  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)
490  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)
491  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)
492  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)
493 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def objects.LeptonAnalyzer.LeptonAnalyzer.attachMiniIsolation (   self,
  mu 
)

Definition at line 404 of file LeptonAnalyzer.py.

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

405  def attachMiniIsolation(self, mu):
406  mu.miniIsoR = 10.0/min(max(mu.pt(), 50),200)
407  # -- version with increasing cone at low pT, gives slightly better performance for tight cuts and low pt leptons
408  # mu.miniIsoR = 10.0/min(max(mu.pt(), 50),200) if mu.pt() > 20 else 4.0/min(max(mu.pt(),10),20)
409  what = "mu" if (abs(mu.pdgId()) == 13) else ("eleB" if mu.isEB() else "eleE")
410  if what == "mu":
411  mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {"mu":0.0001,"eleB":0,"eleE":0.015}[what], 0.0);
412  else:
413  mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {"mu":0.0001,"eleB":0,"eleE":0.015}[what], 0.0,self.IsolationComputer.selfVetoNone);
415  if self.miniIsolationPUCorr == None: puCorr = self.cfg_ana.mu_isoCorr if what=="mu" else self.cfg_ana.ele_isoCorr
416  else: puCorr = self.miniIsolationPUCorr
417 
418  if puCorr == "weights":
419  if what == "mu":
420  mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.01, 0.5);
421  else:
422  mu.miniAbsIsoNeutral = ( self.IsolationComputer.photonAbsIsoWeighted( mu.physObj, mu.miniIsoR, 0.08 if what == "eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone) +
423  self.IsolationComputer.neutralHadAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone) )
424  else:
425  if what == "mu":
426  mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.01, 0.5);
427  else:
428  mu.miniAbsIsoPho = self.IsolationComputer.photonAbsIsoRaw( mu.physObj, mu.miniIsoR, 0.08 if what == "eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone)
429  mu.miniAbsIsoNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
430  mu.miniAbsIsoNeutral = mu.miniAbsIsoPho + mu.miniAbsIsoNHad
431  # -- version relying on PF candidate vetos; apparently less performant, and the isolation computed at RECO level doesn't have them
432  #mu.miniAbsIsoPhoSV = self.IsolationComputer.photonAbsIsoRaw( mu.physObj, mu.miniIsoR, 0.0, 0.0)
433  #mu.miniAbsIsoNHadSV = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.0, 0.0)
434  #mu.miniAbsIsoNeutral = mu.miniAbsIsoPhoSV + mu.miniAbsIsoNHadSV
435  if puCorr == "rhoArea":
436  mu.miniAbsIsoNeutral = max(0.0, mu.miniAbsIsoNeutral - mu.rho * mu.EffectiveArea03 * (mu.miniIsoR/0.3)**2)
437  elif puCorr == "deltaBeta":
438  if what == "mu":
439  mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.01, 0.5);
440  else:
441  mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.015 if what == "eleE" else 0.0, 0.0,self.IsolationComputer.selfVetoNone);
442  mu.miniAbsIsoNeutral = max(0.0, mu.miniAbsIsoNeutral - 0.5*mu.miniAbsIsoPU)
443  elif puCorr != 'raw':
444  raise RuntimeError, "Unsupported miniIsolationCorr name '" + puCorr + "'! For now only 'rhoArea', 'deltaBeta', 'raw', 'weights' are supported (and 'weights' is not tested)."
445 
446  mu.miniAbsIso = mu.miniAbsIsoCharged + mu.miniAbsIsoNeutral
447  mu.miniRelIso = mu.miniAbsIso/mu.pt()
448 
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 515 of file LeptonAnalyzer.py.

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

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

516  def isFromB(self,particle,bid=5, done={}):
517  for i in xrange( particle.numberOfMothers() ):
518  mom = particle.mother(i)
519  momid = abs(mom.pdgId())
520  if momid / 1000 == bid or momid / 100 == bid or momid == bid:
521  return True
522  elif mom.status() == 2 and self.isFromB(mom, done=done):
523  return True
524  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 291 of file LeptonAnalyzer.py.

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

292  def makeAllElectrons(self, event):
293  """
294  make a list of all electrons, and apply basic corrections to them
295  """
296  allelectrons = map( Electron, self.handles['electrons'].product() )
297 
298  ## Duplicate removal for fast sim (to be checked if still necessary in latest greatest 5.3.X releases)
299  allelenodup = []
300  for e in allelectrons:
301  dup = False
302  for e2 in allelenodup:
303  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():
304  dup = True
305  break
306  if not dup: allelenodup.append(e)
307  allelectrons = allelenodup
308 
309  # fill EA for rho-corrected isolation
310  for ele in allelectrons:
311  ele.rho = float(self.handles['rhoEle'].product()[0])
312  if self.eleEffectiveArea == "Data2012":
313  # https://twiki.cern.ch/twiki/bin/viewauth/CMS/EgammaEARhoCorrection?rev=14
314  SCEta = abs(ele.superCluster().eta())
315  if SCEta < 1.0 : ele.EffectiveArea03 = 0.13 # 0.130;
316  elif SCEta < 1.479: ele.EffectiveArea03 = 0.14 # 0.137;
317  elif SCEta < 2.0 : ele.EffectiveArea03 = 0.07 # 0.067;
318  elif SCEta < 2.2 : ele.EffectiveArea03 = 0.09 # 0.089;
319  elif SCEta < 2.3 : ele.EffectiveArea03 = 0.11 # 0.107;
320  elif SCEta < 2.4 : ele.EffectiveArea03 = 0.11 # 0.110;
321  else : ele.EffectiveArea03 = 0.14 # 0.138;
322  if SCEta < 1.0 : ele.EffectiveArea04 = 0.208;
323  elif SCEta < 1.479: ele.EffectiveArea04 = 0.209;
324  elif SCEta < 2.0 : ele.EffectiveArea04 = 0.115;
325  elif SCEta < 2.2 : ele.EffectiveArea04 = 0.143;
326  elif SCEta < 2.3 : ele.EffectiveArea04 = 0.183;
327  elif SCEta < 2.4 : ele.EffectiveArea04 = 0.194;
328  else : ele.EffectiveArea04 = 0.261;
329  elif self.eleEffectiveArea == "Phys14_25ns_v1":
330  aeta = abs(ele.eta())
331  if aeta < 0.800: ele.EffectiveArea03 = 0.1013
332  elif aeta < 1.300: ele.EffectiveArea03 = 0.0988
333  elif aeta < 2.000: ele.EffectiveArea03 = 0.0572
334  elif aeta < 2.200: ele.EffectiveArea03 = 0.0842
335  else: ele.EffectiveArea03 = 0.1530
336  if aeta < 0.800: ele.EffectiveArea04 = 0.1830
337  elif aeta < 1.300: ele.EffectiveArea04 = 0.1734
338  elif aeta < 2.000: ele.EffectiveArea04 = 0.1077
339  elif aeta < 2.200: ele.EffectiveArea04 = 0.1565
340  else: ele.EffectiveArea04 = 0.2680
341  elif self.eleEffectiveArea == "Spring15_50ns_v1":
342  SCEta = abs(ele.superCluster().eta())
343  ## ----- https://github.com/ikrav/cmssw/blob/egm_id_747_v2/RecoEgamma/ElectronIdentification/data/Spring15/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_50ns.txt
344  if SCEta < 0.800: ele.EffectiveArea03 = 0.0973
345  elif SCEta < 1.300: ele.EffectiveArea03 = 0.0954
346  elif SCEta < 2.000: ele.EffectiveArea03 = 0.0632
347  elif SCEta < 2.200: ele.EffectiveArea03 = 0.0727
348  else: ele.EffectiveArea03 = 0.1337
349  # warning: EAs not computed for cone DR=0.4 yet. Do not correct
350  ele.EffectiveArea04 = 0.0
351  elif self.eleEffectiveArea == "Spring15_25ns_v1":
352  SCEta = abs(ele.superCluster().eta())
353  ## ----- https://github.com/ikrav/cmssw/blob/egm_id_747_v2/RecoEgamma/ElectronIdentification/data/Spring15/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_25ns.txt
354  if SCEta < 1.000: ele.EffectiveArea03 = 0.1752
355  elif SCEta < 1.479: ele.EffectiveArea03 = 0.1862
356  elif SCEta < 2.000: ele.EffectiveArea03 = 0.1411
357  elif SCEta < 2.200: ele.EffectiveArea03 = 0.1534
358  elif SCEta < 2.300: ele.EffectiveArea03 = 0.1903
359  elif SCEta < 2.400: ele.EffectiveArea03 = 0.2243
360  else: ele.EffectiveArea03 = 0.2687
361  # warning: EAs not computed for cone DR=0.4 yet. Do not correct
362  ele.EffectiveArea04 = 0.0
363  else: raise RuntimeError, "Unsupported value for ele_effectiveAreas: can only use Data2012 (rho: ?), Phys14_v1 and Spring15_v1 (rho: fixedGridRhoFastjetAll)"
364 
365  # Electron scale calibrations
366  if self.cfg_ana.doElectronScaleCorrections:
367  for ele in allelectrons:
368  self.electronEnergyCalibrator.correct(ele, event.run)
369 
370  # Attach the vertex
371  for ele in allelectrons:
372  ele.associatedVertex = event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]
373 
374  # Compute relIso with R=0.3 and R=0.4 cones
375  for ele in allelectrons:
376  if self.cfg_ana.ele_isoCorr=="rhoArea" :
377  ele.absIso03 = (ele.chargedHadronIsoR(0.3) + max(ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3)-ele.rho*ele.EffectiveArea03,0))
378  ele.absIso04 = (ele.chargedHadronIsoR(0.4) + max(ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4)-ele.rho*ele.EffectiveArea04,0))
379  elif self.cfg_ana.ele_isoCorr=="deltaBeta" :
380  ele.absIso03 = (ele.chargedHadronIsoR(0.3) + max( ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3) - ele.puChargedHadronIsoR(0.3)/2, 0.0))
381  ele.absIso04 = (ele.chargedHadronIsoR(0.4) + max( ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4) - ele.puChargedHadronIsoR(0.4)/2, 0.0))
382  else :
383  raise RuntimeError, "Unsupported ele_isoCorr name '" + str(self.cfg_ana.ele_isoCorr) + "'! For now only 'rhoArea' and 'deltaBeta' are supported."
384  ele.relIso03 = ele.absIso03/ele.pt()
385  ele.relIso04 = ele.absIso04/ele.pt()
386 
387  # Set tight MVA id
388  for ele in allelectrons:
389  if self.cfg_ana.ele_tightId=="MVA" :
390  ele.tightIdResult = ele.electronID("POG_MVA_ID_Trig_full5x5")
391  elif self.cfg_ana.ele_tightId=="Cuts_2012" :
392  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")
393  elif self.cfg_ana.ele_tightId=="Cuts_PHYS14_25ns_v1_ConvVetoDxyDz" :
394  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")
395 
396  else :
397  try:
398  ele.tightIdResult = ele.electronID(self.cfg_ana.ele_tightId)
399  except RuntimeError:
400  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."
401 
402 
403  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, HTTP.RequestManager.handles, and python.multivaluedict.map().

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  elif self.muEffectiveArea == "Spring15_25ns_v1":
260  aeta = abs(mu.eta())
261  if aeta < 0.800: mu.EffectiveArea03 = 0.0735
262  elif aeta < 1.300: mu.EffectiveArea03 = 0.0619
263  elif aeta < 2.000: mu.EffectiveArea03 = 0.0465
264  elif aeta < 2.200: mu.EffectiveArea03 = 0.0433
265  else: mu.EffectiveArea03 = 0.0577
266  mu.EffectiveArea04 = 0 # not computed
267  else: raise RuntimeError, "Unsupported value for mu_effectiveAreas: can only use Data2012 (rho: ?) and Phys14_25ns_v1 or Spring15_25ns_v1 (rho: fixedGridRhoFastjetAll)"
268  # Attach the vertex to them, for dxy/dz calculation
269  for mu in allmuons:
270  mu.associatedVertex = event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]
271  mu.setTrackForDxyDz(self.cfg_ana.muon_dxydz_track)
272 
273  # Set tight id if specified
274  if hasattr(self.cfg_ana, "mu_tightId"):
275  for mu in allmuons:
276  mu.tightIdResult = mu.muonID(self.cfg_ana.mu_tightId)
277 
278  # Compute relIso in 0.3 and 0.4 cones
279  for mu in allmuons:
280  if self.cfg_ana.mu_isoCorr=="rhoArea" :
281  mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt + max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.rho * mu.EffectiveArea03,0.0))
282  mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt + max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.rho * mu.EffectiveArea04,0.0))
283  elif self.cfg_ana.mu_isoCorr=="deltaBeta" :
284  mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt + max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.pfIsolationR03().sumPUPt/2,0.0))
285  mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt + max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.pfIsolationR04().sumPUPt/2,0.0))
286  else :
287  raise RuntimeError, "Unsupported mu_isoCorr name '" + str(self.cfg_ana.mu_isoCorr) + "'! For now only 'rhoArea' and 'deltaBeta' are supported."
288  mu.relIso03 = mu.absIso03/mu.pt()
289  mu.relIso04 = mu.absIso04/mu.pt()
290  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 525 of file LeptonAnalyzer.py.

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

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

526  def matchAnyLeptons(self, event):
527  event.anyLeptons = [ x for x in event.genParticles if x.status() == 1 and abs(x.pdgId()) in [11,13] ]
528  leps = event.inclusiveLeptons if hasattr(event, 'inclusiveLeptons') else event.selectedLeptons
529  match = matchObjectCollection3(leps, event.anyLeptons, deltaRMax = 0.3, filter = lambda x,y : abs(x.pdgId()) == abs(y.pdgId()))
530  for lep in leps:
531  gen = match[lep]
532  lep.mcMatchAny_gp = gen
533  if gen:
534  if self.isFromB(gen): lep.mcMatchAny = 5 # B (inclusive of B->D)
535  elif self.isFromB(gen,bid=4): lep.mcMatchAny = 4 # Charm
536  else: lep.mcMatchAny = 1
537  else:
538  lep.mcMatchAny = 0
539  # fix case where the matching with the only prompt leptons failed, but we still ended up with a prompt match
540  if gen != None and hasattr(lep,'mcMatchId') and lep.mcMatchId == 0:
541  if isPromptLepton(gen, False): lep.mcMatchId = 100
542  elif not hasattr(lep,'mcMatchId'):
543  lep.mcMatchId = 0
544  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 494 of file LeptonAnalyzer.py.

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

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

495  def matchLeptons(self, event):
496  def plausible(rec,gen):
497  if abs(rec.pdgId()) == 11 and abs(gen.pdgId()) != 11: return False
498  if abs(rec.pdgId()) == 13 and abs(gen.pdgId()) != 13: return False
499  dr = deltaR(rec.eta(),rec.phi(),gen.eta(),gen.phi())
500  if dr < 0.3: return True
501  if rec.pt() < 10 and abs(rec.pdgId()) == 13 and gen.pdgId() != rec.pdgId(): return False
502  if dr < 0.7: return True
503  if min(rec.pt(),gen.pt())/max(rec.pt(),gen.pt()) < 0.3: return False
504  return True
505 
506  leps = event.inclusiveLeptons if self.cfg_ana.match_inclusiveLeptons else event.selectedLeptons
507  match = matchObjectCollection3(leps,
508  event.genleps + event.gentauleps,
509  deltaRMax = 1.2, filter = plausible)
510  for lep in leps:
511  gen = match[lep]
512  lep.mcMatchId = (gen.sourceId if gen != None else 0)
513  lep.mcMatchTau = (gen in event.gentauleps if gen else -99)
514  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 545 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().

546  def process(self, event):
547  self.readCollections( event.input )
548  self.counters.counter('events').inc('all events')
549 
550  #call the leptons functions
551  self.makeLeptons(event)
552 
553  if self.cfg_comp.isMC and self.cfg_ana.do_mc_match:
554  self.matchLeptons(event)
555  self.matchAnyLeptons(event)
556 
557  return True
558 
559 #A default config
setattr(LeptonAnalyzer,"defaultConfig",cfg.Analyzer(

Member Data Documentation

objects.LeptonAnalyzer.LeptonAnalyzer.class_object = LeptonAnalyzer,
static

Definition at line 561 of file LeptonAnalyzer.py.

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

Definition at line 564 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)

--— https://github.com/ikrav/cmssw/blob/egm_id_747_v2/RecoEgamma/ElectronIdentification/data/Spring15/effAreaElectrons_cone03_pfNeuHadronsAndPhotons_50ns.txt

Definition at line 311 of file LeptonAnalyzer.py.

objects.LeptonAnalyzer.LeptonAnalyzer.miniIsolationPUCorr

Definition at line 414 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 563 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 566 of file LeptonAnalyzer.py.

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

Definition at line 565 of file LeptonAnalyzer.py.