FairRoot/PandaRoot
PndMvaTools.h
Go to the documentation of this file.
1 /* ********************************************
2  * MVA Tools and function definitions. *
3  * Author: M.Babai@rug.nl *
4  * Version: *
5  * License: *
6  * *******************************************
7  */
8 #pragma once
9 #ifndef PND_MVA_TOOLS_H
10 #define PND_MVA_TOOLS_H
11 
12 // C++
13 #include <cstdlib>
14 #include <iostream>
15 #include <fstream>
16 #include <vector>
17 #include <string>
18 #include <algorithm>
19 #include <limits>
20 
21 // ROOT
22 #include "TFile.h"
23 #include "TTree.h"
24 
31 {
32  //public:
33  // Constructors
34  explicit ClassifierOutPuts()
35  : realLabel ("ALABEL"),
36  givenLabel("NOLABEL"),
37  sgValue(0.00),
38  bgValue(0.00),
39  mom(0.00)
40  {};
41 
48  explicit ClassifierOutPuts(std::string const& Rlabel,
49  std::string const& Glabel,
50  float sgVal, float bgVal, float p)
51  : realLabel(Rlabel),
52  givenLabel(Glabel),
53  sgValue(sgVal),
54  bgValue(bgVal),
55  mom(p)
56  {};
57 
58  // Destructor
60  {};
61 
62  // Copy Const
64  : realLabel(ot.realLabel),
66  sgValue(ot.sgValue),
67  bgValue(ot.bgValue),
68  mom(ot.mom)
69  {};
70 
71  // Operators.
73  {
74  // check for self-assignment
75  if( this != &ot )
76  {
77  // Copy (deep)
78  this->realLabel = ot.realLabel;
79  this->givenLabel = ot.givenLabel;
80  this->sgValue = ot.sgValue;
81  this->bgValue = ot.bgValue;
82  this->mom = ot.mom;
83  }
84  return (*this);
85  };
86 
87  inline bool operator> (ClassifierOutPuts const& ot) const
88  {
89  return (this->sgValue > ot.sgValue);
90  };
91 
92  inline bool operator< (ClassifierOutPuts const& ot) const
93  {
94  return (this->sgValue < ot.sgValue);
95  };
96 
97  // Variables
98  std::string realLabel;// Original label
99  std::string givenLabel;// Given label
100  float sgValue;// Classifier output for label signal
101  float bgValue;// Classifier output for label background
102  float mom; // Momentum (reco.)
103 
104  //protected:
105 private:
106  //==
107  inline bool operator==(ClassifierOutPuts const& ot) const;
108 };
109 
113 struct ROCPoints
114 {
115  // Constructors
116  explicit ROCPoints()
117  : FP_rate(0.0),
118  TP_rate(0.0),
119  TN_rate(0.0),
120  FN_rate(0.0),
121  fp(0),
122  tp(0),
123  fn(0),
124  tn(0),
125  thr(0.0)
126  {};
138  explicit ROCPoints(float const fpr, float const tpr,
139  float const tnr, float const fnr,
140  size_t const nfp, size_t const ntp,
141  size_t const nfn, size_t const ntn,
142  float const curThr)
143  : FP_rate(fpr),
144  TP_rate(tpr),
145  TN_rate(tnr),
146  FN_rate(fnr),
147  fp(nfp),
148  tp(ntp),
149  fn(nfn),
150  tn(ntn),
151  thr(curThr)
152  {};
153 
154  // Destructor
155  virtual ~ROCPoints()
156  {};
157 
158  // Copy Const
159  ROCPoints(ROCPoints const& ot)
160  : FP_rate(ot.FP_rate),
161  TP_rate(ot.TP_rate),
162  TN_rate(ot.TN_rate),
163  FN_rate(ot.FN_rate),
164  fp(ot.fp),
165  tp(ot.tp),
166  fn(ot.fn),
167  tn(ot.tn),
168  thr(ot.thr)
169  {};
170 
171  // Operators.
173  {
174  // check for self-assignment
175  if(this != &ot)
176  {
177  this->FP_rate = ot.FP_rate;
178  this->TP_rate = ot.TP_rate;
179  this->TN_rate = ot.TN_rate;
180  this->FN_rate = ot.FN_rate;
181  this->fp = ot.fp;
182  this->tp = ot.tp;
183  this->fn = ot.fn;
184  this->tn = ot.tn;
185  this->thr = ot.thr;
186  }
187  return (*this);
188  };
189 
190  // Variables
191  float FP_rate;// False positief rate
192  float TP_rate;// True positief rate
193  float TN_rate;// True negatief rate
194  float FN_rate;// False negatief rate
195  size_t fp;// False positief count
196  size_t tp;// True positief count
197  size_t fn;// False negatief
198  size_t tn;// True negatief
199  float thr;// Treshold value
200 
201  // protected:
202 
203 private:
204  bool operator==(ROCPoints const& ot) const;
205  bool operator>( ROCPoints const& ot) const;
206  bool operator<( ROCPoints const& ot) const;
207 };
208 
209 //____________ Functions and modifiers.
210 //______________________________________________________________
222 void Produce_ROC(std::vector< ClassifierOutPuts >& input,
223  std::string const& SigName, std::string const& BgName,
224  size_t sigCnt, size_t bgCnt, std::vector< ROCPoints >& Roc);
229 void print(std::vector< ClassifierOutPuts > const& OutPutList);
230 
235 void print(std::map<std::string, float> const& ClsMapOut);
236 
244 std::map<std::string, size_t>* readEvents(char const* infile,
245  std::vector<std::string> const& varNames,
246  std::vector<std::string> const& classNames,
247  std::vector<std::pair<std::string, std::vector<float>* > >& Outcontainer);
248 
253 void printRoc(std::vector< ROCPoints > const& RocList);
254 
260 void WriteRocToFile( std::string const& FileName,
261  std::vector< ROCPoints > const& RocList);
262 
263 //____________________ C style function declarations
264 #ifdef __cplusplus
265 extern "C"
266 {
267 #endif
268  // Place your C code and/or C headers here.
269 #ifdef __cplusplus
270 }
271 #endif
272 
273 #endif
274 //interface definition
275 /*
276  Test for GCC > 3.2.0
277  #if __GNUC__ > 3 || (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || (__GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ > 0) ) )
278 */
bool operator<(ClassifierOutPuts const &ot) const
Definition: PndMvaTools.h:92
ClassifierOutPuts(ClassifierOutPuts const &ot)
Definition: PndMvaTools.h:63
bool operator>(ROCPoints const &ot) const
size_t fn
Definition: PndMvaTools.h:197
bool operator==(ClassifierOutPuts const &ot) const
ROCPoints(float const fpr, float const tpr, float const tnr, float const fnr, size_t const nfp, size_t const ntp, size_t const nfn, size_t const ntn, float const curThr)
Definition: PndMvaTools.h:138
TString FileName
virtual ~ClassifierOutPuts()
Definition: PndMvaTools.h:59
Double_t p
Definition: anasim.C:58
ClassifierOutPuts(std::string const &Rlabel, std::string const &Glabel, float sgVal, float bgVal, float p)
Definition: PndMvaTools.h:48
size_t tn
Definition: PndMvaTools.h:198
size_t fp
Definition: PndMvaTools.h:195
float thr
Definition: PndMvaTools.h:199
bool operator<(ROCPoints const &ot) const
float TN_rate
Definition: PndMvaTools.h:193
float FN_rate
Definition: PndMvaTools.h:194
ClassifierOutPuts & operator=(ClassifierOutPuts const &ot)
Definition: PndMvaTools.h:72
float TP_rate
Definition: PndMvaTools.h:192
size_t tp
Definition: PndMvaTools.h:196
void WriteRocToFile(std::string const &FileName, std::vector< ROCPoints > const &RocList)
float FP_rate
Definition: PndMvaTools.h:188
virtual ~ROCPoints()
Definition: PndMvaTools.h:155
std::string givenLabel
Definition: PndMvaTools.h:99
std::string realLabel
Definition: PndMvaTools.h:95
void Produce_ROC(std::vector< ClassifierOutPuts > &input, std::string const &SigName, std::string const &BgName, size_t sigCnt, size_t bgCnt, std::vector< ROCPoints > &Roc)
std::map< std::string, size_t > * readEvents(char const *infile, std::vector< std::string > const &varNames, std::vector< std::string > const &classNames, std::vector< std::pair< std::string, std::vector< float > * > > &Outcontainer)
void printRoc(std::vector< ROCPoints > const &RocList)
ROCPoints(ROCPoints const &ot)
Definition: PndMvaTools.h:159
void print(std::vector< ClassifierOutPuts > const &OutPutList)
ROCPoints & operator=(ROCPoints const &ot)
Definition: PndMvaTools.h:172
TFile infile("dedx_out.root","READ")
bool operator==(ROCPoints const &ot) const
bool operator>(ClassifierOutPuts const &ot) const
Definition: PndMvaTools.h:87