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