10 """ Electron MVA wrapper class.
13 def __init__(self, name, tag, categoryCuts, xmls, variablesFile, debug=False):
18 self.
xmls = ROOT.vector(ROOT.string)()
19 for x
in xmls: self.xmls.push_back(x)
24 '''returns a tuple mva_value, category
25 ele: a reco::GsfElectron
28 rho: energy density in the event
29 debug: enable debugging mode.
33 event.getByLabel(('slimmedElectrons'), ele_handle)
34 event.getByLabel(('fixedGridRhoFastjetAll'), rho_handle)
36 electrons = ele_handle.product()
37 rho = rho_handle.product()
39 mva, category = electron_mva_id(electron[0], rho)
43 ROOT.gInterpreter.Declare(
'#include "RecoEgamma/ElectronIdentification/interface/ElectronMVAEstimatorRun2.h"')
44 ROOT.gSystem.Load(
"libRecoEgammaElectronIdentification")
45 categoryCutStrings = ROOT.vector(ROOT.string)()
47 categoryCutStrings.push_back(x)
52 category = ctypes.c_int(0)
53 mva = self.estimator.mvaValue(ele, rho[0], category)
54 return mva, category.value
58 '''Working Points. Keeps track of the cuts associated to a given flavour of the MVA ID
59 for each working point and allows to test the working points'''
61 def __init__(self, name, tag, working_points, logistic_transform=False):
68 new_definitions = dict()
69 for wpname, definitions
in working_points.items():
70 new_definitions[wpname] = dict()
71 for name, cut
in definitions.cuts.items():
72 categ_id = int(name.lstrip(
'cutCategory'))
73 cut = cut.replace(
'pt',
'x')
74 formula = ROOT.TFormula(
'_'.
join([self.
name, wpname, name]), cut)
75 new_definitions[wpname][categ_id] = formula
76 return new_definitions
78 def passed(self, ele, mva, category, wp):
79 '''return true if ele passes wp'''
82 mva = 2.0/(1.0+
exp(-2.0*mva))-1
83 return mva > threshold
89 import EleMVA_6CategoriesCuts, mvaVariablesFile, EleMVA_3CategoriesCuts
91 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff \
92 import mvaWeightFiles
as Fall17_iso_V2_weightFiles
93 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff \
94 import mvaWeightFiles
as Fall17_noIso_V2_weightFiles
95 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff \
96 import mvaSpring16WeightFiles_V1
as mvaSpring16GPWeightFiles_V1
97 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff \
98 import mvaSpring16WeightFiles_V1
as mvaSpring16HZZWeightFiles_V1
100 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff \
101 import workingPoints
as mvaSpring16GP_V1_workingPoints
102 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff \
103 import workingPoints
as mvaSpring16HZZ_V1_workingPoints
104 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff \
105 import workingPoints
as Fall17_iso_V2_workingPoints
106 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff \
107 import workingPoints
as Fall17_noIso_V2_workingPoints
112 "Fall17IsoV2" :
ElectronMVAID(
"ElectronMVAEstimatorRun2",
"Fall17IsoV2",
113 EleMVA_6CategoriesCuts, Fall17_iso_V2_weightFiles, mvaVariablesFile),
114 "Fall17NoIsoV2" :
ElectronMVAID(
"ElectronMVAEstimatorRun2",
"Fall17NoIsoV2",
115 EleMVA_6CategoriesCuts, Fall17_noIso_V2_weightFiles, mvaVariablesFile),
116 "Spring16HZZV1" :
ElectronMVAID(
"ElectronMVAEstimatorRun2",
"Spring16HZZV1",
117 EleMVA_6CategoriesCuts, mvaSpring16HZZWeightFiles_V1, mvaVariablesFile),
118 "Spring16GPV1" :
ElectronMVAID(
"ElectronMVAEstimatorRun2",
"Spring16GeneralPurposeV1",
119 EleMVA_3CategoriesCuts, mvaSpring16GPWeightFiles_V1, mvaVariablesFile),
123 "Fall17IsoV2" :
WorkingPoints(
"ElectronMVAEstimatorRun2",
"Fall17IsoV2",
124 Fall17_iso_V2_workingPoints),
125 "Fall17NoIsoV2" :
WorkingPoints(
"ElectronMVAEstimatorRun2",
"Fall17NoIsoV2",
126 Fall17_noIso_V2_workingPoints),
127 "Spring16HZZV1" :
WorkingPoints(
"ElectronMVAEstimatorRun2",
"Spring16HZZV1",
128 mvaSpring16HZZ_V1_workingPoints, logistic_transform=
True),
129 "Spring16GPV1" :
WorkingPoints(
"ElectronMVAEstimatorRun2",
"Spring16GeneralPurposeV1",
130 mvaSpring16GP_V1_workingPoints, logistic_transform=
True),
Exp< T >::type exp(const T &t)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def _reformat_cut_definitions
static std::string join(char **cmd)