7 #include "TMVA/MethodBase.h" 12 fMethodname(
"BDTG method"),
13 fisInitialized(kFALSE),
15 fUseBinnedVersion(kTRUE),
35 std::vector<std::string> tempWeightFileVector;
36 tempWeightFileVector.push_back(weightsfile);
37 initialize(methodName,type,kFALSE,tempWeightFileVector);
44 Bool_t useBinnedVersion,
45 std::vector<std::string> weightsfiles
61 UInt_t ExpectedNBins = 0;
76 std::cout <<
"Error: Expected Number of bins = " <<
fNMVABins <<
" does not equal to weightsfiles.size() = " 77 << weightsfiles.size() << std::endl;
87 TMVA::Reader *tmpTMVAReader =
new TMVA::Reader(
"!Color:!Silent:Error" );
88 tmpTMVAReader->SetVerbose(kTRUE);
104 tmpTMVAReader->AddVariable(
"noZSsee", &
fMVAVar_see);
105 tmpTMVAReader->AddVariable(
"noZSspp", &
fMVAVar_spp);
109 tmpTMVAReader->AddVariable(
"noZSr9", &
fMVAVar_R9);
118 tmpTMVAReader->AddSpectator(
"pt", &
fMVAVar_pt);
127 tmpTMVAReader->AddVariable(
"ele_oldsigmaietaieta", &
fMVAVar_see);
128 tmpTMVAReader->AddVariable(
"ele_oldsigmaiphiiphi", &
fMVAVar_spp);
130 tmpTMVAReader->AddVariable(
"ele_oldr9", &
fMVAVar_R9);
133 tmpTMVAReader->AddVariable(
"ele_he", &
fMVAVar_HoE);
143 tmpTMVAReader->AddVariable(
"ele_ep", &
fMVAVar_EoP);
148 tmpTMVAReader->AddVariable(
"ele_deltaetain", &
fMVAVar_deta);
149 tmpTMVAReader->AddVariable(
"ele_deltaphiin", &
fMVAVar_dphi);
154 tmpTMVAReader->AddSpectator(
"ele_pT", &
fMVAVar_pt);
165 if ((
fMethodname.find(
"BDT") == 0) && (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length()-strlen(
".xml.gz"))) {
166 gzFile
file = gzopen(weightsfiles[
i].c_str(),
"rb");
167 if (file ==
nullptr) {
std::cout <<
"Error opening gzip file associated to " << weightsfiles[
i] << std::endl;
throw cms::Exception(
"Configuration",
"Error reading zipped XML file"); }
168 std::vector<char>
data;
169 data.reserve(1024*1024*10);
170 unsigned int bufflen = 32*1024;
171 char *buff =
reinterpret_cast<char *
>(malloc(bufflen));
172 if (buff ==
nullptr) {
std::cout <<
"Error creating buffer for " << weightsfiles[
i] << std::endl; gzclose(file);
throw cms::Exception(
"Configuration",
"Error reading zipped XML file"); }
174 while ((read = gzread(file, buff, bufflen)) != 0) {
175 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"); }
176 data.insert(data.end(), buff, buff+read);
178 if (gzclose(file) != Z_OK) {
std::cout <<
"Error closing gzip file associated to " << weightsfiles[
i] << std::endl; }
180 data.push_back(
'\0');
181 fTMVAMethod.push_back(dynamic_cast<TMVA::MethodBase*>(tmpTMVAReader->BookMVA(TMVA::Types::kBDT, &data[0])));
183 if (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length()-strlen(
".xml.gz")) {
184 std::cout <<
"Error: xml.gz unsupported for method " <<
fMethodname <<
", weight file " << weightsfiles[
i] << std::endl;
throw cms::Exception(
"Configuration",
"Error reading zipped XML file");
189 if (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length()-strlen(
".xml.gz")) {
190 std::cout <<
"Error: xml.gz unsupported for method " <<
fMethodname <<
", weight file " << weightsfiles[
i] << std::endl; abort();
195 <<
" , type == " << type <<
" , " 196 <<
"Load weights file : " << weightsfiles[
i]
200 std::cout <<
"Electron ID MVA Completed\n";
209 unsigned int bin = 0;
214 if (pt < 10 && fabs(eta) < 1.479) bin = 0;
215 if (pt < 10 && fabs(eta) >= 1.479) bin = 1;
216 if (pt >= 10 && fabs(eta) < 1.479) bin = 2;
217 if (pt >= 10 && fabs(eta) >= 1.479) bin = 3;
224 if (pt >= 10 && fabs(eta) < 1.479) bin = 0;
225 if (pt >= 10 && fabs(eta) >= 1.479) bin = 1;
230 if (pt < 10 && fabs(eta) < 0.8) bin = 0;
231 if (pt < 10 && fabs(eta) >= 0.8 && fabs(eta) < 1.479) bin = 1;
232 if (pt < 10 && fabs(eta) >= 1.479) bin = 2;
233 if (pt >= 10 && fabs(eta) < 0.8) bin = 3;
234 if (pt >= 10 && fabs(eta) >= 0.8 && fabs(eta) < 1.479) bin = 4;
235 if (pt >= 10 && fabs(eta) >= 1.479) bin = 5;
255 std::cout <<
"Error: EGammaMvaEleEstimatorCSA14 not properly initialized.\n";
260 std::cout <<
"Error: This method should be called for kTrig or kNonTrig or kNonTrigPhys14 MVA only" <<std::endl;
272 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
327 const double gsfsign = ( (-ele.
gsfTrack()->dxy(vertex.
position())) >=0 ) ? 1. : -1.;
332 double ip3d = gsfsign*ip3dpv.second.value();
333 double ip3derr = ip3dpv.second.error();
342 Double_t
mva = -9999;
374 <<
" pt " << fMVAVar_pt <<std::endl;
375 std::cout <<
" ### MVA " << mva <<std::endl;
389 std::cout <<
"Error: EGammaMvaEleEstimatorCSA14 not properly initialized.\n";
394 std::cout <<
"Error: This method should be called for kTrig or kNonTrig or kNonTrigPhys14 MVA only" <<std::endl;
406 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
446 Double_t
mva = -9999;
476 <<
" pt " << fMVAVar_pt <<std::endl;
477 std::cout <<
" ### MVA " << mva <<std::endl;
Float_t fMVAVar_OneMinusE1x5E5x5
void initialize(std::string methodName, std::string weightsfile, EGammaMvaEleEstimatorCSA14::MVAType type)
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
virtual TrackRef closestCtfTrackRef() const
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 pt() const final
transverse momentum
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
float full5x5_sigmaIetaIeta() const
float deltaEtaSuperClusterTrackAtVtx() const
float hadronicOverEm() const
EGammaMvaEleEstimatorCSA14()
float deltaPhiSuperClusterTrackAtVtx() const
float eEleClusterOverPout() const
Float_t fMVAVar_kfhitsall
bin
set the eta bin as selection string.
double p() const final
magnitude of momentum vector
Analysis-level electron class.
reco::TrackRef closestCtfTrackRef() const override
override the reco::GsfElectron::closestCtfTrackRef method, to access the internal storage of the trac...
UInt_t GetMVABin(double eta, double pt) const
float deltaEtaSeedClusterTrackAtCalo() const
char data[epos_bytes_allocation]
SuperClusterRef superCluster() const override
reference to a SuperCluster
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...
Float_t fMVAVar_eleEoPout