29 #include <TMVA/Types.h>
30 #include <TMVA/MethodBase.h>
31 #include "TMVA/Reader.h"
41 #include <boost/filesystem.hpp>
43 using namespace PhysicsTools;
52 ~ProcTMVA()
override {}
54 void configure(ConfIterator iter,
unsigned int n)
override;
55 void eval(ValueIterator iter,
unsigned int n)
const override;
58 std::unique_ptr<TMVA::Reader>
reader;
59 TMVA::MethodBase *method;
71 reader = std::make_unique<TMVA::Reader>(
"!Color:Silent");
76 std::getline(izs, methodName);
79 std::getline(izs, tmp);
80 std::istringstream iss(tmp);
82 for (
unsigned int i = 0;
i <
nVars;
i++) {
83 std::getline(izs, tmp);
84 reader->DataInfo().AddVariable(tmp.c_str());
90 while (std::getline(izs, line)) {
96 TMVA::Types::EMVA methodType = TMVA::Types::Instance().GetMethodType(methodName);
98 if (weight_text.find(
"<?xml") != std::string::npos) {
99 method =
dynamic_cast<TMVA::MethodBase *
>(
reader->BookMVA(methodType, weight_text.c_str()));
102 TString weight_file_name(boost::filesystem::unique_path().c_str());
103 std::ofstream weight_file;
104 weight_file.open(weight_file_name.Data());
105 weight_file << weight_text;
107 edm::LogInfo(
"LegacyMVA") <<
"Building legacy TMVA plugin - "
108 <<
"the weights are being stored in " << weight_file_name << std::endl;
109 methodName_t.Append(methodName.c_str());
110 method =
dynamic_cast<TMVA::MethodBase *
>(
reader->BookMVA(methodName_t, weight_file_name));
111 remove(weight_file_name.Data());
179 void ProcTMVA::configure(ConfIterator iter,
unsigned int n) {
183 for (
unsigned int i = 0;
i <
n;
i++)
184 iter++(Variable::FLAG_NONE);
186 iter << Variable::FLAG_NONE;
189 void ProcTMVA::eval(ValueIterator iter,
unsigned int n)
const {
190 std::vector<Float_t>
inputs;
192 for (
unsigned int i = 0;
i <
n;
i++)
193 inputs.push_back(*iter++);
194 std::unique_ptr<TMVA::Event> evt(
new TMVA::Event(inputs, 2));
196 double result = method->GetMvaValue(evt.get());
#define MVA_COMPUTER_DEFINE_PLUGIN(T)
Log< level::Info, false > LogInfo