Skip to content

Commit

Permalink
Merge pull request cms-sw#661 from gpetruc/spring16_mva_ele_id_80X
Browse files Browse the repository at this point in the history
Spring16 MVA electron id
  • Loading branch information
gpetruc committed Jun 29, 2016
2 parents bd04652 + c0fd151 commit 8b40e76
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
4 changes: 4 additions & 0 deletions PhysicsTools/Heppy/python/analyzers/objects/LeptonAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ def makeAllElectrons(self, event):
for ele in allelectrons:
ele.associatedVertex = goodVertices[0] if len(goodVertices)>0 else event.vertices[0]

# Attach the event (for MVA Id)
for ele in allelectrons:
ele.event = event.input.object()

# Compute relIso with R=0.3 and R=0.4 cones
for ele in allelectrons:
if self.cfg_ana.ele_isoCorr=="rhoArea" :
Expand Down
30 changes: 23 additions & 7 deletions PhysicsTools/Heppy/python/physicsobjects/Electron.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def electronID( self, id, vertex=None, rho=None ):
elif id == "POG_MVA_ID_Spring15_NonTrig_Tight": return self.mvaIDRun2("NonTrigSpring15MiniAOD","Tight")
elif id == "MVA_ID_NonTrig_Phys14Fix_HZZ": return self.mvaIDRun2("NonTrigPhys14Fix","HZZ")
elif id == "MVA_ID_NonTrig_Spring15_HZZ": return self.mvaIDRun2("NonTrigSpring15MiniAOD","HZZ")
elif id == "MVA_ID_NonTrig_Spring16_HZZ": return self.mvaIDRun2("Spring16","HZZ")
elif id.startswith("POG_Cuts_ID_"):
return self.cutBasedId(id.replace("POG_Cuts_ID_","POG_"))
for ID in self.electronIDs():
Expand Down Expand Up @@ -204,13 +205,17 @@ def mvaRun2( self, name, debug = False ):
self._mvaRun2[name] = self.physObj.userFloat("ElectronMVAEstimatorRun2Spring15NonTrig25nsV1Values")
return self._mvaRun2[name]
if name not in ElectronMVAID_ByName: raise RuntimeError, "Unknown electron run2 mva id %s (known ones are: %s)\n" % (name, ElectronMVAID_ByName.keys())
if self.associatedVertex == None: raise RuntimeError, "You need to set electron.associatedVertex before calling any MVA"
if self.rho == None: raise RuntimeError, "You need to set electron.rho before calling any MVA"
# -v---- below is correct in Heppy 74X, but probably not functional anyway
self._mvaRun2[name] = ElectronMVAID_ByName[name](self.physObj, self.associatedVertex, self.rho, True, debug)
# -v---- below would be correct for CMGTools 74X witht the updated Spring15 MVA electron ID
#if self.event == None: raise RuntimeError, "You need to set electron.event before calling any MVA"
#self._mvaRun2[name] = ElectronMVAID_ByName[name](self.physObj, self.associatedVertex, self.event, self.rho, True, debug)
if name in ("Spring16",):
if self.event == None: raise RuntimeError, "You need to set electron.event before calling any new MVA"
self._mvaRun2[name] = ElectronMVAID_ByName[name](self.physObj, self.event, self.associatedVertex, self.rho, debug)
else:
if self.associatedVertex == None: raise RuntimeError, "You need to set electron.associatedVertex before calling any MVA"
if self.rho == None: raise RuntimeError, "You need to set electron.rho before calling any MVA"
# -v---- below is correct in Heppy 74X, but probably not functional anyway
self._mvaRun2[name] = ElectronMVAID_ByName[name](self.physObj, self.associatedVertex, self.rho, True, debug)
# -v---- below would be correct for CMGTools 74X witht the updated Spring15 MVA electron ID
#if self.event == None: raise RuntimeError, "You need to set electron.event before calling any MVA"
#self._mvaRun2[name] = ElectronMVAID_ByName[name](self.physObj, self.associatedVertex, self.event, self.rho, True, debug)
return self._mvaRun2[name]

def mvaIDTight(self, full5x5=False):
Expand Down Expand Up @@ -312,6 +317,17 @@ def mvaIDRun2(self, name, wp):
elif eta < 1.479: return self.mvaRun2(name) > -0.235222
else: return self.mvaRun2(name) > -0.67099
else: raise RuntimeError, "Ele MVA ID Working point not found"
elif name == "Spring16":
if wp == "HZZ":
if self.pt() <= 10:
if eta < 0.8 : return self.mvaRun2(name) > -0.211;
elif eta < 1.479: return self.mvaRun2(name) > -0.396;
else : return self.mvaRun2(name) > -0.215;
else:
if eta < 0.8 : return self.mvaRun2(name) > -0.870;
elif eta < 1.479: return self.mvaRun2(name) > -0.838;
else : return self.mvaRun2(name) > -0.763;
else: raise RuntimeError, "Ele MVA ID Working point not found"
else: raise RuntimeError, "Ele MVA ID type not found"


Expand Down
26 changes: 26 additions & 0 deletions PhysicsTools/Heppy/python/physicsutils/ElectronMVAID.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ def __call__(self,ele,vtx,rho,full5x5=False,debug=False):
self._init = True
return self.estimator.mvaValue(ele,vtx,rho,full5x5,debug)

class ElectronMVAID_Spring16:
def __init__(self,name,tag,*xmls):
self.name = name
self.tag = tag
self.sxmls = ROOT.vector(ROOT.string)()
for x in xmls: self.sxmls.push_back(x)
self._init = False
def __call__(self,ele,event,vtx,rho,debug=False):
if not self._init:
ROOT.gSystem.Load("libRecoEgammaElectronIdentification")
self.estimator = ROOT.ElectronMVAEstimatorRun2Spring16(self.tag)
self.estimator.init(self.sxmls)
self._init = True
return self.estimator.mvaValue(ele,event)



ElectronMVAID_Trig = ElectronMVAID("BDT", "Trig",
"EgammaAnalysis/ElectronTools/data/Electrons_BDTG_TrigV0_Cat1.weights.xml.gz",
"EgammaAnalysis/ElectronTools/data/Electrons_BDTG_TrigV0_Cat2.weights.xml.gz",
Expand Down Expand Up @@ -76,6 +93,14 @@ def __call__(self,ele,vtx,rho,full5x5=False,debug=False):
"EgammaAnalysis/ElectronTools/data/PHYS14/EIDmva_EB2_10_oldscenario2phys14_BDT.weights.xml.gz",
"EgammaAnalysis/ElectronTools/data/PHYS14/EIDmva_EE_10_oldscenario2phys14_BDT.weights.xml.gz",
)
ElectronMVAID_Spring16 = ElectronMVAID_Spring16("ElectronMVAEstimatorRun2Spring16V1","V1",
"RecoEgamma/ElectronIdentification/data/Spring16/EIDmva_EB1_5_oldNT_PROPER_Spring16_DY_v1_BDT.weights.xml",
"RecoEgamma/ElectronIdentification/data/Spring16/EIDmva_EB2_5_oldNT_PROPER_Spring16_DY_v1_BDT.weights.xml",
"RecoEgamma/ElectronIdentification/data/Spring16/EIDmva_EE_5_oldNT_PROPER_Spring16_DY_v1_BDT.weights.xml",
"RecoEgamma/ElectronIdentification/data/Spring16/EIDmva_EB1_10_oldNT_PROPER_Spring16_DY_v1_BDT.weights.xml",
"RecoEgamma/ElectronIdentification/data/Spring16/EIDmva_EB2_10_oldNT_PROPER_Spring16_DY_v1_BDT.weights.xml",
"RecoEgamma/ElectronIdentification/data/Spring16/EIDmva_EE_10_oldNT_PROPER_Spring16_DY_v1_BDT.weights.xml"
)

ElectronMVAID_ByName = {
'Trig':ElectronMVAID_Trig,
Expand All @@ -86,4 +111,5 @@ def __call__(self,ele,vtx,rho,full5x5=False,debug=False):
'NonTrigCSA14bx25':ElectronMVAID_NonTrigCSA14bx25,
'NonTrigCSA14bx50':ElectronMVAID_NonTrigCSA14bx50,
'NonTrigPhys14':ElectronMVAID_NonTrigPhys14,
'Spring16':ElectronMVAID_Spring16,
}

0 comments on commit 8b40e76

Please sign in to comment.