Belle II Software  release-05-02-19
Options.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Keck *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 #ifndef INCLUDE_GUARD_BELLE2_MVA_OPTIONS_HEADER
13 #define INCLUDE_GUARD_BELLE2_MVA_OPTIONS_HEADER
14 
15 #include <boost/program_options.hpp>
16 #include <boost/program_options/errors.hpp>
17 #include <boost/property_tree/ptree_fwd.hpp>
18 
19 #include <string>
20 #include <vector>
21 #include <functional>
22 
23 namespace po = boost::program_options;
24 
25 namespace Belle2 {
30  namespace MVA {
31 
32 
36  class Options {
37  public:
42  virtual void load(const boost::property_tree::ptree& pt) = 0;
43 
48  virtual void save(boost::property_tree::ptree& pt) const = 0;
49 
53  virtual po::options_description getDescription() = 0;
54 
58  virtual ~Options() = default;
59  };
60 
64  class GeneralOptions : public Options {
65 
66  public:
71  virtual void load(const boost::property_tree::ptree& pt) override;
72 
77  virtual void save(boost::property_tree::ptree& pt) const override;
78 
82  virtual po::options_description getDescription() override;
83 
84  std::string m_method;
85  std::string m_identifier;
86  std::vector<std::string> m_datafiles;
87  std::string m_treename = "ntuple";
88  std::vector<std::string> m_variables;
89  std::vector<std::string> m_spectators;
90  int m_signal_class = 1;
91  std::string m_target_variable = "isSignal";
92  std::string m_weight_variable = "__weight__";
93  unsigned int m_max_events = 0;
94  };
95 
99  class SpecificOptions : public Options {
100 
101  public:
105  virtual std::string getMethod() const = 0;
106 
107  };
108 
112  class MetaOptions : public Options {
113 
114  public:
119  virtual void load(const boost::property_tree::ptree& pt) override;
120 
125  virtual void save(boost::property_tree::ptree& pt) const override;
126 
130  virtual po::options_description getDescription() override;
131 
132  bool m_use_splot = false;
133  std::string m_splot_variable = "M";
134  std::vector<std::string> m_splot_mc_files;
135  bool m_splot_combined = false;
136  bool m_splot_boosted = false;
139  std::vector<std::string> m_sideband_mc_files;
140  std::string m_sideband_variable =
141  "";
143  bool m_use_reweighting = false;
144  std::string m_reweighting_identifier = "";
146  "";
147  std::vector<std::string> m_reweighting_data_files;
148  std::vector<std::string> m_reweighting_mc_files;
149  };
150 
151  template<typename T>
152  std::function<void(T)> check_bounds(T min, T max, const std::string& name)
153  {
154  return [name, min, max](T v) -> void {
155  if (v <= min || v >= max)
156  {
157  throw po::validation_error(po::validation_error::invalid_option_value, name,
158  std::to_string(min) + " <= " + name + " <= " + std::to_string(max) + ": provided value " + std::to_string(v));
159  }
160  };
161  }
162 
163  template<typename T>
164  std::function<void(std::vector<T>)> check_bounds_vector(T min, T max, const std::string& name)
165  {
166  return [name, min, max](const std::vector<T>& vec) -> void {
167  for (auto v : vec)
168  {
169  if (v <= min || v >= max) {
170  throw po::validation_error(po::validation_error::invalid_option_value, name,
171  std::to_string(min) + " <= " + name + " <= " + std::to_string(max) + ": provided value " + std::to_string(v));
172  }
173  }
174  };
175  }
176 
177  }
179 }
180 #endif
Belle2::MVA::GeneralOptions::m_identifier
std::string m_identifier
Identifier containing the finished training.
Definition: Options.h:85
Belle2::MVA::Options::getDescription
virtual po::options_description getDescription()=0
Returns a program options description for all available options.
Belle2::MVA::MetaOptions::m_use_sideband_substraction
bool m_use_sideband_substraction
Use sideband substraction.
Definition: Options.h:138
Belle2::MVA::MetaOptions::m_reweighting_data_files
std::vector< std::string > m_reweighting_data_files
Data files for the pretraining.
Definition: Options.h:147
Belle2::MVA::MetaOptions::m_splot_boosted
bool m_splot_boosted
Use boosted sPlot training (aPlot)
Definition: Options.h:136
Belle2::MVA::MetaOptions::load
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:134
Belle2::MVA::Options::save
virtual void save(boost::property_tree::ptree &pt) const =0
Save mechanism (used by Weightfile) to store Options in a xml tree.
Belle2::MVA::GeneralOptions::m_max_events
unsigned int m_max_events
Maximum number of events to process, 0 means all.
Definition: Options.h:93
Belle2::MVA::MetaOptions::m_reweighting_mc_files
std::vector< std::string > m_reweighting_mc_files
MC files for the pretraining.
Definition: Options.h:148
Belle2::MVA::MetaOptions::m_sideband_mc_files
std::vector< std::string > m_sideband_mc_files
used to estimate the number of events in the different regions
Definition: Options.h:139
Belle2::MVA::MetaOptions::m_reweighting_variable
std::string m_reweighting_variable
Variable defining for which events the reweighting should be used (1) or not used (0).
Definition: Options.h:145
Belle2::MVA::GeneralOptions::load
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:52
Belle2::MVA::GeneralOptions::m_weight_variable
std::string m_weight_variable
Weight variable (branch name) defining the weights.
Definition: Options.h:92
Belle2::MVA::MetaOptions::m_splot_variable
std::string m_splot_variable
Discriminating variable.
Definition: Options.h:133
Belle2::MVA::MetaOptions::getDescription
virtual po::options_description getDescription() override
Returns a program options description for all available options.
Definition: Options.cc:107
Belle2::MVA::GeneralOptions::getDescription
virtual po::options_description getDescription() override
Returns a program options description for all available options.
Definition: Options.cc:29
Belle2::MVA::SpecificOptions
Specific Options, all mehtod Options have to inherit from this class.
Definition: Options.h:99
Belle2::MVA::MetaOptions::m_splot_mc_files
std::vector< std::string > m_splot_mc_files
Monte carlo files used for the distribution of the discriminating variable.
Definition: Options.h:134
Belle2::MVA::MetaOptions::save
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:174
Belle2::MVA::MetaOptions::m_reweighting_identifier
std::string m_reweighting_identifier
Identifier used to save the reweighting expert.
Definition: Options.h:144
Belle2::MVA::GeneralOptions::m_treename
std::string m_treename
Name of the TTree inside the datafile containing the training data.
Definition: Options.h:87
Belle2::MVA::GeneralOptions::m_spectators
std::vector< std::string > m_spectators
Vector of all spectators (branch names) used in the training.
Definition: Options.h:89
Belle2::MVA::GeneralOptions::m_method
std::string m_method
Name of the MVA method to use.
Definition: Options.h:84
Belle2::MVA::Options
Abstract base class of all Options given to the MVA interface.
Definition: Options.h:36
Belle2::MVA::MetaOptions::m_use_reweighting
bool m_use_reweighting
Use a pretraining of data against mc and weight the mc afterwards.
Definition: Options.h:143
Belle2::MVA::MetaOptions::m_use_splot
bool m_use_splot
Use splot training.
Definition: Options.h:132
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MVA::GeneralOptions::m_target_variable
std::string m_target_variable
Target variable (branch name) defining the target.
Definition: Options.h:91
Belle2::MVA::GeneralOptions::m_signal_class
int m_signal_class
Signal class which is used as signal in a classification problem.
Definition: Options.h:90
Belle2::MVA::Options::~Options
virtual ~Options()=default
Virtual default destructor.
Belle2::MVA::GeneralOptions::m_variables
std::vector< std::string > m_variables
Vector of all variables (branch names) used in the training.
Definition: Options.h:88
Belle2::MVA::GeneralOptions
General options which are shared by all MVA trainings.
Definition: Options.h:64
Belle2::MVA::GeneralOptions::m_datafiles
std::vector< std::string > m_datafiles
Name of the datafiles containing the training data.
Definition: Options.h:86
Belle2::MVA::MetaOptions::m_splot_combined
bool m_splot_combined
Combine sPlot training with PDF classifier for discriminating variable.
Definition: Options.h:135
Belle2::MVA::MetaOptions::m_sideband_variable
std::string m_sideband_variable
Variable defining the signal region (1) background region (2) negative signal region (3) or unused (o...
Definition: Options.h:140
Belle2::MVA::MetaOptions
Meta Options which modify the underlying training by doing sPlot, Multiclass and HyperparameterSearch...
Definition: Options.h:112
Belle2::MVA::GeneralOptions::save
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:81
Belle2::MVA::SpecificOptions::getMethod
virtual std::string getMethod() const =0
Returns method name, used in the interface to register the method.
Belle2::MVA::Options::load
virtual void load(const boost::property_tree::ptree &pt)=0
Load mechanism (used by Weightfile) to load Options from a xml tree.