Belle II Software development
TMVA.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <mva/methods/TMVA.h>
10#include <framework/logging/Logger.h>
11#include <framework/utilities/MakeROOTCompatible.h>
12#include <framework/utilities/ScopeGuard.h>
13
14#include <TPluginManager.h>
15
16#include <boost/algorithm/string.hpp>
17#include <filesystem>
18#include <memory>
19
20namespace Belle2 {
25 namespace MVA {
26
27 void TMVAOptions::load(const boost::property_tree::ptree& pt)
28 {
29 int version = pt.get<int>("TMVA_version");
30 if (version != 1) {
31 B2ERROR("Unknown weightfile version " << std::to_string(version));
32 throw std::runtime_error("Unknown weightfile version " + std::to_string(version));
33 }
34 m_method = pt.get<std::string>("TMVA_method");
35 m_type = pt.get<std::string>("TMVA_type");
36 m_config = pt.get<std::string>("TMVA_config");
37 m_factoryOption = pt.get<std::string>("TMVA_factoryOption");
38 m_prepareOption = pt.get<std::string>("TMVA_prepareOption");
39 m_workingDirectory = pt.get<std::string>("TMVA_workingDirectory");
40 m_prefix = pt.get<std::string>("TMVA_prefix");
41 }
42
43 void TMVAOptions::save(boost::property_tree::ptree& pt) const
44 {
45 pt.put("TMVA_version", 1);
46 pt.put("TMVA_method", m_method);
47 pt.put("TMVA_type", m_type);
48 pt.put("TMVA_config", m_config);
49 pt.put("TMVA_factoryOption", m_factoryOption);
50 pt.put("TMVA_prepareOption", m_prepareOption);
51 pt.put("TMVA_workingDirectory", m_workingDirectory);
52 pt.put("TMVA_prefix", m_prefix);
53 }
54
55 po::options_description TMVAOptions::getDescription()
56 {
57 po::options_description description("TMVA options");
58 description.add_options()
59 ("tmva_method", po::value<std::string>(&m_method), "TMVA Method Name")
60 ("tmva_type", po::value<std::string>(&m_type), "TMVA Method Type (e.g. Plugin, BDT, ...)")
61 ("tmva_config", po::value<std::string>(&m_config), "TMVA Configuration string for the method")
62 ("tmva_working_directory", po::value<std::string>(&m_workingDirectory), "TMVA working directory which stores e.g. TMVA.root")
63 ("tmva_factory", po::value<std::string>(&m_factoryOption), "TMVA Factory options passed to TMVAFactory constructor")
64 ("tmva_prepare", po::value<std::string>(&m_prepareOption),
65 "TMVA Prepare options passed to prepareTrainingAndTestTree function");
66 return description;
67 }
68
69 void TMVAOptionsClassification::load(const boost::property_tree::ptree& pt)
70 {
72 transform2probability = pt.get<bool>("TMVA_transform2probability");
73 }
74
75 void TMVAOptionsClassification::save(boost::property_tree::ptree& pt) const
76 {
78 pt.put("TMVA_transform2probability", transform2probability);
79 }
80
82 {
83 po::options_description description = TMVAOptions::getDescription();
84 description.add_options()
85 ("tmva_transform2probability", po::value<bool>(&transform2probability), "TMVA Transform output of classifier to a probability");
86 return description;
87 }
88
89 void TMVAOptionsMulticlass::load(const boost::property_tree::ptree& pt)
90 {
92
93 unsigned int numberOfClasses = pt.get<unsigned int>("TMVA_number_classes", 1);
94 m_classes.resize(numberOfClasses);
95 for (unsigned int i = 0; i < numberOfClasses; ++i) {
96 m_classes[i] = pt.get<std::string>(std::string("TMVA_classes") + std::to_string(i));
97 }
98 }
99
100 void TMVAOptionsMulticlass::save(boost::property_tree::ptree& pt) const
101 {
103
104 pt.put("TMVA_number_classes", m_classes.size());
105 for (unsigned int i = 0; i < m_classes.size(); ++i) {
106 pt.put(std::string("TMVA_classes") + std::to_string(i), m_classes[i]);
107 }
108 }
109
111 {
112 po::options_description description = TMVAOptions::getDescription();
113 description.add_options()
114 ("tmva_classes", po::value<std::vector<std::string>>(&m_classes)->required()->multitoken(),
115 "class name identifiers for multi-class mode");
116 return description;
117 }
118
119 TMVATeacher::TMVATeacher(const GeneralOptions& general_options, const TMVAOptions& _specific_options) : Teacher(general_options),
120 specific_options(_specific_options) { }
121
122 Weightfile TMVATeacher::trainFactory(TMVA::Factory& factory, TMVA::DataLoader& data_loader, const std::string& jobName) const
123 {
124 data_loader.PrepareTrainingAndTestTree("", specific_options.m_prepareOption);
125
126 if (specific_options.m_type == "Plugins") {
127 auto base = std::string("TMVA@@MethodBase");
128 auto regexp1 = std::string(".*_") + specific_options.m_method + std::string(".*");
129 auto regexp2 = std::string(".*") + specific_options.m_method + std::string(".*");
130 auto className = std::string("TMVA::Method") + specific_options.m_method;
131 auto ctor1 = std::string("Method") + specific_options.m_method + std::string("(TMVA::DataSetInfo&,TString)");
132 auto ctor2 = std::string("Method") + specific_options.m_method + std::string("(TString&,TString&,TMVA::DataSetInfo&,TString&)");
133 auto pluginName = std::string("TMVA") + specific_options.m_method;
134
135 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp1.c_str(), className.c_str(), pluginName.c_str(), ctor1.c_str());
136 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp2.c_str(), className.c_str(), pluginName.c_str(), ctor2.c_str());
137 }
138
139 if (!factory.BookMethod(&data_loader, specific_options.m_type, specific_options.m_method, specific_options.m_config)) {
140 B2ERROR("TMVA Method with name " + specific_options.m_method + " cannot be booked.");
141 }
142
143 Weightfile weightfile;
144 std::string logfilename = weightfile.generateFileName(".log");
145
146 // Pipe stdout into a logfile to get TMVA output, which contains valuable information
147 // which cannot be retrieved otherwise!
148 // Hence we do some black magic here
149 // TODO Using ROOT_VERSION 6.08 this should be possible without this workaround
150 auto logfile = open(logfilename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
151 auto saved_stdout = dup(STDOUT_FILENO);
152 dup2(logfile, 1);
153
154 factory.TrainAllMethods();
155 factory.TestAllMethods();
156 factory.EvaluateAllMethods();
157
158 // Reset original output
159 dup2(saved_stdout, STDOUT_FILENO);
160 close(saved_stdout);
161 close(logfile);
162
163
164 weightfile.addOptions(m_general_options);
165 weightfile.addFile("TMVA_Weightfile", std::string("TMVA/weights/") + jobName + "_" + specific_options.m_method + ".weights.xml");
166 weightfile.addFile("TMVA_Logfile", logfilename);
167
168 // We have to parse the TMVA output to get the feature importances, there is no other way currently
169 std::string begin = "Ranking input variables (method specific)";
170 std::string end = "-----------------------------------";
171 std::string line;
172 std::ifstream file(logfilename, std::ios::in);
173 std::map<std::string, float> feature_importances;
174 int state = 0;
175 while (std::getline(file, line)) {
176 if (state == 0 && line.find(begin) != std::string::npos) {
177 state = 1;
178 continue;
179 }
180 if (state >= 1 and state <= 4) {
181 state++;
182 continue;
183 }
184 if (state == 5) {
185 if (line.find(end) != std::string::npos)
186 break;
187 std::vector<std::string> strs;
188 boost::split(strs, line, boost::is_any_of(":"));
189 std::string variable = strs[2];
190 boost::trim(variable);
192 float importance = std::stof(strs[3]);
193 feature_importances[variable] = importance;
194 }
195 }
196 weightfile.addFeatureImportance(feature_importances);
197
198 return weightfile;
199
200 }
201
202
204 const TMVAOptionsClassification& _specific_options) : TMVATeacher(general_options, _specific_options),
205 specific_options(_specific_options) { }
206
208 {
209
210 unsigned int numberOfFeatures = training_data.getNumberOfFeatures();
211 unsigned int numberOfSpectators = training_data.getNumberOfSpectators();
212 unsigned int numberOfEvents = training_data.getNumberOfEvents();
213
214 std::string directory = specific_options.m_workingDirectory;
215 if (specific_options.m_workingDirectory.empty()) {
216 char* directory_template = strdup((std::filesystem::temp_directory_path() / "Basf2TMVA.XXXXXX").c_str());
217 directory = mkdtemp(directory_template);
218 free(directory_template);
219 }
220
221 auto guard = ScopeGuard::guardWorkingDirectory(directory);
222
223 std::string jobName = specific_options.m_prefix;
224 if (jobName.empty())
225 jobName = "TMVA";
226 TFile classFile((jobName + ".root").c_str(), "RECREATE");
227 classFile.cd();
228
229 TMVA::Tools::Instance();
230 TMVA::DataLoader data_loader(jobName);
231 TMVA::Factory factory(jobName, &classFile, specific_options.m_factoryOption);
232
233
234 // Add variables to the factory
235 for (const auto& var : m_general_options.m_variables) {
236 data_loader.AddVariable(Belle2::MakeROOTCompatible::makeROOTCompatible(var));
237 }
238
239 // Add variables to the factory
240 for (const auto& var : m_general_options.m_spectators) {
241 data_loader.AddSpectator(Belle2::MakeROOTCompatible::makeROOTCompatible(var));
242 }
243
244 data_loader.SetWeightExpression(Belle2::MakeROOTCompatible::makeROOTCompatible(m_general_options.m_weight_variable));
245
246 auto* signal_tree = new TTree("signal_tree", "signal_tree");
247 auto* background_tree = new TTree("background_tree", "background_tree");
248
249 for (unsigned int iFeature = 0; iFeature < numberOfFeatures; ++iFeature) {
250 signal_tree->Branch(Belle2::MakeROOTCompatible::makeROOTCompatible(m_general_options.m_variables[iFeature]).c_str(),
251 &training_data.m_input[iFeature]);
252 background_tree->Branch(Belle2::MakeROOTCompatible::makeROOTCompatible(m_general_options.m_variables[iFeature]).c_str(),
253 &training_data.m_input[iFeature]);
254 }
255
256 for (unsigned int iSpectator = 0; iSpectator < numberOfSpectators; ++iSpectator) {
257 signal_tree->Branch(Belle2::MakeROOTCompatible::makeROOTCompatible(m_general_options.m_spectators[iSpectator]).c_str(),
258 &training_data.m_spectators[iSpectator]);
259 background_tree->Branch(Belle2::MakeROOTCompatible::makeROOTCompatible(m_general_options.m_spectators[iSpectator]).c_str(),
260 &training_data.m_spectators[iSpectator]);
261 }
262
263 signal_tree->Branch("__weight__", &training_data.m_weight);
264 background_tree->Branch("__weight__", &training_data.m_weight);
265
266 for (unsigned int iEvent = 0; iEvent < numberOfEvents; ++iEvent) {
267 training_data.loadEvent(iEvent);
268 if (training_data.m_isSignal) {
269 signal_tree->Fill();
270 } else {
271 background_tree->Fill();
272 }
273 }
274
275 data_loader.AddSignalTree(signal_tree);
276 data_loader.AddBackgroundTree(background_tree);
277 auto weightfile = trainFactory(factory, data_loader, jobName);
278
279 weightfile.addOptions(specific_options);
280 weightfile.addSignalFraction(training_data.getSignalFraction());
281
282 delete signal_tree;
283 delete background_tree;
284
285 if (specific_options.m_workingDirectory.empty()) {
286 std::filesystem::remove_all(directory);
287 }
288
289 return weightfile;
290
291 }
292
294 const TMVAOptionsMulticlass& _specific_options) : TMVATeacher(general_options, _specific_options),
295 specific_options(_specific_options) { }
296
297 // Implement me!
299 {
300 B2ERROR("Training TMVAMulticlass classifiers within the MVA package has not been implemented yet.");
301 (void) training_data;
302 return Weightfile();
303 }
304
306 const TMVAOptionsRegression& _specific_options) : TMVATeacher(general_options, _specific_options),
307 specific_options(_specific_options) { }
308
310 {
311
312 unsigned int numberOfFeatures = training_data.getNumberOfFeatures();
313 unsigned int numberOfSpectators = training_data.getNumberOfSpectators();
314 unsigned int numberOfEvents = training_data.getNumberOfEvents();
315
316 std::string directory = specific_options.m_workingDirectory;
317 if (specific_options.m_workingDirectory.empty()) {
318 char* directory_template = strdup((std::filesystem::temp_directory_path() / "Basf2TMVA.XXXXXX").c_str());
319 directory = mkdtemp(directory_template);
320 free(directory_template);
321 }
322
323 auto guard = ScopeGuard::guardWorkingDirectory(directory);
324
325 std::string jobName = specific_options.m_prefix;
326 if (jobName.empty())
327 jobName = "TMVA";
328 TFile classFile((jobName + ".root").c_str(), "RECREATE");
329 classFile.cd();
330
331 TMVA::Tools::Instance();
332 TMVA::DataLoader data_loader(jobName);
333 TMVA::Factory factory(jobName, &classFile, specific_options.m_factoryOption);
334
335 // Add variables to the factory
336 for (const auto& var : m_general_options.m_variables) {
337 data_loader.AddVariable(Belle2::MakeROOTCompatible::makeROOTCompatible(var));
338 }
339
340 // Add variables to the factory
341 for (const auto& var : m_general_options.m_spectators) {
342 data_loader.AddSpectator(Belle2::MakeROOTCompatible::makeROOTCompatible(var));
343 }
344
345 data_loader.AddTarget(Belle2::MakeROOTCompatible::makeROOTCompatible(m_general_options.m_target_variable));
346
347 auto* regression_tree = new TTree("regression_tree", "regression_tree");
348
349 for (unsigned int iFeature = 0; iFeature < numberOfFeatures; ++iFeature) {
350 regression_tree->Branch(Belle2::MakeROOTCompatible::makeROOTCompatible(m_general_options.m_variables[iFeature]).c_str(),
351 &training_data.m_input[iFeature]);
352 }
353 for (unsigned int iSpectator = 0; iSpectator < numberOfSpectators; ++iSpectator) {
354 regression_tree->Branch(Belle2::MakeROOTCompatible::makeROOTCompatible(m_general_options.m_spectators[iSpectator]).c_str(),
355 &training_data.m_spectators[iSpectator]);
356 }
357 regression_tree->Branch(Belle2::MakeROOTCompatible::makeROOTCompatible(m_general_options.m_target_variable).c_str(),
358 &training_data.m_target);
359
360 regression_tree->Branch("__weight__", &training_data.m_weight);
361
362 for (unsigned int iEvent = 0; iEvent < numberOfEvents; ++iEvent) {
363 training_data.loadEvent(iEvent);
364 regression_tree->Fill();
365 }
366
367 data_loader.AddRegressionTree(regression_tree);
368 data_loader.SetWeightExpression(Belle2::MakeROOTCompatible::makeROOTCompatible(m_general_options.m_weight_variable), "Regression");
369
370 auto weightfile = trainFactory(factory, data_loader, jobName);
371 weightfile.addOptions(specific_options);
372
373 delete regression_tree;
374
375 if (specific_options.m_workingDirectory.empty()) {
376 std::filesystem::remove_all(directory);
377 }
378
379 return weightfile;
380
381 }
382
383 void TMVAExpert::load(Weightfile& weightfile)
384 {
385
386 // Initialize TMVA and ROOT stuff
387 TMVA::Tools::Instance();
388
389 m_expert = std::make_unique<TMVA::Reader>("!Color:Silent");
390
391 GeneralOptions general_options;
392 weightfile.getOptions(general_options);
393 m_input_cache.resize(general_options.m_variables.size(), 0);
394 for (unsigned int i = 0; i < general_options.m_variables.size(); ++i) {
395 m_expert->AddVariable(Belle2::MakeROOTCompatible::makeROOTCompatible(general_options.m_variables[i]), &m_input_cache[i]);
396 }
397 m_spectators_cache.resize(general_options.m_spectators.size(), 0);
398 for (unsigned int i = 0; i < general_options.m_spectators.size(); ++i) {
399 m_expert->AddSpectator(Belle2::MakeROOTCompatible::makeROOTCompatible(general_options.m_spectators[i]), &m_spectators_cache[i]);
400 }
401
402 if (weightfile.containsElement("TMVA_Logfile")) {
403 std::string custom_weightfile = weightfile.generateFileName("logfile");
404 weightfile.getFile("TMVA_Logfile", custom_weightfile);
405 }
406
407 }
408
410 {
411
412 weightfile.getOptions(specific_options);
413 if (specific_options.transform2probability) {
414 expert_signalFraction = weightfile.getSignalFraction();
415 }
416
417 // TMVA parses the method type for plugins out of the weightfile name, so we must ensure that it has the expected format
418 std::string custom_weightfile = weightfile.generateFileName(std::string("_") + specific_options.m_method + ".weights.xml");
419 weightfile.getFile("TMVA_Weightfile", custom_weightfile);
420
421 TMVAExpert::load(weightfile);
422
423 if (specific_options.m_type == "Plugins") {
424 auto base = std::string("TMVA@@MethodBase");
425 auto regexp1 = std::string(".*_") + specific_options.m_method + std::string(".*");
426 auto regexp2 = std::string(".*") + specific_options.m_method + std::string(".*");
427 auto className = std::string("TMVA::Method") + specific_options.m_method;
428 auto ctor1 = std::string("Method") + specific_options.m_method + std::string("(TMVA::DataSetInfo&,TString)");
429 auto ctor2 = std::string("Method") + specific_options.m_method + std::string("(TString&,TString&,TMVA::DataSetInfo&,TString&)");
430 auto pluginName = std::string("TMVA") + specific_options.m_method;
431
432 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp1.c_str(), className.c_str(), pluginName.c_str(), ctor1.c_str());
433 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp2.c_str(), className.c_str(), pluginName.c_str(), ctor2.c_str());
434 B2INFO("Registered new TMVA Plugin named " << pluginName);
435 }
436
437 if (!m_expert->BookMVA(specific_options.m_method, custom_weightfile)) {
438 B2FATAL("Could not set up expert! Please see preceding error message from TMVA!");
439 }
440
441 }
442
444 {
445
446 weightfile.getOptions(specific_options);
447
448 // TMVA parses the method type for plugins out of the weightfile name, so we must ensure that it has the expected format
449 std::string custom_weightfile = weightfile.generateFileName(std::string("_") + specific_options.m_method + ".weights.xml");
450 weightfile.getFile("TMVA_Weightfile", custom_weightfile);
451
452 TMVAExpert::load(weightfile);
453
454 if (specific_options.m_type == "Plugins") {
455 auto base = std::string("TMVA@@MethodBase");
456 auto regexp1 = std::string(".*_") + specific_options.m_method + std::string(".*");
457 auto regexp2 = std::string(".*") + specific_options.m_method + std::string(".*");
458 auto className = std::string("TMVA::Method") + specific_options.m_method;
459 auto ctor1 = std::string("Method") + specific_options.m_method + std::string("(TMVA::DataSetInfo&,TString)");
460 auto ctor2 = std::string("Method") + specific_options.m_method + std::string("(TString&,TString&,TMVA::DataSetInfo&,TString&)");
461 auto pluginName = std::string("TMVA") + specific_options.m_method;
462
463 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp1.c_str(), className.c_str(), pluginName.c_str(), ctor1.c_str());
464 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp2.c_str(), className.c_str(), pluginName.c_str(), ctor2.c_str());
465 B2INFO("Registered new TMVA Plugin named " << pluginName);
466 }
467
468 if (!m_expert->BookMVA(specific_options.m_method, custom_weightfile)) {
469 B2FATAL("Could not set up expert! Please see preceding error message from TMVA!");
470 }
471
472 }
473
475 {
476
477 weightfile.getOptions(specific_options);
478
479 // TMVA parses the method type for plugins out of the weightfile name, so we must ensure that it has the expected format
480 std::string custom_weightfile = weightfile.generateFileName(std::string("_") + specific_options.m_method + ".weights.xml");
481 weightfile.getFile("TMVA_Weightfile", custom_weightfile);
482
483 TMVAExpert::load(weightfile);
484
485 if (specific_options.m_type == "Plugins") {
486 auto base = std::string("TMVA@@MethodBase");
487 auto regexp1 = std::string(".*_") + specific_options.m_method + std::string(".*");
488 auto regexp2 = std::string(".*") + specific_options.m_method + std::string(".*");
489 auto className = std::string("TMVA::Method") + specific_options.m_method;
490 auto ctor1 = std::string("Method") + specific_options.m_method + std::string("(TMVA::DataSetInfo&,TString)");
491 auto ctor2 = std::string("Method") + specific_options.m_method + std::string("(TString&,TString&,TMVA::DataSetInfo&,TString&)");
492 auto pluginName = std::string("TMVA") + specific_options.m_method;
493
494 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp1.c_str(), className.c_str(), pluginName.c_str(), ctor1.c_str());
495 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp2.c_str(), className.c_str(), pluginName.c_str(), ctor2.c_str());
496 B2INFO("Registered new TMVA Plugin named " << pluginName);
497 }
498
499 if (!m_expert->BookMVA(specific_options.m_method, custom_weightfile)) {
500 B2FATAL("Could not set up expert! Please see preceding error message from TMVA!");
501 }
502
503 }
504
505 std::vector<float> TMVAExpertClassification::apply(Dataset& test_data) const
506 {
507
508 std::vector<float> probabilities(test_data.getNumberOfEvents());
509 for (unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
510 test_data.loadEvent(iEvent);
511 for (unsigned int i = 0; i < m_input_cache.size(); ++i)
512 m_input_cache[i] = test_data.m_input[i];
513 for (unsigned int i = 0; i < m_spectators_cache.size(); ++i)
514 m_spectators_cache[i] = test_data.m_spectators[i];
515 if (specific_options.transform2probability)
516 probabilities[iEvent] = m_expert->GetProba(specific_options.m_method, expert_signalFraction);
517 else
518 probabilities[iEvent] = m_expert->EvaluateMVA(specific_options.m_method);
519 }
520 return probabilities;
521
522 }
523
524 std::vector<std::vector<float>> TMVAExpertMulticlass::applyMulticlass(Dataset& test_data) const
525 {
526
527 std::vector<std::vector<float>> probabilities(test_data.getNumberOfEvents());
528
529 for (unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
530 test_data.loadEvent(iEvent);
531 for (unsigned int i = 0; i < m_input_cache.size(); ++i)
532 m_input_cache[i] = test_data.m_input[i];
533 for (unsigned int i = 0; i < m_spectators_cache.size(); ++i)
534 m_spectators_cache[i] = test_data.m_spectators[i];
535 probabilities[iEvent] = m_expert->EvaluateMulticlass(specific_options.m_method);
536 }
537 return probabilities;
538 }
539
540 std::vector<float> TMVAExpertRegression::apply(Dataset& test_data) const
541 {
542
543 std::vector<float> prediction(test_data.getNumberOfEvents());
544 for (unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
545 test_data.loadEvent(iEvent);
546 for (unsigned int i = 0; i < m_input_cache.size(); ++i)
547 m_input_cache[i] = test_data.m_input[i];
548 prediction[iEvent] = m_expert->EvaluateMVA(specific_options.m_method);
549 }
550 return prediction;
551
552 }
553
554 }
556}
Abstract base class of all Datasets given to the MVA interface The current event can always be access...
Definition Dataset.h:33
General options which are shared by all MVA trainings.
Definition Options.h:62
TMVAOptionsClassification specific_options
Method specific options.
Definition TMVA.h:320
virtual std::vector< float > apply(Dataset &test_data) const override
Apply this m_expert onto a dataset.
Definition TMVA.cc:505
float expert_signalFraction
Signal fraction used to calculate the probability.
Definition TMVA.h:321
virtual void load(Weightfile &weightfile) override
Load the expert from a Weightfile.
Definition TMVA.cc:409
TMVAOptionsMulticlass specific_options
Method specific options.
Definition TMVA.h:355
virtual void load(Weightfile &weightfile) override
Load the expert from a Weightfile.
Definition TMVA.cc:443
virtual std::vector< std::vector< float > > applyMulticlass(Dataset &test_data) const override
Apply this m_expert onto a dataset.
Definition TMVA.cc:524
virtual std::vector< float > apply(Dataset &test_data) const override
Apply this m_expert onto a dataset.
Definition TMVA.cc:540
TMVAOptionsRegression specific_options
Method specific options.
Definition TMVA.h:378
virtual void load(Weightfile &weightfile) override
Load the expert from a Weightfile.
Definition TMVA.cc:474
std::vector< float > m_input_cache
Input Cache for TMVA::Reader: Otherwise we would have to set the branch addresses in each apply call.
Definition TMVA.h:296
std::unique_ptr< TMVA::Reader > m_expert
TMVA::Reader pointer.
Definition TMVA.h:294
std::vector< float > m_spectators_cache
Spectators Cache for TMVA::Reader: Otherwise we would have to set the branch addresses in each apply ...
Definition TMVA.h:298
virtual void load(Weightfile &weightfile) override
Load the expert from a Weightfile.
Definition TMVA.cc:383
Options for the TMVA Classification MVA method.
Definition TMVA.h:80
virtual po::options_description getDescription() override
Returns a program options description for all available options.
Definition TMVA.cc:81
bool transform2probability
Transform output of method to a probability.
Definition TMVA.h:115
virtual void load(const boost::property_tree::ptree &pt) override
Load mechanism to load Options from a xml tree.
Definition TMVA.cc:69
virtual void save(boost::property_tree::ptree &pt) const override
Save mechanism to store Options in a xml tree.
Definition TMVA.cc:75
Options for the TMVA Multiclass MVA method.
Definition TMVA.h:122
std::vector< std::string > m_classes
Class name identifiers.
Definition TMVA.h:158
virtual po::options_description getDescription() override
Returns a program options description for all available options.
Definition TMVA.cc:110
virtual void load(const boost::property_tree::ptree &pt) override
Load mechanism to load Options from a xml tree.
Definition TMVA.cc:89
virtual void save(boost::property_tree::ptree &pt) const override
Save mechanism to store Options in a xml tree.
Definition TMVA.cc:100
Options for the TMVA Regression MVA method.
Definition TMVA.h:166
Options for the TMVA MVA method.
Definition TMVA.h:34
std::string m_prepareOption
Prepare options passed to prepareTrainingAndTestTree method.
Definition TMVA.h:72
std::string m_prefix
Prefix used for all files generated by TMVA.
Definition TMVA.h:74
std::string m_config
TMVA config string for the chosen method.
Definition TMVA.h:66
std::string m_method
tmva method name
Definition TMVA.h:60
virtual po::options_description getDescription() override
Returns a program options description for all available options.
Definition TMVA.cc:55
std::string m_factoryOption
Factory options passed to tmva factory.
Definition TMVA.h:71
std::string m_type
tmva method type
Definition TMVA.h:61
std::string m_workingDirectory
Working directory of TMVA, if empty a temporary directory is used.
Definition TMVA.h:73
virtual void load(const boost::property_tree::ptree &pt) override
Load mechanism to load Options from a xml tree.
Definition TMVA.cc:27
virtual void save(boost::property_tree::ptree &pt) const override
Save mechanism to store Options in a xml tree.
Definition TMVA.cc:43
TMVATeacherClassification(const GeneralOptions &general_options, const TMVAOptionsClassification &_specific_options)
Constructs a new teacher using the GeneralOptions and specific options of this training.
Definition TMVA.cc:203
TMVAOptionsClassification specific_options
Method specific options.
Definition TMVA.h:231
virtual Weightfile train(Dataset &training_data) const override
Train a mva method using the given dataset returning a Weightfile.
Definition TMVA.cc:207
TMVATeacherMulticlass(const GeneralOptions &general_options, const TMVAOptionsMulticlass &_specific_options)
Constructs a new teacher using the GeneralOptions and specific options of this training.
Definition TMVA.cc:293
TMVAOptionsMulticlass specific_options
Method specific options.
Definition TMVA.h:254
virtual Weightfile train(Dataset &training_data) const override
Train a mva method using the given dataset returning a Weightfile.
Definition TMVA.cc:298
TMVATeacherRegression(const GeneralOptions &general_options, const TMVAOptionsRegression &_specific_options)
Constructs a new teacher using the GeneralOptions and specific options of this training.
Definition TMVA.cc:305
TMVAOptionsRegression specific_options
Method specific options.
Definition TMVA.h:277
virtual Weightfile train(Dataset &training_data) const override
Train a mva method using the given dataset returning a Weightfile.
Definition TMVA.cc:309
TMVATeacher(const GeneralOptions &general_options, const TMVAOptions &_specific_options)
Constructs a new teacher using the GeneralOptions and specific options of this training.
Definition TMVA.cc:119
Weightfile trainFactory(TMVA::Factory &factory, TMVA::DataLoader &data_loader, const std::string &jobName) const
Train a mva method using the given data loader returning a Weightfile.
Definition TMVA.cc:122
TMVAOptions specific_options
Method specific options.
Definition TMVA.h:207
GeneralOptions m_general_options
GeneralOptions containing all shared options.
Definition Teacher.h:49
Teacher(const GeneralOptions &general_options)
Constructs a new teacher using the GeneralOptions for this training.
Definition Teacher.cc:18
The Weightfile class serializes all information about a training into an xml tree.
Definition Weightfile.h:38
static std::string makeROOTCompatible(std::string str)
Remove special characters that ROOT dislikes in branch names, e.g.
static std::string invertMakeROOTCompatible(std::string str)
Invert makeROOTCompatible operation.
static ScopeGuard guardWorkingDirectory()
Create a ScopeGuard of the current working directory.
Definition ScopeGuard.h:296
Abstract base class for different kinds of events.