9#include <mva/interface/Options.h>
11#include <boost/property_tree/ptree.hpp>
12#include <gtest/gtest.h>
18 TEST(OptionsTest, GeneralOptions)
23 EXPECT_EQ(general_options.m_method,
"");
24 EXPECT_EQ(general_options.m_identifier,
"");
25 EXPECT_EQ(general_options.m_datafiles.size(), 0);
26 EXPECT_EQ(general_options.m_treename,
"ntuple");
27 EXPECT_EQ(general_options.m_variables.size(), 0);
28 EXPECT_EQ(general_options.m_spectators.size(), 0);
29 EXPECT_EQ(general_options.m_signal_class, 1);
30 EXPECT_EQ(general_options.m_nClasses, 2);
31 EXPECT_EQ(general_options.m_target_variable,
"isSignal");
32 EXPECT_EQ(general_options.m_weight_variable,
"__weight__");
33 EXPECT_EQ(general_options.m_max_events, 0u);
35 general_options.m_method =
"Method";
36 general_options.m_identifier =
"Weightfile";
37 general_options.m_datafiles = {
"Datafile"};
38 general_options.m_treename =
"Tree";
39 general_options.m_variables = {
"v",
"a",
"r",
"s"};
40 general_options.m_spectators = {
"x",
"M"};
41 general_options.m_signal_class = 2;
42 general_options.m_nClasses = 4;
43 general_options.m_max_events = 100;
44 general_options.m_target_variable =
"Target";
45 general_options.m_weight_variable =
"Weight";
47 boost::property_tree::ptree pt;
48 general_options.save(pt);
49 EXPECT_EQ(pt.get<std::string>(
"method"),
"Method");
50 EXPECT_EQ(pt.get<std::string>(
"weightfile"),
"Weightfile");
51 EXPECT_EQ(pt.get<
unsigned int>(
"number_data_files"), 1);
52 EXPECT_EQ(pt.get<std::string>(
"datafile0"),
"Datafile");
53 EXPECT_EQ(pt.get<std::string>(
"treename"),
"Tree");
54 EXPECT_EQ(pt.get<std::string>(
"target_variable"),
"Target");
55 EXPECT_EQ(pt.get<std::string>(
"weight_variable"),
"Weight");
56 EXPECT_EQ(pt.get<
int>(
"signal_class"), 2);
57 EXPECT_EQ(pt.get<
unsigned int>(
"nClasses"), 4);
58 EXPECT_EQ(pt.get<
unsigned int>(
"max_events"), 100u);
59 EXPECT_EQ(pt.get<
unsigned int>(
"number_feature_variables"), 4);
60 EXPECT_EQ(pt.get<std::string>(
"variable0"),
"v");
61 EXPECT_EQ(pt.get<std::string>(
"variable1"),
"a");
62 EXPECT_EQ(pt.get<std::string>(
"variable2"),
"r");
63 EXPECT_EQ(pt.get<std::string>(
"variable3"),
"s");
64 EXPECT_EQ(pt.get<
unsigned int>(
"number_spectator_variables"), 2);
65 EXPECT_EQ(pt.get<std::string>(
"spectator0"),
"x");
66 EXPECT_EQ(pt.get<std::string>(
"spectator1"),
"M");
69 general_options2.
load(pt);
71 EXPECT_EQ(general_options2.
m_method,
"Method");
74 EXPECT_EQ(general_options2.
m_datafiles[0],
"Datafile");
75 EXPECT_EQ(general_options2.
m_treename,
"Tree");
91 auto description = general_options.getDescription();
92 EXPECT_EQ(description.options().size(), 12);
95 TEST(OptionsTest, MetaOptions)
98 EXPECT_EQ(meta_options.m_use_splot,
false);
99 EXPECT_EQ(meta_options.m_splot_variable,
"M");
100 EXPECT_EQ(meta_options.m_splot_mc_files.size(), 0);
101 EXPECT_EQ(meta_options.m_splot_combined,
false);
102 EXPECT_EQ(meta_options.m_splot_boosted,
false);
103 EXPECT_EQ(meta_options.m_use_sideband_subtraction,
false);
104 EXPECT_EQ(meta_options.m_sideband_variable,
"");
105 EXPECT_EQ(meta_options.m_sideband_mc_files.size(), 0u);
106 EXPECT_EQ(meta_options.m_use_reweighting,
false);
107 EXPECT_EQ(meta_options.m_reweighting_identifier,
"");
108 EXPECT_EQ(meta_options.m_reweighting_variable,
"");
109 EXPECT_EQ(meta_options.m_reweighting_data_files.size(), 0u);
110 EXPECT_EQ(meta_options.m_reweighting_mc_files.size(), 0u);
112 meta_options.m_use_reweighting =
true;
113 meta_options.m_reweighting_identifier =
"test";
114 meta_options.m_reweighting_variable =
"A";
115 meta_options.m_reweighting_mc_files = {
"reweighting_mc.root"};
116 meta_options.m_reweighting_data_files = {
"reweighting_data.root"};
117 meta_options.m_use_sideband_subtraction =
true;
118 meta_options.m_sideband_variable =
"B";
119 meta_options.m_sideband_mc_files = {
"sideband_mc.root"};
120 meta_options.m_use_splot =
true;
121 meta_options.m_splot_variable =
"Q";
122 meta_options.m_splot_mc_files = {
"splot_mc.root"};
123 meta_options.m_splot_combined =
true;
124 meta_options.m_splot_boosted =
true;
126 boost::property_tree::ptree pt;
127 meta_options.save(pt);
128 EXPECT_EQ(pt.get<
bool>(
"use_splot"),
true);
129 EXPECT_EQ(pt.get<
bool>(
"splot_combined"),
true);
130 EXPECT_EQ(pt.get<
bool>(
"splot_boosted"),
true);
131 EXPECT_EQ(pt.get<
unsigned int>(
"splot_number_of_mc_files"), 1);
132 EXPECT_EQ(pt.get<std::string>(
"splot_mc_file0"),
"splot_mc.root");
133 EXPECT_EQ(pt.get<std::string>(
"splot_variable"),
"Q");
134 EXPECT_EQ(pt.get<
bool>(
"use_sideband_subtraction"),
true);
135 EXPECT_EQ(pt.get<std::string>(
"sideband_variable"),
"B");
136 EXPECT_EQ(pt.get<
bool>(
"use_reweighting"),
true);
137 EXPECT_EQ(pt.get<std::string>(
"reweighting_identifier"),
"test");
138 EXPECT_EQ(pt.get<std::string>(
"reweighting_variable"),
"A");
139 EXPECT_EQ(pt.get<
unsigned int>(
"reweighting_number_of_mc_files"), 1);
140 EXPECT_EQ(pt.get<std::string>(
"reweighting_mc_file0"),
"reweighting_mc.root");
141 EXPECT_EQ(pt.get<
unsigned int>(
"reweighting_number_of_data_files"), 1);
142 EXPECT_EQ(pt.get<std::string>(
"reweighting_data_file0"),
"reweighting_data.root");
143 EXPECT_EQ(pt.get<
unsigned int>(
"sideband_number_of_mc_files"), 1);
144 EXPECT_EQ(pt.get<std::string>(
"sideband_mc_file0"),
"sideband_mc.root");
147 meta_options2.
load(pt);
168 auto description = meta_options.getDescription();
169 EXPECT_EQ(description.options().size(), 13);
General options which are shared by all MVA trainings.
std::vector< std::string > m_datafiles
Name of the datafiles containing the training data.
int m_signal_class
Signal class which is used as signal in a classification problem.
std::vector< std::string > m_variables
Vector of all variables (branch names) used in the training.
std::string m_weight_variable
Weight variable (branch name) defining the weights.
std::vector< std::string > m_spectators
Vector of all spectators (branch names) used in the training.
std::string m_method
Name of the MVA method to use.
unsigned int m_max_events
Maximum number of events to process, 0 means all.
virtual void load(const boost::property_tree::ptree &pt) override
Load mechanism (used by Weightfile) to load Options from a xml tree.
std::string m_treename
Name of the TTree inside the datafile containing the training data.
std::string m_target_variable
Target variable (branch name) defining the target.
unsigned int m_nClasses
Number of classes in a classification problem.
std::string m_identifier
Identifier containing the finished training.
Abstract base class for different kinds of events.