Skip to content

Commit

Permalink
adapted to change in the LeptonIsolation interface in Heppy
Browse files Browse the repository at this point in the history
  • Loading branch information
cbernet committed Sep 13, 2018
1 parent 4bea2c4 commit 385cdb3
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 53 deletions.
4 changes: 2 additions & 2 deletions H2TauTau/python/proto/analyzers/LeptonWeighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def process(self, event):

iso = None
if hasattr(lep, 'muonId'): # muon
iso = lep.relIsoR(R=0.4, dBetaFactor=0.5)
iso = lep.relIso(0.4, dbeta_factor=0.5)

if hasattr(lep, 'mvaNonTrigV0'): # electron
iso = lep.relIsoR(R=0.3, dBetaFactor=0.5)
iso = lep.relIso(R=0.3, dbeta_factor=0.5)

# Get scale factors
for sf_name, sf in self.scaleFactors.items():
Expand Down
17 changes: 9 additions & 8 deletions H2TauTau/python/proto/analyzers/MuEleAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def testLeg2Iso(self, muon, isocut):
'''Muon isolation to be implemented'''
if isocut is None:
isocut = self.cfg_ana.iso2
return muon.relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0) < isocut
return muon.relIso(0.4, dbeta_factor=0.5, all_charged=0) < isocut

def testVertex(self, lepton):
'''Tests vertex constraints, for mu and electron'''
Expand All @@ -202,7 +202,7 @@ def testLeg1Iso(self, electron, isocut):
'''
if isocut is None:
isocut = self.cfg_ana.iso2
return electron.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0) < isocut
return electron.relIso(0.3, dbeta_factor=0.5, all_charged=0) < isocut

def otherLeptonVeto(self, leptons, otherLeptons, isocut=None):
'''Second electron veto '''
Expand All @@ -212,7 +212,7 @@ def otherLeptonVeto(self, leptons, otherLeptons, isocut=None):
electron.passConversionVeto() and
electron.gsfTrack().hitPattern().numberOfHits(ROOT.reco.HitPattern.MISSING_INNER_HITS) <= 1 and
electron.mvaIDRun2('NonTrigSpring15MiniAOD', 'POG90') and
electron.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0) < 0.3]
electron.relIso(0.3, dbeta_factor=0.5, all_charged=0) < 0.3]

if len(vOtherLeptons) > 1:
return False
Expand All @@ -226,7 +226,7 @@ def thirdLeptonVeto(self, leptons, otherLeptons, isocut=None):
muon.muonIDMoriond17() and
self.testVertex(muon) and
self.testLegKine(muon, ptcut=10, etacut=2.4) and
muon.relIsoR(R=0.4, dBetaFactor=0.5, allCharged=False) < 0.3]
muon.relIso(0.4, dbeta_factor=0.5, all_charged=False) < 0.3]

if len(vLeptons) > 1:
return False
Expand All @@ -247,9 +247,10 @@ def bestDiLepton(self, diLeptons):
if len(diLeptons) == 1:
return diLeptons[0]

minRelIso = min(d.leg2().relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0) for d in diLeptons)
minRelIso = min(d.leg2().relIso(0.4, dbeta_factor=0.5, all_charged=0) for d in diLeptons)

diLeps = [dil for dil in diLeptons if dil.leg2().relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0) == minRelIso]
diLeps = [dil for dil in diLeptons if dil.leg2().relIso(0.4,
dbeta_factor=0.5, all_charged=0) == minRelIso]

if len(diLeps) == 1:
return diLeps[0]
Expand All @@ -261,9 +262,9 @@ def bestDiLepton(self, diLeptons):
if len(diLeps) == 1:
return diLeps[0]

minIso = min(d.leg1().relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0) for d in diLeps)
minIso = min(d.leg1().relIso(0.3, dbeta_factor=0.5, all_charged=0) for d in diLeps)

diLeps = [dil for dil in diLeps if dil.leg1().relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0) == minIso]
diLeps = [dil for dil in diLeps if dil.leg1().relIso(0.3, dbeta_factor=0.5, all_charged=0) == minIso]

if len(diLeps) == 1:
return diLeps[0]
Expand Down
6 changes: 3 additions & 3 deletions H2TauTau/python/proto/analyzers/MuMuAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def testLeg2Iso(self, muon, isocut):
if isocut is None:
isocut = self.cfg_ana.iso2

return muon.relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0) < isocut
return muon.relIso(0.4, dbeta_factor=0.5, all_charged=0) < isocut

def testElectronID(self, electron):
return electron.mvaIDRun2('Spring16', 'POG90')
Expand All @@ -212,7 +212,7 @@ def otherLeptonVeto(self, leptons, otherLeptons, isoCut=0.3):
self.testElectronID(electron) and
electron.passConversionVeto() and
electron.physObj.gsfTrack().hitPattern().numberOfHits(ROOT.reco.HitPattern.MISSING_INNER_HITS) <= 1 and
electron.relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0) < 0.3]
electron.relIso(0.4, dbeta_factor=0.5, all_charged=0) < 0.3]

if len(vOtherLeptons) > 0:
return False
Expand All @@ -239,7 +239,7 @@ def bestDiLepton(self, diLeptons):
if len(diLeptons) == 1:
return diLeptons[0]

least_iso_highest_pt = lambda dl: (dl.leg1().relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0), -dl.leg1().pt(), dl.leg2().relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0), -dl.leg2().pt())
least_iso_highest_pt = lambda dl: (dl.leg1().relIso(0.4, dbeta_factor=0.5, all_charged=0), -dl.leg1().pt(), dl.leg2().relIso(0.4, dbeta_factor=0.5, all_charged=0), -dl.leg2().pt())

return sorted(diLeptons, key=lambda dil : least_iso_highest_pt(dil))[0]

14 changes: 7 additions & 7 deletions H2TauTau/python/proto/analyzers/TauEleAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def buildLeptons(self, cms_leptons, event):
pyl.rho = event.rho
pyl.event = event.input.object()

if pyl.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0) > 0.3:
if pyl.relIso(0.3, dbeta_factor=0.5, all_charged=0) > 0.3:
continue

leptons.append(pyl)
Expand Down Expand Up @@ -212,14 +212,14 @@ def testLeg1ID(self, electron):
def testLeg1Iso(self, leg, isocut): # electron
if isocut is None:
isocut = self.cfg_ana.iso2
return leg.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0) < isocut
return leg.relIso(0.3, dbeta_factor=0.5, all_charged=0) < isocut

def testLooseleg1(self, leg): # electrons
''' pt, eta and isolation selection for electrons
used in the di-electron veto.
pt 15, eta 2.5, dB relIso 0.3
'''
if (leg.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0) > 0.3 or
if (leg.relIso(0.3, dbeta_factor=0.5, all_charged=0) > 0.3 or
abs(leg.eta()) > 2.5 or
leg.pt() < 15 or
not self.testVetoElectronID(leg) or
Expand All @@ -233,15 +233,15 @@ def testTightOtherLepton(self, muon):
self.testVertex(muon) and \
abs(muon.eta()) < 2.4 and \
muon.pt() > 10. and \
muon.relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0) < 0.3
muon.relIso(0.4, dbeta_factor=0.5, all_charged=0) < 0.3

def otherLeptonVeto(self, leptons, otherLeptons, isoCut=0.3):
# count veto muons
vOtherLeptons = [muon for muon in otherLeptons if
muon.muonIDMoriond17() and
self.testVertex(muon) and
self.testLegKine(muon, ptcut=10, etacut=2.4) and
muon.relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0) < 0.3]
muon.relIso(0.4, dbeta_factor=0.5, all_charged=0) < 0.3]

if len(vOtherLeptons) > 0:
return False
Expand All @@ -254,7 +254,7 @@ def thirdLeptonVeto(self, leptons, otherLeptons, isoCut=0.3):
self.testLegKine(electron, ptcut=10, etacut=2.5) and
self.testVertex(electron) and
self.testElectronID(electron) and
electron.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0) < 0.3]
electron.relIso(0.3, dbeta_factor=0.5, all_charged=0) < 0.3]

if len(vLeptons) > 1:
return False
Expand Down Expand Up @@ -285,7 +285,7 @@ def bestDiLepton(self, diLeptons):
if len(diLeptons) == 1:
return diLeptons[0]

least_iso_highest_pt = lambda dl: (dl.leg1().relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0), -dl.leg1().pt(), -dl.leg2().tauID("byIsolationMVArun2v1DBoldDMwLTraw"), -dl.leg2().pt())
least_iso_highest_pt = lambda dl: (dl.leg1().relIso(0.3, dbeta_factor=0.5, all_charged=0), -dl.leg1().pt(), -dl.leg2().tauID("byIsolationMVArun2v1DBoldDMwLTraw"), -dl.leg2().pt())

return sorted(diLeptons, key=lambda dil : least_iso_highest_pt(dil))[0]

Expand Down
8 changes: 4 additions & 4 deletions H2TauTau/python/proto/analyzers/TauJetMuAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ def testLeg1Iso(self, muon, isocut):
if isocut is None:
isocut = self.cfg_ana.iso2

return muon.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=False) < isocut
return muon.relIso(0.3, dbeta_factor=0.5, all_charged=False) < isocut

def thirdLeptonVeto(self, leptons, otherLeptons, isoCut=0.3):
# count tight muons
vLeptons = [muon for muon in leptons if
muon.muonIDMoriond17() and
self.testVertex(muon) and
self.testLegKine(muon, ptcut=10, etacut=2.4) and
muon.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=False) < 0.3]
muon.relIso(0.3, dbeta_factor=0.5, all_charged=False) < 0.3]

if len(vLeptons) > 1:
return False
Expand All @@ -189,7 +189,7 @@ def otherLeptonVeto(self, leptons, otherLeptons, isoCut=0.3):
self.testElectronID(electron) and
electron.passConversionVeto() and
electron.physObj.gsfTrack().hitPattern().numberOfHits(ROOT.reco.HitPattern.MISSING_INNER_HITS) <= 1 and
electron.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0) < 0.3]
electron.relIso(0.3, dbeta_factor=0.5, all_charged=0) < 0.3]

if len(vOtherLeptons) > 0:
return False
Expand Down Expand Up @@ -233,7 +233,7 @@ def bestDiLepton(self, diLeptons):
if len(diLeptons) == 1:
return diLeptons[0]

least_iso_highest_pt = lambda dl: (dl.leg1().relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0), -dl.leg1().pt(), -dl.leg2().pt())
least_iso_highest_pt = lambda dl: (dl.leg1().relIso(0.3, dbeta_factor=0.5, all_charged=0), -dl.leg1().pt(), -dl.leg2().pt())

return sorted(diLeptons, key=lambda dil : least_iso_highest_pt(dil))[0]

6 changes: 3 additions & 3 deletions H2TauTau/python/proto/analyzers/TauMuAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def testLeg1Iso(self, muon, isocut):
if isocut is None:
isocut = self.cfg_ana.iso2

return muon.relIsoR(R=0.4, dBetaFactor=0.5, allCharged=False) < isocut
return muon.relIso(0.4, dbeta_factor=0.5, all_charged=False) < isocut

def thirdLeptonVeto(self, leptons, otherLeptons, isoCut=0.3):
# count tight muons
Expand Down Expand Up @@ -215,7 +215,7 @@ def otherLeptonVeto(self, leptons, otherLeptons, isoCut=0.3):
self.testElectronID(electron) and
electron.passConversionVeto() and
electron.physObj.gsfTrack().hitPattern().numberOfHits(ROOT.reco.HitPattern.MISSING_INNER_HITS) <= 1 and
electron.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0) < 0.3]
electron.relIso(0.3, dbeta_factor=0.5, all_charged=0) < 0.3]

if len(vOtherLeptons) > 0:
return False
Expand Down Expand Up @@ -259,7 +259,7 @@ def bestDiLepton(self, diLeptons):
if len(diLeptons) == 1:
return diLeptons[0]

least_iso_highest_pt = lambda dl: (dl.leg1().relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0), -dl.leg1().pt(), -dl.leg2().tauID("byIsolationMVArun2v1DBoldDMwLTraw"), -dl.leg2().pt())
least_iso_highest_pt = lambda dl: (dl.leg1().relIso(0.4, dbeta_factor=0.5, all_charged=0), -dl.leg1().pt(), -dl.leg2().tauID("byIsolationMVArun2v1DBoldDMwLTraw"), -dl.leg2().pt())

return sorted(diLeptons, key=lambda dil : least_iso_highest_pt(dil))[0]

4 changes: 2 additions & 2 deletions H2TauTau/python/proto/analyzers/TauTauAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def buildOtherLeptons(self, cmgLeptons, event):
pyl.event = event.input.object()
if not pyl.muonIDMoriond17():
continue
if not pyl.relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0) < 0.3:
if not pyl.relIso(0.4, dbeta_factor=0.5, all_charged=0) < 0.3:
continue
if not self.testLegKine(pyl, ptcut=10, etacut=2.4):
continue
Expand All @@ -185,7 +185,7 @@ def buildLeptons(self, cmgOtherLeptons, event):
pyl.event = event.input.object()
if not pyl.mvaIDRun2('Spring16', 'POG90'):
continue
if not pyl.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0) < 0.3:
if not pyl.relIso(0.3, dbeta_factor=0.5, all_charged=0) < 0.3:
continue
if not self.testLegKine(pyl, ptcut=10, etacut=2.5):
continue
Expand Down
10 changes: 5 additions & 5 deletions H2TauTau/python/proto/analyzers/TreeVariables.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ def default():
Variable('eid_tight', lambda ele : ele.cutBasedId('POG_SPRING15_25ns_v1_Tight')),
Variable('nhits_missing', lambda ele : ele.physObj.gsfTrack().hitPattern().numberOfHits(1), int),
Variable('pass_conv_veto', lambda ele : ele.passConversionVeto()),
Variable('reliso05', lambda lep : lep.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0)),
Variable('reliso05_04', lambda lep : lep.relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0)),
Variable('reliso05_04', lambda lep : lep.relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0)),
Variable('reliso05', lambda lep : lep.relIso(0.3, dbeta_factor=0.5, all_charged=0)),
Variable('reliso05_04', lambda lep : lep.relIso(0.4, dbeta_factor=0.5, all_charged=0)),
Variable('reliso05_04', lambda lep : lep.relIso(0.4, dbeta_factor=0.5, all_charged=0)),
Variable('weight_tracking', lambda lep : getattr(lep, 'weight_tracking', 1.)),
]

# muon
muon_vars = [
Variable('reliso05', lambda lep : lep.relIsoR(R=0.4, dBetaFactor=0.5, allCharged=0)),
Variable('reliso05_03', lambda lep : lep.relIsoR(R=0.3, dBetaFactor=0.5, allCharged=0)),
Variable('reliso05', lambda lep : lep.relIso(0.4, dbeta_factor=0.5, all_charged=0)),
Variable('reliso05_03', lambda lep : lep.relIso(0.3, dbeta_factor=0.5, all_charged=0)),
Variable('muonid_loose', lambda muon : muon.muonID('POG_ID_Loose')),
Variable('muonid_medium', lambda muon : muon.muonID('POG_ID_Medium_ICHEP')),
Variable('muonid_tight', lambda muon : muon.muonID('POG_ID_Tight')),
Expand Down
18 changes: 9 additions & 9 deletions HToZZ4L/python/analyzers/zzTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
# ----------------------
# Extra isolation variables
NTupleVariable("relIsoAfterFSR", lambda x : x.relIsoAfterFSR, help="RelIso after FSR"),
NTupleVariable("chargedHadIso04", lambda x : x.chargedHadronIsoR(0.4), help="PF Abs Iso, R=0.4, charged hadrons only"),
NTupleVariable("neutralHadIso04", lambda x : x.neutralHadronIsoR(0.4), help="PF Abs Iso, R=0.4, neutral hadrons only"),
NTupleVariable("photonIso04", lambda x : x.photonIsoR(0.4), help="PF Abs Iso, R=0.4, photons only"),
NTupleVariable("puChargedHadIso04", lambda x : x.puChargedHadronIsoR(0.4), help="PF Abs Iso, R=0.4, pileup charged hadrons only"),
NTupleVariable("chargedHadIso04", lambda x : x.chargedHadronIso(0.4), help="PF Abs Iso, R=0.4, charged hadrons only"),
NTupleVariable("neutralHadIso04", lambda x : x.neutralHadronIso(0.4), help="PF Abs Iso, R=0.4, neutral hadrons only"),
NTupleVariable("photonIso04", lambda x : x.photonIso(0.4), help="PF Abs Iso, R=0.4, photons only"),
NTupleVariable("puChargedHadIso04", lambda x : x.puChargedHadronIso(0.4), help="PF Abs Iso, R=0.4, pileup charged hadrons only"),
NTupleVariable("rho", lambda x : x.rho, help="rho for isolation"),
NTupleVariable("EffectiveArea04", lambda x : x.EffectiveArea04, help="EA for isolation"),
NTupleVariable("chargedHadIso03", lambda x : x.chargedHadronIsoR(0.3), help="PF Abs Iso, R=0.3, charged hadrons only"),
NTupleVariable("neutralHadIso03", lambda x : x.neutralHadronIsoR(0.3), help="PF Abs Iso, R=0.3, neutral hadrons only"),
NTupleVariable("photonIso03", lambda x : x.photonIsoR(0.3), help="PF Abs Iso, R=0.3, photons only"),
NTupleVariable("puChargedHadIso03", lambda x : x.puChargedHadronIsoR(0.3), help="PF Abs Iso, R=0.3, pileup charged hadrons only"),
NTupleVariable("chargedHadIso03", lambda x : x.chargedHadronIso(0.3), help="PF Abs Iso, R=0.3, charged hadrons only"),
NTupleVariable("neutralHadIso03", lambda x : x.neutralHadronIso(0.3), help="PF Abs Iso, R=0.3, neutral hadrons only"),
NTupleVariable("photonIso03", lambda x : x.photonIso(0.3), help="PF Abs Iso, R=0.3, photons only"),
NTupleVariable("puChargedHadIso03", lambda x : x.puChargedHadronIso(0.3), help="PF Abs Iso, R=0.3, pileup charged hadrons only"),
NTupleVariable("EffectiveArea03", lambda x : x.EffectiveArea03, help="EA for isolation"),
# ----------------------
NTupleVariable("hasFSR", lambda x : len(x.fsrPhotons), int),
Expand Down Expand Up @@ -67,7 +67,7 @@
NTupleVariable("mvaIdSpring15", lambda lepton : lepton.mvaRun2("NonTrigSpring15MiniAOD") if abs(lepton.pdgId()) == 11 else 1, help="EGamma POG MVA ID for non-triggering electrons, Spring15 re-training; 1 for muons"),
# ----------------------
NTupleVariable("relIsoAfterFSR", lambda x : x.relIsoAfterFSR, help="RelIso after FSR"),
NTupleVariable("chargedHadIso03", lambda x : x.chargedHadronIsoR(0.3), help="PF Abs Iso, R=0.3, charged hadrons only"),
NTupleVariable("chargedHadIso03", lambda x : x.chargedHadronIso(0.3), help="PF Abs Iso, R=0.3, charged hadrons only"),
# ----------------------
NTupleVariable("hasOwnFSR", lambda x : len(x.ownFsrPhotons), int),
NTupleSubObject("p4WithFSR", lambda x : x.p4WithFSR(), fourVectorType),
Expand Down
2 changes: 1 addition & 1 deletion TTHAnalysis/python/analyzers/ttHTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
NTupleVariable("miniRelIsoNeutral", lambda x : getattr(x,'miniAbsIsoNeutral',-99)/x.pt()),
NTupleVariable("jetNDauChargedMVASel", lambda lepton : sum((deltaR(x.eta(),x.phi(),lepton.jet.eta(),lepton.jet.phi())<=0.4 and x.charge()!=0 and x.fromPV()>1 and x.hasTrackDetails() and qualityTrk(x.pseudoTrack(),lepton.associatedVertex)) for x in lepton.jet.daughterPtrVector()) if hasattr(lepton,'jet') and lepton.jet != lepton else 0, help="n charged daughters (with selection for ttH lepMVA) of nearest jet"),
# More ID
NTupleVariable("chargedHadRelIso04", lambda x : x.chargedHadronIsoR(0.4)/x.pt(), help="PF Rel Iso, R=0.4, charged hadrons only"),
NTupleVariable("chargedHadRelIso04", lambda x : x.chargedHadronIso(0.4)/x.pt(), help="PF Rel Iso, R=0.4, charged hadrons only"),
NTupleVariable("trackerLayers", lambda x : (x.track() if abs(x.pdgId())==13 else x.gsfTrack()).hitPattern().trackerLayersWithMeasurement(), int, help="Tracker Layers"),
NTupleVariable("pixelLayers", lambda x : (x.track() if abs(x.pdgId())==13 else x.gsfTrack()).hitPattern().pixelLayersWithMeasurement(), int, help="Pixel Layers"),
NTupleVariable("chargeConsistency", lambda lepton : ( lepton.isGsfCtfScPixChargeConsistent() + lepton.isGsfScPixChargeConsistent() ) if abs(lepton.pdgId()) == 11 else abs(lepton.muonBestTrack().charge() + lepton.innerTrack().charge() + lepton.tunePMuonBestTrack().charge() + ( lepton.globalTrack().charge() + lepton.outerTrack().charge() if lepton.isGlobalMuon() else 0) ), int, help="Tight charge criteria: for electrons, 2 if isGsfCtfScPixChargeConsistent, 1 if only isGsfScPixChargeConsistent, 0 otherwise; for muons, absolute value of the sum of all the charges (5 for global-muons, 3 for global muons)"),
Expand Down
Loading

0 comments on commit 385cdb3

Please sign in to comment.