File indexing completed on 2025-08-05 08:14:10
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
0060
0061
0062
0063
0064
0065
0066
0067 #include <vector>
0068 #include <cmath>
0069 #include <string>
0070 #include <iostream>
0071
0072 #ifndef IClassifierReader__def
0073 #define IClassifierReader__def
0074
0075 class IClassifierReader {
0076
0077 public:
0078
0079
0080 IClassifierReader() : fStatusIsClean( true ) {}
0081 virtual ~IClassifierReader() {}
0082
0083
0084 virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
0085
0086
0087 bool IsStatusClean() const { return fStatusIsClean; }
0088
0089 protected:
0090
0091 bool fStatusIsClean;
0092 };
0093
0094 #endif
0095
0096 class ReadCuts : public IClassifierReader {
0097
0098 public:
0099
0100
0101 ReadCuts( std::vector<std::string>& theInputVars )
0102 : IClassifierReader(),
0103 fClassName( "ReadCuts" ),
0104 fNvars( 5 ),
0105 fIsNormalised( false )
0106 {
0107
0108 const char* inputVars[] = { "abs(track_deta)", "abs(cluster_deta)", "abs(cluster_dphi)", "abs(track_dlayer)", "approach_dist" };
0109
0110
0111 if (theInputVars.size() <= 0) {
0112 std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
0113 fStatusIsClean = false;
0114 }
0115
0116 if (theInputVars.size() != fNvars) {
0117 std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
0118 << theInputVars.size() << " != " << fNvars << std::endl;
0119 fStatusIsClean = false;
0120 }
0121
0122
0123 for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
0124 if (theInputVars[ivar] != inputVars[ivar]) {
0125 std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
0126 << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
0127 fStatusIsClean = false;
0128 }
0129 }
0130
0131
0132 fVmin[0] = 0;
0133 fVmax[0] = 0;
0134 fVmin[1] = 0;
0135 fVmax[1] = 0;
0136 fVmin[2] = 0;
0137 fVmax[2] = 0;
0138 fVmin[3] = 0;
0139 fVmax[3] = 0;
0140 fVmin[4] = 0;
0141 fVmax[4] = 0;
0142
0143
0144 fType[0] = 'F';
0145 fType[1] = 'F';
0146 fType[2] = 'F';
0147 fType[3] = 'I';
0148 fType[4] = 'F';
0149
0150
0151 Initialize();
0152
0153 }
0154
0155
0156 virtual ~ReadCuts() {
0157 Clear();
0158 }
0159
0160
0161
0162
0163 double GetMvaValue( const std::vector<double>& inputValues ) const;
0164
0165 private:
0166
0167
0168 void Clear();
0169
0170
0171 const char* fClassName;
0172
0173 const size_t fNvars;
0174 size_t GetNvar() const { return fNvars; }
0175 char GetType( int ivar ) const { return fType[ivar]; }
0176
0177
0178 const bool fIsNormalised;
0179 bool IsNormalised() const { return fIsNormalised; }
0180 double fVmin[5];
0181 double fVmax[5];
0182 double NormVariable( double x, double xmin, double xmax ) const {
0183
0184 return 2*(x - xmin)/(xmax - xmin) - 1.0;
0185 }
0186
0187
0188 char fType[5];
0189
0190
0191 void Initialize();
0192 double GetMvaValue__( const std::vector<double>& inputValues ) const;
0193
0194
0195
0196 };
0197 inline double ReadCuts::GetMvaValue( const std::vector<double>& inputValues ) const
0198 {
0199
0200 double retval = 0;
0201
0202
0203 if (!IsStatusClean()) {
0204 std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
0205 << " because status is dirty" << std::endl;
0206 retval = 0;
0207 }
0208 else {
0209 if (IsNormalised()) {
0210
0211 std::vector<double> iV;
0212 iV.reserve(inputValues.size());
0213 int ivar = 0;
0214 for (std::vector<double>::const_iterator varIt = inputValues.begin();
0215 varIt != inputValues.end(); varIt++, ivar++) {
0216 iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
0217 }
0218 retval = GetMvaValue__( iV );
0219 }
0220 else {
0221 retval = GetMvaValue__( inputValues );
0222 }
0223 }
0224
0225 return retval;
0226 }