7 #include "TMVA/MethodBase.h" 13 fMethodname(
"BDTG method"),
14 fisInitialized(kFALSE),
16 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
62 UInt_t ExpectedNBins = 0;
77 std::cout <<
"Error: Expected Number of bins = " <<
fNMVABins <<
" does not equal to weightsfiles.size() = " 78 << weightsfiles.size() << std::endl;
88 TMVA::Reader *tmpTMVAReader =
new TMVA::Reader(
"!Color:!Silent:Error" );
89 tmpTMVAReader->SetVerbose(kTRUE);
105 tmpTMVAReader->AddVariable(
"noZSsee", &
fMVAVar_see);
106 tmpTMVAReader->AddVariable(
"noZSspp", &
fMVAVar_spp);
110 tmpTMVAReader->AddVariable(
"noZSr9", &
fMVAVar_R9);
119 tmpTMVAReader->AddSpectator(
"pt", &
fMVAVar_pt);
128 tmpTMVAReader->AddVariable(
"ele_oldsigmaietaieta", &
fMVAVar_see);
129 tmpTMVAReader->AddVariable(
"ele_oldsigmaiphiiphi", &
fMVAVar_spp);
131 tmpTMVAReader->AddVariable(
"ele_oldr9", &
fMVAVar_R9);
134 tmpTMVAReader->AddVariable(
"ele_he", &
fMVAVar_HoE);
144 tmpTMVAReader->AddVariable(
"ele_ep", &
fMVAVar_EoP);
149 tmpTMVAReader->AddVariable(
"ele_deltaetain", &
fMVAVar_deta);
150 tmpTMVAReader->AddVariable(
"ele_deltaphiin", &
fMVAVar_dphi);
155 tmpTMVAReader->AddSpectator(
"ele_pT", &
fMVAVar_pt);
166 if ((
fMethodname.find(
"BDT") == 0) && (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length()-strlen(
".xml.gz"))) {
167 gzFile
file = gzopen(weightsfiles[
i].c_str(),
"rb");
168 if (file ==
nullptr) {
std::cout <<
"Error opening gzip file associated to " << weightsfiles[
i] << std::endl;
throw cms::Exception(
"Configuration",
"Error reading zipped XML file"); }
169 std::vector<char>
data;
170 data.reserve(1024*1024*10);
171 unsigned int bufflen = 32*1024;
172 char *buff =
reinterpret_cast<char *
>(malloc(bufflen));
173 if (buff ==
nullptr) {
std::cout <<
"Error creating buffer for " << weightsfiles[
i] << std::endl; gzclose(file);
throw cms::Exception(
"Configuration",
"Error reading zipped XML file"); }
175 while ((read = gzread(file, buff, bufflen)) != 0) {
176 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"); }
177 data.insert(data.end(), buff, buff+read);
179 if (gzclose(file) != Z_OK) {
std::cout <<
"Error closing gzip file associated to " << weightsfiles[
i] << std::endl; }
181 data.push_back(
'\0');
182 fTMVAMethod.push_back(dynamic_cast<TMVA::MethodBase*>(tmpTMVAReader->BookMVA(TMVA::Types::kBDT, &data[0])));
184 if (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length()-strlen(
".xml.gz")) {
185 std::cout <<
"Error: xml.gz unsupported for method " <<
fMethodname <<
", weight file " << weightsfiles[
i] << std::endl;
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] << std::endl; abort();
196 <<
" , type == " << type <<
" , " 197 <<
"Load weights file : " << weightsfiles[
i]
201 std::cout <<
"Electron ID MVA Completed\n";
210 unsigned int bin = 0;
215 if (pt < 10 && fabs(eta) < 1.479) bin = 0;
216 if (pt < 10 && fabs(eta) >= 1.479) bin = 1;
217 if (pt >= 10 && fabs(eta) < 1.479) bin = 2;
218 if (pt >= 10 && fabs(eta) >= 1.479) bin = 3;
225 if (pt >= 10 && fabs(eta) < 1.479) bin = 0;
226 if (pt >= 10 && fabs(eta) >= 1.479) bin = 1;
231 if (pt < 10 && fabs(eta) < 0.8) bin = 0;
232 if (pt < 10 && fabs(eta) >= 0.8 && fabs(eta) < 1.479) bin = 1;
233 if (pt < 10 && fabs(eta) >= 1.479) bin = 2;
234 if (pt >= 10 && fabs(eta) < 0.8) bin = 3;
235 if (pt >= 10 && fabs(eta) >= 0.8 && fabs(eta) < 1.479) bin = 4;
236 if (pt >= 10 && fabs(eta) >= 1.479) bin = 5;
256 std::cout <<
"Error: EGammaMvaEleEstimatorCSA14 not properly initialized.\n";
261 std::cout <<
"Error: This method should be called for kTrig or kNonTrig or kNonTrigPhys14 MVA only" <<std::endl;
273 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
328 const double gsfsign = ( (-ele.
gsfTrack()->dxy(vertex.
position())) >=0 ) ? 1. : -1.;
333 double ip3d = gsfsign*ip3dpv.second.value();
334 double ip3derr = ip3dpv.second.error();
343 Double_t
mva = -9999;
375 <<
" pt " << fMVAVar_pt <<std::endl;
376 std::cout <<
" ### MVA " << mva <<std::endl;
390 std::cout <<
"Error: EGammaMvaEleEstimatorCSA14 not properly initialized.\n";
395 std::cout <<
"Error: This method should be called for kTrig or kNonTrig or kNonTrigPhys14 MVA only" <<std::endl;
407 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
447 Double_t
mva = -9999;
477 <<
" pt " << fMVAVar_pt <<std::endl;
478 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
constexpr bool isNotFinite(T x)
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)
constexpr bool isFinite(T x)
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