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  public:
37  explicit PndKnnClassify(std::string const &inputFile, std::vector<std::string> const &classNames, std::vector<std::string> const &varNames);
39  virtual ~PndKnnClassify();
40 
46  void GetMvaValues(std::vector<float> eventData, std::map<std::string, float> &result);
52  std::string *Classify(std::vector<float> EvtData);
53 
59  inline void SetEvtParam(float const scFact, double const weight);
60 
62  inline void SetKnn(size_t const N);
63 
65  inline size_t GetKnn();
66 
70  virtual void Initialize();
71 
73  void print() { m_module->Print(); }
75 
76  // ================== Private ===============
77  private:
78  // To avoid mistakes. ;)
79  PndKnnClassify(PndKnnClassify const &other);
80  PndKnnClassify &operator=(PndKnnClassify const &other);
81 
85  void InitKNN();
86 
88  typedef std::list<std::pair<const TMVA::kNN::Node<TMVA::kNN::Event> *, float>> ResList;
89 
90  size_t m_knn;
91  float m_ScaleFact;
92  double m_weight;
93  TMVA::kNN::ModulekNN *m_module; // TMVA Knn module.
94 
98  std::map<std::string, size_t> m_classIndices;
99 }; // End of classifier interface definition
100 
101 //___________________ Inline implementation. __________________________________
102 inline void PndKnnClassify::SetEvtParam(float const scFact, double const weight)
103 {
104  m_ScaleFact = scFact;
105  m_weight = weight;
106 };
107 
108 inline void PndKnnClassify::SetKnn(size_t const N)
109 {
110  m_knn = N;
111 };
112 
113 inline size_t PndKnnClassify::GetKnn()
114 {
115  return m_knn;
116 };
117 #endif
void GetMvaValues(std::vector< float > eventData, std::map< std::string, float > &result)
!< Type definition of the neighbour list.
virtual ~PndKnnClassify()
Destructor.
PndKnnClassify(std::string const &inputFile, std::vector< std::string > const &classNames, std::vector< std::string > const &varNames)
void SetEvtParam(float const scFact, double const weight)
void SetKnn(size_t const N)
Set the number of neighbours.
std::string * Classify(std::vector< float > EvtData)
void print()
DEBUG Produces a lot of output.
virtual void Initialize()
size_t GetKnn()
Get the number of neighbours.