Logo ROOT   6.10/09
Reference Guide
TMVAClassification_Cuts.class.C
Go to the documentation of this file.
1 // Class: ReadCuts
2 // Automatically generated by MethodBase::MakeClass
3 //
4 
5 /* configuration options =====================================================
6 
7 #GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8 
9 Method : Cuts::Cuts
10 TMVA Release : 4.2.1 [262657]
11 ROOT Release : 6.10/09 [395785]
12 Creator : sftnight
13 Date : Thu May 31 12:04:19 2018
14 Host : Linux SFT-ubuntu-1710-1 4.13.0-31-generic #34-Ubuntu SMP Fri Jan 19 16:34:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
15 Dir : /mnt/build/workspace/root-makedoc-v610/rootspi/rdoc/src/v6-10-00-patches/documentation/doxygen
16 Training events: 2000
17 Analysis type : [Classification]
18 
19 
20 #OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-
21 
22 # Set by User:
23 V: "False" [Verbose output (short form of "VerbosityLevel" below - overrides the latter one)]
24 H: "False" [Print method-specific help message]
25 FitMethod: "MC" [Minimisation Method (GA, SA, and MC are the primary methods to be used; the others have been introduced for testing purposes and are depreciated)]
26 EffMethod: "EffSel" [Selection Method]
27 # Default:
28 VerbosityLevel: "Default" [Verbosity level]
29 VarTransform: "None" [List of variable transformations performed before training, e.g., "D_Background,P_Signal,G,N_AllClasses" for: "Decorrelation, PCA-transformation, Gaussianisation, Normalisation, each for the given class of events ('AllClasses' denotes all events of all classes, if no class indication is given, 'All' is assumed)"]
30 CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
31 IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
32 CutRangeMin[0]: "-1.000000e+00" [Minimum of allowed cut range (set per variable)]
33  CutRangeMin[1]: "-1.000000e+00"
34  CutRangeMin[2]: "-1.000000e+00"
35  CutRangeMin[3]: "-1.000000e+00"
36 CutRangeMax[0]: "-1.000000e+00" [Maximum of allowed cut range (set per variable)]
37  CutRangeMax[1]: "-1.000000e+00"
38  CutRangeMax[2]: "-1.000000e+00"
39  CutRangeMax[3]: "-1.000000e+00"
40 VarProp[0]: "FSmart" [Categorisation of cuts]
41  VarProp[1]: "FSmart"
42  VarProp[2]: "FSmart"
43  VarProp[3]: "FSmart"
44 ##
45 
46 
47 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
48 
49 NVar 4
50 var1+var2 myvar1 myvar1 myvar1 'F' [-8.14423561096,7.26972866058]
51 var1-var2 myvar2 myvar2 Expression 2 'F' [-3.96643972397,4.0258936882]
52 var3 var3 var3 Variable 3 units 'F' [-5.03730010986,4.27845287323]
53 var4 var4 var4 Variable 4 units 'F' [-5.95050764084,4.64035463333]
54 NSpec 2
55 var1*2 spec1 spec1 Spectator 1 units 'F' [-9.91655540466,8.67800140381]
56 var1*3 spec2 spec2 Spectator 2 units 'F' [-14.874833107,13.0170021057]
57 
58 
59 ============================================================================ */
60 
61 #include <vector>
62 #include <cmath>
63 #include <string>
64 #include <iostream>
65 
66 #ifndef IClassifierReader__def
67 #define IClassifierReader__def
68 
69 class IClassifierReader {
70 
71  public:
72 
73  // constructor
74  IClassifierReader() : fStatusIsClean( true ) {}
75  virtual ~IClassifierReader() {}
76 
77  // return classifier response
78  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
79 
80  // returns classifier status
81  bool IsStatusClean() const { return fStatusIsClean; }
82 
83  protected:
84 
85  bool fStatusIsClean;
86 };
87 
88 #endif
89 
90 class ReadCuts : public IClassifierReader {
91 
92  public:
93 
94  // constructor
95  ReadCuts( std::vector<std::string>& theInputVars )
96  : IClassifierReader(),
97  fClassName( "ReadCuts" ),
98  fNvars( 4 ),
99  fIsNormalised( false )
100  {
101  // the training input variables
102  const char* inputVars[] = { "var1+var2", "var1-var2", "var3", "var4" };
103 
104  // sanity checks
105  if (theInputVars.size() <= 0) {
106  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
107  fStatusIsClean = false;
108  }
109 
110  if (theInputVars.size() != fNvars) {
111  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
112  << theInputVars.size() << " != " << fNvars << std::endl;
113  fStatusIsClean = false;
114  }
115 
116  // validate input variables
117  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
118  if (theInputVars[ivar] != inputVars[ivar]) {
119  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
120  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
121  fStatusIsClean = false;
122  }
123  }
124 
125  // initialize min and max vectors (for normalisation)
126  fVmin[0] = 0;
127  fVmax[0] = 0;
128  fVmin[1] = 0;
129  fVmax[1] = 0;
130  fVmin[2] = 0;
131  fVmax[2] = 0;
132  fVmin[3] = 0;
133  fVmax[3] = 0;
134 
135  // initialize input variable types
136  fType[0] = 'F';
137  fType[1] = 'F';
138  fType[2] = 'F';
139  fType[3] = 'F';
140 
141  // initialize constants
142  Initialize();
143 
144  }
145 
146  // destructor
147  virtual ~ReadCuts() {
148  Clear(); // method-specific
149  }
150 
151  // the classifier response
152  // "inputValues" is a vector of input values in the same order as the
153  // variables given to the constructor
154  double GetMvaValue( const std::vector<double>& inputValues ) const;
155 
156  private:
157 
158  // method-specific destructor
159  void Clear();
160 
161  // common member variables
162  const char* fClassName;
163 
164  const size_t fNvars;
165  size_t GetNvar() const { return fNvars; }
166  char GetType( int ivar ) const { return fType[ivar]; }
167 
168  // normalisation of input variables
169  const bool fIsNormalised;
170  bool IsNormalised() const { return fIsNormalised; }
171  double fVmin[4];
172  double fVmax[4];
173  double NormVariable( double x, double xmin, double xmax ) const {
174  // normalise to output range: [-1, 1]
175  return 2*(x - xmin)/(xmax - xmin) - 1.0;
176  }
177 
178  // type of input variable: 'F' or 'I'
179  char fType[4];
180 
181  // initialize internal variables
182  void Initialize();
183  double GetMvaValue__( const std::vector<double>& inputValues ) const;
184 
185  // private members (method specific)
186  // not implemented for class: "ReadCuts"
187 };
188  inline double ReadCuts::GetMvaValue( const std::vector<double>& inputValues ) const
189  {
190  // classifier response value
191  double retval = 0;
192 
193  // classifier response, sanity check first
194  if (!IsStatusClean()) {
195  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
196  << " because status is dirty" << std::endl;
197  retval = 0;
198  }
199  else {
200  if (IsNormalised()) {
201  // normalise variables
202  std::vector<double> iV;
203  iV.reserve(inputValues.size());
204  int ivar = 0;
205  for (std::vector<double>::const_iterator varIt = inputValues.begin();
206  varIt != inputValues.end(); varIt++, ivar++) {
207  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
208  }
209  retval = GetMvaValue__( iV );
210  }
211  else {
212  retval = GetMvaValue__( inputValues );
213  }
214  }
215 
216  return retval;
217  }
float xmin
Definition: THbookFile.cxx:93
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
Double_t x[n]
Definition: legend1.C:17
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
float xmax
Definition: THbookFile.cxx:93
PyObject * fType