NukNNPID Class Reference

#include <NukNNPID.h>

List of all members.

Classes

struct  Point

Public Member Functions

 NukNNPID ()
 ~NukNNPID ()
void Initialize (TString fileName, int k)
double GetDistributionWidth (vector< double > &vec, double width)
void AddPars (string parName, double wt)
void PrintWeights ()
void PrintMMatrix ()
double GetPID (bool isMC, string metric)

Static Public Member Functions

static double EuclideanDistancePID (const Point &p1, const Point &p2)
static double MahalanobisDistancePID (const Point &p1, const Point &p2)

Public Attributes

vector< PointtrainPoints
Point testPoint
vector< string > pars
vector< double > wts
int NN
bool initialized

Private Attributes

NuVPTreePID< Point,
NukNNPID::EuclideanDistancePID > 
treeEuclidean
NuVPTreePID< Point,
NukNNPID::MahalanobisDistancePID > 
treeMahalanobis

Detailed Description

Definition at line 29 of file NukNNPID.h.


Constructor & Destructor Documentation

NukNNPID::NukNNPID (  )  [inline]

Definition at line 47 of file NukNNPID.h.

References initialized.

00047             {
00048     initialized = false;
00049   };

NukNNPID::~NukNNPID (  )  [inline]

Definition at line 50 of file NukNNPID.h.

00050 {};


Member Function Documentation

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

Definition at line 106 of file NukNNPID.cxx.

References pars, and wts.

Referenced by NuPIDInterface::GetRoIDPlus().

00106                                                {
00107   pars.push_back(parName);
00108   wts.push_back(wt);
00109 }

double NukNNPID::EuclideanDistancePID ( const Point p1,
const Point p2 
) [static]

Definition at line 25 of file NukNNPID.cxx.

References NukNNPID::Point::par.

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

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

Definition at line 89 of file NukNNPID.cxx.

Referenced by Initialize().

00089                                                                       {
00090   double quantileBeg = (1. - width) / 2.;
00091   double quantileEnd = quantileBeg + width;
00092 
00093   int indexBeg = (int)(vec.size() * quantileBeg);
00094   nth_element(vec.begin(), vec.begin() + indexBeg, vec.end());
00095   double beg = vec[indexBeg];    
00096 
00097   int indexEnd = (int)(vec.size() * quantileEnd);
00098   nth_element(vec.begin(), vec.begin() + indexEnd, vec.end());
00099   double end = vec[indexEnd];    
00100 
00101   return end - beg;
00102 }

double NukNNPID::GetPID ( bool  isMC,
string  metric 
)

Definition at line 137 of file NukNNPID.cxx.

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

Referenced by NuPIDInterface::GetRoIDPlus().

00137                                                {
00138   vector<Point> results;
00139   vector<double> distances;
00140 
00141   // use Euclidean or Mahalanobis metric
00142   if(metric == "Euclidean")
00143     treeEuclidean.search( testPoint, NN + 1, &results, &distances );
00144   else if(metric == "Mahalanobis")
00145     treeMahalanobis.search( testPoint, NN + 1, &results, &distances );
00146   else{
00147     cout << "Given distance metric does not exist" << endl;
00148     abort();
00149   }
00150 
00151   // for MC, use leave-one-out method
00152   double sum = 0.;
00153   if(isMC)
00154     for( unsigned int j = 1; j < results.size(); j++){
00155       if(results[j].signalMC) 
00156         sum++;
00157     }
00158   else
00159     for( unsigned int j = 0; j < results.size() - 1; j++){
00160       if (results[j].signalMC) 
00161         sum++;
00162     }
00163 
00164   return sum / (double)NN;
00165 }

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

Definition at line 34 of file NukNNPID.cxx.

References NuVPTreePID< T, distance >::create(), GetDistributionWidth(), initialized, NN, NukNNPID::Point::par, pars, NukNNPID::Point::signalMC, trainPoints, treeEuclidean, treeMahalanobis, and wts.

Referenced by NuPIDInterface::GetRoIDPlus().

00034                                                 {
00035 
00036   trainPoints.clear();
00037   TFile* f = new TFile(fileName);
00038   TTree* t = (TTree*) f->Get("trainPID");
00039 
00040   vector<Point> fullTrainS;
00041   vector<Point> fullTrainB;
00042 
00043   for(Int_t i=0; i < t->GetEntries(); i++){
00044     t->GetEntry(i);
00045     Point point;
00046     point.signalMC = t->GetLeaf("signalMC")->GetValue();    
00047     for(unsigned int j = 0; j < pars.size(); j++)
00048       point.par.push_back(t->GetLeaf(pars[j].c_str())->GetValue());    
00049 
00050     if(point.signalMC)
00051       fullTrainS.push_back(point);
00052     else
00053       fullTrainB.push_back(point);
00054   }
00055 
00056   cout << "number of training signal/background events for roID = " << fullTrainB.size() << endl;
00057   
00058   int numEvtsMax = (fullTrainS.size() < fullTrainB.size()) ? fullTrainS.size() : fullTrainB.size();
00059   int numEvts = numEvtsMax;
00060 
00061   for(int i=0; i < numEvts; i++){
00062     trainPoints.push_back(fullTrainS[i]);
00063     trainPoints.push_back(fullTrainB[i]);
00064   }
00065 
00066   // set weights
00067   for(unsigned int i = 0; i < pars.size(); i++)
00068     if(wts[i] < 0){
00069       vector<double> vec;
00070       for(unsigned int j = 0; j < trainPoints.size(); j++)
00071         vec.push_back(trainPoints[j].par[i]);
00072       wts[i] = 1. / this->GetDistributionWidth(vec, 0.8);
00073     }
00074 
00075   // apply weights
00076   for(unsigned int i = 0; i < trainPoints.size(); i++)
00077     for(unsigned int j = 0; j < pars.size(); j++)
00078       trainPoints[i].par[j] *= wts[j];
00079 
00080   treeEuclidean.create(trainPoints);   
00081   treeMahalanobis.create(trainPoints);   
00082   NN = k;
00083   f->Close();
00084   initialized = true;
00085 }

double NukNNPID::MahalanobisDistancePID ( const Point p1,
const Point p2 
) [static]

Definition at line 11 of file NukNNPID.cxx.

References MuELoss::a, MAXPID, and NukNNPID::Point::par.

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

void NukNNPID::PrintMMatrix (  ) 

Definition at line 124 of file NukNNPID.cxx.

References pars.

Referenced by NuPIDInterface::GetRoIDPlus().

00124                            {
00125 
00126   cout << "Mahalanobis metric" << endl;
00127   for(unsigned int i = 0; i < pars.size(); i++){
00128     for(unsigned int j = 0; j < pars.size(); j++){
00129       cout << setw(10) << MMPID[i][j];
00130     }
00131     cout << endl;
00132   }
00133 }

void NukNNPID::PrintWeights (  ) 

Definition at line 113 of file NukNNPID.cxx.

References pars, and wts.

Referenced by NuPIDInterface::GetRoIDPlus().

00113                            {
00114   
00115   std::cout << std::setw(25) << "parameter" << std::setw(20) << "weight" << std::endl; 
00116   std::cout << std::setw(25) << "---------" << std::setw(20) << "------" << std::endl; 
00117   for(unsigned int i = 0; i < pars.size(); i++)
00118     std::cout << std::setw(25) << pars[i] << std::setw(20) << wts[i] << std::endl; 
00119 
00120 }


Member Data Documentation

Definition at line 44 of file NukNNPID.h.

Referenced by NuPIDInterface::GetRoIDPlus(), Initialize(), and NukNNPID().

Definition at line 42 of file NukNNPID.h.

Referenced by GetPID(), NuPIDInterface::GetRoIDPlus(), and Initialize().

Definition at line 37 of file NukNNPID.h.

Referenced by GetPID(), and NuPIDInterface::GetRoIDPlus().

Definition at line 36 of file NukNNPID.h.

Referenced by Initialize().

NuVPTreePID<Point, NukNNPID::EuclideanDistancePID> NukNNPID::treeEuclidean [private]

Definition at line 62 of file NukNNPID.h.

Referenced by GetPID(), and Initialize().

NuVPTreePID<Point, NukNNPID::MahalanobisDistancePID> NukNNPID::treeMahalanobis [private]

Definition at line 63 of file NukNNPID.h.

Referenced by GetPID(), and Initialize().

Definition at line 40 of file NukNNPID.h.

Referenced by AddPars(), NuPIDInterface::GetRoIDPlus(), 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