1 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
2 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
3 from PhysicsTools.Heppy.physicsobjects.Electron
import Electron
4 from PhysicsTools.Heppy.physicsobjects.Muon
import Muon
8 from PhysicsTools.Heppy.physicsutils.RochesterCorrections
import rochcor
9 from PhysicsTools.Heppy.physicsutils.MuScleFitCorrector
import MuScleFitCorr
10 from PhysicsTools.Heppy.physicsutils.KalmanMuonCorrector
import KalmanMuonCorrector
11 from PhysicsTools.Heppy.physicsutils.ElectronCalibrator
import Run2ElectronCalibrator
13 import PhysicsTools.HeppyCore.framework.config
as cfg
18 from ROOT
import heppy
24 def __init__(self, cfg_ana, cfg_comp, looperName ):
25 super(LeptonAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
26 if hasattr(self.cfg_ana,
'doMuScleFitCorrections'):
27 raise RuntimeError(
"doMuScleFitCorrections is not supported. Please set instead doMuonScaleCorrections = ( 'MuScleFit', <name> )")
28 if hasattr(self.cfg_ana,
'doRochesterCorrections'):
29 raise RuntimeError(
"doRochesterCorrections is not supported. Please set instead doMuonScaleCorrections = ( 'Rochester', <name> )")
30 if self.cfg_ana.doMuonScaleCorrections:
31 algo, options = self.cfg_ana.doMuonScaleCorrections
33 corr = options[
'MC' if self.cfg_comp.isMC
else 'Data']
36 options[
'isSync']
if 'isSync' in options
else False,
37 options[
'smearMode']
if 'smearMode' in options
else "ebe")
38 elif algo ==
"Rochester":
39 print "WARNING: the Rochester correction in heppy is still from Run 1"
41 elif algo ==
"MuScleFit":
42 print "WARNING: the MuScleFit correction in heppy is still from Run 1 (and probably no longer functional)"
43 if options
not in [
"prompt",
"prompt-sync",
"rereco",
"rereco-sync" ]:
44 raise RuntimeError(
'MuScleFit correction name must be one of [ "prompt", "prompt-sync", "rereco", "rereco-sync" ] ')
45 rereco = (
"prompt" not in self.cfg_ana.doMuScleFitCorrections)
46 sync = (
"sync" in self.cfg_ana.doMuScleFitCorrections)
48 else:
raise RuntimeError(
"Unknown muon scale correction algorithm")
52 if self.cfg_ana.doElectronScaleCorrections:
53 conf = cfg_ana.doElectronScaleCorrections
54 self.electronEnergyCalibrator = Run2ElectronCalibrator(
58 conf[
'isSync']
if 'isSync' in conf
else False,
63 if hasattr(cfg_ana,
'loose_electron_isoCut'):
64 self.eleIsoCut = cfg_ana.loose_electron_isoCut
66 self.eleIsoCut =
lambda ele : (
67 ele.relIso03 <= self.cfg_ana.loose_electron_relIso
and
68 ele.absIso03 < getattr(self.cfg_ana,
'loose_electron_absIso',9e99))
69 if hasattr(cfg_ana,
'loose_muon_isoCut'):
70 self.muIsoCut = cfg_ana.loose_muon_isoCut
72 self.muIsoCut =
lambda mu : (
73 mu.relIso03 <= self.cfg_ana.loose_muon_relIso
and
74 mu.absIso03 < getattr(self.cfg_ana,
'loose_muon_absIso',9e99))
78 self.
eleEffectiveArea = getattr(cfg_ana,
'ele_effectiveAreas',
"Spring15_25ns_v1")
79 self.
muEffectiveArea = getattr(cfg_ana,
'mu_effectiveAreas',
"Spring15_25ns_v1")
81 self.doMiniIsolation = getattr(cfg_ana,
'doMiniIsolation',
False)
82 if self.doMiniIsolation:
86 raise RuntimeError(
"miniIsolationVetoLeptons should be None, or 'any' (all reco leptons), or 'inclusive' (all inclusive leptons)")
92 self.doIsoAnnulus = getattr(cfg_ana,
'doIsoAnnulus',
False)
94 if not self.doMiniIsolation:
97 self.doIsolationScan = getattr(cfg_ana,
'doIsolationScan',
False)
98 if self.doIsolationScan:
99 if self.doMiniIsolation:
117 self.handles[
'muons'] = AutoHandle(self.cfg_ana.muons,
"std::vector<pat::Muon>")
118 self.handles[
'electrons'] = AutoHandle(self.cfg_ana.electrons,
"std::vector<pat::Electron>")
121 self.handles[
'rhoMu'] = AutoHandle( self.cfg_ana.rhoMuon,
'double')
123 self.handles[
'rhoEle'] = AutoHandle( self.cfg_ana.rhoElectron,
'double')
125 if self.doMiniIsolation
or self.doIsolationScan:
126 self.handles[
'packedCandidates'] = AutoHandle( self.cfg_ana.packedCandidates,
'std::vector<pat::PackedCandidate>')
130 self.mchandles[
'genPhotons'] = AutoHandle(
'packedGenParticles',
'std::vector<pat::PackedGenParticle>' )
132 self.mchandles[
'genPhotons'] = AutoHandle(
'prunedGenParticles',
'std::vector<reco::GenParticle>' )
135 super(LeptonAnalyzer,self).
beginLoop(setup)
136 self.counters.addCounter(
'events')
137 count = self.counters.counter(
'events')
138 count.register(
'all events')
147 event.inclusiveLeptons = []
150 event.selectedLeptons = []
151 event.selectedMuons = []
152 event.selectedElectrons = []
153 event.otherLeptons = []
155 if self.doMiniIsolation
or self.doIsolationScan:
156 self.IsolationComputer.setPackedCandidates(self.handles[
'packedCandidates'].product())
157 if self.doMiniIsolation:
159 for lep
in self.handles[
'muons'].product():
160 self.IsolationComputer.addVetos(lep)
161 for lep
in self.handles[
'electrons'].product():
162 self.IsolationComputer.addVetos(lep)
172 inclusiveElectrons = []
174 if (mu.track().isNonnull()
and mu.muonID(self.cfg_ana.inclusive_muon_id)
and
175 mu.pt()>self.cfg_ana.inclusive_muon_pt
and abs(mu.eta())<self.cfg_ana.inclusive_muon_eta
and
176 abs(mu.dxy())<self.cfg_ana.inclusive_muon_dxy
and abs(mu.dz())<self.cfg_ana.inclusive_muon_dz):
177 inclusiveMuons.append(mu)
178 for ele
in allelectrons:
179 if ( ele.electronID(self.cfg_ana.inclusive_electron_id)
and
180 ele.pt()>self.cfg_ana.inclusive_electron_pt
and abs(ele.eta())<self.cfg_ana.inclusive_electron_eta
and
181 abs(ele.dxy())<self.cfg_ana.inclusive_electron_dxy
and abs(ele.dz())<self.cfg_ana.inclusive_electron_dz
and
182 ele.lostInner()<=self.cfg_ana.inclusive_electron_lostHits ):
183 inclusiveElectrons.append(ele)
184 event.inclusiveLeptons = inclusiveMuons + inclusiveElectrons
186 if self.doMiniIsolation:
188 for lep
in event.inclusiveLeptons:
189 self.IsolationComputer.addVetos(lep.physObj)
190 for lep
in event.inclusiveLeptons:
193 if self.doIsoAnnulus:
194 for lep
in event.inclusiveLeptons:
197 if self.doIsolationScan:
198 for lep
in event.inclusiveLeptons:
202 for mu
in inclusiveMuons:
203 if (mu.muonID(self.cfg_ana.loose_muon_id)
and
204 mu.pt() > self.cfg_ana.loose_muon_pt
and abs(mu.eta()) < self.cfg_ana.loose_muon_eta
and
205 abs(mu.dxy()) < self.cfg_ana.loose_muon_dxy
and abs(mu.dz()) < self.cfg_ana.loose_muon_dz
and
207 mu.looseIdSusy =
True
208 event.selectedLeptons.append(mu)
209 event.selectedMuons.append(mu)
211 mu.looseIdSusy =
False
212 event.otherLeptons.append(mu)
213 looseMuons = event.selectedLeptons[:]
214 for ele
in inclusiveElectrons:
215 if (ele.electronID(self.cfg_ana.loose_electron_id)
and
216 ele.pt()>self.cfg_ana.loose_electron_pt
and abs(ele.eta())<self.cfg_ana.loose_electron_eta
and
217 abs(ele.dxy()) < self.cfg_ana.loose_electron_dxy
and abs(ele.dz())<self.cfg_ana.loose_electron_dz
and
218 self.eleIsoCut(ele)
and
219 ele.lostInner() <= self.cfg_ana.loose_electron_lostHits
and
220 (
True if getattr(self.cfg_ana,
'notCleaningElectrons',
False)
else (
bestMatch(ele, looseMuons)[1] > (self.cfg_ana.min_dr_electron_muon**2)) )):
221 event.selectedLeptons.append(ele)
222 event.selectedElectrons.append(ele)
223 ele.looseIdSusy =
True
225 event.otherLeptons.append(ele)
226 ele.looseIdSusy =
False
228 event.otherLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
229 event.selectedLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
230 event.selectedMuons.sort(key =
lambda l : l.pt(), reverse =
True)
231 event.selectedElectrons.sort(key =
lambda l : l.pt(), reverse =
True)
232 event.inclusiveLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
234 for lepton
in event.selectedLeptons:
235 if hasattr(self,
'efficiency'):
236 self.efficiency.attachToObject(lepton)
240 make a list of all muons, and apply basic corrections to them
243 allmuons = map( Muon, self.handles[
'muons'].product() )
247 self.muonScaleCorrector.correct_all(allmuons, event.run)
250 if self.cfg_ana.doSegmentBasedMuonCleaning:
251 isgood = cmgMuonCleanerBySegments.clean( self.handles[
'muons'].product() )
253 for i,mu
in enumerate(allmuons):
254 if isgood[i]: newmu.append(mu)
259 mu.rho = float(self.handles[
'rhoMu'].product()[0])
261 if aeta < 1.0 : mu.EffectiveArea03 = 0.382;
262 elif aeta < 1.47 : mu.EffectiveArea03 = 0.317;
263 elif aeta < 2.0 : mu.EffectiveArea03 = 0.242;
264 elif aeta < 2.2 : mu.EffectiveArea03 = 0.326;
265 elif aeta < 2.3 : mu.EffectiveArea03 = 0.462;
266 else : mu.EffectiveArea03 = 0.372;
267 if aeta < 1.0 : mu.EffectiveArea04 = 0.674;
268 elif aeta < 1.47 : mu.EffectiveArea04 = 0.565;
269 elif aeta < 2.0 : mu.EffectiveArea04 = 0.442;
270 elif aeta < 2.2 : mu.EffectiveArea04 = 0.515;
271 elif aeta < 2.3 : mu.EffectiveArea04 = 0.821;
272 else : mu.EffectiveArea04 = 0.660;
275 if aeta < 0.800: mu.EffectiveArea03 = 0.0913
276 elif aeta < 1.300: mu.EffectiveArea03 = 0.0765
277 elif aeta < 2.000: mu.EffectiveArea03 = 0.0546
278 elif aeta < 2.200: mu.EffectiveArea03 = 0.0728
279 else: mu.EffectiveArea03 = 0.1177
280 if aeta < 0.800: mu.EffectiveArea04 = 0.1564
281 elif aeta < 1.300: mu.EffectiveArea04 = 0.1325
282 elif aeta < 2.000: mu.EffectiveArea04 = 0.0913
283 elif aeta < 2.200: mu.EffectiveArea04 = 0.1212
284 else: mu.EffectiveArea04 = 0.2085
287 if aeta < 0.800: mu.EffectiveArea03 = 0.0735
288 elif aeta < 1.300: mu.EffectiveArea03 = 0.0619
289 elif aeta < 2.000: mu.EffectiveArea03 = 0.0465
290 elif aeta < 2.200: mu.EffectiveArea03 = 0.0433
291 else: mu.EffectiveArea03 = 0.0577
292 mu.EffectiveArea04 = 0
293 else:
raise RuntimeError(
"Unsupported value for mu_effectiveAreas: can only use Data2012 (rho: ?) and Phys14_25ns_v1 or Spring15_25ns_v1 (rho: fixedGridRhoFastjetAll)")
296 mu.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
297 mu.setTrackForDxyDz(self.cfg_ana.muon_dxydz_track)
300 if hasattr(self.cfg_ana,
"mu_tightId"):
302 mu.tightIdResult = mu.muonID(self.cfg_ana.mu_tightId)
306 if self.cfg_ana.mu_isoCorr==
"rhoArea" :
307 mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt +
max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.rho * mu.EffectiveArea03,0.0))
308 mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt +
max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.rho * mu.EffectiveArea04,0.0))
309 elif self.cfg_ana.mu_isoCorr==
"deltaBeta" :
310 mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt +
max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.pfIsolationR03().sumPUPt/2,0.0))
311 mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt +
max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.pfIsolationR04().sumPUPt/2,0.0))
313 raise RuntimeError(
"Unsupported mu_isoCorr name '" + str(self.cfg_ana.mu_isoCorr) +
"'! For now only 'rhoArea' and 'deltaBeta' are supported.")
314 mu.relIso03 = mu.absIso03/mu.pt()
315 mu.relIso04 = mu.absIso04/mu.pt()
320 make a list of all electrons, and apply basic corrections to them
322 allelectrons = map( Electron, self.handles[
'electrons'].product() )
326 for e
in allelectrons:
328 for e2
in allelenodup:
329 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():
332 if not dup: allelenodup.append(e)
333 allelectrons = allelenodup
336 for ele
in allelectrons:
337 ele.rho = float(self.handles[
'rhoEle'].product()[0])
340 SCEta =
abs(ele.superCluster().
eta())
341 if SCEta < 1.0 : ele.EffectiveArea03 = 0.13
342 elif SCEta < 1.479: ele.EffectiveArea03 = 0.14
343 elif SCEta < 2.0 : ele.EffectiveArea03 = 0.07
344 elif SCEta < 2.2 : ele.EffectiveArea03 = 0.09
345 elif SCEta < 2.3 : ele.EffectiveArea03 = 0.11
346 elif SCEta < 2.4 : ele.EffectiveArea03 = 0.11
347 else : ele.EffectiveArea03 = 0.14
348 if SCEta < 1.0 : ele.EffectiveArea04 = 0.208;
349 elif SCEta < 1.479: ele.EffectiveArea04 = 0.209;
350 elif SCEta < 2.0 : ele.EffectiveArea04 = 0.115;
351 elif SCEta < 2.2 : ele.EffectiveArea04 = 0.143;
352 elif SCEta < 2.3 : ele.EffectiveArea04 = 0.183;
353 elif SCEta < 2.4 : ele.EffectiveArea04 = 0.194;
354 else : ele.EffectiveArea04 = 0.261;
356 aeta =
abs(ele.eta())
357 if aeta < 0.800: ele.EffectiveArea03 = 0.1013
358 elif aeta < 1.300: ele.EffectiveArea03 = 0.0988
359 elif aeta < 2.000: ele.EffectiveArea03 = 0.0572
360 elif aeta < 2.200: ele.EffectiveArea03 = 0.0842
361 else: ele.EffectiveArea03 = 0.1530
362 if aeta < 0.800: ele.EffectiveArea04 = 0.1830
363 elif aeta < 1.300: ele.EffectiveArea04 = 0.1734
364 elif aeta < 2.000: ele.EffectiveArea04 = 0.1077
365 elif aeta < 2.200: ele.EffectiveArea04 = 0.1565
366 else: ele.EffectiveArea04 = 0.2680
368 SCEta =
abs(ele.superCluster().
eta())
370 if SCEta < 0.800: ele.EffectiveArea03 = 0.0973
371 elif SCEta < 1.300: ele.EffectiveArea03 = 0.0954
372 elif SCEta < 2.000: ele.EffectiveArea03 = 0.0632
373 elif SCEta < 2.200: ele.EffectiveArea03 = 0.0727
374 else: ele.EffectiveArea03 = 0.1337
376 ele.EffectiveArea04 = 0.0
378 SCEta =
abs(ele.superCluster().
eta())
380 if SCEta < 1.000: ele.EffectiveArea03 = 0.1752
381 elif SCEta < 1.479: ele.EffectiveArea03 = 0.1862
382 elif SCEta < 2.000: ele.EffectiveArea03 = 0.1411
383 elif SCEta < 2.200: ele.EffectiveArea03 = 0.1534
384 elif SCEta < 2.300: ele.EffectiveArea03 = 0.1903
385 elif SCEta < 2.400: ele.EffectiveArea03 = 0.2243
386 else: ele.EffectiveArea03 = 0.2687
388 ele.EffectiveArea04 = 0.0
389 else:
raise RuntimeError(
"Unsupported value for ele_effectiveAreas: can only use Data2012 (rho: ?), Phys14_v1 and Spring15_v1 (rho: fixedGridRhoFastjetAll)")
392 if self.cfg_ana.doElectronScaleCorrections:
393 for ele
in allelectrons:
394 self.electronEnergyCalibrator.correct(ele, event.run)
397 for ele
in allelectrons:
398 ele.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
401 for ele
in allelectrons:
402 if self.cfg_ana.ele_isoCorr==
"rhoArea" :
403 ele.absIso03 = (ele.chargedHadronIsoR(0.3) +
max(ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3)-ele.rho*ele.EffectiveArea03,0))
404 ele.absIso04 = (ele.chargedHadronIsoR(0.4) +
max(ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4)-ele.rho*ele.EffectiveArea04,0))
405 elif self.cfg_ana.ele_isoCorr==
"deltaBeta" :
406 ele.absIso03 = (ele.chargedHadronIsoR(0.3) +
max( ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3) - ele.puChargedHadronIsoR(0.3)/2, 0.0))
407 ele.absIso04 = (ele.chargedHadronIsoR(0.4) +
max( ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4) - ele.puChargedHadronIsoR(0.4)/2, 0.0))
409 raise RuntimeError(
"Unsupported ele_isoCorr name '" + str(self.cfg_ana.ele_isoCorr) +
"'! For now only 'rhoArea' and 'deltaBeta' are supported.")
410 ele.relIso03 = ele.absIso03/ele.pt()
411 ele.relIso04 = ele.absIso04/ele.pt()
414 for ele
in allelectrons:
415 if self.cfg_ana.ele_tightId==
"MVA" :
416 ele.tightIdResult = ele.electronID(
"POG_MVA_ID_Trig_full5x5")
417 elif self.cfg_ana.ele_tightId==
"Cuts_2012" :
418 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")
419 elif self.cfg_ana.ele_tightId==
"Cuts_PHYS14_25ns_v1_ConvVetoDxyDz" :
420 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")
421 elif self.cfg_ana.ele_tightId==
"Cuts_SPRING15_25ns_v1_ConvVetoDxyDz" :
422 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")
426 ele.tightIdResult = ele.electronID(self.cfg_ana.ele_tightId)
428 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.")
434 mu.miniIsoR = 10.0/
min(
max(mu.pt(), 50),200)
437 what =
"mu" if (
abs(mu.pdgId()) == 13)
else (
"eleB" if mu.isEB()
else "eleE")
439 mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what], 0.0);
441 mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what], 0.0,self.IsolationComputer.selfVetoNone);
443 if self.
miniIsolationPUCorr ==
None: puCorr = self.cfg_ana.mu_isoCorr
if what==
"mu" else self.cfg_ana.ele_isoCorr
446 if puCorr ==
"weights":
448 mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.01, 0.5);
450 mu.miniAbsIsoNeutral = ( self.IsolationComputer.photonAbsIsoWeighted( mu.physObj, mu.miniIsoR, 0.08
if what ==
"eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone) +
451 self.IsolationComputer.neutralHadAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone) )
454 mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.01, 0.5);
456 mu.miniAbsIsoPho = self.IsolationComputer.photonAbsIsoRaw( mu.physObj, mu.miniIsoR, 0.08
if what ==
"eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone)
457 mu.miniAbsIsoNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
458 mu.miniAbsIsoNeutral = mu.miniAbsIsoPho + mu.miniAbsIsoNHad
463 if puCorr ==
"rhoArea":
464 mu.miniAbsIsoNeutral =
max(0.0, mu.miniAbsIsoNeutral - mu.rho * mu.EffectiveArea03 * (mu.miniIsoR/0.3)**2)
465 elif puCorr ==
"deltaBeta":
467 mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.01, 0.5);
469 mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.015
if what ==
"eleE" else 0.0, 0.0,self.IsolationComputer.selfVetoNone);
470 mu.miniAbsIsoNeutral =
max(0.0, mu.miniAbsIsoNeutral - 0.5*mu.miniAbsIsoPU)
471 elif puCorr !=
'raw':
472 raise RuntimeError(
"Unsupported miniIsolationCorr name '" + puCorr +
"'! For now only 'rhoArea', 'deltaBeta', 'raw', 'weights' are supported (and 'weights' is not tested).")
474 mu.miniAbsIso = mu.miniAbsIsoCharged + mu.miniAbsIsoNeutral
475 mu.miniRelIso = mu.miniAbsIso/mu.pt()
479 mu.miniIsoR = 10.0/
min(
max(mu.pt(), 50),200)
480 mu.absIsoAnCharged = self.IsolationComputer.chargedAbsIso (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
481 mu.absIsoAnPho = self.IsolationComputer.photonAbsIsoRaw (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
482 mu.absIsoAnNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
483 mu.absIsoAnPU = self.IsolationComputer.puAbsIso (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
484 mu.absIsoAnNeutral =
max(0.0, mu.absIsoAnPho + mu.absIsoAnNHad - 0.5*mu.absIsoAnPU)
486 mu.absIsoAn04 = mu.absIsoAnCharged + mu.absIsoAnNeutral
487 mu.relIsoAn04 = mu.absIsoAn04/mu.pt()
492 what =
"mu" if (
abs(mu.pdgId()) == 13)
else (
"eleB" if mu.isEB()
else "eleE")
493 vetoreg = {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what]
496 mu.ScanAbsIsoCharged005 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.05, vetoreg, 0.0)
497 mu.ScanAbsIsoCharged01 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.1, vetoreg, 0.0)
498 mu.ScanAbsIsoCharged02 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.2, vetoreg, 0.0)
499 mu.ScanAbsIsoCharged03 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.3, vetoreg, 0.0)
500 mu.ScanAbsIsoCharged04 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.4, vetoreg, 0.0)
502 mu.ScanAbsIsoCharged005 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.05, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
503 mu.ScanAbsIsoCharged01 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.1, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
504 mu.ScanAbsIsoCharged02 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.2, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
505 mu.ScanAbsIsoCharged03 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.3, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
506 mu.ScanAbsIsoCharged04 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.4, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
509 mu.ScanAbsIsoNeutral005 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.05, 0.01, 0.5)
510 mu.ScanAbsIsoNeutral01 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.1, 0.01, 0.5)
511 mu.ScanAbsIsoNeutral02 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.2, 0.01, 0.5)
512 mu.ScanAbsIsoNeutral03 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.3, 0.01, 0.5)
513 mu.ScanAbsIsoNeutral04 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.4, 0.01, 0.5)
515 vetoreg = {
"eleB":0.0,
"eleE":0.08}[what]
516 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)
517 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)
518 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)
519 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)
520 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)
524 def plausible(rec,gen):
525 if abs(rec.pdgId()) == 11
and abs(gen.pdgId()) != 11:
return False
526 if abs(rec.pdgId()) == 13
and abs(gen.pdgId()) != 13:
return False
527 dr =
deltaR(rec.eta(),rec.phi(),gen.eta(),gen.phi())
528 if dr < 0.3:
return True
529 if rec.pt() < 10
and abs(rec.pdgId()) == 13
and gen.pdgId() != rec.pdgId():
return False
530 if dr < 0.7:
return True
531 if min(rec.pt(),gen.pt())/
max(rec.pt(),gen.pt()) < 0.3:
return False
534 leps = event.inclusiveLeptons
if self.cfg_ana.match_inclusiveLeptons
else event.selectedLeptons
536 event.genleps + event.gentauleps,
537 deltaRMax = 1.2, filter = plausible)
540 lep.mcMatchId = (gen.sourceId
if gen !=
None else 0)
541 lep.mcMatchTau = (gen
in event.gentauleps
if gen
else -99)
545 for i
in xrange( particle.numberOfMothers() ):
546 mom = particle.mother(i)
547 momid =
abs(mom.pdgId())
548 if momid / 1000 == bid
or momid / 100 == bid
or momid == bid:
550 elif mom.status() == 2
and self.
isFromB(mom, done=done, bid=bid):
555 event.anyLeptons = [ x
for x
in event.genParticles
if x.status() == 1
and abs(x.pdgId())
in [11,13] ]
556 leps = event.inclusiveLeptons
if hasattr(event,
'inclusiveLeptons')
else event.selectedLeptons
560 lep.mcMatchAny_gp = gen
562 if self.
isFromB(gen): lep.mcMatchAny = 5
563 elif self.
isFromB(gen,bid=4): lep.mcMatchAny = 4
564 else: lep.mcMatchAny = 1
565 if not getattr(lep,
'mcLep',
None): lep.mcLep = gen
567 if not getattr(lep,
'mcLep',
None): lep.mcLep =
None
570 if gen !=
None and hasattr(lep,
'mcMatchId')
and lep.mcMatchId == 0:
571 if isPromptLepton(gen,
False)
or (gen.isPromptFinalState()
or gen.isDirectPromptTauDecayProductFinalState()):
574 elif not hasattr(lep,
'mcMatchId'):
576 if not hasattr(lep,
'mcMatchTau'): lep.mcMatchTau = 0
579 event.anyPho = [ x
for x
in self.mchandles[
'genPhotons'].product()
if x.status() == 1
and x.pdgId() == 22
and x.pt() > 1.0 ]
580 leps = event.inclusiveLeptons
if hasattr(event,
'inclusiveLeptons')
else event.selectedLeptons
581 leps = [ l
for l
in leps
if abs(l.pdgId()) == 11 ]
582 plausible =
lambda rec, gen : 0.3*gen.pt() < rec.pt()
and rec.pt() < 1.5*gen.pt()
587 if lep.mcPho
and lep.mcLep:
590 dr =
deltaR(rec.eta(),rec.phi(),gen.eta(),gen.phi())
591 dptRel =
abs(rec.pt()-gen.pt())/gen.pt()
592 return dr + 0.2*dptRel
595 if getattr(lep,
'mcMatchAny_gp',
None)
and lep.mcMatchAny_gp != lep.mcLep:
597 if dlep <= dpho: lep.mcPho =
None
600 self.readCollections( event.input )
601 self.counters.counter(
'events').inc(
'all events')
606 if self.cfg_comp.isMC
and self.cfg_ana.do_mc_match:
615 setattr(LeptonAnalyzer,
"defaultConfig",cfg.Analyzer(
617 class_object=LeptonAnalyzer,
619 muons=
'slimmedMuons',
620 electrons=
'slimmedElectrons',
621 rhoMuon=
'fixedGridRhoFastjetAll',
622 rhoElectron =
'fixedGridRhoFastjetAll',
625 doMuonScaleCorrections=
False,
626 doElectronScaleCorrections=
False,
627 doSegmentBasedMuonCleaning=
False,
629 inclusive_muon_id =
"POG_ID_Loose",
630 inclusive_muon_pt = 3,
631 inclusive_muon_eta = 2.4,
632 inclusive_muon_dxy = 0.5,
633 inclusive_muon_dz = 1.0,
634 muon_dxydz_track =
"muonBestTrack",
636 loose_muon_id =
"POG_ID_Loose",
638 loose_muon_eta = 2.4,
639 loose_muon_dxy = 0.05,
641 loose_muon_relIso = 0.4,
644 inclusive_electron_id =
"",
645 inclusive_electron_pt = 5,
646 inclusive_electron_eta = 2.5,
647 inclusive_electron_dxy = 0.5,
648 inclusive_electron_dz = 1.0,
649 inclusive_electron_lostHits = 1.0,
651 loose_electron_id =
"",
652 loose_electron_pt = 7,
653 loose_electron_eta = 2.4,
654 loose_electron_dxy = 0.05,
655 loose_electron_dz = 0.2,
656 loose_electron_relIso = 0.4,
658 loose_electron_lostHits = 1.0,
660 mu_isoCorr =
"rhoArea" ,
661 mu_effectiveAreas =
"Spring15_25ns_v1",
662 mu_tightId =
"POG_ID_Tight" ,
664 ele_isoCorr =
"rhoArea" ,
665 ele_effectiveAreas =
"Spring15_25ns_v1" ,
666 ele_tightId =
"Cuts_2012" ,
668 min_dr_electron_muon = 0.02,
670 doMiniIsolation =
False,
671 packedCandidates =
'packedPFCandidates',
672 miniIsolationPUCorr =
'rhoArea',
674 miniIsolationVetoLeptons =
None,
676 doIsoAnnulus =
False,
679 do_mc_match_photons =
False,
680 match_inclusiveLeptons =
False,
Abs< T >::type abs(const T &t)
double deltaR(double eta1, double eta2, double phi1, double phi2)
eleEffectiveArea
Duplicate removal for fast sim (to be checked if still necessary in latest greatest 5...
miniIsolationVetoLeptons
inclusive leptons = all leptons that could be considered somewhere in the analysis, with minimal requirements (used e.g.
def matchObjectCollection3