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