66 #ifndef IClassifierReader__def 67 #define IClassifierReader__def 69 class IClassifierReader {
74 IClassifierReader() : fStatusIsClean(
true ) {}
75 virtual ~IClassifierReader() {}
78 virtual double GetMvaValue(
const std::vector<double>& inputValues )
const = 0;
81 bool IsStatusClean()
const {
return fStatusIsClean; }
90 class ReadCutsD :
public IClassifierReader {
95 ReadCutsD( std::vector<std::string>& theInputVars )
96 : IClassifierReader(),
97 fClassName(
"ReadCutsD" ),
99 fIsNormalised(
false )
102 const char* inputVars[] = {
"var1+var2",
"var1-var2",
"var3",
"var4" };
105 if (theInputVars.size() <= 0) {
106 std::cout <<
"Problem in class \"" << fClassName <<
"\": empty input vector" << std::endl;
107 fStatusIsClean =
false;
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;
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;
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;
149 virtual ~ReadCutsD() {
156 double GetMvaValue(
const std::vector<double>& inputValues )
const;
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;
172 const char* fClassName;
175 size_t GetNvar()
const {
return fNvars; }
179 const bool fIsNormalised;
180 bool IsNormalised()
const {
return fIsNormalised; }
183 double NormVariable(
double x,
double xmin,
double xmax )
const {
185 return 2*(x -
xmin)/(xmax - xmin) - 1.0;
193 double GetMvaValue__(
const std::vector<double>& inputValues )
const;
198 inline double ReadCutsD::GetMvaValue(
const std::vector<double>& inputValues )
const 204 if (!IsStatusClean()) {
205 std::cout <<
"Problem in class \"" << fClassName <<
"\": cannot return classifier response" 206 <<
" because status is dirty" << std::endl;
210 if (IsNormalised()) {
212 std::vector<double> iV;
213 iV.reserve(inputValues.size());
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] ));
220 retval = GetMvaValue__( iV );
223 std::vector<double> iV;
225 for (std::vector<double>::const_iterator varIt = inputValues.begin();
226 varIt != inputValues.end(); varIt++, ivar++) {
227 iV.push_back(*varIt);
230 retval = GetMvaValue__( iV );
238 inline void ReadCutsD::InitTransform_1()
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;
292 inline void ReadCutsD::Transform_1( std::vector<double>& iv,
int cls)
const 295 if (cls < 0 || cls > 2) {
301 static std::vector<int> indicesGet;
302 static std::vector<int> indicesPut;
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);
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);
319 std::vector<double> tv;
320 for (
int i=0; i<4;i++) {
322 for (
int j=0; j<4; j++)
323 v += iv[indicesGet.at(j)] * fDecTF_1[cls][i][j];
326 for (
int i=0; i<4;i++) iv[indicesPut.at(i)] = tv[i];
330 inline void ReadCutsD::InitTransform()
336 inline void ReadCutsD::Transform( std::vector<double>& iv,
int sigOrBgd )
const 338 Transform_1( iv, sigOrBgd );
Type GetType(const std::string &Name)
void Initialize(Bool_t useTMVAStyle=kTRUE)