Logo ROOT   6.12/07
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 
9 Method : Cuts::CutsD
10 TMVA Release : 4.2.1 [262657]
11 ROOT Release : 6.12/07 [396295]
12 Creator : sftnight
13 Date : Sat Sep 29 23:25:12 2018
14 Host : Linux ec-ubuntu-14-04-x86-64-2 3.13.0-157-generic #207-Ubuntu SMP Mon Aug 20 16:44:59 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
15 Dir : /mnt/build/workspace/root-makedoc-v612/rootspi/rdoc/src/v6-12-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 VarTransform: "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)"]
25 H: "False" [Print method-specific help message]
26 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)]
27 EffMethod: "EffSel" [Selection Method]
28 # Default:
29 VerbosityLevel: "Default" [Verbosity level]
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 <array>
62 #include <vector>
63 #include <cmath>
64 #include <string>
65 #include <iostream>
66 
67 #ifndef IClassifierReader__def
68 #define IClassifierReader__def
69 
70 class 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 
91 class 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  fIsNormalised( false )
101  {
102  // the training input variables
103  const char* inputVars[] = { "var1+var2", "var1-var2", "var3", "var4" };
104 
105  // sanity checks
106  if (theInputVars.size() <= 0) {
107  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
108  fStatusIsClean = false;
109  }
110 
111  if (theInputVars.size() != fNvars) {
112  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
113  << theInputVars.size() << " != " << fNvars << std::endl;
114  fStatusIsClean = false;
115  }
116 
117  // validate input variables
118  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
119  if (theInputVars[ivar] != inputVars[ivar]) {
120  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
121  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
122  fStatusIsClean = false;
123  }
124  }
125 
126  // initialize min and max vectors (for normalisation)
127  fVmin[0] = -4.33193111419678;
128  fVmax[0] = 4.13924121856689;
129  fVmin[1] = -3.67709016799927;
130  fVmax[1] = 3.65852665901184;
131  fVmin[2] = -3.82367396354675;
132  fVmax[2] = 3.87669587135315;
133  fVmin[3] = -4.0755443572998;
134  fVmax[3] = 3.28273677825928;
135 
136  // initialize input variable types
137  fType[0] = 'F';
138  fType[1] = 'F';
139  fType[2] = 'F';
140  fType[3] = 'F';
141 
142  // initialize constants
143  Initialize();
144 
145  // initialize transformation
146  InitTransform();
147  }
148 
149  // destructor
150  virtual ~ReadCutsD() {
151  Clear(); // method-specific
152  }
153 
154  // the classifier response
155  // "inputValues" is a vector of input values in the same order as the
156  // variables given to the constructor
157  double GetMvaValue( const std::vector<double>& inputValues ) const;
158 
159  private:
160 
161  // method-specific destructor
162  void Clear();
163 
164  // input variable transformation
165 
166  double fDecTF_1[3][4][4];
167  void InitTransform_1();
168  void Transform_1( std::vector<double> & iv, int sigOrBgd ) const;
169  void InitTransform();
170  void Transform( std::vector<double> & iv, int sigOrBgd ) const;
171 
172  // common member variables
173  const char* fClassName;
174 
175  const size_t fNvars;
176  size_t GetNvar() const { return fNvars; }
177  char GetType( int ivar ) const { return fType[ivar]; }
178 
179  // normalisation of input variables
180  const bool fIsNormalised;
181  bool IsNormalised() const { return fIsNormalised; }
182  double fVmin[4];
183  double fVmax[4];
184  double NormVariable( double x, double xmin, double xmax ) const {
185  // normalise to output range: [-1, 1]
186  return 2*(x - xmin)/(xmax - xmin) - 1.0;
187  }
188 
189  // type of input variable: 'F' or 'I'
190  char fType[4];
191 
192  // initialize internal variables
193  void Initialize();
194  double GetMvaValue__( const std::vector<double>& inputValues ) const;
195 
196  // private members (method specific)
197  // not implemented for class: "ReadCutsD"
198 };
199  inline double ReadCutsD::GetMvaValue( const std::vector<double>& inputValues ) const
200  {
201  // classifier response value
202  double retval = 0;
203 
204  // classifier response, sanity check first
205  if (!IsStatusClean()) {
206  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
207  << " because status is dirty" << std::endl;
208  retval = 0;
209  }
210  else {
211  if (IsNormalised()) {
212  // normalise variables
213  std::vector<double> iV;
214  iV.reserve(inputValues.size());
215  int ivar = 0;
216  for (std::vector<double>::const_iterator varIt = inputValues.begin();
217  varIt != inputValues.end(); varIt++, ivar++) {
218  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
219  }
220  Transform( iV, -1 );
221  retval = GetMvaValue__( iV );
222  }
223  else {
224  std::vector<double> iV;
225  int ivar = 0;
226  for (std::vector<double>::const_iterator varIt = inputValues.begin();
227  varIt != inputValues.end(); varIt++, ivar++) {
228  iV.push_back(*varIt);
229  }
230  Transform( iV, -1 );
231  retval = GetMvaValue__( iV );
232  }
233  }
234 
235  return retval;
236  }
237 
238 //_______________________________________________________________________
239 inline void ReadCutsD::InitTransform_1()
240 {
241  // Decorrelation transformation, initialisation
242  fDecTF_1[0][0][0] = 1.25719213024;
243  fDecTF_1[0][0][1] = 0.0741312801175;
244  fDecTF_1[0][0][2] = -0.129488374563;
245  fDecTF_1[0][0][3] = -1.12729166617;
246  fDecTF_1[0][1][0] = 0.0741312801175;
247  fDecTF_1[0][1][1] = 0.919041474312;
248  fDecTF_1[0][1][2] = 0.150275932861;
249  fDecTF_1[0][1][3] = -0.216647404573;
250  fDecTF_1[0][2][0] = -0.129488374563;
251  fDecTF_1[0][2][1] = 0.150275932861;
252  fDecTF_1[0][2][2] = 1.84972631436;
253  fDecTF_1[0][2][3] = -0.934543246776;
254  fDecTF_1[0][3][0] = -1.12729166617;
255  fDecTF_1[0][3][1] = -0.216647404573;
256  fDecTF_1[0][3][2] = -0.934543246776;
257  fDecTF_1[0][3][3] = 2.99752758195;
258  fDecTF_1[1][0][0] = 1.24281513542;
259  fDecTF_1[1][0][1] = 0.0648152051086;
260  fDecTF_1[1][0][2] = -0.150088956275;
261  fDecTF_1[1][0][3] = -1.09110802363;
262  fDecTF_1[1][1][0] = 0.0648152051086;
263  fDecTF_1[1][1][1] = 0.934140800916;
264  fDecTF_1[1][1][2] = 0.108344126828;
265  fDecTF_1[1][1][3] = -0.218357923054;
266  fDecTF_1[1][2][0] = -0.150088956275;
267  fDecTF_1[1][2][1] = 0.108344126828;
268  fDecTF_1[1][2][2] = 1.79915918204;
269  fDecTF_1[1][2][3] = -0.882003781889;
270  fDecTF_1[1][3][0] = -1.09110802363;
271  fDecTF_1[1][3][1] = -0.218357923054;
272  fDecTF_1[1][3][2] = -0.882003781889;
273  fDecTF_1[1][3][3] = 2.88426088942;
274  fDecTF_1[2][0][0] = 1.11526262065;
275  fDecTF_1[2][0][1] = 0.0356099235628;
276  fDecTF_1[2][0][2] = -0.199971755483;
277  fDecTF_1[2][0][3] = -0.796872057176;
278  fDecTF_1[2][1][0] = 0.0356099235628;
279  fDecTF_1[2][1][1] = 0.916090161623;
280  fDecTF_1[2][1][2] = 0.116419550846;
281  fDecTF_1[2][1][3] = -0.131134389786;
282  fDecTF_1[2][2][0] = -0.199971755483;
283  fDecTF_1[2][2][1] = 0.116419550846;
284  fDecTF_1[2][2][2] = 1.7870036012;
285  fDecTF_1[2][2][3] = -0.785928558579;
286  fDecTF_1[2][3][0] = -0.796872057176;
287  fDecTF_1[2][3][1] = -0.131134389786;
288  fDecTF_1[2][3][2] = -0.785928558579;
289  fDecTF_1[2][3][3] = 2.15508430057;
290 }
291 
292 //_______________________________________________________________________
293 inline void ReadCutsD::Transform_1( std::vector<double>& iv, int cls) const
294 {
295  // Decorrelation transformation
296  if (cls < 0 || cls > 2) {
297  if (2 > 1 ) cls = 2;
298  else cls = 2;
299  }
300 
301  // define the indices of the variables which are transformed by this transformation
302  static std::vector<int> indicesGet;
303  static std::vector<int> indicesPut;
304 
305  if ( indicesGet.empty() ) {
306  indicesGet.reserve(fNvars);
307  indicesGet.push_back( 0);
308  indicesGet.push_back( 1);
309  indicesGet.push_back( 2);
310  indicesGet.push_back( 3);
311  }
312  if ( indicesPut.empty() ) {
313  indicesPut.reserve(fNvars);
314  indicesPut.push_back( 0);
315  indicesPut.push_back( 1);
316  indicesPut.push_back( 2);
317  indicesPut.push_back( 3);
318  }
319 
320  std::vector<double> tv;
321  for (int i=0; i<4;i++) {
322  double v = 0;
323  for (int j=0; j<4; j++)
324  v += iv[indicesGet.at(j)] * fDecTF_1[cls][i][j];
325  tv.push_back(v);
326  }
327  for (int i=0; i<4;i++) iv[indicesPut.at(i)] = tv[i];
328 }
329 
330 //_______________________________________________________________________
331 inline void ReadCutsD::InitTransform()
332 {
333  InitTransform_1();
334 }
335 
336 //_______________________________________________________________________
337 inline void ReadCutsD::Transform( std::vector<double>& iv, int sigOrBgd ) const
338 {
339  Transform_1( iv, sigOrBgd );
340 }
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
SVector< double, 2 > v
Definition: Dict.h:5
float xmax
Definition: THbookFile.cxx:93
PyObject * fType