NukNN Class Reference

#include <NukNN.h>

List of all members.

Classes

struct  Point

Public Member Functions

 NukNN ()
 ~NukNN ()
void Initialize (TString fileName, int k)
double GetDistributionWidth (vector< double > &vec, double width)
double GetSigmaOfLeaf (TTree *t, string leaf)
void AddPars (string parName, double wt)
void PrintWeights ()
void PrintMMatrix ()
double GetShwEnergy (bool isMC, string metric, bool useMedian)
double MasakiCorrectionFactorNthOrder (double E, vector< double > constList)
void SetMasakiCorrectionConstants ()

Static Public Member Functions

static double MahalanobisDistance (const Point &p1, const Point &p2)
static double EuclideanDistance (const Point &p1, const Point &p2)

Public Attributes

vector< PointtrainPoints
Point testPoint
vector< string > pars
vector< double > wts
int NN
bool initialized
vector< double > shwEnkNNCorND1
vector< double > shwEnkNNCorND2
vector< double > shwEnkNNCorND3
vector< double > shwEnkNNPlusCorND1
vector< double > shwEnkNNPlusCorND2
vector< double > shwEnkNNCorFD1
vector< double > shwEnkNNCorFD2
vector< double > shwEnkNNCorFD3
vector< double > shwEnkNNPlusCorFD1
vector< double > shwEnkNNPlusCorFD2
vector< double > shwEnkNNPlusCorFD3

Private Attributes

NuVPTree< Point,
NukNN::MahalanobisDistance > 
treeMahalanobis
NuVPTree< Point,
NukNN::EuclideanDistance > 
treeEuclidean

Detailed Description

Definition at line 32 of file NukNN.h.


Constructor & Destructor Documentation

NukNN::NukNN (  )  [inline]

Definition at line 66 of file NukNN.h.

References initialized.

00066          {
00067     initialized = false;
00068   };

NukNN::~NukNN (  )  [inline]

Definition at line 69 of file NukNN.h.

00069 {};


Member Function Documentation

void NukNN::AddPars ( string  parName,
double  wt 
)

Definition at line 111 of file NukNN.cxx.

References pars, and wts.

Referenced by NuReco::GetShowerEnergykNN().

00111                                             {
00112   pars.push_back(parName);
00113   wts.push_back(wt);
00114 }

double NukNN::EuclideanDistance ( const Point p1,
const Point p2 
) [static]

Definition at line 26 of file NukNN.cxx.

References NukNN::Point::par.

00026                                                                           {
00027   double sumSq = 0.;
00028   for(unsigned int i = 0; i < p1.par.size(); i++)
00029     sumSq += pow(p1.par[i] - p2.par[i], 2);
00030   return sqrt(sumSq);
00031 }

double NukNN::GetDistributionWidth ( vector< double > &  vec,
double  width 
)

Definition at line 82 of file NukNN.cxx.

Referenced by Initialize().

00082                                                                    {
00083   double quantileBeg = (1. - width) / 2.;
00084   double quantileEnd = quantileBeg + width;
00085 
00086   int indexBeg = (int)(vec.size() * quantileBeg);
00087   nth_element(vec.begin(), vec.begin() + indexBeg, vec.end());
00088   double beg = vec[indexBeg];
00089 
00090   int indexEnd = (int)(vec.size() * quantileEnd);
00091   nth_element(vec.begin(), vec.begin() + indexEnd, vec.end());
00092   double end = vec[indexEnd];
00093 
00094   return end - beg;
00095 }    

double NukNN::GetShwEnergy ( bool  isMC,
string  metric,
bool  useMedian 
)

Definition at line 142 of file NukNN.cxx.

References NN, NuVPTree< T, distance >::search(), testPoint, treeEuclidean, and treeMahalanobis.

Referenced by NuReco::GetShowerEnergykNN().

00142                                                                   {
00143   vector<Point> results;
00144   vector<double> distances;
00145   vector<double> mcList(NN);
00146 
00147   // use Euclidean or Mahalanobis metric
00148   if(metric == "Euclidean")
00149     treeEuclidean.search( testPoint, NN + 1, &results, &distances );
00150   else if(metric == "Mahalanobis")
00151     treeMahalanobis.search( testPoint, NN + 1, &results, &distances );
00152   else{
00153     cout << "Given distance metric does not exist" << endl;
00154     abort();
00155   }
00156 
00157   // for MC, use leave-one-out method
00158   if(isMC)
00159     for( unsigned int j = 1; j < results.size(); j++) mcList[j - 1] = results[j].shwEnMC;
00160   else
00161     for( unsigned int j = 0; j < results.size() - 1; j++) mcList[j] = results[j].shwEnMC; 
00162 
00163   // use mean or median
00164   if(useMedian){
00165     int index = (int)(NN * 0.5);
00166     nth_element(mcList.begin(), mcList.begin() + index, mcList.end());
00167     return mcList[index];
00168   }
00169   else{
00170     double sum = 0.;
00171     for(int i = 0; i < NN; i++) sum += mcList[i];
00172     return sum / (double)NN;
00173   }
00174 }

double NukNN::GetSigmaOfLeaf ( TTree *  t,
string  leaf 
)

Definition at line 99 of file NukNN.cxx.

References Form().

Referenced by Initialize().

00099                                                  {
00100   TCanvas* c1 = new TCanvas("c1", "c1", 800, 600);
00101   TH1* h1 = new TH1D("h1", "h1", 1000, 0, 1000);
00102   t->Draw(Form("%s>>h1", leaf.c_str()));
00103   double rms = h1->GetRMS();
00104   delete h1;
00105   delete c1;
00106   return rms;
00107 }

void NukNN::Initialize ( TString  fileName,
int  k 
)

Definition at line 35 of file NukNN.cxx.

References NuVPTree< T, distance >::create(), GetDistributionWidth(), GetSigmaOfLeaf(), initialized, NN, NukNN::Point::par, pars, SetMasakiCorrectionConstants(), NukNN::Point::shwEnMC, trainPoints, treeEuclidean, treeMahalanobis, and wts.

Referenced by NuReco::GetShowerEnergykNN().

00035                                              {
00036 
00037   trainPoints.clear();
00038   TFile* f = new TFile(fileName);
00039   TTree* t = (TTree*) f->Get("trainShw");
00040 
00041   for(unsigned int i=0; i < t->GetEntries(); i++){
00042     t->GetEntry(i);
00043     Point point;
00044     point.shwEnMC = t->GetLeaf("shwEnMC")->GetValue();    
00045     for(unsigned int j = 0; j < pars.size(); j++)
00046       point.par.push_back(t->GetLeaf(pars[j].c_str())->GetValue());
00047     trainPoints.push_back(point);
00048   }
00049 
00050   // set weights
00051   for(unsigned int i = 0; i < pars.size(); i++){
00052 
00053     if(wts[i] == -1){
00054       vector<double> vec;
00055       for(unsigned int j = 0; j < trainPoints.size(); j++)
00056         vec.push_back(trainPoints[j].par[i]);
00057       wts[i] = 1. / this->GetDistributionWidth(vec, 0.8);
00058     }
00059 
00060     if(wts[i] == -2)
00061       wts[i] = 1. / GetSigmaOfLeaf(t, pars[i]);  
00062   }
00063 
00064   // apply weights
00065   for(unsigned int i = 0; i < trainPoints.size(); i++)
00066     for(unsigned int j = 0; j < pars.size(); j++)
00067       trainPoints[i].par[j] *= wts[j];       
00068 
00069   treeMahalanobis.create(trainPoints);   
00070   treeEuclidean.create(trainPoints);   
00071 
00072   NN = k;
00073   initialized = true;
00074 
00075   this->SetMasakiCorrectionConstants();
00076 
00077   f->Close();
00078 }

double NukNN::MahalanobisDistance ( const Point p1,
const Point p2 
) [static]

Definition at line 12 of file NukNN.cxx.

References MuELoss::a, MAX, and NukNN::Point::par.

00012                                                                             {
00013   double sumSq = 0.;
00014   double a;
00015   for(int i = 0; i < MAX; i++){
00016     a = 0.;
00017     for(int j = 0; j < MAX; j++)
00018       a += MM[i][j] * (p1.par[j] - p2.par[j]);
00019     sumSq += a * a;
00020   }
00021   return sqrt(sumSq);
00022 }

double NukNN::MasakiCorrectionFactorNthOrder ( double  E,
vector< double >  constList 
)

Definition at line 178 of file NukNN.cxx.

Referenced by NuReco::GetShowerEnergykNN().

00178                                                                               {
00179   double corr = 0.;
00180 
00181   double cutoff_low = 0.2;
00182   double cutoff_high = 50;
00183 
00184   if(E > cutoff_high) E = cutoff_high;
00185   if(E < cutoff_low)  E = cutoff_low;
00186 
00187   const double y = TMath::Log(E);
00188   for(unsigned int i = 0; i < constList.size(); i++)
00189     corr += constList[i] * pow(y, (double)i);
00190 
00191   return corr;
00192 }

void NukNN::PrintMMatrix (  ) 

Definition at line 129 of file NukNN.cxx.

References pars.

Referenced by NuReco::GetShowerEnergykNN().

00129                         {
00130 
00131   cout << "Mahalanobis distance matrix" << endl;
00132   for(unsigned int i = 0; i < pars.size(); i++){
00133     for(unsigned int j = 0; j < pars.size(); j++){
00134       cout << setw(10) << MM[i][j];
00135     }
00136     cout << endl;
00137   }
00138 }

void NukNN::PrintWeights (  ) 

Definition at line 118 of file NukNN.cxx.

References pars, and wts.

Referenced by NuReco::GetShowerEnergykNN().

00118                         {
00119   
00120   std::cout << std::setw(25) << "parameter" << std::setw(25) << "weight" << std::endl; 
00121   std::cout << std::setw(25) << "---------" << std::setw(25) << "------" << std::endl; 
00122   for(unsigned int i = 0; i < pars.size(); i++)
00123     std::cout << std::setw(25) << pars[i] << std::setw(25) << wts[i] << std::endl; 
00124 
00125 }

void NukNN::SetMasakiCorrectionConstants (  ) 

Definition at line 196 of file NukNN.cxx.

References MuELoss::e, shwEnkNNCorFD1, shwEnkNNCorFD2, shwEnkNNCorFD3, shwEnkNNCorND1, shwEnkNNCorND2, shwEnkNNCorND3, shwEnkNNPlusCorFD1, shwEnkNNPlusCorFD2, shwEnkNNPlusCorFD3, shwEnkNNPlusCorND1, and shwEnkNNPlusCorND2.

Referenced by Initialize().

00196                                         {
00197 
00198   // constants for shwEnkNN at ND
00199 
00200   shwEnkNNCorND1.push_back(1.18162);
00201   shwEnkNNCorND1.push_back(-0.242337);
00202   shwEnkNNCorND1.push_back(0.0618788);
00203   shwEnkNNCorND1.push_back(0.0603348);
00204   shwEnkNNCorND1.push_back(0.0331363);
00205   shwEnkNNCorND1.push_back(-0.126568);
00206   shwEnkNNCorND1.push_back(0.0283246);
00207   shwEnkNNCorND1.push_back(0.0406211);
00208   shwEnkNNCorND1.push_back(-0.0202272);
00209   shwEnkNNCorND1.push_back(0.00103472);
00210   shwEnkNNCorND1.push_back(0.000653826);
00211   shwEnkNNCorND1.push_back(7.51621e-05);
00212   shwEnkNNCorND1.push_back(-6.1426e-05);
00213   shwEnkNNCorND1.push_back(6.25176e-06);
00214 
00215   shwEnkNNCorND2.push_back(1.0578);
00216   shwEnkNNCorND2.push_back(-0.131799);
00217   shwEnkNNCorND2.push_back(0.0628569);
00218   shwEnkNNCorND2.push_back(0.0665649);
00219   shwEnkNNCorND2.push_back(0.0105704);
00220   shwEnkNNCorND2.push_back(-0.108205);
00221   shwEnkNNCorND2.push_back(0.0365208);
00222   shwEnkNNCorND2.push_back(0.0274313);
00223   shwEnkNNCorND2.push_back(-0.0165728);
00224   shwEnkNNCorND2.push_back(0.00111656);
00225   shwEnkNNCorND2.push_back(0.00058755);
00226   shwEnkNNCorND2.push_back(4.96399e-05);
00227   shwEnkNNCorND2.push_back(-5.58875e-05);
00228   shwEnkNNCorND2.push_back(6.12562e-06);
00229   
00230   shwEnkNNCorND3.push_back(1.00605);
00231   shwEnkNNCorND3.push_back(-0.0346666);
00232   shwEnkNNCorND3.push_back(0.044294);
00233   shwEnkNNCorND3.push_back(-0.0173247);
00234   shwEnkNNCorND3.push_back(0.00803254);
00235   shwEnkNNCorND3.push_back(-0.011049);
00236   shwEnkNNCorND3.push_back(0.00484063);
00237   shwEnkNNCorND3.push_back(-0.000158379);
00238   shwEnkNNCorND3.push_back(-0.000114895);
00239   shwEnkNNCorND3.push_back(-3.80213e-05);
00240   shwEnkNNCorND3.push_back(4.0528e-07);
00241   shwEnkNNCorND3.push_back(2.44944e-06);
00242   shwEnkNNCorND3.push_back(6.10605e-07);
00243   shwEnkNNCorND3.push_back(-1.62669e-07);
00244   
00245   // constants for shwEnkNNPlus at ND
00246 
00247   shwEnkNNPlusCorND1.push_back(1.06284);
00248   shwEnkNNPlusCorND1.push_back(-0.143215);
00249   shwEnkNNPlusCorND1.push_back(0.0819303);
00250   shwEnkNNPlusCorND1.push_back(0.0147987);
00251   shwEnkNNPlusCorND1.push_back(0.0241282);
00252   shwEnkNNPlusCorND1.push_back(-0.0927105);
00253   shwEnkNNPlusCorND1.push_back(0.0148482);
00254   shwEnkNNPlusCorND1.push_back(0.0335596);
00255   shwEnkNNPlusCorND1.push_back(-0.0128114);
00256   shwEnkNNPlusCorND1.push_back(-0.000440327);
00257   shwEnkNNPlusCorND1.push_back(0.000313687);
00258   shwEnkNNPlusCorND1.push_back(0.000136753);
00259   shwEnkNNPlusCorND1.push_back(-6.65469e-06);
00260   shwEnkNNPlusCorND1.push_back(-1.1374e-05);
00261   shwEnkNNPlusCorND1.push_back(1.5042e-06);
00262 
00263   shwEnkNNPlusCorND2.push_back(1.00693);
00264   shwEnkNNPlusCorND2.push_back(-0.0473305);
00265   shwEnkNNPlusCorND2.push_back(0.0536249);
00266   shwEnkNNPlusCorND2.push_back(0.0057608);
00267   shwEnkNNPlusCorND2.push_back(0.0214805);
00268   shwEnkNNPlusCorND2.push_back(-0.062965);
00269   shwEnkNNPlusCorND2.push_back(0.0135152);
00270   shwEnkNNPlusCorND2.push_back(0.0193679);
00271   shwEnkNNPlusCorND2.push_back(-0.00826655);
00272   shwEnkNNPlusCorND2.push_back(-0.000137949);
00273   shwEnkNNPlusCorND2.push_back(0.00022307);
00274   shwEnkNNPlusCorND2.push_back(8.25752e-05);
00275   shwEnkNNPlusCorND2.push_back(-6.4035e-06);
00276   shwEnkNNPlusCorND2.push_back(-7.18305e-06);
00277   shwEnkNNPlusCorND2.push_back(1.01482e-06);
00278 
00279   // constants for shwEnkNN at FD
00280 
00281   shwEnkNNCorFD1.push_back(1.13772);
00282   shwEnkNNCorFD1.push_back(-0.166812);
00283   shwEnkNNCorFD1.push_back(0.0148493);
00284   shwEnkNNCorFD1.push_back(0.0445932);
00285   shwEnkNNCorFD1.push_back(0.0725407);
00286   shwEnkNNCorFD1.push_back(-0.0929858);
00287   shwEnkNNCorFD1.push_back(-0.025135);
00288   shwEnkNNCorFD1.push_back(0.0483781);
00289   shwEnkNNCorFD1.push_back(-0.00513379);
00290   shwEnkNNCorFD1.push_back(-0.00782185);
00291   shwEnkNNCorFD1.push_back(0.00241321);
00292   shwEnkNNCorFD1.push_back(6.5952e-05);
00293   shwEnkNNCorFD1.push_back(-0.000103016);
00294   shwEnkNNCorFD1.push_back(1.032e-05);
00295 
00296   shwEnkNNCorFD2.push_back(1.03582);
00297   shwEnkNNCorFD2.push_back(-0.069859);
00298   shwEnkNNCorFD2.push_back(0.0175867);
00299   shwEnkNNCorFD2.push_back(0.0173974);
00300   shwEnkNNCorFD2.push_back(0.0565575);
00301   shwEnkNNCorFD2.push_back(-0.0597788);
00302   shwEnkNNCorFD2.push_back(-0.0171495);
00303   shwEnkNNCorFD2.push_back(0.0306122);
00304   shwEnkNNCorFD2.push_back(-0.0035366);
00305   shwEnkNNCorFD2.push_back(-0.00477625);
00306   shwEnkNNCorFD2.push_back(0.00155021);
00307   shwEnkNNCorFD2.push_back(2.05402e-05);
00308   shwEnkNNCorFD2.push_back(-6.27977e-05);
00309   shwEnkNNCorFD2.push_back(6.55726e-06);
00310 
00311   shwEnkNNCorFD3.push_back(1.00185);
00312   shwEnkNNCorFD3.push_back(-0.0126679);
00313   shwEnkNNCorFD3.push_back(0.0178596);
00314   shwEnkNNCorFD3.push_back(-0.0137966);
00315   shwEnkNNCorFD3.push_back(0.0121133);
00316   shwEnkNNCorFD3.push_back(-0.0060715);
00317   shwEnkNNCorFD3.push_back(-0.000827368);
00318   shwEnkNNCorFD3.push_back(0.00151891);
00319   shwEnkNNCorFD3.push_back(-0.000273934);
00320   shwEnkNNCorFD3.push_back(-1.5363e-05);
00321   shwEnkNNCorFD3.push_back(-9.03632e-06);
00322   shwEnkNNCorFD3.push_back(3.09541e-06);
00323   shwEnkNNCorFD3.push_back(6.95435e-07);
00324   shwEnkNNCorFD3.push_back(-1.63402e-07);
00325 
00326   // constants for shwEnkNNPlus at FD
00327 
00328   shwEnkNNPlusCorFD1.push_back(1.03508);
00329   shwEnkNNPlusCorFD1.push_back(-0.0827673);
00330   shwEnkNNPlusCorFD1.push_back(0.0856139);
00331   shwEnkNNPlusCorFD1.push_back(-0.0227678);
00332   shwEnkNNPlusCorFD1.push_back(-0.0118109);
00333   shwEnkNNPlusCorFD1.push_back(-0.0286834);
00334   shwEnkNNPlusCorFD1.push_back(0.0179097);
00335   shwEnkNNPlusCorFD1.push_back(0.0059722);
00336   shwEnkNNPlusCorFD1.push_back(-0.00471709);
00337   shwEnkNNPlusCorFD1.push_back(0.000363811);
00338   shwEnkNNPlusCorFD1.push_back(0.000101678);
00339   shwEnkNNPlusCorFD1.push_back(2.55843e-05);
00340   shwEnkNNPlusCorFD1.push_back(-1.21145e-05);
00341   shwEnkNNPlusCorFD1.push_back(9.61564e-07);
00342 
00343   shwEnkNNPlusCorFD2.push_back(1.00403);
00344   shwEnkNNPlusCorFD2.push_back(-0.0184821);
00345   shwEnkNNPlusCorFD2.push_back(-0.0100716);
00346   shwEnkNNPlusCorFD2.push_back(0.0203413);
00347   shwEnkNNPlusCorFD2.push_back(0.077363);
00348   shwEnkNNPlusCorFD2.push_back(-0.0858747);
00349   shwEnkNNPlusCorFD2.push_back(-0.0118705);
00350   shwEnkNNPlusCorFD2.push_back(0.0368323);
00351   shwEnkNNPlusCorFD2.push_back(-0.00641658);
00352   shwEnkNNPlusCorFD2.push_back(-0.00483844);
00353   shwEnkNNPlusCorFD2.push_back(0.00170626);
00354   shwEnkNNPlusCorFD2.push_back(3.99971e-05);
00355   shwEnkNNPlusCorFD2.push_back(-7.71867e-05);
00356   shwEnkNNPlusCorFD2.push_back(8.03461e-06);
00357 
00358   shwEnkNNPlusCorFD3.push_back(0.994532);
00359   shwEnkNNPlusCorFD3.push_back(0.0108867);
00360   shwEnkNNPlusCorFD3.push_back(-0.0121048);
00361   shwEnkNNPlusCorFD3.push_back(0.00170159);
00362   shwEnkNNPlusCorFD3.push_back(0.0260444);
00363   shwEnkNNPlusCorFD3.push_back(-0.0287689);
00364   shwEnkNNPlusCorFD3.push_back(0.00565379);
00365   shwEnkNNPlusCorFD3.push_back(0.0052153);
00366   shwEnkNNPlusCorFD3.push_back(-0.00261506);
00367   shwEnkNNPlusCorFD3.push_back(0.000233742);
00368   shwEnkNNPlusCorFD3.push_back(3.48796e-05);
00369   shwEnkNNPlusCorFD3.push_back(1.30876e-05);
00370   shwEnkNNPlusCorFD3.push_back(-6.2893e-06);
00371   shwEnkNNPlusCorFD3.push_back(5.71341e-07);
00372 
00373 }


Member Data Documentation

Definition at line 46 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), Initialize(), and NukNN().

int NukNN::NN

Definition at line 45 of file NukNN.h.

Referenced by GetShwEnergy(), and Initialize().

Definition at line 42 of file NukNN.h.

Referenced by AddPars(), NuReco::GetShowerEnergykNN(), Initialize(), PrintMMatrix(), and PrintWeights().

Definition at line 57 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and SetMasakiCorrectionConstants().

Definition at line 58 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and SetMasakiCorrectionConstants().

Definition at line 59 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and SetMasakiCorrectionConstants().

Definition at line 50 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and SetMasakiCorrectionConstants().

Definition at line 51 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and SetMasakiCorrectionConstants().

Definition at line 52 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and SetMasakiCorrectionConstants().

Definition at line 61 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and SetMasakiCorrectionConstants().

Definition at line 62 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and SetMasakiCorrectionConstants().

Definition at line 63 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and SetMasakiCorrectionConstants().

Definition at line 54 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and SetMasakiCorrectionConstants().

Definition at line 55 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and SetMasakiCorrectionConstants().

Definition at line 40 of file NukNN.h.

Referenced by NuReco::GetShowerEnergykNN(), and GetShwEnergy().

Definition at line 39 of file NukNN.h.

Referenced by Initialize().

NuVPTree<Point, NukNN::EuclideanDistance> NukNN::treeEuclidean [private]

Definition at line 85 of file NukNN.h.

Referenced by GetShwEnergy(), and Initialize().

NuVPTree<Point, NukNN::MahalanobisDistance> NukNN::treeMahalanobis [private]

Definition at line 84 of file NukNN.h.

Referenced by GetShwEnergy(), and Initialize().

vector<double> NukNN::wts

Definition at line 43 of file NukNN.h.

Referenced by AddPars(), NuReco::GetShowerEnergykNN(), Initialize(), and PrintWeights().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1