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

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

339  def attachMiniIsolation(self, mu):
340  mu.miniIsoR = 10.0/min(max(mu.pt(), 50),200)
341  # -- version with increasing cone at low pT, gives slightly better performance for tight cuts and low pt leptons
342  # mu.miniIsoR = 10.0/min(max(mu.pt(), 50),200) if mu.pt() > 20 else 4.0/min(max(mu.pt(),10),20)
343  what = "mu" if (abs(mu.pdgId()) == 13) else ("eleB" if mu.isEB() else "eleE")
344  mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {"mu":0.0001,"eleB":0,"eleE":0.015}[what], 0.0);
345  if self.miniIsolationPUCorr == "weights":
346  if what == "mu":
347  mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.01, 0.5);
348  else:
349  mu.miniAbsIsoNeutral = ( self.IsolationComputer.photonAbsIsoWeighted( mu.physObj, mu.miniIsoR, 0.08 if what == "eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone) +
350  self.IsolationComputer.neutralHadAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone) )
351  else:
352  if what == "mu":
353  mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.01, 0.5);
354  else:
355  mu.miniAbsIsoPho = self.IsolationComputer.photonAbsIsoRaw( mu.physObj, mu.miniIsoR, 0.08 if what == "eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone)
356  mu.miniAbsIsoNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
357  mu.miniAbsIsoNeutral = mu.miniAbsIsoPho + mu.miniAbsIsoNHad
358  # -- version relying on PF candidate vetos; apparently less performant, and the isolation computed at RECO level doesn't have them
359  #mu.miniAbsIsoPhoSV = self.IsolationComputer.photonAbsIsoRaw( mu.physObj, mu.miniIsoR, 0.0, 0.0)
360  #mu.miniAbsIsoNHadSV = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.0, 0.0)
361  #mu.miniAbsIsoNeutral = mu.miniAbsIsoPhoSV + mu.miniAbsIsoNHadSV
362  if self.miniIsolationPUCorr == "rhoArea":
363  mu.miniAbsIsoNeutral = max(0.0, mu.miniAbsIsoNeutral - mu.rho * mu.EffectiveArea03 * (mu.miniIsoR/0.3)**2)
364  elif self.miniIsolationPUCorr == "deltaBeta":
365  if what == "mu":
366  mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.01, 0.5);
367  else:
368  mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.015 if what == "eleE" else 0.0, 0.0);
369  mu.miniAbsIsoNeutral = max(0.0, mu.miniAbsIsoNeutral - 0.5*mu.miniAbsIsoPU)
370  elif self.miniIsolationPUCorr != 'raw':
371  raise RuntimeError, "Unsupported miniIsolationCorr name '" + str(self.cfg_ana.miniIsolationCorr) + "'! For now only 'rhoArea', 'deltaBeta', 'raw', 'weights' are supported (and 'weights' is not tested)."
372  mu.miniAbsIso = mu.miniAbsIsoCharged + mu.miniAbsIsoNeutral
373  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 394 of file LeptonAnalyzer.py.

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

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

395  def isFromB(self,particle,bid=5, done={}):
396  for i in xrange( particle.numberOfMothers() ):
397  mom = particle.mother(i)
398  momid = abs(mom.pdgId())
399  if momid / 1000 == bid or momid / 100 == bid or momid == bid:
400  return True
401  elif mom.status() == 2 and self.isFromB(mom, done=done):
402  return True
403  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 253 of file LeptonAnalyzer.py.

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

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

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

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

405  def matchAnyLeptons(self, event):
406  event.anyLeptons = [ x for x in event.genParticles if x.status() == 1 and abs(x.pdgId()) in [11,13] ]
407  leps = event.inclusiveLeptons if hasattr(event, 'inclusiveLeptons') else event.selectedLeptons
408  match = matchObjectCollection3(leps, event.anyLeptons, deltaRMax = 0.3, filter = lambda x,y : abs(x.pdgId()) == abs(y.pdgId()))
409  for lep in leps:
410  gen = match[lep]
411  lep.mcMatchAny_gp = gen
412  if gen:
413  if self.isFromB(gen): lep.mcMatchAny = 5 # B (inclusive of B->D)
414  elif self.isFromB(gen,bid=4): lep.mcMatchAny = 4 # Charm
415  else: lep.mcMatchAny = 1
416  else:
417  lep.mcMatchAny = 0
418  # fix case where the matching with the only prompt leptons failed, but we still ended up with a prompt match
419  if gen != None and hasattr(lep,'mcMatchId') and lep.mcMatchId == 0:
420  if isPromptLepton(gen, False): lep.mcMatchId = 100
421  elif not hasattr(lep,'mcMatchId'):
422  lep.mcMatchId = 0
423  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:38
def objects.LeptonAnalyzer.LeptonAnalyzer.matchLeptons (   self,
  event 
)

Definition at line 374 of file LeptonAnalyzer.py.

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

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

375  def matchLeptons(self, event):
376  def plausible(rec,gen):
377  if abs(rec.pdgId()) == 11 and abs(gen.pdgId()) != 11: return False
378  if abs(rec.pdgId()) == 13 and abs(gen.pdgId()) != 13: return False
379  dr = deltaR(rec.eta(),rec.phi(),gen.eta(),gen.phi())
380  if dr < 0.3: return True
381  if rec.pt() < 10 and abs(rec.pdgId()) == 13 and gen.pdgId() != rec.pdgId(): return False
382  if dr < 0.7: return True
383  if min(rec.pt(),gen.pt())/max(rec.pt(),gen.pt()) < 0.3: return False
384  return True
385 
386  leps = event.inclusiveLeptons if self.cfg_ana.match_inclusiveLeptons else event.selectedLeptons
387  match = matchObjectCollection3(leps,
388  event.genleps + event.gentauleps,
389  deltaRMax = 1.2, filter = plausible)
390  for lep in leps:
391  gen = match[lep]
392  lep.mcMatchId = (gen.sourceId if gen != None else 0)
393  lep.mcMatchTau = (gen in event.gentauleps if gen else -99)
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:38
def objects.LeptonAnalyzer.LeptonAnalyzer.process (   self,
  event 
)

Definition at line 424 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.__init__(), ConfigBuilder.ConfigBuilder.addExtraStream(), ConfigBuilder.ConfigBuilder.anyOf(), ConfigBuilder.ConfigBuilder.completeInputCommand(), ConfigBuilder.ConfigBuilder.doNotInlineEventContent(), ConfigBuilder.ConfigBuilder.PrintAllModules.leave(), ConfigBuilder.ConfigBuilder.prepare(), ConfigBuilder.ConfigBuilder.prepare_ALCA(), ConfigBuilder.ConfigBuilder.prepare_DQM(), ConfigBuilder.ConfigBuilder.prepare_FASTSIM(), ConfigBuilder.ConfigBuilder.prepare_HARVESTING(), ConfigBuilder.ConfigBuilder.prepare_HLT(), ConfigBuilder.ConfigBuilder.prepare_LHE(), ConfigBuilder.ConfigBuilder.prepare_VALIDATION(), ConfigBuilder.ConfigBuilder.renameHLTprocessInSequence(), ConfigBuilder.ConfigBuilder.renameInputTagsInSequence(), and ConfigBuilder.ConfigBuilder.scheduleSequence().

425  def process(self, event):
426  self.readCollections( event.input )
427  self.counters.counter('events').inc('all events')
428 
429  #call the leptons functions
430  self.makeLeptons(event)
431 
432  if self.cfg_comp.isMC and self.cfg_ana.do_mc_match:
433  self.matchLeptons(event)
434  self.matchAnyLeptons(event)
435 
436  return True
437 
438 #A default config
setattr(LeptonAnalyzer,"defaultConfig",cfg.Analyzer(

Member Data Documentation

objects.LeptonAnalyzer.LeptonAnalyzer.class_object = LeptonAnalyzer,
static

Definition at line 440 of file LeptonAnalyzer.py.

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

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

objects.LeptonAnalyzer.LeptonAnalyzer.miniIsolationPUCorr

Definition at line 344 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 442 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 445 of file LeptonAnalyzer.py.

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

Definition at line 444 of file LeptonAnalyzer.py.