28 #include <TMVA/Types.h>
29 #include <TMVA/MethodBase.h>
30 #include "TMVA/Reader.h"
39 using namespace PhysicsTools;
48 ProcTMVA(
const char *
name,
51 virtual ~ProcTMVA() {}
53 virtual void configure(ConfIterator iter,
unsigned int n);
54 virtual void eval(ValueIterator iter,
unsigned int n)
const;
57 std::auto_ptr<TMVA::Reader>
reader;
58 std::auto_ptr<TMVA::MethodBase>
method;
59 std::string methodName;
68 ProcTMVA::ProcTMVA(
const char *
name,
74 reader = std::auto_ptr<TMVA::Reader>(
new TMVA::Reader(
"!Color:Silent" ));
77 reinterpret_cast<const char*>(&calib->
store.front()),
81 std::getline(izs, methodName);
84 std::getline(izs, tmp);
85 std::istringstream iss(tmp);
87 for(
unsigned int i = 0;
i < nVars;
i++) {
88 std::getline(izs, tmp);
89 reader->DataInfo().AddVariable(tmp.c_str());
93 std::string weight_text;
95 while (std::getline(izs, line)) {
102 TMVA::Types::EMVA methodType =
103 TMVA::Types::Instance().GetMethodType(methodName);
105 if (weight_text.find(
"<?xml") != std::string::npos) {
106 method = std::auto_ptr<TMVA::MethodBase>
107 (
dynamic_cast<TMVA::MethodBase*
>
108 (
reader->BookMVA( methodType, weight_text.c_str() ) ) );
111 TString weight_file_name(std::tmpnam(
NULL));
112 std::ofstream weight_file;
113 weight_file.open(weight_file_name.Data());
114 weight_file << weight_text;
116 edm::LogInfo(
"LegacyMVA") <<
"Building legacy TMVA plugin - "
117 <<
"the weights are being stored in " << weight_file_name << std::endl;
118 methodName_t.Append(methodName.c_str());
119 method = std::auto_ptr<TMVA::MethodBase>
120 (
dynamic_cast<TMVA::MethodBase*
>
121 (
reader->BookMVA( methodName_t, weight_file_name ) ) );
122 remove(weight_file_name.Data());
190 void ProcTMVA::configure(ConfIterator iter,
unsigned int n)
195 for(
unsigned int i = 0;
i <
n;
i++)
196 iter++(Variable::FLAG_NONE);
198 iter << Variable::FLAG_NONE;
201 void ProcTMVA::eval(ValueIterator iter,
unsigned int n)
const
203 std::vector<Float_t>
inputs;
205 for(
unsigned int i = 0;
i <
n;
i++)
206 inputs.push_back(*iter++);
207 std::auto_ptr<TMVA::Event> evt(
new TMVA::Event(inputs, 2));
detail::ThreadSafeRegistry< ParameterSetID, ParameterSet, ProcessParameterSetIDCache > Registry
MVATrainerComputer * calib
std::vector< std::vector< double > > tmp
MVA_COMPUTER_DEFINE_PLUGIN(ProcTMVA)