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.ElectronCalibrator
import EmbeddedElectronCalibrator
12 import PhysicsTools.HeppyCore.framework.config
as cfg
17 from ROOT
import heppy
23 def __init__(self, cfg_ana, cfg_comp, looperName ):
24 super(LeptonAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
25 if self.cfg_ana.doMuScleFitCorrections
and self.cfg_ana.doMuScleFitCorrections !=
"none":
26 if self.cfg_ana.doMuScleFitCorrections
not in [
"none",
"prompt",
"prompt-sync",
"rereco",
"rereco-sync" ]:
27 raise RuntimeError,
'doMuScleFitCorrections must be one of "none", "prompt", "prompt-sync", "rereco", "rereco-sync"'
28 rereco = (
"prompt" not in self.cfg_ana.doMuScleFitCorrections)
29 sync = (
"sync" in self.cfg_ana.doMuScleFitCorrections)
30 self.
muscleCorr = MuScleFitCorr(cfg_comp.isMC, rereco, sync)
31 if hasattr(self.cfg_ana,
"doRochesterCorrections")
and self.cfg_ana.doRochesterCorrections:
32 raise RuntimeError,
"You can't run both Rochester and MuScleFit corrections!"
34 self.cfg_ana.doMuScleFitCorrections =
False
36 self.electronEnergyCalibrator = EmbeddedElectronCalibrator()
40 if hasattr(cfg_ana,
'loose_electron_isoCut'):
41 self.eleIsoCut = cfg_ana.loose_electron_isoCut
43 self.eleIsoCut =
lambda ele : (
44 ele.relIso03 <= self.cfg_ana.loose_electron_relIso
and
45 ele.absIso03 < getattr(self.cfg_ana,
'loose_electron_absIso',9e99))
46 if hasattr(cfg_ana,
'loose_muon_isoCut'):
47 self.muIsoCut = cfg_ana.loose_muon_isoCut
49 self.muIsoCut =
lambda mu : (
50 mu.relIso03 <= self.cfg_ana.loose_muon_relIso
and
51 mu.absIso03 < getattr(self.cfg_ana,
'loose_muon_absIso',9e99))
55 self.
eleEffectiveArea = getattr(cfg_ana,
'ele_effectiveAreas',
"Spring15_25ns_v1")
56 self.
muEffectiveArea = getattr(cfg_ana,
'mu_effectiveAreas',
"Spring15_25ns_v1")
58 self.doMiniIsolation = getattr(cfg_ana,
'doMiniIsolation',
False)
59 if self.doMiniIsolation:
63 raise RuntimeError,
"miniIsolationVetoLeptons should be None, or 'any' (all reco leptons), or 'inclusive' (all inclusive leptons)"
69 self.doIsoAnnulus = getattr(cfg_ana,
'doIsoAnnulus',
False)
71 if not self.doMiniIsolation:
74 self.doIsolationScan = getattr(cfg_ana,
'doIsolationScan',
False)
75 if self.doIsolationScan:
76 if self.doMiniIsolation:
92 self.handles[
'muons'] = AutoHandle(self.cfg_ana.muons,
"std::vector<pat::Muon>")
93 self.handles[
'electrons'] = AutoHandle(self.cfg_ana.electrons,
"std::vector<pat::Electron>")
96 self.handles[
'rhoMu'] = AutoHandle( self.cfg_ana.rhoMuon,
'double')
98 self.handles[
'rhoEle'] = AutoHandle( self.cfg_ana.rhoElectron,
'double')
100 if self.doMiniIsolation
or self.doIsolationScan:
101 self.handles[
'packedCandidates'] = AutoHandle( self.cfg_ana.packedCandidates,
'std::vector<pat::PackedCandidate>')
103 super(LeptonAnalyzer,self).
beginLoop(setup)
104 self.counters.addCounter(
'events')
105 count = self.counters.counter(
'events')
106 count.register(
'all events')
115 event.inclusiveLeptons = []
118 event.selectedLeptons = []
119 event.selectedMuons = []
120 event.selectedElectrons = []
121 event.otherLeptons = []
123 if self.doMiniIsolation
or self.doIsolationScan:
124 self.IsolationComputer.setPackedCandidates(self.handles[
'packedCandidates'].product())
125 if self.doMiniIsolation:
127 for lep
in self.handles[
'muons'].product():
128 self.IsolationComputer.addVetos(lep)
129 for lep
in self.handles[
'electrons'].product():
130 self.IsolationComputer.addVetos(lep)
140 inclusiveElectrons = []
142 if (mu.track().isNonnull()
and mu.muonID(self.cfg_ana.inclusive_muon_id)
and
143 mu.pt()>self.cfg_ana.inclusive_muon_pt
and abs(mu.eta())<self.cfg_ana.inclusive_muon_eta
and
144 abs(mu.dxy())<self.cfg_ana.inclusive_muon_dxy
and abs(mu.dz())<self.cfg_ana.inclusive_muon_dz):
145 inclusiveMuons.append(mu)
146 for ele
in allelectrons:
147 if ( ele.electronID(self.cfg_ana.inclusive_electron_id)
and
148 ele.pt()>self.cfg_ana.inclusive_electron_pt
and abs(ele.eta())<self.cfg_ana.inclusive_electron_eta
and
149 abs(ele.dxy())<self.cfg_ana.inclusive_electron_dxy
and abs(ele.dz())<self.cfg_ana.inclusive_electron_dz
and
150 ele.lostInner()<=self.cfg_ana.inclusive_electron_lostHits ):
151 inclusiveElectrons.append(ele)
152 event.inclusiveLeptons = inclusiveMuons + inclusiveElectrons
154 if self.doMiniIsolation:
156 for lep
in event.inclusiveLeptons:
157 self.IsolationComputer.addVetos(lep.physObj)
158 for lep
in event.inclusiveLeptons:
161 if self.doIsoAnnulus:
162 for lep
in event.inclusiveLeptons:
165 if self.doIsolationScan:
166 for lep
in event.inclusiveLeptons:
170 for mu
in inclusiveMuons:
171 if (mu.muonID(self.cfg_ana.loose_muon_id)
and
172 mu.pt() > self.cfg_ana.loose_muon_pt
and abs(mu.eta()) < self.cfg_ana.loose_muon_eta
and
173 abs(mu.dxy()) < self.cfg_ana.loose_muon_dxy
and abs(mu.dz()) < self.cfg_ana.loose_muon_dz
and
175 mu.looseIdSusy =
True
176 event.selectedLeptons.append(mu)
177 event.selectedMuons.append(mu)
179 mu.looseIdSusy =
False
180 event.otherLeptons.append(mu)
181 looseMuons = event.selectedLeptons[:]
182 for ele
in inclusiveElectrons:
183 if (ele.electronID(self.cfg_ana.loose_electron_id)
and
184 ele.pt()>self.cfg_ana.loose_electron_pt
and abs(ele.eta())<self.cfg_ana.loose_electron_eta
and
185 abs(ele.dxy()) < self.cfg_ana.loose_electron_dxy
and abs(ele.dz())<self.cfg_ana.loose_electron_dz
and
186 self.eleIsoCut(ele)
and
187 ele.lostInner() <= self.cfg_ana.loose_electron_lostHits
and
188 (
True if getattr(self.cfg_ana,
'notCleaningElectrons',
False)
else (
bestMatch(ele, looseMuons)[1] > (self.cfg_ana.min_dr_electron_muon**2)) )):
189 event.selectedLeptons.append(ele)
190 event.selectedElectrons.append(ele)
191 ele.looseIdSusy =
True
193 event.otherLeptons.append(ele)
194 ele.looseIdSusy =
False
196 event.otherLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
197 event.selectedLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
198 event.selectedMuons.sort(key =
lambda l : l.pt(), reverse =
True)
199 event.selectedElectrons.sort(key =
lambda l : l.pt(), reverse =
True)
200 event.inclusiveLeptons.sort(key =
lambda l : l.pt(), reverse =
True)
202 for lepton
in event.selectedLeptons:
203 if hasattr(self,
'efficiency'):
204 self.efficiency.attachToObject(lepton)
208 make a list of all muons, and apply basic corrections to them
211 allmuons =
map( Muon, self.handles[
'muons'].product() )
214 if self.cfg_ana.doMuScleFitCorrections:
216 self.muscleCorr.correct(mu, event.run)
217 elif self.cfg_ana.doRochesterCorrections:
219 corp4 = rochcor.corrected_p4(mu, event.run)
223 if self.cfg_ana.doSegmentBasedMuonCleaning:
224 isgood = cmgMuonCleanerBySegments.clean( self.handles[
'muons'].product() )
226 for i,mu
in enumerate(allmuons):
227 if isgood[i]: newmu.append(mu)
232 mu.rho = float(self.handles[
'rhoMu'].product()[0])
234 if aeta < 1.0 : mu.EffectiveArea03 = 0.382;
235 elif aeta < 1.47 : mu.EffectiveArea03 = 0.317;
236 elif aeta < 2.0 : mu.EffectiveArea03 = 0.242;
237 elif aeta < 2.2 : mu.EffectiveArea03 = 0.326;
238 elif aeta < 2.3 : mu.EffectiveArea03 = 0.462;
239 else : mu.EffectiveArea03 = 0.372;
240 if aeta < 1.0 : mu.EffectiveArea04 = 0.674;
241 elif aeta < 1.47 : mu.EffectiveArea04 = 0.565;
242 elif aeta < 2.0 : mu.EffectiveArea04 = 0.442;
243 elif aeta < 2.2 : mu.EffectiveArea04 = 0.515;
244 elif aeta < 2.3 : mu.EffectiveArea04 = 0.821;
245 else : mu.EffectiveArea04 = 0.660;
248 if aeta < 0.800: mu.EffectiveArea03 = 0.0913
249 elif aeta < 1.300: mu.EffectiveArea03 = 0.0765
250 elif aeta < 2.000: mu.EffectiveArea03 = 0.0546
251 elif aeta < 2.200: mu.EffectiveArea03 = 0.0728
252 else: mu.EffectiveArea03 = 0.1177
253 if aeta < 0.800: mu.EffectiveArea04 = 0.1564
254 elif aeta < 1.300: mu.EffectiveArea04 = 0.1325
255 elif aeta < 2.000: mu.EffectiveArea04 = 0.0913
256 elif aeta < 2.200: mu.EffectiveArea04 = 0.1212
257 else: mu.EffectiveArea04 = 0.2085
260 if aeta < 0.800: mu.EffectiveArea03 = 0.0735
261 elif aeta < 1.300: mu.EffectiveArea03 = 0.0619
262 elif aeta < 2.000: mu.EffectiveArea03 = 0.0465
263 elif aeta < 2.200: mu.EffectiveArea03 = 0.0433
264 else: mu.EffectiveArea03 = 0.0577
265 mu.EffectiveArea04 = 0
266 else:
raise RuntimeError,
"Unsupported value for mu_effectiveAreas: can only use Data2012 (rho: ?) and Phys14_25ns_v1 or Spring15_25ns_v1 (rho: fixedGridRhoFastjetAll)"
269 mu.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
270 mu.setTrackForDxyDz(self.cfg_ana.muon_dxydz_track)
273 if hasattr(self.cfg_ana,
"mu_tightId"):
275 mu.tightIdResult = mu.muonID(self.cfg_ana.mu_tightId)
279 if self.cfg_ana.mu_isoCorr==
"rhoArea" :
280 mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt +
max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.rho * mu.EffectiveArea03,0.0))
281 mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt +
max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.rho * mu.EffectiveArea04,0.0))
282 elif self.cfg_ana.mu_isoCorr==
"deltaBeta" :
283 mu.absIso03 = (mu.pfIsolationR03().sumChargedHadronPt +
max( mu.pfIsolationR03().sumNeutralHadronEt + mu.pfIsolationR03().sumPhotonEt - mu.pfIsolationR03().sumPUPt/2,0.0))
284 mu.absIso04 = (mu.pfIsolationR04().sumChargedHadronPt +
max( mu.pfIsolationR04().sumNeutralHadronEt + mu.pfIsolationR04().sumPhotonEt - mu.pfIsolationR04().sumPUPt/2,0.0))
286 raise RuntimeError,
"Unsupported mu_isoCorr name '" + str(self.cfg_ana.mu_isoCorr) +
"'! For now only 'rhoArea' and 'deltaBeta' are supported."
287 mu.relIso03 = mu.absIso03/mu.pt()
288 mu.relIso04 = mu.absIso04/mu.pt()
293 make a list of all electrons, and apply basic corrections to them
295 allelectrons =
map( Electron, self.handles[
'electrons'].product() )
299 for e
in allelectrons:
301 for e2
in allelenodup:
302 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():
305 if not dup: allelenodup.append(e)
306 allelectrons = allelenodup
309 for ele
in allelectrons:
310 ele.rho = float(self.handles[
'rhoEle'].product()[0])
313 SCEta =
abs(ele.superCluster().
eta())
314 if SCEta < 1.0 : ele.EffectiveArea03 = 0.13
315 elif SCEta < 1.479: ele.EffectiveArea03 = 0.14
316 elif SCEta < 2.0 : ele.EffectiveArea03 = 0.07
317 elif SCEta < 2.2 : ele.EffectiveArea03 = 0.09
318 elif SCEta < 2.3 : ele.EffectiveArea03 = 0.11
319 elif SCEta < 2.4 : ele.EffectiveArea03 = 0.11
320 else : ele.EffectiveArea03 = 0.14
321 if SCEta < 1.0 : ele.EffectiveArea04 = 0.208;
322 elif SCEta < 1.479: ele.EffectiveArea04 = 0.209;
323 elif SCEta < 2.0 : ele.EffectiveArea04 = 0.115;
324 elif SCEta < 2.2 : ele.EffectiveArea04 = 0.143;
325 elif SCEta < 2.3 : ele.EffectiveArea04 = 0.183;
326 elif SCEta < 2.4 : ele.EffectiveArea04 = 0.194;
327 else : ele.EffectiveArea04 = 0.261;
329 aeta =
abs(ele.eta())
330 if aeta < 0.800: ele.EffectiveArea03 = 0.1013
331 elif aeta < 1.300: ele.EffectiveArea03 = 0.0988
332 elif aeta < 2.000: ele.EffectiveArea03 = 0.0572
333 elif aeta < 2.200: ele.EffectiveArea03 = 0.0842
334 else: ele.EffectiveArea03 = 0.1530
335 if aeta < 0.800: ele.EffectiveArea04 = 0.1830
336 elif aeta < 1.300: ele.EffectiveArea04 = 0.1734
337 elif aeta < 2.000: ele.EffectiveArea04 = 0.1077
338 elif aeta < 2.200: ele.EffectiveArea04 = 0.1565
339 else: ele.EffectiveArea04 = 0.2680
341 SCEta =
abs(ele.superCluster().
eta())
343 if SCEta < 0.800: ele.EffectiveArea03 = 0.0973
344 elif SCEta < 1.300: ele.EffectiveArea03 = 0.0954
345 elif SCEta < 2.000: ele.EffectiveArea03 = 0.0632
346 elif SCEta < 2.200: ele.EffectiveArea03 = 0.0727
347 else: ele.EffectiveArea03 = 0.1337
349 ele.EffectiveArea04 = 0.0
351 SCEta =
abs(ele.superCluster().
eta())
353 if SCEta < 1.000: ele.EffectiveArea03 = 0.1752
354 elif SCEta < 1.479: ele.EffectiveArea03 = 0.1862
355 elif SCEta < 2.000: ele.EffectiveArea03 = 0.1411
356 elif SCEta < 2.200: ele.EffectiveArea03 = 0.1534
357 elif SCEta < 2.300: ele.EffectiveArea03 = 0.1903
358 elif SCEta < 2.400: ele.EffectiveArea03 = 0.2243
359 else: ele.EffectiveArea03 = 0.2687
361 ele.EffectiveArea04 = 0.0
362 else:
raise RuntimeError,
"Unsupported value for ele_effectiveAreas: can only use Data2012 (rho: ?), Phys14_v1 and Spring15_v1 (rho: fixedGridRhoFastjetAll)"
365 if self.cfg_ana.doElectronScaleCorrections:
366 for ele
in allelectrons:
367 self.electronEnergyCalibrator.correct(ele, event.run)
370 for ele
in allelectrons:
371 ele.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
374 for ele
in allelectrons:
375 if self.cfg_ana.ele_isoCorr==
"rhoArea" :
376 ele.absIso03 = (ele.chargedHadronIsoR(0.3) +
max(ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3)-ele.rho*ele.EffectiveArea03,0))
377 ele.absIso04 = (ele.chargedHadronIsoR(0.4) +
max(ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4)-ele.rho*ele.EffectiveArea04,0))
378 elif self.cfg_ana.ele_isoCorr==
"deltaBeta" :
379 ele.absIso03 = (ele.chargedHadronIsoR(0.3) +
max( ele.neutralHadronIsoR(0.3)+ele.photonIsoR(0.3) - ele.puChargedHadronIsoR(0.3)/2, 0.0))
380 ele.absIso04 = (ele.chargedHadronIsoR(0.4) +
max( ele.neutralHadronIsoR(0.4)+ele.photonIsoR(0.4) - ele.puChargedHadronIsoR(0.4)/2, 0.0))
382 raise RuntimeError,
"Unsupported ele_isoCorr name '" + str(self.cfg_ana.ele_isoCorr) +
"'! For now only 'rhoArea' and 'deltaBeta' are supported."
383 ele.relIso03 = ele.absIso03/ele.pt()
384 ele.relIso04 = ele.absIso04/ele.pt()
387 for ele
in allelectrons:
388 if self.cfg_ana.ele_tightId==
"MVA" :
389 ele.tightIdResult = ele.electronID(
"POG_MVA_ID_Trig_full5x5")
390 elif self.cfg_ana.ele_tightId==
"Cuts_2012" :
391 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")
392 elif self.cfg_ana.ele_tightId==
"Cuts_PHYS14_25ns_v1_ConvVetoDxyDz" :
393 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")
397 ele.tightIdResult = ele.electronID(self.cfg_ana.ele_tightId)
399 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."
405 mu.miniIsoR = 10.0/
min(
max(mu.pt(), 50),200)
408 what =
"mu" if (
abs(mu.pdgId()) == 13)
else (
"eleB" if mu.isEB()
else "eleE")
410 mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what], 0.0);
412 mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what], 0.0,self.IsolationComputer.selfVetoNone);
414 if self.
miniIsolationPUCorr ==
None: puCorr = self.cfg_ana.mu_isoCorr
if what==
"mu" else self.cfg_ana.ele_isoCorr
417 if puCorr ==
"weights":
419 mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.01, 0.5);
421 mu.miniAbsIsoNeutral = ( self.IsolationComputer.photonAbsIsoWeighted( mu.physObj, mu.miniIsoR, 0.08
if what ==
"eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone) +
422 self.IsolationComputer.neutralHadAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone) )
425 mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.01, 0.5);
427 mu.miniAbsIsoPho = self.IsolationComputer.photonAbsIsoRaw( mu.physObj, mu.miniIsoR, 0.08
if what ==
"eleE" else 0.0, 0.0, self.IsolationComputer.selfVetoNone)
428 mu.miniAbsIsoNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, mu.miniIsoR, 0.0, 0.0, self.IsolationComputer.selfVetoNone)
429 mu.miniAbsIsoNeutral = mu.miniAbsIsoPho + mu.miniAbsIsoNHad
434 if puCorr ==
"rhoArea":
435 mu.miniAbsIsoNeutral =
max(0.0, mu.miniAbsIsoNeutral - mu.rho * mu.EffectiveArea03 * (mu.miniIsoR/0.3)**2)
436 elif puCorr ==
"deltaBeta":
438 mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.01, 0.5);
440 mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.015
if what ==
"eleE" else 0.0, 0.0,self.IsolationComputer.selfVetoNone);
441 mu.miniAbsIsoNeutral =
max(0.0, mu.miniAbsIsoNeutral - 0.5*mu.miniAbsIsoPU)
442 elif puCorr !=
'raw':
443 raise RuntimeError,
"Unsupported miniIsolationCorr name '" + puCorr +
"'! For now only 'rhoArea', 'deltaBeta', 'raw', 'weights' are supported (and 'weights' is not tested)."
445 mu.miniAbsIso = mu.miniAbsIsoCharged + mu.miniAbsIsoNeutral
446 mu.miniRelIso = mu.miniAbsIso/mu.pt()
450 mu.miniIsoR = 10.0/
min(
max(mu.pt(), 50),200)
451 mu.absIsoAnCharged = self.IsolationComputer.chargedAbsIso (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
452 mu.absIsoAnPho = self.IsolationComputer.photonAbsIsoRaw (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
453 mu.absIsoAnNHad = self.IsolationComputer.neutralHadAbsIsoRaw(mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
454 mu.absIsoAnPU = self.IsolationComputer.puAbsIso (mu.physObj, 0.4, mu.miniIsoR, 0.0, self.IsolationComputer.selfVetoNone)
455 mu.absIsoAnNeutral =
max(0.0, mu.absIsoAnPho + mu.absIsoAnNHad - 0.5*mu.absIsoAnPU)
457 mu.absIsoAn04 = mu.absIsoAnCharged + mu.absIsoAnNeutral
458 mu.relIsoAn04 = mu.absIsoAn04/mu.pt()
463 what =
"mu" if (
abs(mu.pdgId()) == 13)
else (
"eleB" if mu.isEB()
else "eleE")
464 vetoreg = {
"mu":0.0001,
"eleB":0,
"eleE":0.015}[what]
467 mu.ScanAbsIsoCharged005 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.05, vetoreg, 0.0)
468 mu.ScanAbsIsoCharged01 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.1, vetoreg, 0.0)
469 mu.ScanAbsIsoCharged02 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.2, vetoreg, 0.0)
470 mu.ScanAbsIsoCharged03 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.3, vetoreg, 0.0)
471 mu.ScanAbsIsoCharged04 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.4, vetoreg, 0.0)
473 mu.ScanAbsIsoCharged005 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.05, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
474 mu.ScanAbsIsoCharged01 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.1, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
475 mu.ScanAbsIsoCharged02 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.2, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
476 mu.ScanAbsIsoCharged03 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.3, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
477 mu.ScanAbsIsoCharged04 = self.IsolationComputer.chargedAbsIso(mu.physObj, 0.4, vetoreg, 0.0, self.IsolationComputer.selfVetoNone)
480 mu.ScanAbsIsoNeutral005 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.05, 0.01, 0.5)
481 mu.ScanAbsIsoNeutral01 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.1, 0.01, 0.5)
482 mu.ScanAbsIsoNeutral02 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.2, 0.01, 0.5)
483 mu.ScanAbsIsoNeutral03 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.3, 0.01, 0.5)
484 mu.ScanAbsIsoNeutral04 = self.IsolationComputer.neutralAbsIsoRaw(mu.physObj, 0.4, 0.01, 0.5)
486 vetoreg = {
"eleB":0.0,
"eleE":0.08}[what]
487 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)
488 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)
489 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)
490 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)
491 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)
495 def plausible(rec,gen):
496 if abs(rec.pdgId()) == 11
and abs(gen.pdgId()) != 11:
return False
497 if abs(rec.pdgId()) == 13
and abs(gen.pdgId()) != 13:
return False
498 dr =
deltaR(rec.eta(),rec.phi(),gen.eta(),gen.phi())
499 if dr < 0.3:
return True
500 if rec.pt() < 10
and abs(rec.pdgId()) == 13
and gen.pdgId() != rec.pdgId():
return False
501 if dr < 0.7:
return True
502 if min(rec.pt(),gen.pt())/
max(rec.pt(),gen.pt()) < 0.3:
return False
505 leps = event.inclusiveLeptons
if self.cfg_ana.match_inclusiveLeptons
else event.selectedLeptons
507 event.genleps + event.gentauleps,
508 deltaRMax = 1.2, filter = plausible)
511 lep.mcMatchId = (gen.sourceId
if gen !=
None else 0)
512 lep.mcMatchTau = (gen
in event.gentauleps
if gen
else -99)
516 for i
in xrange( particle.numberOfMothers() ):
517 mom = particle.mother(i)
518 momid =
abs(mom.pdgId())
519 if momid / 1000 == bid
or momid / 100 == bid
or momid == bid:
521 elif mom.status() == 2
and self.
isFromB(mom, done=done):
526 event.anyLeptons = [ x
for x
in event.genParticles
if x.status() == 1
and abs(x.pdgId())
in [11,13] ]
527 leps = event.inclusiveLeptons
if hasattr(event,
'inclusiveLeptons')
else event.selectedLeptons
531 lep.mcMatchAny_gp = gen
533 if self.
isFromB(gen): lep.mcMatchAny = 5
534 elif self.
isFromB(gen,bid=4): lep.mcMatchAny = 4
535 else: lep.mcMatchAny = 1
539 if gen !=
None and hasattr(lep,
'mcMatchId')
and lep.mcMatchId == 0:
541 elif not hasattr(lep,
'mcMatchId'):
543 if not hasattr(lep,
'mcMatchTau'): lep.mcMatchTau = 0
546 self.readCollections( event.input )
547 self.counters.counter(
'events').inc(
'all events')
552 if self.cfg_comp.isMC
and self.cfg_ana.do_mc_match:
559 setattr(LeptonAnalyzer,
"defaultConfig",cfg.Analyzer(
561 class_object=LeptonAnalyzer,
563 muons=
'slimmedMuons',
564 electrons=
'slimmedElectrons',
565 rhoMuon=
'fixedGridRhoFastjetAll',
566 rhoElectron =
'fixedGridRhoFastjetAll',
569 doMuScleFitCorrections=
False,
570 doRochesterCorrections=
False,
571 doElectronScaleCorrections=
False,
572 doSegmentBasedMuonCleaning=
False,
574 inclusive_muon_id =
"POG_ID_Loose",
575 inclusive_muon_pt = 3,
576 inclusive_muon_eta = 2.4,
577 inclusive_muon_dxy = 0.5,
578 inclusive_muon_dz = 1.0,
579 muon_dxydz_track =
"muonBestTrack",
581 loose_muon_id =
"POG_ID_Loose",
583 loose_muon_eta = 2.4,
584 loose_muon_dxy = 0.05,
586 loose_muon_relIso = 0.4,
589 inclusive_electron_id =
"",
590 inclusive_electron_pt = 5,
591 inclusive_electron_eta = 2.5,
592 inclusive_electron_dxy = 0.5,
593 inclusive_electron_dz = 1.0,
594 inclusive_electron_lostHits = 1.0,
596 loose_electron_id =
"",
597 loose_electron_pt = 7,
598 loose_electron_eta = 2.4,
599 loose_electron_dxy = 0.05,
600 loose_electron_dz = 0.2,
601 loose_electron_relIso = 0.4,
603 loose_electron_lostHits = 1.0,
605 mu_isoCorr =
"rhoArea" ,
606 mu_effectiveAreas =
"Spring15_25ns_v1",
607 mu_tightId =
"POG_ID_Tight" ,
609 ele_isoCorr =
"rhoArea" ,
610 ele_effectiveAreas =
"Spring15_25ns_v1" ,
611 ele_tightId =
"Cuts_2012" ,
613 min_dr_electron_muon = 0.02,
615 doMiniIsolation =
False,
616 packedCandidates =
'packedPFCandidates',
617 miniIsolationPUCorr =
'rhoArea',
619 miniIsolationVetoLeptons =
None,
621 doIsoAnnulus =
False,
624 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