File indexing completed on 2025-08-06 08:14:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 #include <vector>
0060 #include <cmath>
0061 #include <string>
0062 #include <iostream>
0063
0064 #ifndef IClassifierReader__def
0065 #define IClassifierReader__def
0066
0067 class IClassifierReader {
0068
0069 public:
0070
0071
0072 IClassifierReader() : fStatusIsClean( true ) {}
0073 virtual ~IClassifierReader() {}
0074
0075
0076 virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
0077
0078
0079 bool IsStatusClean() const { return fStatusIsClean; }
0080
0081 protected:
0082
0083 bool fStatusIsClean;
0084 };
0085
0086 #endif
0087
0088 class ReadCuts : public IClassifierReader {
0089
0090 public:
0091
0092
0093 ReadCuts( std::vector<std::string>& theInputVars )
0094 : IClassifierReader(),
0095 fClassName( "ReadCuts" ),
0096 fNvars( 4 ),
0097 fIsNormalised( false )
0098 {
0099
0100 const char* inputVars[] = { "track_layer", "track_pT", "track_dca", "cluster_prob" };
0101
0102
0103 if (theInputVars.size() <= 0) {
0104 std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
0105 fStatusIsClean = false;
0106 }
0107
0108 if (theInputVars.size() != fNvars) {
0109 std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
0110 << theInputVars.size() << " != " << fNvars << std::endl;
0111 fStatusIsClean = false;
0112 }
0113
0114
0115 for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
0116 if (theInputVars[ivar] != inputVars[ivar]) {
0117 std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
0118 << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
0119 fStatusIsClean = false;
0120 }
0121 }
0122
0123
0124 fVmin[0] = 0;
0125 fVmax[0] = 0;
0126 fVmin[1] = 0;
0127 fVmax[1] = 0;
0128 fVmin[2] = 0;
0129 fVmax[2] = 0;
0130 fVmin[3] = 0;
0131 fVmax[3] = 0;
0132
0133
0134 fType[0] = 'I';
0135 fType[1] = 'F';
0136 fType[2] = 'F';
0137 fType[3] = 'F';
0138
0139
0140 Initialize();
0141
0142 }
0143
0144
0145 virtual ~ReadCuts() {
0146 Clear();
0147 }
0148
0149
0150
0151
0152 double GetMvaValue( const std::vector<double>& inputValues ) const;
0153
0154 private:
0155
0156
0157 void Clear();
0158
0159
0160 const char* fClassName;
0161
0162 const size_t fNvars;
0163 size_t GetNvar() const { return fNvars; }
0164 char GetType( int ivar ) const { return fType[ivar]; }
0165
0166
0167 const bool fIsNormalised;
0168 bool IsNormalised() const { return fIsNormalised; }
0169 double fVmin[4];
0170 double fVmax[4];
0171 double NormVariable( double x, double xmin, double xmax ) const {
0172
0173 return 2*(x - xmin)/(xmax - xmin) - 1.0;
0174 }
0175
0176
0177 char fType[4];
0178
0179
0180 void Initialize();
0181 double GetMvaValue__( const std::vector<double>& inputValues ) const;
0182
0183
0184
0185 };
0186 inline double ReadCuts::GetMvaValue( const std::vector<double>& inputValues ) const
0187 {
0188
0189 double retval = 0;
0190
0191
0192 if (!IsStatusClean()) {
0193 std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
0194 << " because status is dirty" << std::endl;
0195 retval = 0;
0196 }
0197 else {
0198 if (IsNormalised()) {
0199
0200 std::vector<double> iV;
0201 iV.reserve(inputValues.size());
0202 int ivar = 0;
0203 for (std::vector<double>::const_iterator varIt = inputValues.begin();
0204 varIt != inputValues.end(); varIt++, ivar++) {
0205 iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
0206 }
0207 retval = GetMvaValue__( iV );
0208 }
0209 else {
0210 retval = GetMvaValue__( inputValues );
0211 }
0212 }
0213
0214 return retval;
0215 }