Belle II Software  release-06-01-15
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 
21 namespace po = boost::program_options;
22 
23 namespace 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;
88  int m_signal_class = 1;
89  std::string m_target_variable = "isSignal";
90  std::string m_weight_variable = "__weight__";
91  unsigned int m_max_events = 0;
92  };
93 
97  class SpecificOptions : public Options {
98 
99  public:
103  virtual std::string getMethod() const = 0;
104 
105  };
106 
110  class MetaOptions : public Options {
111 
112  public:
117  virtual void load(const boost::property_tree::ptree& pt) override;
118 
123  virtual void save(boost::property_tree::ptree& pt) const override;
124 
128  virtual po::options_description getDescription() override;
129 
130  bool m_use_splot = false;
131  std::string m_splot_variable = "M";
132  std::vector<std::string> m_splot_mc_files;
133  bool m_splot_combined = false;
134  bool m_splot_boosted = false;
137  std::vector<std::string> m_sideband_mc_files;
138  std::string m_sideband_variable =
139  "";
141  bool m_use_reweighting = false;
142  std::string m_reweighting_identifier = "";
144  "";
145  std::vector<std::string> m_reweighting_data_files;
146  std::vector<std::string> m_reweighting_mc_files;
147  };
148 
149  template<typename T>
150  std::function<void(T)> check_bounds(T min, T max, const std::string& name)
151  {
152  return [name, min, max](T v) -> void {
153  if (v <= min || v >= max)
154  {
155  throw po::validation_error(po::validation_error::invalid_option_value, name,
156  std::to_string(min) + " <= " + name + " <= " + std::to_string(max) + ": provided value " + std::to_string(v));
157  }
158  };
159  }
160 
161  template<typename T>
162  std::function<void(std::vector<T>)> check_bounds_vector(T min, T max, const std::string& name)
163  {
164  return [name, min, max](const std::vector<T>& vec) -> void {
165  for (auto v : vec)
166  {
167  if (v <= min || v >= max) {
168  throw po::validation_error(po::validation_error::invalid_option_value, name,
169  std::to_string(min) + " <= " + name + " <= " + std::to_string(max) + ": provided value " + std::to_string(v));
170  }
171  }
172  };
173  }
174 
175  }
177 }
178 #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:90
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:91
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:42
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: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:71
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:110
std::string m_reweighting_variable
Variable defining for which events the reweighting should be used (1) or not used (0).
Definition: Options.h:143
bool m_use_reweighting
Use a pretraining of data against mc and weight the mc afterwards.
Definition: Options.h:141
virtual po::options_description getDescription() override
Returns a program options description for all available options.
Definition: Options.cc:97
bool m_use_splot
Use splot training.
Definition: Options.h:130
std::string m_splot_variable
Discriminating variable.
Definition: Options.h:131
std::vector< std::string > m_reweighting_mc_files
MC files for the pretraining.
Definition: Options.h:146
std::vector< std::string > m_reweighting_data_files
Data files for the pretraining.
Definition: Options.h:145
bool m_splot_combined
Combine sPlot training with PDF classifier for discriminating variable.
Definition: Options.h:133
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:124
std::string m_reweighting_identifier
Identifier used to save the reweighting expert.
Definition: Options.h:142
bool m_splot_boosted
Use boosted sPlot training (aPlot)
Definition: Options.h:134
std::vector< std::string > m_splot_mc_files
Monte carlo files used for the distribution of the discriminating variable.
Definition: Options.h:132
std::string m_sideband_variable
Variable defining the signal region (1) background region (2) negative signal region (3) or unused (o...
Definition: Options.h:138
std::vector< std::string > m_sideband_mc_files
used to estimate the number of events in the different regions
Definition: Options.h:137
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:164
bool m_use_sideband_subtraction
Use sideband subtraction.
Definition: Options.h:136
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:97
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.