1 from __future__
import print_function
2 from builtins
import range
3 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
4 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
5 from PhysicsTools.Heppy.physicsobjects.Electron
import Electron
6 from PhysicsTools.Heppy.physicsobjects.Muon
import Muon
10 from PhysicsTools.Heppy.physicsutils.RochesterCorrections
import rochcor
11 from PhysicsTools.Heppy.physicsutils.MuScleFitCorrector
import MuScleFitCorr
12 from PhysicsTools.Heppy.physicsutils.KalmanMuonCorrector
import KalmanMuonCorrector
13 from PhysicsTools.Heppy.physicsutils.ElectronCalibrator
import Run2ElectronCalibrator
15 import PhysicsTools.HeppyCore.framework.config
as cfg
20 from ROOT
import heppy
26 def __init__(self, cfg_ana, cfg_comp, looperName ):
27 super(LeptonAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
28 if hasattr(self.cfg_ana,
'doMuScleFitCorrections'):
29 raise RuntimeError(
"doMuScleFitCorrections is not supported. Please set instead doMuonScaleCorrections = ( 'MuScleFit', <name> )")
30 if hasattr(self.cfg_ana,
'doRochesterCorrections'):
31 raise RuntimeError(
"doRochesterCorrections is not supported. Please set instead doMuonScaleCorrections = ( 'Rochester', <name> )")
32 if self.cfg_ana.doMuonScaleCorrections:
33 algo, options = self.cfg_ana.doMuonScaleCorrections
35 corr = options[
'MC' if self.cfg_comp.isMC
else 'Data']
38 options[
'isSync']
if 'isSync' in options
else False,
39 options[
'smearMode']
if 'smearMode' in options
else "ebe")
40 elif algo ==
"Rochester":
41 print(
"WARNING: the Rochester correction in heppy is still from Run 1")
43 elif algo ==
"MuScleFit":
44 print(
"WARNING: the MuScleFit correction in heppy is still from Run 1 (and probably no longer functional)")
45 if options
not in [
"prompt",
"prompt-sync",
"rereco",
"rereco-sync" ]:
46 raise RuntimeError(
'MuScleFit correction name must be one of [ "prompt", "prompt-sync", "rereco", "rereco-sync" ] ')
47 rereco = (
"prompt" not in self.cfg_ana.doMuScleFitCorrections)
48 sync = (
"sync" in self.cfg_ana.doMuScleFitCorrections)
50 else:
raise RuntimeError(
"Unknown muon scale correction algorithm")
54 if self.cfg_ana.doElectronScaleCorrections:
55 conf = cfg_ana.doElectronScaleCorrections
60 conf[
'isSync']
if 'isSync' in conf
else False,
65 if hasattr(cfg_ana,
'loose_electron_isoCut'):
69 ele.relIso03 <= self.cfg_ana.loose_electron_relIso
and 70 ele.absIso03 < getattr(self.cfg_ana,
'loose_electron_absIso',9e99))
71 if hasattr(cfg_ana,
'loose_muon_isoCut'):
75 mu.relIso03 <= self.cfg_ana.loose_muon_relIso
and 76 mu.absIso03 < getattr(self.cfg_ana,
'loose_muon_absIso',9e99))
88 raise RuntimeError(
"miniIsolationVetoLeptons should be None, or 'any' (all reco leptons), or 'inclusive' (all inclusive leptons)")
119 self.handles[
'muons'] = AutoHandle(self.cfg_ana.muons,
"std::vector<pat::Muon>")
120 self.handles[
'electrons'] = AutoHandle(self.cfg_ana.electrons,
"std::vector<pat::Electron>")
123 self.handles[
'rhoMu'] = AutoHandle( self.cfg_ana.rhoMuon,
'double')
125 self.handles[
'rhoEle'] = AutoHandle( self.cfg_ana.rhoElectron,
'double')
128 self.handles[
'packedCandidates'] = AutoHandle( self.cfg_ana.packedCandidates,
'std::vector<pat::PackedCandidate>')
132 self.mchandles[
'genPhotons'] = AutoHandle(
'packedGenParticles',
'std::vector<pat::PackedGenParticle>' )
134 self.mchandles[
'genPhotons'] = AutoHandle(
'prunedGenParticles',
'std::vector<reco::GenParticle>' )
137 super(LeptonAnalyzer,self).
beginLoop(setup)
138 self.counters.addCounter(
'events')
139 count = self.counters.
counter(
'events')
140 count.register(
'all events')
149 event.inclusiveLeptons = []
152 event.selectedLeptons = []
153 event.selectedMuons = []
154 event.selectedElectrons = []
155 event.otherLeptons = []
158 self.
IsolationComputer.setPackedCandidates(self.handles[
'packedCandidates'].product())
161 for lep
in self.handles[
'muons'].product():
163 for lep
in self.handles[
'electrons'].product():
174 inclusiveElectrons = []
176 if (mu.track().isNonnull()
and mu.muonID(self.cfg_ana.inclusive_muon_id)
and 177 mu.pt()>self.cfg_ana.inclusive_muon_pt
and abs(mu.eta())<self.cfg_ana.inclusive_muon_eta
and 178 abs(mu.dxy())<self.cfg_ana.inclusive_muon_dxy
and abs(mu.dz())<self.cfg_ana.inclusive_muon_dz):
179 inclusiveMuons.append(mu)
180 for ele
in allelectrons:
181 if ( ele.electronID(self.cfg_ana.inclusive_electron_id)
and 182 ele.pt()>self.cfg_ana.inclusive_electron_pt
and abs(ele.eta())<self.cfg_ana.inclusive_electron_eta
and 183 abs(ele.dxy())<self.cfg_ana.inclusive_electron_dxy
and abs(ele.dz())<self.cfg_ana.inclusive_electron_dz
and 184 ele.lostInner()<=self.cfg_ana.inclusive_electron_lostHits ):
185 inclusiveElectrons.append(ele)
186 event.inclusiveLeptons = inclusiveMuons + inclusiveElectrons
190 for lep
in event.inclusiveLeptons:
192 for lep
in event.inclusiveLeptons:
196 for lep
in event.inclusiveLeptons:
200 for lep
in event.inclusiveLeptons:
204 for mu
in inclusiveMuons:
205 if (mu.muonID(self.cfg_ana.loose_muon_id)
and 206 mu.pt() > self.cfg_ana.loose_muon_pt
and abs(mu.eta()) < self.cfg_ana.loose_muon_eta
and 207 abs(mu.dxy()) < self.cfg_ana.loose_muon_dxy
and abs(mu.dz()) < self.cfg_ana.loose_muon_dz
and 209 mu.looseIdSusy =
True 210 event.selectedLeptons.append(mu)
211 event.selectedMuons.append(mu)
213 mu.looseIdSusy =
False 214 event.otherLeptons.append(mu)
215 looseMuons = event.selectedLeptons[:]
216 for ele
in inclusiveElectrons:
217 if (ele.electronID(self.cfg_ana.loose_electron_id)
and 218 ele.pt()>self.cfg_ana.loose_electron_pt
and abs(ele.eta())<self.cfg_ana.loose_electron_eta
and 219 abs(ele.dxy()) < self.cfg_ana.loose_electron_dxy
and abs(ele.dz())<self.cfg_ana.loose_electron_dz
and 221 ele.lostInner() <= self.cfg_ana.loose_electron_lostHits
and 222 (
True if getattr(self.cfg_ana,
'notCleaningElectrons',
False)
else (
bestMatch(ele, looseMuons)[1] > (self.cfg_ana.min_dr_electron_muon**2)) )):
223 event.selectedLeptons.append(ele)
224 event.selectedElectrons.append(ele)
225 ele.looseIdSusy =
True 227 event.otherLeptons.append(ele)
228 ele.looseIdSusy =
False 230 event.otherLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
231 event.selectedLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
232 event.selectedMuons.sort(key =
lambda l : l.pt(), reverse =
True)
233 event.selectedElectrons.sort(key =
lambda l : l.pt(), reverse =
True)
234 event.inclusiveLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
236 for lepton
in event.selectedLeptons:
237 if hasattr(self,
'efficiency'):
238 self.efficiency.attachToObject(lepton)
242 make a list of all muons, and apply basic corrections to them 245 allmuons =
map( Muon, self.handles[
'muons'].product() )
252 if self.cfg_ana.doSegmentBasedMuonCleaning:
253 isgood = cmgMuonCleanerBySegments.clean( self.handles[
'muons'].product() )
255 for i,mu
in enumerate(allmuons):
256 if isgood[i]: newmu.append(mu)
261 mu.rho =
float(self.handles[
'rhoMu'].product()[0])
263 if aeta < 1.0 : mu.EffectiveArea03 = 0.382;
264 elif aeta < 1.47 : mu.EffectiveArea03 = 0.317;
265 elif aeta < 2.0 : mu.EffectiveArea03 = 0.242;
266 elif aeta < 2.2 : mu.EffectiveArea03 = 0.326;
267 elif aeta < 2.3 : mu.EffectiveArea03 = 0.462;
268 else : mu.EffectiveArea03 = 0.372;
269 if aeta < 1.0 : mu.EffectiveArea04 = 0.674;
270 elif aeta < 1.47 : mu.EffectiveArea04 = 0.565;
271 elif aeta < 2.0 : mu.EffectiveArea04 = 0.442;
272 elif aeta < 2.2 : mu.EffectiveArea04 = 0.515;
273 elif aeta < 2.3 : mu.EffectiveArea04 = 0.821;
274 else : mu.EffectiveArea04 = 0.660;
277 if aeta < 0.800: mu.EffectiveArea03 = 0.0913
278 elif aeta < 1.300: mu.EffectiveArea03 = 0.0765
279 elif aeta < 2.000: mu.EffectiveArea03 = 0.0546
280 elif aeta < 2.200: mu.EffectiveArea03 = 0.0728
281 else: mu.EffectiveArea03 = 0.1177
282 if aeta < 0.800: mu.EffectiveArea04 = 0.1564
283 elif aeta < 1.300: mu.EffectiveArea04 = 0.1325
284 elif aeta < 2.000: mu.EffectiveArea04 = 0.0913
285 elif aeta < 2.200: mu.EffectiveArea04 = 0.1212
286 else: mu.EffectiveArea04 = 0.2085
289 if aeta < 0.800: mu.EffectiveArea03 = 0.0735
290 elif aeta < 1.300: mu.EffectiveArea03 = 0.0619
291 elif aeta < 2.000: mu.EffectiveArea03 = 0.0465
292 elif aeta < 2.200: mu.EffectiveArea03 = 0.0433
293 else: mu.EffectiveArea03 = 0.0577
294 mu.EffectiveArea04 = 0
295 else:
raise RuntimeError(
"Unsupported value for mu_effectiveAreas: can only use Data2012 (rho: ?) and Phys14_25ns_v1 or Spring15_25ns_v1 (rho: fixedGridRhoFastjetAll)")
298 mu.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
299 mu.setTrackForDxyDz(self.cfg_ana.muon_dxydz_track)
302 if hasattr(self.cfg_ana,
"mu_tightId"):
304 mu.tightIdResult = mu.muonID(self.cfg_ana.mu_tightId)
308 if self.cfg_ana.mu_isoCorr==
"rhoArea" :
309 mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt +
max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.rho * mu.EffectiveArea03,0.0))
310 mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt +
max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.rho * mu.EffectiveArea04,0.0))
311 elif self.cfg_ana.mu_isoCorr==
"deltaBeta" :
312 mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt +
max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.pfIsolationR03().sumPUPt/2,0.0))
313 mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt +
max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.pfIsolationR04().sumPUPt/2,0.0))
315 raise RuntimeError(
"Unsupported mu_isoCorr name '" +
str(self.cfg_ana.mu_isoCorr) +
"'! For now only 'rhoArea' and 'deltaBeta' are supported.")
316 mu.relIso03 = mu.absIso03/mu.pt()
317 mu.relIso04 = mu.absIso04/mu.pt()
322 make a list of all electrons, and apply basic corrections to them 324 allelectrons =
map( Electron, self.handles[
'electrons'].product() )
328 for e
in allelectrons:
330 for e2
in allelenodup:
331 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():
334 if not dup: allelenodup.append(e)
335 allelectrons = allelenodup
338 for ele
in allelectrons:
339 ele.rho =
float(self.handles[
'rhoEle'].product()[0])
342 SCEta =
abs(ele.superCluster().
eta())
343 if SCEta < 1.0 : ele.EffectiveArea03 = 0.13
344 elif SCEta < 1.479: ele.EffectiveArea03 = 0.14
345 elif SCEta < 2.0 : ele.EffectiveArea03 = 0.07
346 elif SCEta < 2.2 : ele.EffectiveArea03 = 0.09
347 elif SCEta < 2.3 : ele.EffectiveArea03 = 0.11
348 elif SCEta < 2.4 : ele.EffectiveArea03 = 0.11
349 else : ele.EffectiveArea03 = 0.14
350 if SCEta < 1.0 : ele.EffectiveArea04 = 0.208;
351 elif SCEta < 1.479: ele.EffectiveArea04 = 0.209;
352 elif SCEta < 2.0 : ele.EffectiveArea04 = 0.115;
353 elif SCEta < 2.2 : ele.EffectiveArea04 = 0.143;
354 elif SCEta < 2.3 : ele.EffectiveArea04 = 0.183;
355 elif SCEta < 2.4 : ele.EffectiveArea04 = 0.194;
356 else : ele.EffectiveArea04 = 0.261;
358 aeta =
abs(ele.eta())
359 if aeta < 0.800: ele.EffectiveArea03 = 0.1013
360 elif aeta < 1.300: ele.EffectiveArea03 = 0.0988
361 elif aeta < 2.000: ele.EffectiveArea03 = 0.0572
362 elif aeta < 2.200: ele.EffectiveArea03 = 0.0842
363 else: ele.EffectiveArea03 = 0.1530
364 if aeta < 0.800: ele.EffectiveArea04 = 0.1830
365 elif aeta < 1.300: ele.EffectiveArea04 = 0.1734
366 elif aeta < 2.000: ele.EffectiveArea04 = 0.1077
367 elif aeta < 2.200: ele.EffectiveArea04 = 0.1565
368 else: ele.EffectiveArea04 = 0.2680
370 SCEta =
abs(ele.superCluster().
eta())
372 if SCEta < 0.800: ele.EffectiveArea03 = 0.0973
373 elif SCEta < 1.300: ele.EffectiveArea03 = 0.0954
374 elif SCEta < 2.000: ele.EffectiveArea03 = 0.0632
375 elif SCEta < 2.200: ele.EffectiveArea03 = 0.0727
376 else: ele.EffectiveArea03 = 0.1337
378 ele.EffectiveArea04 = 0.0
380 SCEta =
abs(ele.superCluster().
eta())
382 if SCEta < 1.000: ele.EffectiveArea03 = 0.1752
383 elif SCEta < 1.479: ele.EffectiveArea03 = 0.1862
384 elif SCEta < 2.000: ele.EffectiveArea03 = 0.1411
385 elif SCEta < 2.200: ele.EffectiveArea03 = 0.1534
386 elif SCEta < 2.300: ele.EffectiveArea03 = 0.1903
387 elif SCEta < 2.400: ele.EffectiveArea03 = 0.2243
388 else: ele.EffectiveArea03 = 0.2687
390 ele.EffectiveArea04 = 0.0
391 else:
raise RuntimeError(
"Unsupported value for ele_effectiveAreas: can only use Data2012 (rho: ?), Phys14_v1 and Spring15_v1 (rho: fixedGridRhoFastjetAll)")
394 if self.cfg_ana.doElectronScaleCorrections:
395 for ele
in allelectrons:
399 for ele
in allelectrons:
400 ele.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
403 for ele
in allelectrons:
404 if self.cfg_ana.ele_isoCorr==
"rhoArea" :
405 ele.absIso03 = (ele.chargedHadronIsoR(0.3) +
max(ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3)-ele.rho*ele.EffectiveArea03,0))
406 ele.absIso04 = (ele.chargedHadronIsoR(0.4) +
max(ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4)-ele.rho*ele.EffectiveArea04,0))
407 elif self.cfg_ana.ele_isoCorr==
"deltaBeta" :
408 ele.absIso03 = (ele.chargedHadronIsoR(0.3) +
max( ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3) - ele.puChargedHadronIsoR(0.3)/2, 0.0))
409 ele.absIso04 = (ele.chargedHadronIsoR(0.4) +
max( ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4) - ele.puChargedHadronIsoR(0.4)/2, 0.0))
411 raise RuntimeError(
"Unsupported ele_isoCorr name '" +
str(self.cfg_ana.ele_isoCorr) +
"'! For now only 'rhoArea' and 'deltaBeta' are supported.")
412 ele.relIso03 = ele.absIso03/ele.pt()
413 ele.relIso04 = ele.absIso04/ele.pt()
416 for ele
in allelectrons:
417 if self.cfg_ana.ele_tightId==
"MVA" :
418 ele.tightIdResult = ele.electronID(
"POG_MVA_ID_Trig_full5x5")
419 elif self.cfg_ana.ele_tightId==
"Cuts_2012" :
420 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")
421 elif self.cfg_ana.ele_tightId==
"Cuts_PHYS14_25ns_v1_ConvVetoDxyDz" :
422 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")
423 elif self.cfg_ana.ele_tightId==
"Cuts_SPRING15_25ns_v1_ConvVetoDxyDz" :
424 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")
428 ele.tightIdResult = ele.electronID(self.cfg_ana.ele_tightId)
430 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.")
436 mu.miniIsoR = 10.0/
min(
max(mu.pt(), 50),200)
439 what =
"mu" if (
abs(mu.pdgId()) == 13)
else (
"eleB" if mu.isEB()
else "eleE")
441 mu.miniAbsIsoCharged = self.
IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what], 0.0);
443 mu.miniAbsIsoCharged = self.
IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what], 0.0,self.
IsolationComputer.selfVetoNone);
445 if self.
miniIsolationPUCorr ==
None: puCorr = self.cfg_ana.mu_isoCorr
if what==
"mu" else self.cfg_ana.ele_isoCorr
448 if puCorr ==
"weights":
450 mu.miniAbsIsoNeutral = self.
IsolationComputer.neutralAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.01, 0.5);
452 mu.miniAbsIsoNeutral = ( self.
IsolationComputer.photonAbsIsoWeighted( mu.physObj, mu.miniIsoR, 0.08
if what ==
"eleE" else 0.0, 0.0, self.
IsolationComputer.selfVetoNone) +
456 mu.miniAbsIsoNeutral = self.
IsolationComputer.neutralAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.01, 0.5);
460 mu.miniAbsIsoNeutral = mu.miniAbsIsoPho + mu.miniAbsIsoNHad
465 if puCorr ==
"rhoArea":
466 mu.miniAbsIsoNeutral =
max(0.0, mu.miniAbsIsoNeutral - mu.rho * mu.EffectiveArea03 * (mu.miniIsoR/0.3)**2)
467 elif puCorr ==
"deltaBeta":
469 mu.miniAbsIsoPU = self.
IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.01, 0.5);
472 mu.miniAbsIsoNeutral =
max(0.0, mu.miniAbsIsoNeutral - 0.5*mu.miniAbsIsoPU)
473 elif puCorr !=
'raw':
474 raise RuntimeError(
"Unsupported miniIsolationCorr name '" + puCorr +
"'! For now only 'rhoArea', 'deltaBeta', 'raw', 'weights' are supported (and 'weights' is not tested).")
476 mu.miniAbsIso = mu.miniAbsIsoCharged + mu.miniAbsIsoNeutral
477 mu.miniRelIso = mu.miniAbsIso/mu.pt()
481 mu.miniIsoR = 10.0/
min(
max(mu.pt(), 50),200)
486 mu.absIsoAnNeutral =
max(0.0, mu.absIsoAnPho + mu.absIsoAnNHad - 0.5*mu.absIsoAnPU)
488 mu.absIsoAn04 = mu.absIsoAnCharged + mu.absIsoAnNeutral
489 mu.relIsoAn04 = mu.absIsoAn04/mu.pt()
494 what =
"mu" if (
abs(mu.pdgId()) == 13)
else (
"eleB" if mu.isEB()
else "eleE")
495 vetoreg = {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what]
498 mu.ScanAbsIsoCharged005 = self.
IsolationComputer.chargedAbsIso(mu.physObj, 0.05, vetoreg, 0.0)
499 mu.ScanAbsIsoCharged01 = self.
IsolationComputer.chargedAbsIso(mu.physObj, 0.1, vetoreg, 0.0)
500 mu.ScanAbsIsoCharged02 = self.
IsolationComputer.chargedAbsIso(mu.physObj, 0.2, vetoreg, 0.0)
501 mu.ScanAbsIsoCharged03 = self.
IsolationComputer.chargedAbsIso(mu.physObj, 0.3, vetoreg, 0.0)
502 mu.ScanAbsIsoCharged04 = self.
IsolationComputer.chargedAbsIso(mu.physObj, 0.4, vetoreg, 0.0)
511 mu.ScanAbsIsoNeutral005 = self.
IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.05, 0.01, 0.5)
512 mu.ScanAbsIsoNeutral01 = self.
IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.1, 0.01, 0.5)
513 mu.ScanAbsIsoNeutral02 = self.
IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.2, 0.01, 0.5)
514 mu.ScanAbsIsoNeutral03 = self.
IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.3, 0.01, 0.5)
515 mu.ScanAbsIsoNeutral04 = self.
IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.4, 0.01, 0.5)
517 vetoreg = {
"eleB":0.0,
"eleE":0.08}[what]
526 def plausible(rec,gen):
527 if abs(rec.pdgId()) == 11
and abs(gen.pdgId()) != 11:
return False 528 if abs(rec.pdgId()) == 13
and abs(gen.pdgId()) != 13:
return False 529 dr =
deltaR(rec.eta(),rec.phi(),gen.eta(),gen.phi())
530 if dr < 0.3:
return True 531 if rec.pt() < 10
and abs(rec.pdgId()) == 13
and gen.pdgId() != rec.pdgId():
return False 532 if dr < 0.7:
return True 533 if min(rec.pt(),gen.pt())/
max(rec.pt(),gen.pt()) < 0.3:
return False 536 leps = event.inclusiveLeptons
if self.cfg_ana.match_inclusiveLeptons
else event.selectedLeptons
538 event.genleps + event.gentauleps,
539 deltaRMax = 1.2, filter = plausible)
542 lep.mcMatchId = (gen.sourceId
if gen !=
None else 0)
543 lep.mcMatchTau = (gen
in event.gentauleps
if gen
else -99)
547 for i
in range( particle.numberOfMothers() ):
548 mom = particle.mother(i)
549 momid =
abs(mom.pdgId())
550 if momid / 1000 == bid
or momid / 100 == bid
or momid == bid:
552 elif mom.status() == 2
and self.
isFromB(mom, done=done, bid=bid):
557 event.anyLeptons = [ x
for x
in event.genParticles
if x.status() == 1
and abs(x.pdgId())
in [11,13] ]
558 leps = event.inclusiveLeptons
if hasattr(event,
'inclusiveLeptons')
else event.selectedLeptons
562 lep.mcMatchAny_gp = gen
564 if self.
isFromB(gen): lep.mcMatchAny = 5
565 elif self.
isFromB(gen,bid=4): lep.mcMatchAny = 4
566 else: lep.mcMatchAny = 1
567 if not getattr(lep,
'mcLep',
None): lep.mcLep = gen
569 if not getattr(lep,
'mcLep',
None): lep.mcLep =
None 572 if gen !=
None and hasattr(lep,
'mcMatchId')
and lep.mcMatchId == 0:
573 if isPromptLepton(gen,
False)
or (gen.isPromptFinalState()
or gen.isDirectPromptTauDecayProductFinalState()):
576 elif not hasattr(lep,
'mcMatchId'):
578 if not hasattr(lep,
'mcMatchTau'): lep.mcMatchTau = 0
581 event.anyPho = [ x
for x
in self.mchandles[
'genPhotons'].product()
if x.status() == 1
and x.pdgId() == 22
and x.pt() > 1.0 ]
582 leps = event.inclusiveLeptons
if hasattr(event,
'inclusiveLeptons')
else event.selectedLeptons
583 leps = [ l
for l
in leps
if abs(l.pdgId()) == 11 ]
584 plausible =
lambda rec, gen : 0.3*gen.pt() < rec.pt()
and rec.pt() < 1.5*gen.pt()
589 if lep.mcPho
and lep.mcLep:
592 dr =
deltaR(rec.eta(),rec.phi(),gen.eta(),gen.phi())
593 dptRel =
abs(rec.pt()-gen.pt())/gen.pt()
594 return dr + 0.2*dptRel
597 if getattr(lep,
'mcMatchAny_gp',
None)
and lep.mcMatchAny_gp != lep.mcLep:
599 if dlep <= dpho: lep.mcPho =
None 602 self.readCollections( event.input )
603 self.counters.
counter(
'events').inc(
'all events')
608 if self.cfg_comp.isMC
and self.cfg_ana.do_mc_match:
617 setattr(LeptonAnalyzer,
"defaultConfig",cfg.Analyzer(
619 class_object=LeptonAnalyzer,
621 muons=
'slimmedMuons',
622 electrons=
'slimmedElectrons',
623 rhoMuon=
'fixedGridRhoFastjetAll',
624 rhoElectron =
'fixedGridRhoFastjetAll',
627 doMuonScaleCorrections=
False,
628 doElectronScaleCorrections=
False,
629 doSegmentBasedMuonCleaning=
False,
631 inclusive_muon_id =
"POG_ID_Loose",
632 inclusive_muon_pt = 3,
633 inclusive_muon_eta = 2.4,
634 inclusive_muon_dxy = 0.5,
635 inclusive_muon_dz = 1.0,
636 muon_dxydz_track =
"muonBestTrack",
638 loose_muon_id =
"POG_ID_Loose",
640 loose_muon_eta = 2.4,
641 loose_muon_dxy = 0.05,
643 loose_muon_relIso = 0.4,
646 inclusive_electron_id =
"",
647 inclusive_electron_pt = 5,
648 inclusive_electron_eta = 2.5,
649 inclusive_electron_dxy = 0.5,
650 inclusive_electron_dz = 1.0,
651 inclusive_electron_lostHits = 1.0,
653 loose_electron_id =
"",
654 loose_electron_pt = 7,
655 loose_electron_eta = 2.4,
656 loose_electron_dxy = 0.05,
657 loose_electron_dz = 0.2,
658 loose_electron_relIso = 0.4,
660 loose_electron_lostHits = 1.0,
662 mu_isoCorr =
"rhoArea" ,
663 mu_effectiveAreas =
"Spring15_25ns_v1",
664 mu_tightId =
"POG_ID_Tight" ,
666 ele_isoCorr =
"rhoArea" ,
667 ele_effectiveAreas =
"Spring15_25ns_v1" ,
668 ele_tightId =
"Cuts_2012" ,
670 min_dr_electron_muon = 0.02,
672 doMiniIsolation =
False,
673 packedCandidates =
'packedPFCandidates',
674 miniIsolationPUCorr =
'rhoArea',
676 miniIsolationVetoLeptons =
None,
678 doIsoAnnulus =
False,
681 do_mc_match_photons =
False,
682 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)
def makeAllMuons(self, event)
def makeAllElectrons(self, event)
def attachIsolationScan(self, mu)
def matchToPhotons(self, event)
def matchLeptons(self, event)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Abs< T >::type abs(const T &t)
def makeLeptons(self, event)
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