File indexing completed on 2025-08-06 08:15:07
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 ReadPDEFoam : public IClassifierReader {
0097
0098 public:
0099
0100
0101 ReadPDEFoam( std::vector<std::string>& theInputVars )
0102 : IClassifierReader(),
0103 fClassName( "ReadPDEFoam" ),
0104 fNvars( 10 ),
0105 fIsNormalised( false )
0106 {
0107
0108 const char* inputVars[] = { "track_deta", "track_dlayer", "track_layer", "track_pT", "approach_dist", "vtx_radius", "vtxTrack_dist", "photon_m", "photon_pT", "cluster_prob" };
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 fVmin[5] = 0;
0143 fVmax[5] = 0;
0144 fVmin[6] = 0;
0145 fVmax[6] = 0;
0146 fVmin[7] = 0;
0147 fVmax[7] = 0;
0148 fVmin[8] = 0;
0149 fVmax[8] = 0;
0150 fVmin[9] = 0;
0151 fVmax[9] = 0;
0152
0153
0154 fType[0] = 'F';
0155 fType[1] = 'I';
0156 fType[2] = 'I';
0157 fType[3] = 'F';
0158 fType[4] = 'F';
0159 fType[5] = 'F';
0160 fType[6] = 'F';
0161 fType[7] = 'F';
0162 fType[8] = 'F';
0163 fType[9] = 'F';
0164
0165
0166 Initialize();
0167
0168 }
0169
0170
0171 virtual ~ReadPDEFoam() {
0172 Clear();
0173 }
0174
0175
0176
0177
0178 double GetMvaValue( const std::vector<double>& inputValues ) const;
0179
0180 private:
0181
0182
0183 void Clear();
0184
0185
0186 const char* fClassName;
0187
0188 const size_t fNvars;
0189 size_t GetNvar() const { return fNvars; }
0190 char GetType( int ivar ) const { return fType[ivar]; }
0191
0192
0193 const bool fIsNormalised;
0194 bool IsNormalised() const { return fIsNormalised; }
0195 double fVmin[10];
0196 double fVmax[10];
0197 double NormVariable( double x, double xmin, double xmax ) const {
0198
0199 return 2*(x - xmin)/(xmax - xmin) - 1.0;
0200 }
0201
0202
0203 char fType[10];
0204
0205
0206 void Initialize();
0207 double GetMvaValue__( const std::vector<double>& inputValues ) const;
0208
0209
0210 inline double ReadPDEFoam::GetMvaValue( const std::vector<double>& inputValues ) const
0211 {
0212
0213 double retval = 0;
0214
0215
0216 if (!IsStatusClean()) {
0217 std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
0218 << " because status is dirty" << std::endl;
0219 retval = 0;
0220 }
0221 else {
0222 if (IsNormalised()) {
0223
0224 std::vector<double> iV;
0225 iV.reserve(inputValues.size());
0226 int ivar = 0;
0227 for (std::vector<double>::const_iterator varIt = inputValues.begin();
0228 varIt != inputValues.end(); varIt++, ivar++) {
0229 iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
0230 }
0231 retval = GetMvaValue__( iV );
0232 }
0233 else {
0234 retval = GetMvaValue__( inputValues );
0235 }
0236 }
0237
0238 return retval;
0239 }