7 #include "TMVA/MethodBase.h"
12 fMethodname(
"BDTG method"),
13 fisInitialized(kFALSE),
15 fUseBinnedVersion(kTRUE),
36 std::vector<std::string> tempWeightFileVector;
37 tempWeightFileVector.push_back(weightsfile);
38 initialize(methodName,type,kFALSE,tempWeightFileVector);
45 Bool_t useBinnedVersion,
46 std::vector<std::string> weightsfiles
63 UInt_t ExpectedNBins = 0;
78 std::cout <<
"Error: Expected Number of bins = " <<
fNMVABins <<
" does not equal to weightsfiles.size() = "
79 << weightsfiles.size() << std::endl;
89 TMVA::Reader *tmpTMVAReader =
new TMVA::Reader(
"!Color:!Silent:Error" );
90 tmpTMVAReader->SetVerbose(kTRUE);
106 tmpTMVAReader->AddVariable(
"noZSsee", &
fMVAVar_see);
107 tmpTMVAReader->AddVariable(
"noZSspp", &
fMVAVar_spp);
111 tmpTMVAReader->AddVariable(
"noZSr9", &
fMVAVar_R9);
120 tmpTMVAReader->AddSpectator(
"pt", &
fMVAVar_pt);
129 tmpTMVAReader->AddVariable(
"ele_oldsigmaietaieta", &
fMVAVar_see);
130 tmpTMVAReader->AddVariable(
"ele_oldsigmaiphiiphi", &
fMVAVar_spp);
132 tmpTMVAReader->AddVariable(
"ele_oldr9", &
fMVAVar_R9);
135 tmpTMVAReader->AddVariable(
"ele_he", &
fMVAVar_HoE);
145 tmpTMVAReader->AddVariable(
"ele_ep", &
fMVAVar_EoP);
150 tmpTMVAReader->AddVariable(
"ele_deltaetain", &
fMVAVar_deta);
151 tmpTMVAReader->AddVariable(
"ele_deltaphiin", &
fMVAVar_dphi);
156 tmpTMVAReader->AddSpectator(
"ele_pT", &
fMVAVar_pt);
167 if ((
fMethodname.find(
"BDT") == 0) && (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length()-strlen(
".xml.gz"))) {
168 gzFile
file = gzopen(weightsfiles[
i].c_str(),
"rb");
169 if (file ==
nullptr) {
std::cout <<
"Error opening gzip file associated to " << weightsfiles[
i] << std::endl;
throw cms::Exception(
"Configuration",
"Error reading zipped XML file"); }
170 std::vector<char>
data;
171 data.reserve(1024*1024*10);
172 unsigned int bufflen = 32*1024;
173 char *buff =
reinterpret_cast<char *
>(malloc(bufflen));
174 if (buff ==
nullptr) {
std::cout <<
"Error creating buffer for " << weightsfiles[
i] << std::endl; gzclose(file);
throw cms::Exception(
"Configuration",
"Error reading zipped XML file"); }
176 while ((read = gzread(file, buff, bufflen)) != 0) {
177 if (read == -1) {
std::cout <<
"Error reading gzip file associated to " << weightsfiles[
i] <<
": " << gzerror(file,&read) << std::endl; gzclose(file); free(buff);
throw cms::Exception(
"Configuration",
"Error reading zipped XML file"); }
178 data.insert(data.end(), buff, buff+
read);
180 if (gzclose(file) != Z_OK) {
std::cout <<
"Error closing gzip file associated to " << weightsfiles[
i] << std::endl; }
182 data.push_back(
'\0');
183 fTMVAMethod.push_back(dynamic_cast<TMVA::MethodBase*>(tmpTMVAReader->BookMVA(TMVA::Types::kBDT, &data[0])));
185 if (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length()-strlen(
".xml.gz")) {
186 std::cout <<
"Error: xml.gz unsupported for method " <<
fMethodname <<
", weight file " << weightsfiles[
i] << std::endl;
throw cms::Exception(
"Configuration",
"Error reading zipped XML file");
191 if (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length()-strlen(
".xml.gz")) {
192 std::cout <<
"Error: xml.gz unsupported for method " <<
fMethodname <<
", weight file " << weightsfiles[
i] << std::endl; abort();
197 <<
" , type == " << type <<
" , "
198 <<
"Load weights file : " << weightsfiles[
i]
202 std::cout <<
"Electron ID MVA Completed\n";
211 unsigned int bin = 0;
216 if (pt < 10 && fabs(eta) < 1.479) bin = 0;
217 if (pt < 10 && fabs(eta) >= 1.479) bin = 1;
218 if (pt >= 10 && fabs(eta) < 1.479) bin = 2;
219 if (pt >= 10 && fabs(eta) >= 1.479) bin = 3;
226 if (pt >= 10 && fabs(eta) < 1.479) bin = 0;
227 if (pt >= 10 && fabs(eta) >= 1.479) bin = 1;
232 if (pt < 10 && fabs(eta) < 0.8) bin = 0;
233 if (pt < 10 && fabs(eta) >= 0.8 && fabs(eta) < 1.479) bin = 1;
234 if (pt < 10 && fabs(eta) >= 1.479) bin = 2;
235 if (pt >= 10 && fabs(eta) < 0.8) bin = 3;
236 if (pt >= 10 && fabs(eta) >= 0.8 && fabs(eta) < 1.479) bin = 4;
237 if (pt >= 10 && fabs(eta) >= 1.479) bin = 5;
257 std::cout <<
"Error: EGammaMvaEleEstimatorCSA14 not properly initialized.\n";
262 std::cout <<
"Error: This method should be called for kTrig or kNonTrig or kNonTrigPhys14 MVA only" <<std::endl;
274 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
329 const double gsfsign = ( (-ele.
gsfTrack()->dxy(vertex.
position())) >=0 ) ? 1. : -1.;
334 double ip3d = gsfsign*ip3dpv.second.value();
335 double ip3derr = ip3dpv.second.error();
344 Double_t
mva = -9999;
376 <<
" pt " << fMVAVar_pt <<std::endl;
377 std::cout <<
" ### MVA " << mva <<std::endl;
391 std::cout <<
"Error: EGammaMvaEleEstimatorCSA14 not properly initialized.\n";
396 std::cout <<
"Error: This method should be called for kTrig or kNonTrig or kNonTrigPhys14 MVA only" <<std::endl;
408 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
448 Double_t
mva = -9999;
478 <<
" pt " << fMVAVar_pt <<std::endl;
479 std::cout <<
" ### MVA " << mva <<std::endl;
Float_t fMVAVar_OneMinusE1x5E5x5
void initialize(std::string methodName, std::string weightsfile, EGammaMvaEleEstimatorCSA14::MVAType type)
bool isNonnull() const
Checks for non-null.
~EGammaMvaEleEstimatorCSA14()
std::vector< TMVA::MethodBase * > fTMVAMethod
float eSuperClusterOverP() const
float full5x5_e5x5() const
Float_t fMVAVar_PreShowerOverRaw
float full5x5_e1x5() const
reco::TransientTrack build(const reco::Track *p) const
float full5x5_sigmaIphiIphi() const
Double_t mvaValue(const reco::GsfElectron &ele, const reco::Vertex &vertex, const TransientTrackBuilder &transientTrackBuilder, noZS::EcalClusterLazyTools myEcalCluster, bool printDebug=kFALSE)
const Point & position() const
position
std::vector< TMVA::Reader * > fTMVAReader
TrackRef closestCtfTrackRef() const
float full5x5_sigmaIetaIeta() const
reco::SuperClusterRef superCluster() const
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
float deltaEtaSuperClusterTrackAtVtx() const
float hadronicOverEm() const
reco::GsfTrackRef gsfTrack() const
override the reco::GsfElectron::gsfTrack method, to access the internal storage of the supercluster ...
EGammaMvaEleEstimatorCSA14()
reco::TrackRef closestCtfTrackRef() const
override the reco::GsfElectron::closestCtfTrackRef method, to access the internal storage of the trac...
virtual SuperClusterRef superCluster() const
reference to a SuperCluster
float deltaPhiSuperClusterTrackAtVtx() const
float eEleClusterOverPout() const
Float_t fMVAVar_kfhitsall
Analysis-level electron class.
virtual double p() const final
magnitude of momentum vector
UInt_t GetMVABin(double eta, double pt) const
float deltaEtaSeedClusterTrackAtCalo() const
char data[epos_bytes_allocation]
Float_t fMVAVar_eleEoPout
virtual GsfTrackRef gsfTrack() const
reference to a GsfTrack
virtual double pt() const final
transverse momentum