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  // public:
32  // Constructors
33  explicit ClassifierOutPuts() : realLabel("ALABEL"), givenLabel("NOLABEL"), sgValue(0.00), bgValue(0.00), mom(0.00){};
34 
41  explicit ClassifierOutPuts(std::string const &Rlabel, std::string const &Glabel, float sgVal, float bgVal, float p)
42  : realLabel(Rlabel), givenLabel(Glabel), sgValue(sgVal), bgValue(bgVal), mom(p){};
43 
44  // Destructor
45  virtual ~ClassifierOutPuts(){};
46 
47  // Copy Const
49 
50  // Operators.
52  {
53  // check for self-assignment
54  if (this != &ot) {
55  // Copy (deep)
56  this->realLabel = ot.realLabel;
57  this->givenLabel = ot.givenLabel;
58  this->sgValue = ot.sgValue;
59  this->bgValue = ot.bgValue;
60  this->mom = ot.mom;
61  }
62  return (*this);
63  };
64 
65  inline bool operator>(ClassifierOutPuts const &ot) const { return (this->sgValue > ot.sgValue); };
66 
67  inline bool operator<(ClassifierOutPuts const &ot) const { return (this->sgValue < ot.sgValue); };
68 
69  // Variables
70  std::string realLabel; // Original label
71  std::string givenLabel; // Given label
72  float sgValue; // Classifier output for label signal
73  float bgValue; // Classifier output for label background
74  float mom; // Momentum (reco.)
75 
76  // protected:
77  private:
78  //==
79  inline bool operator==(ClassifierOutPuts const &ot) const;
80 };
81 
85 struct ROCPoints {
86  // Constructors
87  explicit ROCPoints() : FP_rate(0.0), TP_rate(0.0), TN_rate(0.0), FN_rate(0.0), fp(0), tp(0), fn(0), tn(0), thr(0.0){};
99  explicit 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)
100  : FP_rate(fpr), TP_rate(tpr), TN_rate(tnr), FN_rate(fnr), fp(nfp), tp(ntp), fn(nfn), tn(ntn), thr(curThr){};
101 
102  // Destructor
103  virtual ~ROCPoints(){};
104 
105  // Copy Const
106  ROCPoints(ROCPoints const &ot) : FP_rate(ot.FP_rate), TP_rate(ot.TP_rate), TN_rate(ot.TN_rate), FN_rate(ot.FN_rate), fp(ot.fp), tp(ot.tp), fn(ot.fn), tn(ot.tn), thr(ot.thr){};
107 
108  // Operators.
110  {
111  // check for self-assignment
112  if (this != &ot) {
113  this->FP_rate = ot.FP_rate;
114  this->TP_rate = ot.TP_rate;
115  this->TN_rate = ot.TN_rate;
116  this->FN_rate = ot.FN_rate;
117  this->fp = ot.fp;
118  this->tp = ot.tp;
119  this->fn = ot.fn;
120  this->tn = ot.tn;
121  this->thr = ot.thr;
122  }
123  return (*this);
124  };
125 
126  // Variables
127  float FP_rate; // False positief rate
128  float TP_rate; // True positief rate
129  float TN_rate; // True negatief rate
130  float FN_rate; // False negatief rate
131  size_t fp; // False positief count
132  size_t tp; // True positief count
133  size_t fn; // False negatief
134  size_t tn; // True negatief
135  float thr; // Treshold value
136 
137  // protected:
138 
139  private:
140  bool operator==(ROCPoints const &ot) const;
141  bool operator>(ROCPoints const &ot) const;
142  bool operator<(ROCPoints const &ot) const;
143 };
144 
145 //____________ Functions and modifiers.
146 //______________________________________________________________
158 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);
163 void print(std::vector<ClassifierOutPuts> const &OutPutList);
164 
169 void print(std::map<std::string, float> const &ClsMapOut);
170 
178 std::map<std::string, size_t> *readEvents(char const *infile, std::vector<std::string> const &varNames, std::vector<std::string> const &classNames,
179  std::vector<std::pair<std::string, std::vector<float> *>> &Outcontainer);
180 
185 void printRoc(std::vector<ROCPoints> const &RocList);
186 
192 void WriteRocToFile(std::string const &FileName, std::vector<ROCPoints> const &RocList);
193 
194 //____________________ C style function declarations
195 #ifdef __cplusplus
196 extern "C" {
197 #endif
198 // Place your C code and/or C headers here.
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif
204 // interface definition
205 /*
206  Test for GCC > 3.2.0
207  #if __GNUC__ > 3 || (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || (__GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ > 0) ) )
208 */
ClassifierOutPuts(ClassifierOutPuts const &ot)
Definition: PndMvaTools.h:48
size_t fn
Definition: PndMvaTools.h:133
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:99
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)
virtual ~ClassifierOutPuts()
Definition: PndMvaTools.h:45
ClassifierOutPuts(std::string const &Rlabel, std::string const &Glabel, float sgVal, float bgVal, float p)
Definition: PndMvaTools.h:41
size_t tn
Definition: PndMvaTools.h:134
size_t fp
Definition: PndMvaTools.h:131
float thr
Definition: PndMvaTools.h:135
float TN_rate
Definition: PndMvaTools.h:129
float FN_rate
Definition: PndMvaTools.h:130
ClassifierOutPuts & operator=(ClassifierOutPuts const &ot)
Definition: PndMvaTools.h:51
float TP_rate
Definition: PndMvaTools.h:128
size_t tp
Definition: PndMvaTools.h:132
void WriteRocToFile(std::string const &FileName, std::vector< ROCPoints > const &RocList)
float FP_rate
Definition: PndMvaTools.h:124
bool operator<(ClassifierOutPuts const &ot) const
Definition: PndMvaTools.h:67
virtual ~ROCPoints()
Definition: PndMvaTools.h:103
std::string givenLabel
Definition: PndMvaTools.h:71
std::string realLabel
Definition: PndMvaTools.h:67
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)
void printRoc(std::vector< ROCPoints > const &RocList)
ROCPoints(ROCPoints const &ot)
Definition: PndMvaTools.h:106
void print(std::vector< ClassifierOutPuts > const &OutPutList)
bool operator>(ClassifierOutPuts const &ot) const
Definition: PndMvaTools.h:65
ROCPoints & operator=(ROCPoints const &ot)
Definition: PndMvaTools.h:109
friend F32vec4 operator==(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:92