Logo ROOT   6.16/01
Reference Guide
TMVAClassification_LD.class.C
Go to the documentation of this file.
1// Class: ReadLD
2// Automatically generated by MethodBase::MakeClass
3//
4
5/* configuration options =====================================================
6
7#GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8
9Method : LD::LD
10TMVA Release : 4.2.1 [262657]
11ROOT Release : 6.16/01 [397313]
12Creator : sftnight
13Date : Sun Dec 19 22:13:32 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: "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)"]
25H: "True" [Print method-specific help message]
26CreateMVAPdfs: "True" [Create PDFs for classifier outputs (signal and background)]
27# Default:
28VerbosityLevel: "Default" [Verbosity level]
29IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
30##
31
32
33#VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
34
35NVar 4
36var1+var2 myvar1 myvar1 myvar1 'F' [-9.33803939819,7.69307804108]
37var1-var2 myvar2 myvar2 Expression 2 'F' [-3.25508260727,4.02912044525]
38var3 var3 var3 Variable 3 units 'F' [-5.2777428627,4.64297914505]
39var4 var4 var4 Variable 4 units 'F' [-5.6007027626,4.67435789108]
40NSpec 2
41var1*2 spec1 spec1 Spectator 1 units 'F' [-9.91655540466,8.7030172348]
42var1*3 spec2 spec2 Spectator 2 units 'F' [-14.874833107,13.0545253754]
43
44
45============================================================================ */
46
47#include <array>
48#include <vector>
49#include <cmath>
50#include <string>
51#include <iostream>
52
53#ifndef IClassifierReader__def
54#define IClassifierReader__def
55
56class IClassifierReader {
57
58 public:
59
60 // constructor
61 IClassifierReader() : fStatusIsClean( true ) {}
62 virtual ~IClassifierReader() {}
63
64 // return classifier response
65 virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
66
67 // returns classifier status
68 bool IsStatusClean() const { return fStatusIsClean; }
69
70 protected:
71
72 bool fStatusIsClean;
73};
74
75#endif
76
77class ReadLD : public IClassifierReader {
78
79 public:
80
81 // constructor
82 ReadLD( std::vector<std::string>& theInputVars )
83 : IClassifierReader(),
84 fClassName( "ReadLD" ),
85 fNvars( 4 )
86 {
87 // the training input variables
88 const char* inputVars[] = { "var1+var2", "var1-var2", "var3", "var4" };
89
90 // sanity checks
91 if (theInputVars.size() <= 0) {
92 std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
93 fStatusIsClean = false;
94 }
95
96 if (theInputVars.size() != fNvars) {
97 std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
98 << theInputVars.size() << " != " << fNvars << std::endl;
99 fStatusIsClean = false;
100 }
101
102 // validate input variables
103 for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
104 if (theInputVars[ivar] != inputVars[ivar]) {
105 std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
106 << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
107 fStatusIsClean = false;
108 }
109 }
110
111 // initialize min and max vectors (for normalisation)
112 fVmin[0] = 0;
113 fVmax[0] = 0;
114 fVmin[1] = 0;
115 fVmax[1] = 0;
116 fVmin[2] = 0;
117 fVmax[2] = 0;
118 fVmin[3] = 0;
119 fVmax[3] = 0;
120
121 // initialize input variable types
122 fType[0] = 'F';
123 fType[1] = 'F';
124 fType[2] = 'F';
125 fType[3] = 'F';
126
127 // initialize constants
128 Initialize();
129
130 }
131
132 // destructor
133 virtual ~ReadLD() {
134 Clear(); // method-specific
135 }
136
137 // the classifier response
138 // "inputValues" is a vector of input values in the same order as the
139 // variables given to the constructor
140 double GetMvaValue( const std::vector<double>& inputValues ) const override;
141
142 private:
143
144 // method-specific destructor
145 void Clear();
146
147 // common member variables
148 const char* fClassName;
149
150 const size_t fNvars;
151 size_t GetNvar() const { return fNvars; }
152 char GetType( int ivar ) const { return fType[ivar]; }
153
154 // normalisation of input variables
155 double fVmin[4];
156 double fVmax[4];
157 double NormVariable( double x, double xmin, double xmax ) const {
158 // normalise to output range: [-1, 1]
159 return 2*(x - xmin)/(xmax - xmin) - 1.0;
160 }
161
162 // type of input variable: 'F' or 'I'
163 char fType[4];
164
165 // initialize internal variables
166 void Initialize();
167 double GetMvaValue__( const std::vector<double>& inputValues ) const;
168
169 // private members (method specific)
170 std::vector<double> fLDCoefficients;
171};
172
173inline void ReadLD::Initialize()
174{
175 fLDCoefficients.push_back( -0.0548834585145 );
176 fLDCoefficients.push_back( -0.309417182502 );
177 fLDCoefficients.push_back( -0.101898689979 );
178 fLDCoefficients.push_back( -0.142337150119 );
179 fLDCoefficients.push_back( 0.705328504943 );
180
181 // sanity check
182 if (fLDCoefficients.size() != fNvars+1) {
183 std::cout << "Problem in class \"" << fClassName << "\"::Initialize: mismatch in number of input values"
184 << fLDCoefficients.size() << " != " << fNvars+1 << std::endl;
185 fStatusIsClean = false;
186 }
187}
188
189inline double ReadLD::GetMvaValue__( const std::vector<double>& inputValues ) const
190{
191 double retval = fLDCoefficients[0];
192 for (size_t ivar = 1; ivar < fNvars+1; ivar++) {
193 retval += fLDCoefficients[ivar]*inputValues[ivar-1];
194 }
195
196 return retval;
197}
198
199// Clean up
200inline void ReadLD::Clear()
201{
202 // clear coefficients
203 fLDCoefficients.clear();
204}
205 inline double ReadLD::GetMvaValue( const std::vector<double>& inputValues ) const
206 {
207 // classifier response value
208 double retval = 0;
209
210 // classifier response, sanity check first
211 if (!IsStatusClean()) {
212 std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
213 << " because status is dirty" << std::endl;
214 retval = 0;
215 }
216 else {
217 retval = GetMvaValue__( inputValues );
218 }
219
220 return retval;
221 }
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