Logo ROOT   6.16/01
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
9Method : Cuts::Cuts
10TMVA Release : 4.2.1 [262657]
11ROOT Release : 6.16/01 [397313]
12Creator : sftnight
13Date : Sun Dec 19 22:13:28 2021
14Host : Linux root-ubuntu-2004-3 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
15Dir : /home/sftnight/build/workspace/root-makedoc-v616/rootspi/rdoc/src/v6-16-00-patches/documentation/doxygen
16Training events: 2000
17Analysis type : [Classification]
18
19
20#OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-
21
22# Set by User:
23V: "False" [Verbose output (short form of "VerbosityLevel" below - overrides the latter one)]
24H: "False" [Print method-specific help message]
25FitMethod: "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)]
26EffMethod: "EffSel" [Selection Method]
27# Default:
28VerbosityLevel: "Default" [Verbosity level]
29VarTransform: "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)"]
30CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
31IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
32CutRangeMin[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"
36CutRangeMax[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"
40VarProp[0]: "FSmart" [Categorisation of cuts]
41 VarProp[1]: "FSmart"
42 VarProp[2]: "FSmart"
43 VarProp[3]: "FSmart"
44##
45
46
47#VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
48
49NVar 4
50var1+var2 myvar1 myvar1 myvar1 'F' [-9.33803939819,7.69307804108]
51var1-var2 myvar2 myvar2 Expression 2 'F' [-3.25508260727,4.02912044525]
52var3 var3 var3 Variable 3 units 'F' [-5.2777428627,4.64297914505]
53var4 var4 var4 Variable 4 units 'F' [-5.6007027626,4.67435789108]
54NSpec 2
55var1*2 spec1 spec1 Spectator 1 units 'F' [-9.91655540466,8.7030172348]
56var1*3 spec2 spec2 Spectator 2 units 'F' [-14.874833107,13.0545253754]
57
58
59============================================================================ */
60
61#include <array>
62#include <vector>
63#include <cmath>
64#include <string>
65#include <iostream>
66
67#ifndef IClassifierReader__def
68#define IClassifierReader__def
69
70class IClassifierReader {
71
72 public:
73
74 // constructor
75 IClassifierReader() : fStatusIsClean( true ) {}
76 virtual ~IClassifierReader() {}
77
78 // return classifier response
79 virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
80
81 // returns classifier status
82 bool IsStatusClean() const { return fStatusIsClean; }
83
84 protected:
85
86 bool fStatusIsClean;
87};
88
89#endif
90
91class ReadCuts : public IClassifierReader {
92
93 public:
94
95 // constructor
96 ReadCuts( std::vector<std::string>& theInputVars )
97 : IClassifierReader(),
98 fClassName( "ReadCuts" ),
99 fNvars( 4 )
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 override;
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 double fVmin[4];
170 double fVmax[4];
171 double NormVariable( double x, double xmin, double xmax ) const {
172 // normalise to output range: [-1, 1]
173 return 2*(x - xmin)/(xmax - xmin) - 1.0;
174 }
175
176 // type of input variable: 'F' or 'I'
177 char fType[4];
178
179 // initialize internal variables
180 void Initialize();
181 double GetMvaValue__( const std::vector<double>& inputValues ) const;
182
183 // private members (method specific)
184 // not implemented for class: "ReadCuts"
185};
186 inline double ReadCuts::GetMvaValue( const std::vector<double>& inputValues ) const
187 {
188 // classifier response value
189 double retval = 0;
190
191 // classifier response, sanity check first
192 if (!IsStatusClean()) {
193 std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
194 << " because status is dirty" << std::endl;
195 retval = 0;
196 }
197 else {
198 retval = GetMvaValue__( inputValues );
199 }
200
201 return retval;
202 }
PyObject * fType
float xmin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
Double_t x[n]
Definition: legend1.C:17
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176