Logo ROOT   6.10/09
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.10/09 [395785]
12 Creator : sftnight
13 Date : Thu May 31 12:04:22 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 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 <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 ReadCutsD : public IClassifierReader {
91 
92  public:
93 
94  // constructor
95  ReadCutsD( std::vector<std::string>& theInputVars )
96  : IClassifierReader(),
97  fClassName( "ReadCutsD" ),
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] = -4.33257102966309;
127  fVmax[0] = 4.13969755172729;
128  fVmin[1] = -3.67693758010864;
129  fVmax[1] = 3.65844249725342;
130  fVmin[2] = -3.82348656654358;
131  fVmax[2] = 3.87650275230408;
132  fVmin[3] = -4.07540273666382;
133  fVmax[3] = 3.2826201915741;
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;
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  const bool fIsNormalised;
180  bool IsNormalised() const { return fIsNormalised; }
181  double fVmin[4];
182  double fVmax[4];
183  double NormVariable( double x, double xmin, double xmax ) const {
184  // normalise to output range: [-1, 1]
185  return 2*(x - xmin)/(xmax - xmin) - 1.0;
186  }
187 
188  // type of input variable: 'F' or 'I'
189  char fType[4];
190 
191  // initialize internal variables
192  void Initialize();
193  double GetMvaValue__( const std::vector<double>& inputValues ) const;
194 
195  // private members (method specific)
196  // not implemented for class: "ReadCutsD"
197 };
198  inline double ReadCutsD::GetMvaValue( const std::vector<double>& inputValues ) const
199  {
200  // classifier response value
201  double retval = 0;
202 
203  // classifier response, sanity check first
204  if (!IsStatusClean()) {
205  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
206  << " because status is dirty" << std::endl;
207  retval = 0;
208  }
209  else {
210  if (IsNormalised()) {
211  // normalise variables
212  std::vector<double> iV;
213  iV.reserve(inputValues.size());
214  int ivar = 0;
215  for (std::vector<double>::const_iterator varIt = inputValues.begin();
216  varIt != inputValues.end(); varIt++, ivar++) {
217  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
218  }
219  Transform( iV, -1 );
220  retval = GetMvaValue__( iV );
221  }
222  else {
223  std::vector<double> iV;
224  int ivar = 0;
225  for (std::vector<double>::const_iterator varIt = inputValues.begin();
226  varIt != inputValues.end(); varIt++, ivar++) {
227  iV.push_back(*varIt);
228  }
229  Transform( iV, -1 );
230  retval = GetMvaValue__( iV );
231  }
232  }
233 
234  return retval;
235  }
236 
237 //_______________________________________________________________________
238 inline void ReadCutsD::InitTransform_1()
239 {
240  // Decorrelation transformation, initialisation
241  fDecTF_1[0][0][0] = 1.25719213024;
242  fDecTF_1[0][0][1] = 0.0741312801175;
243  fDecTF_1[0][0][2] = -0.129488374563;
244  fDecTF_1[0][0][3] = -1.12729166617;
245  fDecTF_1[0][1][0] = 0.0741312801175;
246  fDecTF_1[0][1][1] = 0.919041474312;
247  fDecTF_1[0][1][2] = 0.150275932861;
248  fDecTF_1[0][1][3] = -0.216647404573;
249  fDecTF_1[0][2][0] = -0.129488374563;
250  fDecTF_1[0][2][1] = 0.150275932861;
251  fDecTF_1[0][2][2] = 1.84972631436;
252  fDecTF_1[0][2][3] = -0.934543246776;
253  fDecTF_1[0][3][0] = -1.12729166617;
254  fDecTF_1[0][3][1] = -0.216647404573;
255  fDecTF_1[0][3][2] = -0.934543246776;
256  fDecTF_1[0][3][3] = 2.99752758195;
257  fDecTF_1[1][0][0] = 1.24279131222;
258  fDecTF_1[1][0][1] = 0.0648448543501;
259  fDecTF_1[1][0][2] = -0.150048699153;
260  fDecTF_1[1][0][3] = -1.09090447338;
261  fDecTF_1[1][1][0] = 0.0648448543501;
262  fDecTF_1[1][1][1] = 0.934067516635;
263  fDecTF_1[1][1][2] = 0.108351448594;
264  fDecTF_1[1][1][3] = -0.218262955298;
265  fDecTF_1[1][2][0] = -0.150048699153;
266  fDecTF_1[1][2][1] = 0.108351448594;
267  fDecTF_1[1][2][2] = 1.79900141278;
268  fDecTF_1[1][2][3] = -0.88198132815;
269  fDecTF_1[1][3][0] = -1.09090447338;
270  fDecTF_1[1][3][1] = -0.218262955298;
271  fDecTF_1[1][3][2] = -0.88198132815;
272  fDecTF_1[1][3][3] = 2.88428284798;
273  fDecTF_1[2][0][0] = 1.11530908969;
274  fDecTF_1[2][0][1] = 0.0356559944342;
275  fDecTF_1[2][0][2] = -0.199957514912;
276  fDecTF_1[2][0][3] = -0.796842132941;
277  fDecTF_1[2][1][0] = 0.0356559944342;
278  fDecTF_1[2][1][1] = 0.916070722826;
279  fDecTF_1[2][1][2] = 0.116422060141;
280  fDecTF_1[2][1][3] = -0.131131719689;
281  fDecTF_1[2][2][0] = -0.199957514912;
282  fDecTF_1[2][2][1] = 0.116422060141;
283  fDecTF_1[2][2][2] = 1.78690863893;
284  fDecTF_1[2][2][3] = -0.785886784465;
285  fDecTF_1[2][3][0] = -0.796842132941;
286  fDecTF_1[2][3][1] = -0.131131719689;
287  fDecTF_1[2][3][2] = -0.785886784465;
288  fDecTF_1[2][3][3] = 2.15499875738;
289 }
290 
291 //_______________________________________________________________________
292 inline void ReadCutsD::Transform_1( std::vector<double>& iv, int cls) const
293 {
294  // Decorrelation transformation
295  if (cls < 0 || cls > 2) {
296  if (2 > 1 ) cls = 2;
297  else cls = 2;
298  }
299 
300  // define the indices of the variables which are transformed by this transformation
301  static std::vector<int> indicesGet;
302  static std::vector<int> indicesPut;
303 
304  if ( indicesGet.empty() ) {
305  indicesGet.reserve(fNvars);
306  indicesGet.push_back( 0);
307  indicesGet.push_back( 1);
308  indicesGet.push_back( 2);
309  indicesGet.push_back( 3);
310  }
311  if ( indicesPut.empty() ) {
312  indicesPut.reserve(fNvars);
313  indicesPut.push_back( 0);
314  indicesPut.push_back( 1);
315  indicesPut.push_back( 2);
316  indicesPut.push_back( 3);
317  }
318 
319  std::vector<double> tv;
320  for (int i=0; i<4;i++) {
321  double v = 0;
322  for (int j=0; j<4; j++)
323  v += iv[indicesGet.at(j)] * fDecTF_1[cls][i][j];
324  tv.push_back(v);
325  }
326  for (int i=0; i<4;i++) iv[indicesPut.at(i)] = tv[i];
327 }
328 
329 //_______________________________________________________________________
330 inline void ReadCutsD::InitTransform()
331 {
332  InitTransform_1();
333 }
334 
335 //_______________________________________________________________________
336 inline void ReadCutsD::Transform( std::vector<double>& iv, int sigOrBgd ) const
337 {
338  Transform_1( iv, sigOrBgd );
339 }
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