00001 #include "MCNNAnalysis/LEMAmbyE50S5111.h"
00002
00003
00004
00005 LEMAmbyE50S5111::LEMAmbyE50S5111()
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 fVmin[4] = -1;
00018 fVmax[4] = 1;
00019
00020
00021 fType[0] = 'F';
00022 fType[1] = 'F';
00023 fType[2] = 'F';
00024 fType[3] = 'F';
00025 fType[4] = 'F';
00026
00027
00028 Initialize();
00029
00030
00031 InitTransform();
00032 }
00033
00034
00035 inline void LEMAmbyE50S5111::Initialize()
00036 {
00037
00038
00039 fLayers = 3;
00040 fLayerSize[0] = 6; fWeights[0] = new double[6];
00041 fLayerSize[1] = 12; fWeights[1] = new double[12];
00042 fLayerSize[2] = 1; fWeights[2] = new double[1];
00043
00044 fWeightMatrix0to1[0][0] = 0.457164863943827;
00045 fWeightMatrix0to1[1][0] = 0.0220928136491208;
00046 fWeightMatrix0to1[2][0] = -0.0220155740490428;
00047 fWeightMatrix0to1[3][0] = 0.0219686579306614;
00048 fWeightMatrix0to1[4][0] = 0.0220231333381128;
00049 fWeightMatrix0to1[5][0] = -0.0220049047643356;
00050 fWeightMatrix0to1[6][0] = 0.0221341437418853;
00051 fWeightMatrix0to1[7][0] = -0.0219962650033325;
00052 fWeightMatrix0to1[8][0] = 0.0220472731270565;
00053 fWeightMatrix0to1[9][0] = 0.0219508308069218;
00054 fWeightMatrix0to1[10][0] = 0.0220989327625126;
00055 fWeightMatrix0to1[0][1] = 3.28101780366812;
00056 fWeightMatrix0to1[1][1] = -0.0776435671584362;
00057 fWeightMatrix0to1[2][1] = 0.0776263099380779;
00058 fWeightMatrix0to1[3][1] = -0.0776158321238156;
00059 fWeightMatrix0to1[4][1] = -0.0776279984708945;
00060 fWeightMatrix0to1[5][1] = 0.0776239268662966;
00061 fWeightMatrix0to1[6][1] = -0.0776528050093853;
00062 fWeightMatrix0to1[7][1] = 0.0776219972306231;
00063 fWeightMatrix0to1[8][1] = -0.0776333912002757;
00064 fWeightMatrix0to1[9][1] = -0.0776118516500025;
00065 fWeightMatrix0to1[10][1] = -0.0776449347033747;
00066 fWeightMatrix0to1[0][2] = 1.23693441152423;
00067 fWeightMatrix0to1[1][2] = -0.13057738176211;
00068 fWeightMatrix0to1[2][2] = 0.130496678670272;
00069 fWeightMatrix0to1[3][2] = -0.130447662171314;
00070 fWeightMatrix0to1[4][2] = -0.130504576619991;
00071 fWeightMatrix0to1[5][2] = 0.13048553150881;
00072 fWeightMatrix0to1[6][2] = -0.130620567960954;
00073 fWeightMatrix0to1[7][2] = 0.130476504870904;
00074 fWeightMatrix0to1[8][2] = -0.130529798327316;
00075 fWeightMatrix0to1[9][2] = -0.130429037619701;
00076 fWeightMatrix0to1[10][2] = -0.130583775555715;
00077 fWeightMatrix0to1[0][3] = -0.199013184025842;
00078 fWeightMatrix0to1[1][3] = 0.0361593634871003;
00079 fWeightMatrix0to1[2][3] = -0.0361047740517259;
00080 fWeightMatrix0to1[3][3] = 0.0360716192096197;
00081 fWeightMatrix0to1[4][3] = 0.0361101163128128;
00082 fWeightMatrix0to1[5][3] = -0.0360972340227785;
00083 fWeightMatrix0to1[6][3] = 0.0361885765061547;
00084 fWeightMatrix0to1[7][3] = -0.0360911283636637;
00085 fWeightMatrix0to1[8][3] = 0.0361271766934121;
00086 fWeightMatrix0to1[9][3] = 0.0360590217410728;
00087 fWeightMatrix0to1[10][3] = 0.0361636884876753;
00088 fWeightMatrix0to1[0][4] = -0.639962278203516;
00089 fWeightMatrix0to1[1][4] = -0.0519357491034027;
00090 fWeightMatrix0to1[2][4] = 0.0519940946882203;
00091 fWeightMatrix0to1[3][4] = -0.0520295581992349;
00092 fWeightMatrix0to1[4][4] = -0.0519883823676268;
00093 fWeightMatrix0to1[5][4] = 0.0520021579314653;
00094 fWeightMatrix0to1[6][4] = -0.0519045490115962;
00095 fWeightMatrix0to1[7][4] = 0.0520086880586148;
00096 fWeightMatrix0to1[8][4] = -0.0519701438024577;
00097 fWeightMatrix0to1[9][4] = -0.0520430382975507;
00098 fWeightMatrix0to1[10][4] = -0.0519311289034354;
00099 fWeightMatrix0to1[0][5] = -2.65616566273247;
00100 fWeightMatrix0to1[1][5] = 0.0242893162510659;
00101 fWeightMatrix0to1[2][5] = -0.0243270284656713;
00102 fWeightMatrix0to1[3][5] = 0.0243499119561036;
00103 fWeightMatrix0to1[4][5] = 0.0243233397486465;
00104 fWeightMatrix0to1[5][5] = -0.0243322339928733;
00105 fWeightMatrix0to1[6][5] = 0.0242691172849299;
00106 fWeightMatrix0to1[7][5] = -0.0243364486492918;
00107 fWeightMatrix0to1[8][5] = 0.0243115571667766;
00108 fWeightMatrix0to1[9][5] = 0.0243586025722464;
00109 fWeightMatrix0to1[10][5] = 0.0242863265606441;
00110
00111 fWeightMatrix1to2[0][0] = 0.331026185122903;
00112 fWeightMatrix1to2[0][1] = -0.114384460634508;
00113 fWeightMatrix1to2[0][2] = 0.114382212447269;
00114 fWeightMatrix1to2[0][3] = -0.114380892573337;
00115 fWeightMatrix1to2[0][4] = -0.114382428341914;
00116 fWeightMatrix1to2[0][5] = 0.114381909256857;
00117 fWeightMatrix1to2[0][6] = -0.114385702040211;
00118 fWeightMatrix1to2[0][7] = 0.114381665049863;
00119 fWeightMatrix1to2[0][8] = -0.114383123779133;
00120 fWeightMatrix1to2[0][9] = -0.114380400108112;
00121 fWeightMatrix1to2[0][10] = -0.114384642740348;
00122 fWeightMatrix1to2[0][11] = 0.491114735426463;
00123
00124
00125 }
00126
00127 inline double LEMAmbyE50S5111::GetMvaValue__( const std::vector<double>& inputValues ) const
00128 {
00129 if (inputValues.size() != (unsigned int)fLayerSize[0]-1) {
00130 std::cout << "Input vector needs to be of size " << fLayerSize[0]-1 << std::endl;
00131 return 0;
00132 }
00133
00134 for (int l=0; l<fLayers; l++)
00135 for (int i=0; i<fLayerSize[l]; i++) fWeights[l][i]=0;
00136
00137 for (int l=0; l<fLayers-1; l++)
00138 fWeights[l][fLayerSize[l]-1]=1;
00139
00140 for (int i=0; i<fLayerSize[0]-1; i++)
00141 fWeights[0][i]=inputValues[i];
00142
00143
00144 for (int o=0; o<fLayerSize[1]-1; o++) {
00145 for (int i=0; i<fLayerSize[0]; i++) {
00146 double inputVal = fWeightMatrix0to1[o][i] * fWeights[0][i];
00147 fWeights[1][o] += inputVal;
00148 }
00149 fWeights[1][o] = ActivationFnc(fWeights[1][o]);
00150 }
00151
00152 for (int o=0; o<fLayerSize[2]; o++) {
00153 for (int i=0; i<fLayerSize[1]; i++) {
00154 double inputVal = fWeightMatrix1to2[o][i] * fWeights[1][i];
00155 fWeights[2][o] += inputVal;
00156 }
00157 }
00158
00159 return fWeights[2][0];
00160 }
00161
00162 double LEMAmbyE50S5111::ActivationFnc(double x) const {
00163
00164 return tanh(x);
00165 }
00166
00167
00168
00169
00170 inline void LEMAmbyE50S5111::Clear()
00171 {
00172
00173 }
00174 inline double LEMAmbyE50S5111::GetMvaValue( const std::vector<double>& inputValues ) const
00175 {
00176
00177 double retval = 0;
00178
00179
00180
00181 if (IsNormalised()) {
00182
00183 std::vector<double> iV;
00184 int ivar = 0;
00185 for (std::vector<double>::const_iterator varIt = inputValues.begin();
00186 varIt != inputValues.end(); varIt++, ivar++) {
00187 iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
00188 }
00189 Transform( iV, -1 );
00190 retval = GetMvaValue__( iV );
00191 }
00192 else {
00193 std::vector<double> iV;
00194 int ivar = 0;
00195 for (std::vector<double>::const_iterator varIt = inputValues.begin();
00196 varIt != inputValues.end(); varIt++, ivar++) {
00197 iV.push_back(*varIt);
00198 }
00199 Transform( iV, -1 );
00200 retval = GetMvaValue__( iV );
00201 }
00202
00203
00204 return retval;
00205 }
00206
00207
00208
00209
00210 inline void LEMAmbyE50S5111::InitTransform_1()
00211 {
00212
00213
00214 fMin_1[0][0] = 0.0228846855462;
00215 fMax_1[0][0] = 0.98898011446;
00216 fMin_1[1][0] = 0.00716135371476;
00217 fMax_1[1][0] = 0.998298585415;
00218 fMin_1[2][0] = 0.00716135371476;
00219 fMax_1[2][0] = 0.998298585415;
00220 fMin_1[0][1] = 0.0475189238787;
00221 fMax_1[0][1] = 1;
00222 fMin_1[1][1] = 0;
00223 fMax_1[1][1] = 1;
00224 fMin_1[2][1] = 0;
00225 fMax_1[2][1] = 1;
00226 fMin_1[0][2] = 0.019999999553;
00227 fMax_1[0][2] = 0.980000019073;
00228 fMin_1[1][2] = 0.019999999553;
00229 fMax_1[1][2] = 0.980000019073;
00230 fMin_1[2][2] = 0.019999999553;
00231 fMax_1[2][2] = 0.980000019073;
00232 fMin_1[0][3] = 0.665335953236;
00233 fMax_1[0][3] = 15.999958992;
00234 fMin_1[1][3] = 0.632570564747;
00235 fMax_1[1][3] = 15.9997463226;
00236 fMin_1[2][3] = 0.632570564747;
00237 fMax_1[2][3] = 15.999958992;
00238 fMin_1[0][4] = 0;
00239 fMax_1[0][4] = 0.998935520649;
00240 fMin_1[1][4] = 0;
00241 fMax_1[1][4] = 0.997940421104;
00242 fMin_1[2][4] = 0;
00243 fMax_1[2][4] = 0.998935520649;
00244
00245 }
00246
00247
00248 inline void LEMAmbyE50S5111::Transform_1( std::vector<double>& iv, int cls) const
00249 {
00250 if (cls < 0 || cls > 2) {
00251 if (2 > 1 ) cls = 2;
00252 else cls = 2;
00253 }
00254 for (int ivar=0;ivar<5;ivar++) {
00255 double offset = fMin_1[cls][ivar];
00256 double scale = 1.0/(fMax_1[cls][ivar]-fMin_1[cls][ivar]);
00257 iv[ivar] = (iv[ivar]-offset)*scale * 2 - 1;
00258 }
00259 }
00260
00261
00262 inline void LEMAmbyE50S5111::InitTransform()
00263 {
00264 InitTransform_1();
00265 }
00266
00267
00268 inline void LEMAmbyE50S5111::Transform( std::vector<double>& iv, int sigOrBgd ) const
00269 {
00270 Transform_1( iv, sigOrBgd );
00271 }
00272
00273
00274
00276
00277
00278 Double_t LEMAmbyE50S5111::GetLEMAmbyE50S5111(NueRecord *nr){
00279
00280
00281 Double_t lemAmby=-1;
00282
00283
00284 Double_t val_mny=-1;
00285 Double_t val_mfqm=-1;
00286 Double_t val_fcc=-1;
00287 Double_t val_recoe=-1;
00288 Double_t val_ncmny=-1;
00289
00290
00291 val_mny = LEMStandard::Getymean(nr,1.0);
00292 val_mfqm = LEMStandard::GetMeanFracQMatched(nr,1.0);
00293 val_fcc = LEMStandard::GetfracCCy(nr,1.0);
00294 val_recoe = nr->srevent.phNueGeV;
00295 val_ncmny = LEMStandard::GetNCymean(nr,1.0);
00296
00297
00298 if (val_ncmny<0||val_mny<0||val_mfqm<0||val_fcc<0||val_recoe<0) {
00299 lemAmby=-1;
00300 } else {
00301
00302 std::vector<double> inputVec( 5 );
00303
00304 inputVec[0]=val_mny;
00305 inputVec[1]=val_mfqm;
00306 inputVec[2]=val_fcc;
00307 inputVec[3]=val_recoe;
00308 inputVec[4]=val_ncmny;
00309
00310
00311 lemAmby = LEMAmbyE50S5111::GetMvaValue(inputVec);
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 Double_t lowval=-0.0997124;
00322 Double_t highval=1.0242;
00323 Double_t midpoint=(lowval+highval)/2.0;
00324 Double_t denom=(highval-lowval)*1.001;
00325
00326 lemAmby = (( lemAmby - lowval ) / denom);
00327
00328
00329
00330
00331
00332 }
00333
00334 return lemAmby;
00335
00336 }
00337
00338
00339 Double_t LEMAmbyE50S5111::GetLEMAmbyE50S5111(NueAnaReader *nueana){
00340
00341 Double_t lemAmby=-1;
00342 lemAmby = GetLEMAmbyE50S5111(nueana->nuerecord);
00343 return lemAmby;
00344
00345 }