LEMNNpid Class Reference

#include <LEMNNpid.h>

List of all members.

Public Member Functions

 LEMNNpid ()
 ~LEMNNpid ()
double GetMvaValue (const std::vector< double > &inputValues) const
Double_t GetLEMpid (NueRecord *nr)
Double_t GetLEMpid (NueAnaReader *nueana)

Private Member Functions

void Clear ()
void InitTransform_1 ()
void Transform_1 (std::vector< double > &iv, int sigOrBgd) const
void InitTransform ()
void Transform (std::vector< double > &iv, int sigOrBgd) const
char GetType (int ivar) const
Bool_t IsNormalised () const
double NormVariable (double x, double xmin, double xmax) const
void Initialize ()
double GetMvaValue__ (const std::vector< double > &inputValues) const
double ActivationFnc (double x) const

Private Attributes

double fMin_1 [3][4]
double fMax_1 [3][4]
const char * fClassName
double fVmin [4]
double fVmax [4]
char fType [4]
int fLayers
int fLayerSize [3]
double fWeightMatrix0to1 [10][5]
double fWeightMatrix1to2 [1][10]
double * fWeights [3]

Detailed Description

Definition at line 26 of file LEMNNpid.h.


Constructor & Destructor Documentation

LEMNNpid::LEMNNpid (  ) 

Definition at line 19 of file LEMNNpid.cxx.

References fType, fVmax, fVmin, Initialize(), and InitTransform().

00020 {
00021 
00022 
00023       // initialize min and max vectors (for normalisation)
00024       fVmin[0] = -1;
00025       fVmax[0] = 0.99999988079071;
00026       fVmin[1] = -1;
00027       fVmax[1] = 1.00000011920929;
00028       fVmin[2] = -1;
00029       fVmax[2] = 1;
00030       fVmin[3] = -1;
00031       fVmax[3] = 1;
00032 
00033       // initialize input variable types
00034       fType[0] = 'F';
00035       fType[1] = 'F';
00036       fType[2] = 'F';
00037       fType[3] = 'F';
00038 
00039       // initialize constants
00040       Initialize();
00041 
00042       // initialize transformation
00043       InitTransform();
00044 }

LEMNNpid::~LEMNNpid (  )  [inline]

Definition at line 32 of file LEMNNpid.h.

00032               {
00033      //Clear(); // method-specific
00034   }


Member Function Documentation

double LEMNNpid::ActivationFnc ( double  x  )  const [private]

Definition at line 150 of file LEMNNpid.cxx.

Referenced by GetMvaValue__().

00150                                              {
00151    // hyperbolic tan
00152    return tanh(x);
00153 }

void LEMNNpid::Clear (  )  [private]
Double_t LEMNNpid::GetLEMpid ( NueAnaReader nueana  ) 

Definition at line 296 of file LEMNNpid.cxx.

References GetLEMpid(), and NueAnaReader::nuerecord.

00296                                                 {
00297 
00298   Double_t lempid=-1;
00299   lempid = GetLEMpid(nueana->nuerecord);
00300   return lempid;
00301 
00302 }

Double_t LEMNNpid::GetLEMpid ( NueRecord nr  ) 

Definition at line 253 of file LEMNNpid.cxx.

References LEMStandard::GetfracCCy(), LEMStandard::GetMeanFracQMatched(), GetMvaValue(), LEMStandard::Getymean(), ANtpEventInfoNue::phNueGeV, and NueRecord::srevent.

Referenced by GetLEMpid().

00253                                          {
00254 
00255   //LEM PID value
00256   Double_t lempid=-1;
00257 
00258   //Input variables
00259   Double_t val_mny=-1;
00260   Double_t val_mfqm=-1;
00261   Double_t val_fcc=-1;
00262   Double_t val_recoe=-1;
00263 
00264   //Define the variables (y_cut = 1.0 = no y cut)
00265   val_mny = LEMStandard::Getymean(nr,1.0);
00266   val_mfqm = LEMStandard::GetMeanFracQMatched(nr,1.0);
00267   val_fcc = LEMStandard::GetfracCCy(nr,1.0);
00268   val_recoe = nr->srevent.phNueGeV;
00269 
00270   //Preselection: return automatic -1 for out of range events.
00271   if (val_mny<0||val_mfqm<0||val_fcc<0||val_recoe<0) {
00272     lempid=-1;
00273   } else {
00274     //Define an input vector with the cariable names.
00275     std::vector<double> inputVec( 4 );
00276 
00277     inputVec[0]=val_mny;
00278     inputVec[1]=val_mfqm;
00279     inputVec[2]=val_fcc;
00280     inputVec[3]=val_recoe;
00281       
00282     //Calculate the LEM discriminant!
00283    lempid = LEMNNpid::GetMvaValue(inputVec);
00284 
00285   
00286   //Transform so that the PID value is between 0.0 to 1.0.
00287   lempid = (lempid + 1.1)/2.2;
00288 
00289   }
00290   //return the PID:
00291   return lempid;
00292 
00293 }

double LEMNNpid::GetMvaValue ( const std::vector< double > &  inputValues  )  const [inline]

Definition at line 160 of file LEMNNpid.cxx.

References fVmax, fVmin, GetMvaValue__(), IsNormalised(), NormVariable(), and Transform().

Referenced by GetLEMpid().

00161    {
00162       // classifier response value
00163       double retval = 0;
00164 
00165       // classifier response, sanity check first
00166 
00167       if (IsNormalised()) { 
00168         //Current settings: this is false, will not be accessed!
00169             // normalise variables
00170             std::vector<double> iV;
00171             int ivar = 0;
00172             for (std::vector<double>::const_iterator varIt = inputValues.begin();
00173                  varIt != inputValues.end(); varIt++, ivar++) {
00174                iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
00175             }
00176             Transform( iV, -1 );
00177             retval = GetMvaValue__( iV );
00178          }
00179          else {
00180            //Current settings: this function will be called!
00181             std::vector<double> iV;
00182             int ivar = 0;
00183             for (std::vector<double>::const_iterator varIt = inputValues.begin();
00184                  varIt != inputValues.end(); varIt++, ivar++) {
00185                iV.push_back(*varIt);
00186             }
00187             Transform( iV, -1 );
00188             retval = GetMvaValue__( iV );
00189          }
00190 
00191 
00192       return retval;
00193    }

double LEMNNpid::GetMvaValue__ ( const std::vector< double > &  inputValues  )  const [inline, private]

Definition at line 115 of file LEMNNpid.cxx.

References ActivationFnc(), fLayers, fLayerSize, fWeightMatrix0to1, fWeightMatrix1to2, and fWeights.

Referenced by GetMvaValue().

00116 {
00117    if (inputValues.size() != (unsigned int)fLayerSize[0]-1) {
00118       std::cout << "Input vector needs to be of size " << fLayerSize[0]-1 << std::endl;
00119       return 0;
00120    }
00121 
00122    for (int l=0; l<fLayers; l++)
00123       for (int i=0; i<fLayerSize[l]; i++) fWeights[l][i]=0;
00124 
00125    for (int l=0; l<fLayers-1; l++)
00126       fWeights[l][fLayerSize[l]-1]=1;
00127 
00128    for (int i=0; i<fLayerSize[0]-1; i++)
00129       fWeights[0][i]=inputValues[i];
00130 
00131    // layer 0 to 1
00132    for (int o=0; o<fLayerSize[1]-1; o++) {
00133       for (int i=0; i<fLayerSize[0]; i++) {
00134          double inputVal = fWeightMatrix0to1[o][i] * fWeights[0][i];
00135          fWeights[1][o] += inputVal;
00136       }
00137       fWeights[1][o] = ActivationFnc(fWeights[1][o]);
00138    }
00139    // layer 1 to 2
00140    for (int o=0; o<fLayerSize[2]; o++) {
00141       for (int i=0; i<fLayerSize[1]; i++) {
00142          double inputVal = fWeightMatrix1to2[o][i] * fWeights[1][i];
00143          fWeights[2][o] += inputVal;
00144       }
00145    }
00146 
00147    return fWeights[2][0];
00148 }

char LEMNNpid::GetType ( int  ivar  )  const [inline, private]

Definition at line 62 of file LEMNNpid.h.

References fType.

00062 { return fType[ivar]; }

void LEMNNpid::Initialize (  )  [inline, private]

Definition at line 49 of file LEMNNpid.cxx.

References fLayers, fLayerSize, fWeightMatrix0to1, fWeightMatrix1to2, and fWeights.

Referenced by LEMNNpid().

00050 {
00051    // build network structure
00052    fLayers = 3;
00053    fLayerSize[0] = 5; fWeights[0] = new double[5]; 
00054    fLayerSize[1] = 10; fWeights[1] = new double[10]; 
00055    fLayerSize[2] = 1; fWeights[2] = new double[1]; 
00056    // weight matrix from layer 0 to 1
00057    fWeightMatrix0to1[0][0] = 0.889941425413383;
00058    fWeightMatrix0to1[1][0] = 0.366186390854502;
00059    fWeightMatrix0to1[2][0] = 0.44254460355319;
00060    fWeightMatrix0to1[3][0] = 0.00530085306908016;
00061    fWeightMatrix0to1[4][0] = -0.200372983040551;
00062    fWeightMatrix0to1[5][0] = 0.342781534917679;
00063    fWeightMatrix0to1[6][0] = -0.738870769259312;
00064    fWeightMatrix0to1[7][0] = 0.00772578139054764;
00065    fWeightMatrix0to1[8][0] = 0.0372978061857464;
00066    fWeightMatrix0to1[0][1] = 5.1432769125001;
00067    fWeightMatrix0to1[1][1] = 0.6044131851872;
00068    fWeightMatrix0to1[2][1] = 2.02097826408062;
00069    fWeightMatrix0to1[3][1] = 0.3471568547056;
00070    fWeightMatrix0to1[4][1] = -0.446532990164852;
00071    fWeightMatrix0to1[5][1] = -0.166667417026606;
00072    fWeightMatrix0to1[6][1] = -3.0208530883406;
00073    fWeightMatrix0to1[7][1] = -0.345320491200302;
00074    fWeightMatrix0to1[8][1] = -2.22848978158512;
00075    fWeightMatrix0to1[0][2] = 0.936295002403589;
00076    fWeightMatrix0to1[1][2] = 0.337190338751075;
00077    fWeightMatrix0to1[2][2] = 2.2931576609196;
00078    fWeightMatrix0to1[3][2] = -0.314685969805727;
00079    fWeightMatrix0to1[4][2] = -0.157041223671765;
00080    fWeightMatrix0to1[5][2] = -1.48842239104701;
00081    fWeightMatrix0to1[6][2] = 1.62542565593655;
00082    fWeightMatrix0to1[7][2] = 0.372574444228969;
00083    fWeightMatrix0to1[8][2] = 0.651466231526043;
00084    fWeightMatrix0to1[0][3] = -1.66108811115591;
00085    fWeightMatrix0to1[1][3] = -0.15384407164396;
00086    fWeightMatrix0to1[2][3] = 0.522115159264936;
00087    fWeightMatrix0to1[3][3] = 0.225644022599161;
00088    fWeightMatrix0to1[4][3] = 0.104423707484473;
00089    fWeightMatrix0to1[5][3] = 1.30217585927118;
00090    fWeightMatrix0to1[6][3] = 1.9649631757483;
00091    fWeightMatrix0to1[7][3] = -0.257189760330795;
00092    fWeightMatrix0to1[8][3] = 2.8518928411204;
00093    fWeightMatrix0to1[0][4] = -3.93244997086547;
00094    fWeightMatrix0to1[1][4] = -0.470680040806735;
00095    fWeightMatrix0to1[2][4] = -3.90891466680297;
00096    fWeightMatrix0to1[3][4] = -0.0832030196438328;
00097    fWeightMatrix0to1[4][4] = 0.348780090893608;
00098    fWeightMatrix0to1[5][4] = 1.24050739284487;
00099    fWeightMatrix0to1[6][4] = 5.3588428249354;
00100    fWeightMatrix0to1[7][4] = 0.0786763341801065;
00101    fWeightMatrix0to1[8][4] = 3.12965561190524;
00102    // weight matrix from layer 1 to 2
00103    fWeightMatrix1to2[0][0] = 0.463726824454029;
00104    fWeightMatrix1to2[0][1] = 0.101441523225367;
00105    fWeightMatrix1to2[0][2] = 0.826274645431397;
00106    fWeightMatrix1to2[0][3] = -0.106336600583923;
00107    fWeightMatrix1to2[0][4] = -0.0207946680096305;
00108    fWeightMatrix1to2[0][5] = -0.237368080198887;
00109    fWeightMatrix1to2[0][6] = 0.720121242573888;
00110    fWeightMatrix1to2[0][7] = 0.12558412063999;
00111    fWeightMatrix1to2[0][8] = -0.207868511196203;
00112    fWeightMatrix1to2[0][9] = 0.170357024493182;
00113 }

void LEMNNpid::InitTransform (  )  [inline, private]

Definition at line 239 of file LEMNNpid.cxx.

References InitTransform_1().

Referenced by LEMNNpid().

00240 {
00241    InitTransform_1();
00242 }

void LEMNNpid::InitTransform_1 (  )  [inline, private]

Definition at line 196 of file LEMNNpid.cxx.

References fMax_1, and fMin_1.

Referenced by InitTransform().

00197 {
00198    fMin_1[0][0] = 0.0223234109581;
00199    fMax_1[0][0] = 0.978451371193;
00200    fMin_1[1][0] = 0.0223234109581;
00201    fMax_1[1][0] = 0.993063926697;
00202    fMin_1[2][0] = 0.0223234109581;
00203    fMax_1[2][0] = 0.993063926697;
00204    fMin_1[0][1] = 0.00539979198948;
00205    fMax_1[0][1] = 1;
00206    fMin_1[1][1] = 0.00539979198948;
00207    fMax_1[1][1] = 1;
00208    fMin_1[2][1] = 0.00539979198948;
00209    fMax_1[2][1] = 1;
00210    fMin_1[0][2] = 0.019999999553;
00211    fMax_1[0][2] = 1;
00212    fMin_1[1][2] = 0.019999999553;
00213    fMax_1[1][2] = 1;
00214    fMin_1[2][2] = 0.019999999553;
00215    fMax_1[2][2] = 1;
00216    fMin_1[0][3] = 0.501049637794;
00217    fMax_1[0][3] = 11.9998979568;
00218    fMin_1[1][3] = 0.500000357628;
00219    fMax_1[1][3] = 11.9999885559;
00220    fMin_1[2][3] = 0.500000357628;
00221    fMax_1[2][3] = 11.9999885559;
00222 }

Bool_t LEMNNpid::IsNormalised (  )  const [inline, private]

Definition at line 67 of file LEMNNpid.h.

Referenced by GetMvaValue().

00067 { return false; }

double LEMNNpid::NormVariable ( double  x,
double  xmin,
double  xmax 
) const [inline, private]

Definition at line 70 of file LEMNNpid.h.

Referenced by GetMvaValue().

00070                                                                    {
00071       // normalise to output range: [-1, 1]
00072       return 2*(x - xmin)/(xmax - xmin) - 1.0;
00073    }

void LEMNNpid::Transform ( std::vector< double > &  iv,
int  sigOrBgd 
) const [inline, private]

Definition at line 245 of file LEMNNpid.cxx.

References Transform_1().

Referenced by GetMvaValue().

00246 {
00247    Transform_1( iv, sigOrBgd );
00248 }

void LEMNNpid::Transform_1 ( std::vector< double > &  iv,
int  sigOrBgd 
) const [inline, private]

Definition at line 225 of file LEMNNpid.cxx.

References fMax_1, and fMin_1.

Referenced by Transform().

00226 {
00227 if (cls < 0 || cls > 2) {
00228    if (2 > 1 ) cls = 2;
00229    else cls = 2;
00230 }
00231    for (int ivar=0;ivar<4;ivar++) {
00232       double offset = fMin_1[cls][ivar];
00233       double scale  = 1.0/(fMax_1[cls][ivar]-fMin_1[cls][ivar]);
00234       iv[ivar] = (iv[ivar]-offset)*scale * 2 - 1;
00235    }
00236 }


Member Data Documentation

const char* LEMNNpid::fClassName [private]

Definition at line 60 of file LEMNNpid.h.

int LEMNNpid::fLayers [private]

Definition at line 86 of file LEMNNpid.h.

Referenced by GetMvaValue__(), and Initialize().

int LEMNNpid::fLayerSize[3] [private]

Definition at line 87 of file LEMNNpid.h.

Referenced by GetMvaValue__(), and Initialize().

double LEMNNpid::fMax_1[3][4] [private]

Definition at line 53 of file LEMNNpid.h.

Referenced by InitTransform_1(), and Transform_1().

double LEMNNpid::fMin_1[3][4] [private]

Definition at line 52 of file LEMNNpid.h.

Referenced by InitTransform_1(), and Transform_1().

char LEMNNpid::fType[4] [private]

Definition at line 76 of file LEMNNpid.h.

Referenced by GetType(), and LEMNNpid().

double LEMNNpid::fVmax[4] [private]

Definition at line 69 of file LEMNNpid.h.

Referenced by GetMvaValue(), and LEMNNpid().

double LEMNNpid::fVmin[4] [private]

Definition at line 68 of file LEMNNpid.h.

Referenced by GetMvaValue(), and LEMNNpid().

double LEMNNpid::fWeightMatrix0to1[10][5] [private]

Definition at line 88 of file LEMNNpid.h.

Referenced by GetMvaValue__(), and Initialize().

double LEMNNpid::fWeightMatrix1to2[1][10] [private]

Definition at line 89 of file LEMNNpid.h.

Referenced by GetMvaValue__(), and Initialize().

double* LEMNNpid::fWeights[3] [private]

Definition at line 91 of file LEMNNpid.h.

Referenced by GetMvaValue__(), and Initialize().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1