1 from __future__
import print_function
2 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
3 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
4 from PhysicsTools.Heppy.physicsobjects.Electron
import Electron
5 from PhysicsTools.Heppy.physicsobjects.Muon
import Muon
9 from PhysicsTools.Heppy.physicsutils.RochesterCorrections
import rochcor
10 from PhysicsTools.Heppy.physicsutils.MuScleFitCorrector
import MuScleFitCorr
11 from PhysicsTools.Heppy.physicsutils.KalmanMuonCorrector
import KalmanMuonCorrector
12 from PhysicsTools.Heppy.physicsutils.ElectronCalibrator
import Run2ElectronCalibrator
14 import PhysicsTools.HeppyCore.framework.config
as cfg
19 from ROOT
import heppy
25 def __init__(self, cfg_ana, cfg_comp, looperName ):
26 super(LeptonAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
27 if hasattr(self.cfg_ana,
'doMuScleFitCorrections'):
28 raise RuntimeError(
"doMuScleFitCorrections is not supported. Please set instead doMuonScaleCorrections = ( 'MuScleFit', <name> )")
29 if hasattr(self.cfg_ana,
'doRochesterCorrections'):
30 raise RuntimeError(
"doRochesterCorrections is not supported. Please set instead doMuonScaleCorrections = ( 'Rochester', <name> )")
31 if self.cfg_ana.doMuonScaleCorrections:
32 algo, options = self.cfg_ana.doMuonScaleCorrections
34 corr = options[
'MC' if self.cfg_comp.isMC
else 'Data']
37 options[
'isSync']
if 'isSync' in options
else False,
38 options[
'smearMode']
if 'smearMode' in options
else "ebe")
39 elif algo ==
"Rochester":
40 print(
"WARNING: the Rochester correction in heppy is still from Run 1")
42 elif algo ==
"MuScleFit":
43 print(
"WARNING: the MuScleFit correction in heppy is still from Run 1 (and probably no longer functional)")
44 if options
not in [
"prompt",
"prompt-sync",
"rereco",
"rereco-sync" ]:
45 raise RuntimeError(
'MuScleFit correction name must be one of [ "prompt", "prompt-sync", "rereco", "rereco-sync" ] ')
46 rereco = (
"prompt" not in self.cfg_ana.doMuScleFitCorrections)
47 sync = (
"sync" in self.cfg_ana.doMuScleFitCorrections)
49 else:
raise RuntimeError(
"Unknown muon scale correction algorithm")
53 if self.cfg_ana.doElectronScaleCorrections:
54 conf = cfg_ana.doElectronScaleCorrections
59 conf[
'isSync']
if 'isSync' in conf
else False,
64 if hasattr(cfg_ana,
'loose_electron_isoCut'):
68 ele.relIso03 <= self.cfg_ana.loose_electron_relIso
and 69 ele.absIso03 < getattr(self.cfg_ana,
'loose_electron_absIso',9e99))
70 if hasattr(cfg_ana,
'loose_muon_isoCut'):
74 mu.relIso03 <= self.cfg_ana.loose_muon_relIso
and 75 mu.absIso03 < getattr(self.cfg_ana,
'loose_muon_absIso',9e99))
87 raise RuntimeError(
"miniIsolationVetoLeptons should be None, or 'any' (all reco leptons), or 'inclusive' (all inclusive leptons)")
118 self.handles[
'muons'] = AutoHandle(self.cfg_ana.muons,
"std::vector<pat::Muon>")
119 self.handles[
'electrons'] = AutoHandle(self.cfg_ana.electrons,
"std::vector<pat::Electron>")
122 self.handles[
'rhoMu'] = AutoHandle( self.cfg_ana.rhoMuon,
'double')
124 self.handles[
'rhoEle'] = AutoHandle( self.cfg_ana.rhoElectron,
'double')
127 self.handles[
'packedCandidates'] = AutoHandle( self.cfg_ana.packedCandidates,
'std::vector<pat::PackedCandidate>')
131 self.mchandles[
'genPhotons'] = AutoHandle(
'packedGenParticles',
'std::vector<pat::PackedGenParticle>' )
133 self.mchandles[
'genPhotons'] = AutoHandle(
'prunedGenParticles',
'std::vector<reco::GenParticle>' )
136 super(LeptonAnalyzer,self).
beginLoop(setup)
137 self.counters.addCounter(
'events')
138 count = self.counters.counter(
'events')
139 count.register(
'all events')
148 event.inclusiveLeptons = []
151 event.selectedLeptons = []
152 event.selectedMuons = []
153 event.selectedElectrons = []
154 event.otherLeptons = []
157 self.IsolationComputer.setPackedCandidates(self.handles[
'packedCandidates'].product())
160 for lep
in self.handles[
'muons'].product():
161 self.IsolationComputer.addVetos(lep)
162 for lep
in self.handles[
'electrons'].product():
163 self.IsolationComputer.addVetos(lep)
173 inclusiveElectrons = []
175 if (mu.track().isNonnull()
and mu.muonID(self.cfg_ana.inclusive_muon_id)
and 176 mu.pt()>self.cfg_ana.inclusive_muon_pt
and abs(mu.eta())<self.cfg_ana.inclusive_muon_eta
and 177 abs(mu.dxy())<self.cfg_ana.inclusive_muon_dxy
and abs(mu.dz())<self.cfg_ana.inclusive_muon_dz):
178 inclusiveMuons.append(mu)
179 for ele
in allelectrons:
180 if ( ele.electronID(self.cfg_ana.inclusive_electron_id)
and 181 ele.pt()>self.cfg_ana.inclusive_electron_pt
and abs(ele.eta())<self.cfg_ana.inclusive_electron_eta
and 182 abs(ele.dxy())<self.cfg_ana.inclusive_electron_dxy
and abs(ele.dz())<self.cfg_ana.inclusive_electron_dz
and 183 ele.lostInner()<=self.cfg_ana.inclusive_electron_lostHits ):
184 inclusiveElectrons.append(ele)
185 event.inclusiveLeptons = inclusiveMuons + inclusiveElectrons
189 for lep
in event.inclusiveLeptons:
190 self.IsolationComputer.addVetos(lep.physObj)
191 for lep
in event.inclusiveLeptons:
195 for lep
in event.inclusiveLeptons:
199 for lep
in event.inclusiveLeptons:
203 for mu
in inclusiveMuons:
204 if (mu.muonID(self.cfg_ana.loose_muon_id)
and 205 mu.pt() > self.cfg_ana.loose_muon_pt
and abs(mu.eta()) < self.cfg_ana.loose_muon_eta
and 206 abs(mu.dxy()) < self.cfg_ana.loose_muon_dxy
and abs(mu.dz()) < self.cfg_ana.loose_muon_dz
and 208 mu.looseIdSusy =
True 209 event.selectedLeptons.append(mu)
210 event.selectedMuons.append(mu)
212 mu.looseIdSusy =
False 213 event.otherLeptons.append(mu)
214 looseMuons = event.selectedLeptons[:]
215 for ele
in inclusiveElectrons:
216 if (ele.electronID(self.cfg_ana.loose_electron_id)
and 217 ele.pt()>self.cfg_ana.loose_electron_pt
and abs(ele.eta())<self.cfg_ana.loose_electron_eta
and 218 abs(ele.dxy()) < self.cfg_ana.loose_electron_dxy
and abs(ele.dz())<self.cfg_ana.loose_electron_dz
and 220 ele.lostInner() <= self.cfg_ana.loose_electron_lostHits
and 221 (
True if getattr(self.cfg_ana,
'notCleaningElectrons',
False)
else (
bestMatch(ele, looseMuons)[1] > (self.cfg_ana.min_dr_electron_muon**2)) )):
222 event.selectedLeptons.append(ele)
223 event.selectedElectrons.append(ele)
224 ele.looseIdSusy =
True 226 event.otherLeptons.append(ele)
227 ele.looseIdSusy =
False 229 event.otherLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
230 event.selectedLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
231 event.selectedMuons.sort(key =
lambda l : l.pt(), reverse =
True)
232 event.selectedElectrons.sort(key =
lambda l : l.pt(), reverse =
True)
233 event.inclusiveLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
235 for lepton
in event.selectedLeptons:
236 if hasattr(self,
'efficiency'):
237 self.efficiency.attachToObject(lepton)
241 make a list of all muons, and apply basic corrections to them 244 allmuons =
map( Muon, self.handles[
'muons'].product() )
248 self.muonScaleCorrector.correct_all(allmuons, event.run)
251 if self.cfg_ana.doSegmentBasedMuonCleaning:
252 isgood = cmgMuonCleanerBySegments.clean( self.handles[
'muons'].product() )
254 for i,mu
in enumerate(allmuons):
255 if isgood[i]: newmu.append(mu)
260 mu.rho =
float(self.handles[
'rhoMu'].product()[0])
262 if aeta < 1.0 : mu.EffectiveArea03 = 0.382;
263 elif aeta < 1.47 : mu.EffectiveArea03 = 0.317;
264 elif aeta < 2.0 : mu.EffectiveArea03 = 0.242;
265 elif aeta < 2.2 : mu.EffectiveArea03 = 0.326;
266 elif aeta < 2.3 : mu.EffectiveArea03 = 0.462;
267 else : mu.EffectiveArea03 = 0.372;
268 if aeta < 1.0 : mu.EffectiveArea04 = 0.674;
269 elif aeta < 1.47 : mu.EffectiveArea04 = 0.565;
270 elif aeta < 2.0 : mu.EffectiveArea04 = 0.442;
271 elif aeta < 2.2 : mu.EffectiveArea04 = 0.515;
272 elif aeta < 2.3 : mu.EffectiveArea04 = 0.821;
273 else : mu.EffectiveArea04 = 0.660;
276 if aeta < 0.800: mu.EffectiveArea03 = 0.0913
277 elif aeta < 1.300: mu.EffectiveArea03 = 0.0765
278 elif aeta < 2.000: mu.EffectiveArea03 = 0.0546
279 elif aeta < 2.200: mu.EffectiveArea03 = 0.0728
280 else: mu.EffectiveArea03 = 0.1177
281 if aeta < 0.800: mu.EffectiveArea04 = 0.1564
282 elif aeta < 1.300: mu.EffectiveArea04 = 0.1325
283 elif aeta < 2.000: mu.EffectiveArea04 = 0.0913
284 elif aeta < 2.200: mu.EffectiveArea04 = 0.1212
285 else: mu.EffectiveArea04 = 0.2085
288 if aeta < 0.800: mu.EffectiveArea03 = 0.0735
289 elif aeta < 1.300: mu.EffectiveArea03 = 0.0619
290 elif aeta < 2.000: mu.EffectiveArea03 = 0.0465
291 elif aeta < 2.200: mu.EffectiveArea03 = 0.0433
292 else: mu.EffectiveArea03 = 0.0577
293 mu.EffectiveArea04 = 0
294 else:
raise RuntimeError(
"Unsupported value for mu_effectiveAreas: can only use Data2012 (rho: ?) and Phys14_25ns_v1 or Spring15_25ns_v1 (rho: fixedGridRhoFastjetAll)")
297 mu.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
298 mu.setTrackForDxyDz(self.cfg_ana.muon_dxydz_track)
301 if hasattr(self.cfg_ana,
"mu_tightId"):
303 mu.tightIdResult = mu.muonID(self.cfg_ana.mu_tightId)
307 if self.cfg_ana.mu_isoCorr==
"rhoArea" :
308 mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt +
max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.rho * mu.EffectiveArea03,0.0))
309 mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt +
max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.rho * mu.EffectiveArea04,0.0))
310 elif self.cfg_ana.mu_isoCorr==
"deltaBeta" :
311 mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt +
max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.pfIsolationR03().sumPUPt/2,0.0))
312 mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt +
max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.pfIsolationR04().sumPUPt/2,0.0))
314 raise RuntimeError(
"Unsupported mu_isoCorr name '" +
str(self.cfg_ana.mu_isoCorr) +
"'! For now only 'rhoArea' and 'deltaBeta' are supported.")
315 mu.relIso03 = mu.absIso03/mu.pt()
316 mu.relIso04 = mu.absIso04/mu.pt()
321 make a list of all electrons, and apply basic corrections to them 323 allelectrons =
map( Electron, self.handles[
'electrons'].product() )
327 for e
in allelectrons:
329 for e2
in allelenodup:
330 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():
333 if not dup: allelenodup.append(e)
334 allelectrons = allelenodup
337 for ele
in allelectrons:
338 ele.rho =
float(self.handles[
'rhoEle'].product()[0])
341 SCEta =
abs(ele.superCluster().
eta())
342 if SCEta < 1.0 : ele.EffectiveArea03 = 0.13
343 elif SCEta < 1.479: ele.EffectiveArea03 = 0.14
344 elif SCEta < 2.0 : ele.EffectiveArea03 = 0.07
345 elif SCEta < 2.2 : ele.EffectiveArea03 = 0.09
346 elif SCEta < 2.3 : ele.EffectiveArea03 = 0.11
347 elif SCEta < 2.4 : ele.EffectiveArea03 = 0.11
348 else : ele.EffectiveArea03 = 0.14
349 if SCEta < 1.0 : ele.EffectiveArea04 = 0.208;
350 elif SCEta < 1.479: ele.EffectiveArea04 = 0.209;
351 elif SCEta < 2.0 : ele.EffectiveArea04 = 0.115;
352 elif SCEta < 2.2 : ele.EffectiveArea04 = 0.143;
353 elif SCEta < 2.3 : ele.EffectiveArea04 = 0.183;
354 elif SCEta < 2.4 : ele.EffectiveArea04 = 0.194;
355 else : ele.EffectiveArea04 = 0.261;
357 aeta =
abs(ele.eta())
358 if aeta < 0.800: ele.EffectiveArea03 = 0.1013
359 elif aeta < 1.300: ele.EffectiveArea03 = 0.0988
360 elif aeta < 2.000: ele.EffectiveArea03 = 0.0572
361 elif aeta < 2.200: ele.EffectiveArea03 = 0.0842
362 else: ele.EffectiveArea03 = 0.1530
363 if aeta < 0.800: ele.EffectiveArea04 = 0.1830
364 elif aeta < 1.300: ele.EffectiveArea04 = 0.1734
365 elif aeta < 2.000: ele.EffectiveArea04 = 0.1077
366 elif aeta < 2.200: ele.EffectiveArea04 = 0.1565
367 else: ele.EffectiveArea04 = 0.2680
369 SCEta =
abs(ele.superCluster().
eta())
371 if SCEta < 0.800: ele.EffectiveArea03 = 0.0973
372 elif SCEta < 1.300: ele.EffectiveArea03 = 0.0954
373 elif SCEta < 2.000: ele.EffectiveArea03 = 0.0632
374 elif SCEta < 2.200: ele.EffectiveArea03 = 0.0727
375 else: ele.EffectiveArea03 = 0.1337
377 ele.EffectiveArea04 = 0.0
379 SCEta =
abs(ele.superCluster().
eta())
381 if SCEta < 1.000: ele.EffectiveArea03 = 0.1752
382 elif SCEta < 1.479: ele.EffectiveArea03 = 0.1862
383 elif SCEta < 2.000: ele.EffectiveArea03 = 0.1411
384 elif SCEta < 2.200: ele.EffectiveArea03 = 0.1534
385 elif SCEta < 2.300: ele.EffectiveArea03 = 0.1903
386 elif SCEta < 2.400: ele.EffectiveArea03 = 0.2243
387 else: ele.EffectiveArea03 = 0.2687
389 ele.EffectiveArea04 = 0.0
390 else:
raise RuntimeError(
"Unsupported value for ele_effectiveAreas: can only use Data2012 (rho: ?), Phys14_v1 and Spring15_v1 (rho: fixedGridRhoFastjetAll)")
393 if self.cfg_ana.doElectronScaleCorrections:
394 for ele
in allelectrons:
395 self.electronEnergyCalibrator.correct(ele, event.run)
398 for ele
in allelectrons:
399 ele.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
402 for ele
in allelectrons:
403 if self.cfg_ana.ele_isoCorr==
"rhoArea" :
404 ele.absIso03 = (ele.chargedHadronIsoR(0.3) +
max(ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3)-ele.rho*ele.EffectiveArea03,0))
405 ele.absIso04 = (ele.chargedHadronIsoR(0.4) +
max(ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4)-ele.rho*ele.EffectiveArea04,0))
406 elif self.cfg_ana.ele_isoCorr==
"deltaBeta" :
407 ele.absIso03 = (ele.chargedHadronIsoR(0.3) +
max( ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3) - ele.puChargedHadronIsoR(0.3)/2, 0.0))
408 ele.absIso04 = (ele.chargedHadronIsoR(0.4) +
max( ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4) - ele.puChargedHadronIsoR(0.4)/2, 0.0))
410 raise RuntimeError(
"Unsupported ele_isoCorr name '" +
str(self.cfg_ana.ele_isoCorr) +
"'! For now only 'rhoArea' and 'deltaBeta' are supported.")
411 ele.relIso03 = ele.absIso03/ele.pt()
412 ele.relIso04 = ele.absIso04/ele.pt()
415 for ele
in allelectrons:
416 if self.cfg_ana.ele_tightId==
"MVA" :
417 ele.tightIdResult = ele.electronID(
"POG_MVA_ID_Trig_full5x5")
418 elif self.cfg_ana.ele_tightId==
"Cuts_2012" :
419 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")
420 elif self.cfg_ana.ele_tightId==
"Cuts_PHYS14_25ns_v1_ConvVetoDxyDz" :
421 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")
422 elif self.cfg_ana.ele_tightId==
"Cuts_SPRING15_25ns_v1_ConvVetoDxyDz" :
423 ele.tightIdResult = -1 + 1*ele.electronID(
"POG_Cuts_ID_SPRING15_25ns_v1_ConvVetoDxyDz_Veto_full5x5") + 1*ele.electronID(
"POG_Cuts_ID_SPRING15_25ns_v1_ConvVetoDxyDz_Loose_full5x5") + 1*ele.electronID(
"POG_Cuts_ID_SPRING15_25ns_v1_ConvVetoDxyDz_Medium_full5x5") + 1*ele.electronID(
"POG_Cuts_ID_SPRING15_25ns_v1_ConvVetoDxyDz_Tight_full5x5")
427 ele.tightIdResult = ele.electronID(self.cfg_ana.ele_tightId)
429 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.")
435 mu.miniIsoR = 10.0/
min(
max(mu.pt(), 50),200)
438 what =
"mu" if (
abs(mu.pdgId()) == 13)
else (
"eleB" if mu.isEB()
else "eleE")
440 mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what], 0.0);
442 mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what], 0.0,self.IsolationComputer.selfVetoNone);
444 if self.
miniIsolationPUCorr ==
None: puCorr = self.cfg_ana.mu_isoCorr
if what==
"mu" else self.cfg_ana.ele_isoCorr
447 if puCorr ==
"weights":
449 mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.01, 0.5);
451 mu.miniAbsIsoNeutral = ( self.IsolationComputer.photonAbsIsoWeighted( mu.physObj, mu.miniIsoR, 0.08
if what ==
"eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone) +
452 self.IsolationComputer.neutralHadAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone) )
455 mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.01, 0.5);
457 mu.miniAbsIsoPho = self.IsolationComputer.photonAbsIsoRaw( mu.physObj, mu.miniIsoR, 0.08
if what ==
"eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone)
458 mu.miniAbsIsoNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
459 mu.miniAbsIsoNeutral = mu.miniAbsIsoPho + mu.miniAbsIsoNHad
464 if puCorr ==
"rhoArea":
465 mu.miniAbsIsoNeutral =
max(0.0, mu.miniAbsIsoNeutral - mu.rho * mu.EffectiveArea03 * (mu.miniIsoR/0.3)**2)
466 elif puCorr ==
"deltaBeta":
468 mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.01, 0.5);
470 mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.015
if what ==
"eleE" else 0.0, 0.0,self.IsolationComputer.selfVetoNone);
471 mu.miniAbsIsoNeutral =
max(0.0, mu.miniAbsIsoNeutral - 0.5*mu.miniAbsIsoPU)
472 elif puCorr !=
'raw':
473 raise RuntimeError(
"Unsupported miniIsolationCorr name '" + puCorr +
"'! For now only 'rhoArea', 'deltaBeta', 'raw', 'weights' are supported (and 'weights' is not tested).")
475 mu.miniAbsIso = mu.miniAbsIsoCharged + mu.miniAbsIsoNeutral
476 mu.miniRelIso = mu.miniAbsIso/mu.pt()
480 mu.miniIsoR = 10.0/
min(
max(mu.pt(), 50),200)
481 mu.absIsoAnCharged = self.IsolationComputer.chargedAbsIso (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
482 mu.absIsoAnPho = self.IsolationComputer.photonAbsIsoRaw (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
483 mu.absIsoAnNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
484 mu.absIsoAnPU = self.IsolationComputer.puAbsIso (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
485 mu.absIsoAnNeutral =
max(0.0, mu.absIsoAnPho + mu.absIsoAnNHad - 0.5*mu.absIsoAnPU)
487 mu.absIsoAn04 = mu.absIsoAnCharged + mu.absIsoAnNeutral
488 mu.relIsoAn04 = mu.absIsoAn04/mu.pt()
493 what =
"mu" if (
abs(mu.pdgId()) == 13)
else (
"eleB" if mu.isEB()
else "eleE")
494 vetoreg = {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what]
497 mu.ScanAbsIsoCharged005 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.05, vetoreg, 0.0)
498 mu.ScanAbsIsoCharged01 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.1, vetoreg, 0.0)
499 mu.ScanAbsIsoCharged02 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.2, vetoreg, 0.0)
500 mu.ScanAbsIsoCharged03 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.3, vetoreg, 0.0)
501 mu.ScanAbsIsoCharged04 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.4, vetoreg, 0.0)
503 mu.ScanAbsIsoCharged005 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.05, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
504 mu.ScanAbsIsoCharged01 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.1, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
505 mu.ScanAbsIsoCharged02 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.2, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
506 mu.ScanAbsIsoCharged03 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.3, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
507 mu.ScanAbsIsoCharged04 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.4, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
510 mu.ScanAbsIsoNeutral005 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.05, 0.01, 0.5)
511 mu.ScanAbsIsoNeutral01 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.1, 0.01, 0.5)
512 mu.ScanAbsIsoNeutral02 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.2, 0.01, 0.5)
513 mu.ScanAbsIsoNeutral03 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.3, 0.01, 0.5)
514 mu.ScanAbsIsoNeutral04 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.4, 0.01, 0.5)
516 vetoreg = {
"eleB":0.0,
"eleE":0.08}[what]
517 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)
518 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)
519 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)
520 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)
521 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)
525 def plausible(rec,gen):
526 if abs(rec.pdgId()) == 11
and abs(gen.pdgId()) != 11:
return False 527 if abs(rec.pdgId()) == 13
and abs(gen.pdgId()) != 13:
return False 528 dr =
deltaR(rec.eta(),rec.phi(),gen.eta(),gen.phi())
529 if dr < 0.3:
return True 530 if rec.pt() < 10
and abs(rec.pdgId()) == 13
and gen.pdgId() != rec.pdgId():
return False 531 if dr < 0.7:
return True 532 if min(rec.pt(),gen.pt())/
max(rec.pt(),gen.pt()) < 0.3:
return False 535 leps = event.inclusiveLeptons
if self.cfg_ana.match_inclusiveLeptons
else event.selectedLeptons
537 event.genleps + event.gentauleps,
538 deltaRMax = 1.2, filter = plausible)
541 lep.mcMatchId = (gen.sourceId
if gen !=
None else 0)
542 lep.mcMatchTau = (gen
in event.gentauleps
if gen
else -99)
546 for i
in xrange( particle.numberOfMothers() ):
547 mom = particle.mother(i)
548 momid =
abs(mom.pdgId())
549 if momid / 1000 == bid
or momid / 100 == bid
or momid == bid:
551 elif mom.status() == 2
and self.
isFromB(mom, done=done, bid=bid):
556 event.anyLeptons = [ x
for x
in event.genParticles
if x.status() == 1
and abs(x.pdgId())
in [11,13] ]
557 leps = event.inclusiveLeptons
if hasattr(event,
'inclusiveLeptons')
else event.selectedLeptons
561 lep.mcMatchAny_gp = gen
563 if self.
isFromB(gen): lep.mcMatchAny = 5
564 elif self.
isFromB(gen,bid=4): lep.mcMatchAny = 4
565 else: lep.mcMatchAny = 1
566 if not getattr(lep,
'mcLep',
None): lep.mcLep = gen
568 if not getattr(lep,
'mcLep',
None): lep.mcLep =
None 571 if gen !=
None and hasattr(lep,
'mcMatchId')
and lep.mcMatchId == 0:
572 if isPromptLepton(gen,
False)
or (gen.isPromptFinalState()
or gen.isDirectPromptTauDecayProductFinalState()):
575 elif not hasattr(lep,
'mcMatchId'):
577 if not hasattr(lep,
'mcMatchTau'): lep.mcMatchTau = 0
580 event.anyPho = [ x
for x
in self.mchandles[
'genPhotons'].product()
if x.status() == 1
and x.pdgId() == 22
and x.pt() > 1.0 ]
581 leps = event.inclusiveLeptons
if hasattr(event,
'inclusiveLeptons')
else event.selectedLeptons
582 leps = [ l
for l
in leps
if abs(l.pdgId()) == 11 ]
583 plausible =
lambda rec, gen : 0.3*gen.pt() < rec.pt()
and rec.pt() < 1.5*gen.pt()
588 if lep.mcPho
and lep.mcLep:
591 dr =
deltaR(rec.eta(),rec.phi(),gen.eta(),gen.phi())
592 dptRel =
abs(rec.pt()-gen.pt())/gen.pt()
593 return dr + 0.2*dptRel
596 if getattr(lep,
'mcMatchAny_gp',
None)
and lep.mcMatchAny_gp != lep.mcLep:
598 if dlep <= dpho: lep.mcPho =
None 601 self.readCollections( event.input )
602 self.counters.counter(
'events').inc(
'all events')
607 if self.cfg_comp.isMC
and self.cfg_ana.do_mc_match:
616 setattr(LeptonAnalyzer,
"defaultConfig",cfg.Analyzer(
618 class_object=LeptonAnalyzer,
620 muons=
'slimmedMuons',
621 electrons=
'slimmedElectrons',
622 rhoMuon=
'fixedGridRhoFastjetAll',
623 rhoElectron =
'fixedGridRhoFastjetAll',
626 doMuonScaleCorrections=
False,
627 doElectronScaleCorrections=
False,
628 doSegmentBasedMuonCleaning=
False,
630 inclusive_muon_id =
"POG_ID_Loose",
631 inclusive_muon_pt = 3,
632 inclusive_muon_eta = 2.4,
633 inclusive_muon_dxy = 0.5,
634 inclusive_muon_dz = 1.0,
635 muon_dxydz_track =
"muonBestTrack",
637 loose_muon_id =
"POG_ID_Loose",
639 loose_muon_eta = 2.4,
640 loose_muon_dxy = 0.05,
642 loose_muon_relIso = 0.4,
645 inclusive_electron_id =
"",
646 inclusive_electron_pt = 5,
647 inclusive_electron_eta = 2.5,
648 inclusive_electron_dxy = 0.5,
649 inclusive_electron_dz = 1.0,
650 inclusive_electron_lostHits = 1.0,
652 loose_electron_id =
"",
653 loose_electron_pt = 7,
654 loose_electron_eta = 2.4,
655 loose_electron_dxy = 0.05,
656 loose_electron_dz = 0.2,
657 loose_electron_relIso = 0.4,
659 loose_electron_lostHits = 1.0,
661 mu_isoCorr =
"rhoArea" ,
662 mu_effectiveAreas =
"Spring15_25ns_v1",
663 mu_tightId =
"POG_ID_Tight" ,
665 ele_isoCorr =
"rhoArea" ,
666 ele_effectiveAreas =
"Spring15_25ns_v1" ,
667 ele_tightId =
"Cuts_2012" ,
669 min_dr_electron_muon = 0.02,
671 doMiniIsolation =
False,
672 packedCandidates =
'packedPFCandidates',
673 miniIsolationPUCorr =
'rhoArea',
675 miniIsolationVetoLeptons =
None,
677 doIsoAnnulus =
False,
680 do_mc_match_photons =
False,
681 match_inclusiveLeptons =
False,
def isFromB(self, particle, bid=5, done={})
def matchAnyLeptons(self, event)
def attachIsoAnnulus04(self, mu)
def beginLoop(self, setup)
def isPromptLepton(lepton, beforeFSR, includeMotherless=True, includeTauDecays=False)
S & print(S &os, JobReport::InputFile const &f)
def makeAllMuons(self, event)
def makeAllElectrons(self, event)
def attachIsolationScan(self, mu)
def matchToPhotons(self, event)
def matchLeptons(self, event)
Abs< T >::type abs(const T &t)
def makeLeptons(self, event)
double deltaR(double eta1, double eta2, double phi1, double phi2)
def attachMiniIsolation(self, mu)
def bestMatch(object, matchCollection)
eleEffectiveArea
Duplicate removal for fast sim (to be checked if still necessary in latest greatest 5...
def __init__(self, cfg_ana, cfg_comp, looperName)
miniIsolationVetoLeptons
inclusive leptons = all leptons that could be considered somewhere in the analysis, with minimal requirements (used e.g.
def matchObjectCollection3