FairRoot/PandaRoot
PndKnnClassify.h
Go to the documentation of this file.
1 /* ************************************
2  * Author: M. Babai (M.Babai@rug.nl) *
3  * *
4  * KNN based pid classifier *
5  * *
6  * Modified: *
7  * *
8  * ************************************/
9 //#pragma once
10 #ifndef PND_KNN_CLASSIFY_H
11 #define PND_KNN_CLASSIFY_H
12 
13 // LOCAL includes
14 #include "PndMvaClassifier.h"
15 
16 // TMVA
17 #include "TMVA/NodekNN.h"
18 #include "TMVA/ModulekNN.h"
19 
20 //____________________________________________
22 // typedef std::list < std::pair<const TMVA::kNN::Node<TMVA::kNN::Event>*, float> > ResList;
23 //____________________________________________
24 
29 {
30  public:
38  explicit PndKnnClassify(std::string const& inputFile,
39  std::vector<std::string> const& classNames,
40  std::vector<std::string> const& varNames);
42  virtual ~PndKnnClassify();
43 
49  void GetMvaValues(std::vector<float> eventData,
50  std::map<std::string, float>& result);
56  std::string* Classify(std::vector<float> EvtData);
57 
63  inline void SetEvtParam(float const scFact, double const weight);
64 
66  inline void SetKnn(size_t const N);
67 
69  inline size_t GetKnn();
70 
74  virtual void Initialize();
75 
77  void print(){m_module->Print();}
79 
80  // ================== Private ===============
81  private:
82  // To avoid mistakes. ;)
83  PndKnnClassify(PndKnnClassify const& other);
85 
89  void InitKNN();
90 
92  typedef std::list < std::pair<const TMVA::kNN::Node<TMVA::kNN::Event>*, float> > ResList;
93 
94  size_t m_knn;
95  float m_ScaleFact;
96  double m_weight;
97  TMVA::kNN::ModulekNN* m_module;// TMVA Knn module.
98 
102  std::map<std::string, size_t> m_classIndices;
103 };//End of classifier interface definition
104 
105 //___________________ Inline implementation. __________________________________
106 inline void PndKnnClassify::SetEvtParam(float const scFact, double const weight)
107 {
108  m_ScaleFact = scFact;
109  m_weight = weight;
110 };
111 
112 inline void PndKnnClassify::SetKnn(size_t const N)
113 {
114  m_knn = N;
115 };
116 
117 inline size_t PndKnnClassify::GetKnn()
118 {
119  return m_knn;
120 };
121 #endif
void InitKNN()
Type definition for the neighbours list.
float m_ScaleFact
Scalefactor Default = 0.8.
std::map< std::string, size_t > m_classIndices
void GetMvaValues(std::vector< float > eventData, std::map< std::string, float > &result)
!&lt; Type definition of the neighbour list.
virtual ~PndKnnClassify()
Destructor.
double m_weight
Event weight.
PndKnnClassify(std::string const &inputFile, std::vector< std::string > const &classNames, std::vector< std::string > const &varNames)
size_t m_knn
Number of required neighbours.
void SetEvtParam(float const scFact, double const weight)
std::list< std::pair< const TMVA::kNN::Node< TMVA::kNN::Event > *, float > > ResList
void SetKnn(size_t const N)
Set the number of neighbours.
std::string * Classify(std::vector< float > EvtData)
TMVA::kNN::ModulekNN * m_module
void print()
DEBUG Produces a lot of output.
virtual void Initialize()
size_t GetKnn()
Get the number of neighbours.
PndKnnClassify & operator=(PndKnnClassify const &other)