7 #include "TMVA/MethodBase.h"
12 : fMethodname(
"BDTG method"), fisInitialized(kFALSE), fMVAType(kTrig), fUseBinnedVersion(kTRUE), fNMVABins(0) {
28 std::vector<std::string> tempWeightFileVector;
29 tempWeightFileVector.push_back(weightsfile);
30 initialize(methodName, type, kFALSE, tempWeightFileVector);
36 Bool_t useBinnedVersion,
37 std::vector<std::string> weightsfiles) {
52 UInt_t ExpectedNBins = 0;
66 <<
" does not equal to weightsfiles.size() = " << weightsfiles.size() << std::endl;
75 TMVA::Reader *tmpTMVAReader =
new TMVA::Reader(
"!Color:!Silent:Error");
76 tmpTMVAReader->SetVerbose(kTRUE);
92 tmpTMVAReader->AddVariable(
"noZSsee", &
fMVAVar_see);
93 tmpTMVAReader->AddVariable(
"noZSspp", &
fMVAVar_spp);
97 tmpTMVAReader->AddVariable(
"noZSr9", &
fMVAVar_R9);
107 tmpTMVAReader->AddSpectator(
"pt", &
fMVAVar_pt);
114 tmpTMVAReader->AddVariable(
"ele_oldsigmaietaieta", &
fMVAVar_see);
115 tmpTMVAReader->AddVariable(
"ele_oldsigmaiphiiphi", &
fMVAVar_spp);
117 tmpTMVAReader->AddVariable(
"ele_oldr9", &
fMVAVar_R9);
120 tmpTMVAReader->AddVariable(
"ele_he", &
fMVAVar_HoE);
131 tmpTMVAReader->AddVariable(
"ele_ep", &
fMVAVar_EoP);
136 tmpTMVAReader->AddVariable(
"ele_deltaetain", &
fMVAVar_deta);
137 tmpTMVAReader->AddVariable(
"ele_deltaphiin", &
fMVAVar_dphi);
140 tmpTMVAReader->AddSpectator(
"ele_pT", &
fMVAVar_pt);
149 (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length() - strlen(
".xml.gz"))) {
150 gzFile
file = gzopen(weightsfiles[
i].c_str(),
"rb");
151 if (file ==
nullptr) {
152 std::cout <<
"Error opening gzip file associated to " << weightsfiles[
i] << std::endl;
153 throw cms::Exception(
"Configuration",
"Error reading zipped XML file");
155 std::vector<char>
data;
156 data.reserve(1024 * 1024 * 10);
157 unsigned int bufflen = 32 * 1024;
158 char *buff =
reinterpret_cast<char *
>(malloc(bufflen));
159 if (buff ==
nullptr) {
160 std::cout <<
"Error creating buffer for " << weightsfiles[
i] << std::endl;
162 throw cms::Exception(
"Configuration",
"Error reading zipped XML file");
165 while ((read = gzread(file, buff, bufflen)) != 0) {
167 std::cout <<
"Error reading gzip file associated to " << weightsfiles[
i] <<
": " << gzerror(file, &read)
171 throw cms::Exception(
"Configuration",
"Error reading zipped XML file");
173 data.insert(data.end(), buff, buff +
read);
175 if (gzclose(file) != Z_OK) {
176 std::cout <<
"Error closing gzip file associated to " << weightsfiles[
i] << std::endl;
179 data.push_back(
'\0');
180 fTMVAMethod.push_back(dynamic_cast<TMVA::MethodBase *>(tmpTMVAReader->BookMVA(TMVA::Types::kBDT, &data[0])));
182 if (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length() - strlen(
".xml.gz")) {
183 std::cout <<
"Error: xml.gz unsupported for method " <<
fMethodname <<
", weight file " << weightsfiles[
i]
185 throw cms::Exception(
"Configuration",
"Error reading zipped XML file");
190 if (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length() - strlen(
".xml.gz")) {
191 std::cout <<
"Error: xml.gz unsupported for method " <<
fMethodname <<
", weight file " << weightsfiles[
i]
197 std::cout <<
"MVABin " << i <<
" : MethodName = " <<
fMethodname <<
" , type == " << type <<
" , "
198 <<
"Load weights file : " << weightsfiles[
i] << std::endl;
201 std::cout <<
"Electron ID MVA Completed\n";
207 unsigned int bin = 0;
211 if (pt < 10 && fabs(eta) < 1.479)
213 if (pt < 10 && fabs(eta) >= 1.479)
215 if (pt >= 10 && fabs(eta) < 1.479)
217 if (pt >= 10 && fabs(eta) >= 1.479)
223 if (pt >= 10 && fabs(eta) < 1.479)
225 if (pt >= 10 && fabs(eta) >= 1.479)
231 if (pt < 10 && fabs(eta) < 0.8)
233 if (pt < 10 && fabs(eta) >= 0.8 && fabs(eta) < 1.479)
235 if (pt < 10 && fabs(eta) >= 1.479)
237 if (pt >= 10 && fabs(eta) < 0.8)
239 if (pt >= 10 && fabs(eta) >= 0.8 && fabs(eta) < 1.479)
241 if (pt >= 10 && fabs(eta) >= 1.479)
257 std::cout <<
"Error: EGammaMvaEleEstimatorCSA14 not properly initialized.\n";
263 std::cout <<
"Error: This method should be called for kTrig or kNonTrig or kNonTrigPhys14 MVA only" << std::endl;
267 bool validKF =
false;
275 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1.;
277 (validKF) ? myTrackRef->numberOfValidHits() : -1.;
334 const double gsfsign = ((-ele.
gsfTrack()->dxy(vertex.
position())) >= 0) ? 1. : -1.;
339 double ip3d = gsfsign * ip3dpv.second.value();
340 double ip3derr = ip3dpv.second.error();
349 Double_t
mva = -9999;
366 std::cout <<
" ### MVA " << mva << std::endl;
374 std::cout <<
"Error: EGammaMvaEleEstimatorCSA14 not properly initialized.\n";
380 std::cout <<
"Error: This method should be called for kTrig or kNonTrig or kNonTrigPhys14 MVA only" << std::endl;
384 bool validKF =
false;
392 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1.;
394 (validKF) ? myTrackRef->numberOfValidHits() : -1.;
428 Double_t
mva = -9999;
444 <<
" pt " << fMVAVar_pt << std::endl;
445 std::cout <<
" ### MVA " << mva << std::endl;
Float_t fMVAVar_OneMinusE1x5E5x5
void initialize(std::string methodName, std::string weightsfile, EGammaMvaEleEstimatorCSA14::MVAType type)
virtual TrackRef closestCtfTrackRef() const
bool isNonnull() const
Checks for non-null.
~EGammaMvaEleEstimatorCSA14()
std::vector< TMVA::MethodBase * > fTMVAMethod
double pt() const final
transverse momentum
float eSuperClusterOverP() const
float full5x5_e5x5() const
Float_t fMVAVar_PreShowerOverRaw
constexpr bool isNotFinite(T x)
float full5x5_e1x5() const
reco::TrackRef closestCtfTrackRef() const override
override the reco::GsfElectron::closestCtfTrackRef method, to access the internal storage of the trac...
reco::TransientTrack build(const reco::Track *p) const
float full5x5_sigmaIphiIphi() const
reco::GsfTrackRef gsfTrack() const override
override the reco::GsfElectron::gsfTrack method, to access the internal storage of the supercluster ...
reco::SuperClusterRef superCluster() const override
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
Double_t mvaValue(const reco::GsfElectron &ele, const reco::Vertex &vertex, const TransientTrackBuilder &transientTrackBuilder, noZS::EcalClusterLazyTools myEcalCluster, bool printDebug=kFALSE)
constexpr bool isFinite(T x)
const Point & position() const
position
std::vector< TMVA::Reader * > fTMVAReader
float full5x5_sigmaIetaIeta() const
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
float deltaEtaSuperClusterTrackAtVtx() const
double p() const final
magnitude of momentum vector
float hadronicOverEm() const
EGammaMvaEleEstimatorCSA14()
float deltaPhiSuperClusterTrackAtVtx() const
float eEleClusterOverPout() const
Float_t fMVAVar_kfhitsall
Analysis-level electron class.
UInt_t GetMVABin(double eta, double pt) const
float deltaEtaSeedClusterTrackAtCalo() const
char data[epos_bytes_allocation]
SuperClusterRef superCluster() const override
reference to a SuperCluster
Float_t fMVAVar_eleEoPout