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)
23 def __call__(self, ele, convs, beam_spot, rho, debug=False):
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) 35 event.getByLabel(('reducedEgamma:reducedConversions'), conv_handle) 36 event.getByLabel(('offlineBeamSpot'), bs_handle) 38 electrons = ele_handle.product() 39 convs = conv_handle.product() 40 beam_spot = bs_handle.product() 41 rho = rho_handle.product() 43 mva, category = electron_mva_id(electron[0], convs, beam_spot, rho) 47 ROOT.gSystem.Load(
"libRecoEgammaElectronIdentification")
48 categoryCutStrings = ROOT.vector(ROOT.string)()
50 categoryCutStrings.push_back(x)
55 extra_vars = self.estimator.getExtraVars(ele, convs, beam_spot, rho[0])
56 category = ctypes.c_int(0)
57 mva = self.estimator.mvaValue(ele, extra_vars, category)
58 return mva, category.value
62 '''Working Points. Keeps track of the cuts associated to a given flavour of the MVA ID 63 for each working point and allows to test the working points''' 65 def __init__(self, name, tag, working_points, logistic_transform=False):
72 new_definitions =
dict()
73 for wpname, definitions
in working_points.iteritems():
74 new_definitions[wpname] =
dict()
75 for name, cut
in definitions.cuts.iteritems():
76 categ_id =
int(name.lstrip(
'cutCategory'))
77 cut = cut.replace(
'pt',
'x')
78 formula = ROOT.TFormula(
'_'.
join([self.
name, wpname, name]), cut)
79 new_definitions[wpname][categ_id] = formula
80 return new_definitions
82 def passed(self, ele, mva, category, wp):
83 '''return true if ele passes wp''' 86 mva = 2.0/(1.0+
exp(-2.0*mva))-1
87 return mva > threshold
93 import EleMVA_6CategoriesCuts, mvaVariablesFile, EleMVA_3CategoriesCuts
95 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff \
96 import mvaWeightFiles
as Fall17_iso_V2_weightFiles
97 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff \
98 import mvaWeightFiles
as Fall17_noIso_V2_weightFiles
99 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff \
100 import mvaSpring16WeightFiles_V1
as mvaSpring16GPWeightFiles_V1
101 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff \
102 import mvaSpring16WeightFiles_V1
as mvaSpring16HZZWeightFiles_V1
104 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff \
105 import workingPoints
as mvaSpring16GP_V1_workingPoints
106 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff \
107 import workingPoints
as mvaSpring16HZZ_V1_workingPoints
108 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff \
109 import workingPoints
as Fall17_iso_V2_workingPoints
110 from RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff \
111 import workingPoints
as Fall17_noIso_V2_workingPoints
116 "Fall17IsoV2" :
ElectronMVAID(
"ElectronMVAEstimatorRun2",
"Fall17IsoV2",
117 EleMVA_6CategoriesCuts, Fall17_iso_V2_weightFiles, mvaVariablesFile),
118 "Fall17NoIsoV2" :
ElectronMVAID(
"ElectronMVAEstimatorRun2",
"Fall17NoIsoV2",
119 EleMVA_6CategoriesCuts, Fall17_noIso_V2_weightFiles, mvaVariablesFile),
120 "Spring16HZZV1" :
ElectronMVAID(
"ElectronMVAEstimatorRun2",
"Spring16HZZV1",
121 EleMVA_6CategoriesCuts, mvaSpring16HZZWeightFiles_V1, mvaVariablesFile),
122 "Spring16GPV1" :
ElectronMVAID(
"ElectronMVAEstimatorRun2",
"Spring16GeneralPurposeV1",
123 EleMVA_3CategoriesCuts, mvaSpring16GPWeightFiles_V1, mvaVariablesFile),
127 "Fall17IsoV2" :
WorkingPoints(
"ElectronMVAEstimatorRun2",
"Fall17IsoV2",
128 Fall17_iso_V2_workingPoints),
129 "Fall17NoIsoV2" :
WorkingPoints(
"ElectronMVAEstimatorRun2",
"Fall17NoIsoV2",
130 Fall17_noIso_V2_workingPoints),
131 "Spring16HZZV1" :
WorkingPoints(
"ElectronMVAEstimatorRun2",
"Spring16HZZV1",
132 mvaSpring16HZZ_V1_workingPoints, logistic_transform=
True),
133 "Spring16GPV1" :
WorkingPoints(
"ElectronMVAEstimatorRun2",
"Spring16GeneralPurposeV1",
134 mvaSpring16GP_V1_workingPoints, logistic_transform=
True),
S & print(S &os, JobReport::InputFile const &f)
def __call__(self, ele, convs, beam_spot, rho, debug=False)
static std::string join(char **cmd)
def _reformat_cut_definitions(self, working_points)
def __init__(self, name, tag, categoryCuts, xmls, variablesFile, debug=False)
def __init__(self, name, tag, working_points, logistic_transform=False)
def passed(self, ele, mva, category, wp)