Logo ROOT   6.16/01
Reference Guide
TMVAClassification_CutsD.class.C
Go to the documentation of this file.
1// Class: ReadCutsD
2// Automatically generated by MethodBase::MakeClass
3//
4
5/* configuration options =====================================================
6
7#GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8
9Method : Cuts::CutsD
10TMVA Release : 4.2.1 [262657]
11ROOT Release : 6.16/01 [397313]
12Creator : sftnight
13Date : Sun Dec 19 22:13:31 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)]
24VarTransform: "Decorrelate" [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)"]
25H: "False" [Print method-specific help message]
26FitMethod: "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)]
27EffMethod: "EffSel" [Selection Method]
28# Default:
29VerbosityLevel: "Default" [Verbosity level]
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 ReadCutsD : public IClassifierReader {
92
93 public:
94
95 // constructor
96 ReadCutsD( std::vector<std::string>& theInputVars )
97 : IClassifierReader(),
98 fClassName( "ReadCutsD" ),
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] = -5.64005947113037;
127 fVmax[0] = 4.8529167175293;
128 fVmin[1] = -2.92915463447571;
129 fVmax[1] = 3.70650386810303;
130 fVmin[2] = -4.17918729782104;
131 fVmax[2] = 3.51799082756042;
132 fVmin[3] = -3.33631753921509;
133 fVmax[3] = 3.39626932144165;
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 // initialize transformation
145 InitTransform();
146 }
147
148 // destructor
149 virtual ~ReadCutsD() {
150 Clear(); // method-specific
151 }
152
153 // the classifier response
154 // "inputValues" is a vector of input values in the same order as the
155 // variables given to the constructor
156 double GetMvaValue( const std::vector<double>& inputValues ) const override;
157
158 private:
159
160 // method-specific destructor
161 void Clear();
162
163 // input variable transformation
164
165 double fDecTF_1[3][4][4];
166 void InitTransform_1();
167 void Transform_1( std::vector<double> & iv, int sigOrBgd ) const;
168 void InitTransform();
169 void Transform( std::vector<double> & iv, int sigOrBgd ) const;
170
171 // common member variables
172 const char* fClassName;
173
174 const size_t fNvars;
175 size_t GetNvar() const { return fNvars; }
176 char GetType( int ivar ) const { return fType[ivar]; }
177
178 // normalisation of input variables
179 double fVmin[4];
180 double fVmax[4];
181 double NormVariable( double x, double xmin, double xmax ) const {
182 // normalise to output range: [-1, 1]
183 return 2*(x - xmin)/(xmax - xmin) - 1.0;
184 }
185
186 // type of input variable: 'F' or 'I'
187 char fType[4];
188
189 // initialize internal variables
190 void Initialize();
191 double GetMvaValue__( const std::vector<double>& inputValues ) const;
192
193 // private members (method specific)
194 // not implemented for class: "ReadCutsD"
195};
196 inline double ReadCutsD::GetMvaValue( const std::vector<double>& inputValues ) const
197 {
198 // classifier response value
199 double retval = 0;
200
201 // classifier response, sanity check first
202 if (!IsStatusClean()) {
203 std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
204 << " because status is dirty" << std::endl;
205 retval = 0;
206 }
207 else {
208 std::vector<double> iV(inputValues);
209 Transform( iV, -1 );
210 retval = GetMvaValue__( iV );
211 }
212
213 return retval;
214 }
215
216//_______________________________________________________________________
217inline void ReadCutsD::InitTransform_1()
218{
219 // Decorrelation transformation, initialisation
220 fDecTF_1[0][0][0] = 1.2722714631;
221 fDecTF_1[0][0][1] = 0.0686064444285;
222 fDecTF_1[0][0][2] = -0.12911102307;
223 fDecTF_1[0][0][3] = -1.09274831745;
224 fDecTF_1[0][1][0] = 0.0686064444285;
225 fDecTF_1[0][1][1] = 0.955508716631;
226 fDecTF_1[0][1][2] = 0.160135175699;
227 fDecTF_1[0][1][3] = -0.260395275481;
228 fDecTF_1[0][2][0] = -0.12911102307;
229 fDecTF_1[0][2][1] = 0.160135175699;
230 fDecTF_1[0][2][2] = 1.82502263962;
231 fDecTF_1[0][2][3] = -0.851610263797;
232 fDecTF_1[0][3][0] = -1.09274831745;
233 fDecTF_1[0][3][1] = -0.260395275481;
234 fDecTF_1[0][3][2] = -0.851610263797;
235 fDecTF_1[0][3][3] = 2.83594069875;
236 fDecTF_1[1][0][0] = 1.25494894161;
237 fDecTF_1[1][0][1] = 0.0623620720116;
238 fDecTF_1[1][0][2] = -0.196685390931;
239 fDecTF_1[1][0][3] = -1.08407302428;
240 fDecTF_1[1][1][0] = 0.0623620720116;
241 fDecTF_1[1][1][1] = 0.989421920502;
242 fDecTF_1[1][1][2] = 0.225698355104;
243 fDecTF_1[1][1][3] = -0.268869598248;
244 fDecTF_1[1][2][0] = -0.196685390931;
245 fDecTF_1[1][2][1] = 0.225698355104;
246 fDecTF_1[1][2][2] = 1.81274154375;
247 fDecTF_1[1][2][3] = -0.812605958671;
248 fDecTF_1[1][3][0] = -1.08407302428;
249 fDecTF_1[1][3][1] = -0.268869598248;
250 fDecTF_1[1][3][2] = -0.812605958671;
251 fDecTF_1[1][3][3] = 2.87018256874;
252 fDecTF_1[2][0][0] = 1.14762966212;
253 fDecTF_1[2][0][1] = 0.0279230119711;
254 fDecTF_1[2][0][2] = -0.199814116336;
255 fDecTF_1[2][0][3] = -0.828429139126;
256 fDecTF_1[2][1][0] = 0.0279230119711;
257 fDecTF_1[2][1][1] = 0.95469118273;
258 fDecTF_1[2][1][2] = 0.185805400506;
259 fDecTF_1[2][1][3] = -0.162300136235;
260 fDecTF_1[2][2][0] = -0.199814116336;
261 fDecTF_1[2][2][1] = 0.185805400506;
262 fDecTF_1[2][2][2] = 1.79132300554;
263 fDecTF_1[2][2][3] = -0.772313501682;
264 fDecTF_1[2][3][0] = -0.828429139126;
265 fDecTF_1[2][3][1] = -0.162300136235;
266 fDecTF_1[2][3][2] = -0.772313501682;
267 fDecTF_1[2][3][3] = 2.19181433911;
268}
269
270//_______________________________________________________________________
271inline void ReadCutsD::Transform_1( std::vector<double>& iv, int cls) const
272{
273 // Decorrelation transformation
274 if (cls < 0 || cls > 2) {
275 if (2 > 1 ) cls = 2;
276 else cls = 2;
277 }
278
279 // define the indices of the variables which are transformed by this transformation
280 static std::vector<int> indicesGet;
281 static std::vector<int> indicesPut;
282
283 if ( indicesGet.empty() ) {
284 indicesGet.reserve(fNvars);
285 indicesGet.push_back( 0);
286 indicesGet.push_back( 1);
287 indicesGet.push_back( 2);
288 indicesGet.push_back( 3);
289 }
290 if ( indicesPut.empty() ) {
291 indicesPut.reserve(fNvars);
292 indicesPut.push_back( 0);
293 indicesPut.push_back( 1);
294 indicesPut.push_back( 2);
295 indicesPut.push_back( 3);
296 }
297
298 std::vector<double> tv;
299 for (int i=0; i<4;i++) {
300 double v = 0;
301 for (int j=0; j<4; j++)
302 v += iv[indicesGet.at(j)] * fDecTF_1[cls][i][j];
303 tv.push_back(v);
304 }
305 for (int i=0; i<4;i++) iv[indicesPut.at(i)] = tv[i];
306}
307
308//_______________________________________________________________________
309inline void ReadCutsD::InitTransform()
310{
311 InitTransform_1();
312}
313
314//_______________________________________________________________________
315inline void ReadCutsD::Transform( std::vector<double>& iv, int sigOrBgd ) const
316{
317 Transform_1( iv, sigOrBgd );
318}
SVector< double, 2 > v
Definition: Dict.h:5
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