Belle II Software development
Options.h
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#pragma once
10#ifndef INCLUDE_GUARD_BELLE2_MVA_OPTIONS_HEADER
11#define INCLUDE_GUARD_BELLE2_MVA_OPTIONS_HEADER
12
13#include <boost/program_options.hpp>
14#include <boost/program_options/errors.hpp>
15#include <boost/property_tree/ptree_fwd.hpp>
16
17#include <string>
18#include <vector>
19#include <functional>
20
21namespace po = boost::program_options;
22
23namespace Belle2 {
28 namespace MVA {
29
30
34 class Options {
35 public:
40 virtual void load(const boost::property_tree::ptree& pt) = 0;
41
46 virtual void save(boost::property_tree::ptree& pt) const = 0;
47
51 virtual po::options_description getDescription() = 0;
52
56 virtual ~Options() = default;
57 };
58
62 class GeneralOptions : public Options {
63
64 public:
69 virtual void load(const boost::property_tree::ptree& pt) override;
70
75 virtual void save(boost::property_tree::ptree& pt) const override;
76
80 virtual po::options_description getDescription() override;
81
82 std::string m_method;
83 std::string m_identifier;
84 std::vector<std::string> m_datafiles;
85 std::string m_treename = "ntuple";
86 std::vector<std::string> m_variables;
87 std::vector<std::string> m_spectators;
89 unsigned int m_nClasses = 2;
90 std::string m_target_variable = "isSignal";
91 std::string m_weight_variable = "__weight__";
92 unsigned int m_max_events = 0;
93 };
94
98 class SpecificOptions : public Options {
99
100 public:
104 virtual std::string getMethod() const = 0;
105
106 };
107
111 class MetaOptions : public Options {
112
113 public:
118 virtual void load(const boost::property_tree::ptree& pt) override;
119
124 virtual void save(boost::property_tree::ptree& pt) const override;
125
129 virtual po::options_description getDescription() override;
130
131 bool m_use_splot = false;
132 std::string m_splot_variable = "M";
133 std::vector<std::string> m_splot_mc_files;
134 bool m_splot_combined = false;
135 bool m_splot_boosted = false;
138 std::vector<std::string> m_sideband_mc_files;
140 "";
142 bool m_use_reweighting = false;
143 std::string m_reweighting_identifier = "";
145 "";
146 std::vector<std::string> m_reweighting_data_files;
147 std::vector<std::string> m_reweighting_mc_files;
148 };
149
150 template<typename T>
151 std::function<void(T)> check_bounds(T min, T max, const std::string& name)
152 {
153 return [name, min, max](T v) -> void {
154 if (v <= min || v >= max)
155 {
156 throw po::validation_error(po::validation_error::invalid_option_value, name,
157 std::to_string(min) + " <= " + name + " <= " + std::to_string(max) + ": provided value " + std::to_string(v));
158 }
159 };
160 }
161
162 template<typename T>
163 std::function<void(std::vector<T>)> check_bounds_vector(T min, T max, const std::string& name)
164 {
165 return [name, min, max](const std::vector<T>& vec) -> void {
166 for (auto v : vec)
167 {
168 if (v <= min || v >= max) {
169 throw po::validation_error(po::validation_error::invalid_option_value, name,
170 std::to_string(min) + " <= " + name + " <= " + std::to_string(max) + ": provided value " + std::to_string(v));
171 }
172 }
173 };
174 }
175
176 }
178}
179#endif
General options which are shared by all MVA trainings.
Definition: Options.h:62
std::vector< std::string > m_datafiles
Name of the datafiles containing the training data.
Definition: Options.h:84
int m_signal_class
Signal class which is used as signal in a classification problem.
Definition: Options.h:88
std::vector< std::string > m_variables
Vector of all variables (branch names) used in the training.
Definition: Options.h:86
std::string m_weight_variable
Weight variable (branch name) defining the weights.
Definition: Options.h:91
std::vector< std::string > m_spectators
Vector of all spectators (branch names) used in the training.
Definition: Options.h:87
std::string m_method
Name of the MVA method to use.
Definition: Options.h:82
unsigned int m_max_events
Maximum number of events to process, 0 means all.
Definition: Options.h:92
virtual po::options_description getDescription() override
Returns a program options description for all available options.
Definition: Options.cc:19
virtual void load(const boost::property_tree::ptree &pt) override
Load mechanism (used by Weightfile) to load Options from a xml tree.
Definition: Options.cc:44
std::string m_treename
Name of the TTree inside the datafile containing the training data.
Definition: Options.h:85
std::string m_target_variable
Target variable (branch name) defining the target.
Definition: Options.h:90
unsigned int m_nClasses
Number of classes in a classification problem.
Definition: Options.h:89
virtual void save(boost::property_tree::ptree &pt) const override
Save mechanism (used by Weightfile) to store Options in a xml tree.
Definition: Options.cc:74
std::string m_identifier
Identifier containing the finished training.
Definition: Options.h:83
Meta Options which modify the underlying training by doing sPlot, Multiclass and HyperparameterSearch...
Definition: Options.h:111
std::string m_reweighting_variable
Variable defining for which events the reweighting should be used (1) or not used (0).
Definition: Options.h:144
bool m_use_reweighting
Use a pretraining of data against mc and weight the mc afterwards.
Definition: Options.h:142
virtual po::options_description getDescription() override
Returns a program options description for all available options.
Definition: Options.cc:101
bool m_use_splot
Use splot training.
Definition: Options.h:131
std::string m_splot_variable
Discriminating variable.
Definition: Options.h:132
std::vector< std::string > m_reweighting_mc_files
MC files for the pretraining.
Definition: Options.h:147
std::vector< std::string > m_reweighting_data_files
Data files for the pretraining.
Definition: Options.h:146
bool m_splot_combined
Combine sPlot training with PDF classifier for discriminating variable.
Definition: Options.h:134
virtual void load(const boost::property_tree::ptree &pt) override
Load mechanism (used by Weightfile) to load Options from a xml tree.
Definition: Options.cc:128
std::string m_reweighting_identifier
Identifier used to save the reweighting expert.
Definition: Options.h:143
bool m_splot_boosted
Use boosted sPlot training (aPlot)
Definition: Options.h:135
std::vector< std::string > m_splot_mc_files
Monte carlo files used for the distribution of the discriminating variable.
Definition: Options.h:133
std::string m_sideband_variable
Variable defining the signal region (1) background region (2) negative signal region (3) or unused (o...
Definition: Options.h:139
std::vector< std::string > m_sideband_mc_files
used to estimate the number of events in the different regions
Definition: Options.h:138
virtual void save(boost::property_tree::ptree &pt) const override
Save mechanism (used by Weightfile) to store Options in a xml tree.
Definition: Options.cc:168
bool m_use_sideband_subtraction
Use sideband subtraction.
Definition: Options.h:137
Abstract base class of all Options given to the MVA interface.
Definition: Options.h:34
virtual ~Options()=default
Virtual default destructor.
virtual po::options_description getDescription()=0
Returns a program options description for all available options.
virtual void load(const boost::property_tree::ptree &pt)=0
Load mechanism (used by Weightfile) to load Options from a xml tree.
virtual void save(boost::property_tree::ptree &pt) const =0
Save mechanism (used by Weightfile) to store Options in a xml tree.
Specific Options, all method Options have to inherit from this class.
Definition: Options.h:98
virtual std::string getMethod() const =0
Returns method name, used in the interface to register the method.
Abstract base class for different kinds of events.