00001 #include "MCNNAnalysis/LEMAmbyE50S491.h"
00002
00003
00004
00005 LEMAmbyE50S491::LEMAmbyE50S491()
00006 {
00007
00008
00009 fVmin[0] = -1;
00010 fVmax[0] = 1;
00011 fVmin[1] = -1;
00012 fVmax[1] = 1;
00013 fVmin[2] = -1;
00014 fVmax[2] = 0.999999940395355;
00015 fVmin[3] = -1;
00016 fVmax[3] = 0.999999940395355;
00017
00018
00019 fType[0] = 'F';
00020 fType[1] = 'F';
00021 fType[2] = 'F';
00022 fType[3] = 'F';
00023
00024
00025 Initialize();
00026
00027
00028 InitTransform();
00029 }
00030
00031
00032 inline void LEMAmbyE50S491::Initialize()
00033 {
00034
00035
00036 fLayers = 3;
00037 fLayerSize[0] = 5; fWeights[0] = new double[5];
00038 fLayerSize[1] = 10; fWeights[1] = new double[10];
00039 fLayerSize[2] = 1; fWeights[2] = new double[1];
00040
00041 fWeightMatrix0to1[0][0] = -0.152318321120594;
00042 fWeightMatrix0to1[1][0] = 0.140038941840388;
00043 fWeightMatrix0to1[2][0] = 0.150830788727814;
00044 fWeightMatrix0to1[3][0] = -0.152255144703905;
00045 fWeightMatrix0to1[4][0] = 0.137836159069207;
00046 fWeightMatrix0to1[5][0] = -0.121184535878213;
00047 fWeightMatrix0to1[6][0] = 0.139033891203744;
00048 fWeightMatrix0to1[7][0] = -0.108956700708734;
00049 fWeightMatrix0to1[8][0] = 0.349134725553892;
00050 fWeightMatrix0to1[0][1] = 0.205967629818834;
00051 fWeightMatrix0to1[1][1] = -0.134852396728545;
00052 fWeightMatrix0to1[2][1] = -0.178592543312265;
00053 fWeightMatrix0to1[3][1] = 0.186278178092904;
00054 fWeightMatrix0to1[4][1] = -0.125205805564187;
00055 fWeightMatrix0to1[5][1] = 0.16269157723916;
00056 fWeightMatrix0to1[6][1] = -0.130902963928656;
00057 fWeightMatrix0to1[7][1] = 0.552392965698308;
00058 fWeightMatrix0to1[8][1] = 2.00605701594573;
00059 fWeightMatrix0to1[0][2] = -0.351796753103481;
00060 fWeightMatrix0to1[1][2] = 0.119495150480259;
00061 fWeightMatrix0to1[2][2] = 0.234526141140616;
00062 fWeightMatrix0to1[3][2] = -0.259501720569135;
00063 fWeightMatrix0to1[4][2] = 0.0971029232485688;
00064 fWeightMatrix0to1[5][2] = -0.311255332162166;
00065 fWeightMatrix0to1[6][2] = 0.110460663357879;
00066 fWeightMatrix0to1[7][2] = -1.42763468116269;
00067 fWeightMatrix0to1[8][2] = 0.962545781664626;
00068 fWeightMatrix0to1[0][3] = 0.118397441928664;
00069 fWeightMatrix0to1[1][3] = -0.0814482182643213;
00070 fWeightMatrix0to1[2][3] = -0.11415203218872;
00071 fWeightMatrix0to1[3][3] = 0.119649439353558;
00072 fWeightMatrix0to1[4][3] = -0.0734675726864178;
00073 fWeightMatrix0to1[5][3] = 0.0952023767112997;
00074 fWeightMatrix0to1[6][3] = -0.0783740766209056;
00075 fWeightMatrix0to1[7][3] = 0.347262763001096;
00076 fWeightMatrix0to1[8][3] = -0.270506518649011;
00077 fWeightMatrix0to1[0][4] = -0.0842070177217706;
00078 fWeightMatrix0to1[1][4] = 0.0156252738586454;
00079 fWeightMatrix0to1[2][4] = 0.0481085654335284;
00080 fWeightMatrix0to1[3][4] = -0.0567634251254012;
00081 fWeightMatrix0to1[4][4] = 0.010838022295969;
00082 fWeightMatrix0to1[5][4] = -0.0359937871007552;
00083 fWeightMatrix0to1[6][4] = 0.0136216961169865;
00084 fWeightMatrix0to1[7][4] = -1.81344309339823;
00085 fWeightMatrix0to1[8][4] = -2.01702270861376;
00086
00087 fWeightMatrix1to2[0][0] = 0.11386357600865;
00088 fWeightMatrix1to2[0][1] = -0.0654124264943447;
00089 fWeightMatrix1to2[0][2] = -0.0759398815499141;
00090 fWeightMatrix1to2[0][3] = 0.0835250008640337;
00091 fWeightMatrix1to2[0][4] = -0.0682978470479161;
00092 fWeightMatrix1to2[0][5] = 0.0451858425686448;
00093 fWeightMatrix1to2[0][6] = -0.0663313873242806;
00094 fWeightMatrix1to2[0][7] = -0.446499096504961;
00095 fWeightMatrix1to2[0][8] = 0.58210274049323;
00096 fWeightMatrix1to2[0][9] = 0.302181334928035;
00097
00098 }
00099
00100 inline double LEMAmbyE50S491::GetMvaValue__( const std::vector<double>& inputValues ) const
00101 {
00102 if (inputValues.size() != (unsigned int)fLayerSize[0]-1) {
00103 std::cout << "Input vector needs to be of size " << fLayerSize[0]-1 << std::endl;
00104 return 0;
00105 }
00106
00107 for (int l=0; l<fLayers; l++)
00108 for (int i=0; i<fLayerSize[l]; i++) fWeights[l][i]=0;
00109
00110 for (int l=0; l<fLayers-1; l++)
00111 fWeights[l][fLayerSize[l]-1]=1;
00112
00113 for (int i=0; i<fLayerSize[0]-1; i++)
00114 fWeights[0][i]=inputValues[i];
00115
00116
00117 for (int o=0; o<fLayerSize[1]-1; o++) {
00118 for (int i=0; i<fLayerSize[0]; i++) {
00119 double inputVal = fWeightMatrix0to1[o][i] * fWeights[0][i];
00120 fWeights[1][o] += inputVal;
00121 }
00122 fWeights[1][o] = ActivationFnc(fWeights[1][o]);
00123 }
00124
00125 for (int o=0; o<fLayerSize[2]; o++) {
00126 for (int i=0; i<fLayerSize[1]; i++) {
00127 double inputVal = fWeightMatrix1to2[o][i] * fWeights[1][i];
00128 fWeights[2][o] += inputVal;
00129 }
00130 }
00131
00132 return fWeights[2][0];
00133 }
00134
00135 double LEMAmbyE50S491::ActivationFnc(double x) const {
00136
00137 return tanh(x);
00138 }
00139
00140
00141
00142
00143 inline void LEMAmbyE50S491::Clear()
00144 {
00145
00146 }
00147 inline double LEMAmbyE50S491::GetMvaValue( const std::vector<double>& inputValues ) const
00148 {
00149
00150 double retval = 0;
00151
00152
00153
00154 if (IsNormalised()) {
00155
00156 std::cout << "Doing some normalization I probably shouldn't" << std::endl;
00157 std::vector<double> iV;
00158 int ivar = 0;
00159 for (std::vector<double>::const_iterator varIt = inputValues.begin();
00160 varIt != inputValues.end(); varIt++, ivar++) {
00161 iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
00162 }
00163 Transform( iV, -1 );
00164 retval = GetMvaValue__( iV );
00165 }
00166 else {
00167 std::vector<double> iV;
00168 int ivar = 0;
00169 for (std::vector<double>::const_iterator varIt = inputValues.begin();
00170 varIt != inputValues.end(); varIt++, ivar++) {
00171 iV.push_back(*varIt);
00172 }
00173 Transform( iV, -1 );
00174 retval = GetMvaValue__( iV );
00175 }
00176
00177
00178 return retval;
00179 }
00180
00181
00182
00183
00184 inline void LEMAmbyE50S491::InitTransform_1()
00185 {
00186
00187
00188 fMin_1[0][0] = 0.0228846855462;
00189 fMax_1[0][0] = 0.98898011446;
00190 fMin_1[1][0] = 0.00716135371476;
00191 fMax_1[1][0] = 0.998298585415;
00192 fMin_1[2][0] = 0.00716135371476;
00193 fMax_1[2][0] = 0.998298585415;
00194 fMin_1[0][1] = 0.0475189238787;
00195 fMax_1[0][1] = 1;
00196 fMin_1[1][1] = 0;
00197 fMax_1[1][1] = 1;
00198 fMin_1[2][1] = 0;
00199 fMax_1[2][1] = 1;
00200 fMin_1[0][2] = 0.019999999553;
00201 fMax_1[0][2] = 0.980000019073;
00202 fMin_1[1][2] = 0.019999999553;
00203 fMax_1[1][2] = 0.980000019073;
00204 fMin_1[2][2] = 0.019999999553;
00205 fMax_1[2][2] = 0.980000019073;
00206 fMin_1[0][3] = 0.665335953236;
00207 fMax_1[0][3] = 15.999958992;
00208 fMin_1[1][3] = 0.632570564747;
00209 fMax_1[1][3] = 15.9997463226;
00210 fMin_1[2][3] = 0.632570564747;
00211 fMax_1[2][3] = 15.999958992;
00212
00213 }
00214
00215
00216 inline void LEMAmbyE50S491::Transform_1( std::vector<double>& iv, int cls) const
00217 {
00218 if (cls < 0 || cls > 2) {
00219 if (2 > 1 ) cls = 2;
00220 else cls = 2;
00221 }
00222 for (int ivar=0;ivar<4;ivar++) {
00223 double offset = fMin_1[cls][ivar];
00224 double scale = 1.0/(fMax_1[cls][ivar]-fMin_1[cls][ivar]);
00225 iv[ivar] = (iv[ivar]-offset)*scale * 2 - 1;
00226 }
00227 }
00228
00229
00230 inline void LEMAmbyE50S491::InitTransform()
00231 {
00232 InitTransform_1();
00233 }
00234
00235
00236 inline void LEMAmbyE50S491::Transform( std::vector<double>& iv, int sigOrBgd ) const
00237 {
00238 Transform_1( iv, sigOrBgd );
00239 }
00240
00241
00242
00244
00245
00246 Double_t LEMAmbyE50S491::GetLEMAmbyE50S491(NueRecord *nr){
00247
00248
00249 Double_t lemAmby=-1;
00250
00251
00252 Double_t val_mny=-1;
00253 Double_t val_mfqm=-1;
00254 Double_t val_fcc=-1;
00255 Double_t val_recoe=-1;
00256
00257
00258 val_mny = LEMStandard::Getymean(nr,1.0);
00259 val_mfqm = LEMStandard::GetMeanFracQMatched(nr,1.0);
00260 val_fcc = LEMStandard::GetfracCCy(nr,1.0);
00261 val_recoe = nr->srevent.phNueGeV;
00262
00263
00264 if (val_mny<0||val_mfqm<0||val_fcc<0||val_recoe<0) {
00265 lemAmby=-1;
00266 } else {
00267
00268 std::vector<double> inputVec( 4 );
00269
00270 inputVec[0]=val_mny;
00271 inputVec[1]=val_mfqm;
00272 inputVec[2]=val_fcc;
00273 inputVec[3]=val_recoe;
00274
00275
00276 lemAmby = LEMAmbyE50S491::GetMvaValue(inputVec);
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 Double_t lowval=-0.0571659;
00287 Double_t highval=1.05873;
00288 Double_t midpoint=(lowval+highval)/2.0;
00289 Double_t denom=(highval-lowval)*1.001;
00290
00291 lemAmby = (( lemAmby - lowval ) / denom);
00292
00293
00294 }
00295
00296 return lemAmby;
00297
00298 }
00299
00300
00301 Double_t LEMAmbyE50S491::GetLEMAmbyE50S491(NueAnaReader *nueana){
00302
00303 Double_t lemAmby=-1;
00304 lemAmby = GetLEMAmbyE50S491(nueana->nuerecord);
00305 return lemAmby;
00306
00307 }