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