Logo ROOT  
Reference Guide
RuleCut.h
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Andreas Hoecker, Joerg Stelzer, Fredrik Tegenfeldt, Helge Voss
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : Rule *
8 * *
9 * Description: *
10 * A class describing a 'rule cut' *
11 * *
12 * *
13 * Authors (alphabetical): *
14 * Fredrik Tegenfeldt <Fredrik.Tegenfeldt@cern.ch> - Iowa State U., USA *
15 * *
16 * Copyright (c) 2005: *
17 * CERN, Switzerland *
18 * Iowa State U. *
19 * *
20 * Redistribution and use in source and binary forms, with or without *
21 * modification, are permitted according to the terms listed in LICENSE *
22 * (http://tmva.sourceforge.net/LICENSE) *
23 **********************************************************************************/
24#ifndef ROOT_TMVA_RuleCut
25#define ROOT_TMVA_RuleCut
26
27#include "TMVA/Event.h"
28
29#include <vector>
30
31namespace TMVA {
32
33 class Node;
34 class MsgLogger;
35
36 class RuleCut {
37
38 public:
39
40 // main constructor
41 RuleCut( const std::vector< const TMVA::Node * > & nodes );
42
43 // copy constructor
44 RuleCut( const RuleCut & other ) : fLogger(0) { Copy( other ); }
45
46 // empty constructor
47 RuleCut();
48
49 // destructor
50 virtual ~RuleCut();
51
52 // evaluate an event
53 inline Bool_t EvalEvent( const Event &eve );
54
55 // get cut range for a given selector
56 Bool_t GetCutRange(Int_t sel,Double_t &rmin, Double_t &rmax, Bool_t &dormin, Bool_t &dormax) const;
57
58 // number of cuts
59 UInt_t GetNcuts() const;
60
61 // set members
62 inline void SetNvars( UInt_t nc );
63 void SetNeve( Double_t n ) { fCutNeve = n; }
64 void SetPurity( Double_t ssb ) { fPurity = ssb; }
65 void SetSelector( Int_t i, UInt_t s ) { fSelector[i] = s; }
66 void SetCutMin( Int_t i, Double_t v ) { fCutMin[i] = v; }
67 void SetCutMax( Int_t i, Double_t v ) { fCutMax[i] = v; }
68 void SetCutDoMin( Int_t i, Bool_t v ) { fCutDoMin[i] = v; }
69 void SetCutDoMax( Int_t i, Bool_t v ) { fCutDoMax[i] = v; }
70
71 // accessors
72 UInt_t GetNvars() const { return fSelector.size(); }
73 UInt_t GetSelector(Int_t is) const { return fSelector[is]; }
74 Double_t GetCutMin(Int_t is) const { return fCutMin[is]; }
75 Double_t GetCutMax(Int_t is) const { return fCutMax[is]; }
76 Char_t GetCutDoMin(Int_t is) const { return fCutDoMin[is]; }
77 Char_t GetCutDoMax(Int_t is) const { return fCutDoMax[is]; }
78 Double_t GetCutNeve() const { return fCutNeve; }
79 Double_t GetPurity() const { return fPurity; }
80
81 private:
82 // copy
83 inline void Copy( const RuleCut & other);
84
85 // make the cuts from the array of nodes
86 void MakeCuts( const std::vector< const TMVA::Node * > & nodes );
87
88 std::vector<UInt_t> fSelector; // array of selectors (expressions)
89 std::vector<Double_t> fCutMin; // array of lower limits
90 std::vector<Double_t> fCutMax; // array of upper limits
91 std::vector<Char_t> fCutDoMin; // array of usage flags for lower limits <--- stores boolean
92 std::vector<Char_t> fCutDoMax; // array of usage flags for upper limits <--- stores boolean
93 Double_t fCutNeve; // N(events) after cut (possibly weighted)
94 Double_t fPurity; // S/(S+B) on training data
95
96
97 mutable MsgLogger* fLogger; // message logger
98 MsgLogger& Log() const { return *fLogger; }
99 };
100}
101
102//_______________________________________________________________________
103inline void TMVA::RuleCut::Copy( const TMVA::RuleCut & other )
104{
105 // copy from another
106 if (&other != this) {
107 for (UInt_t ns=0; ns<other.GetNvars(); ns++) {
108 fSelector.push_back( other.GetSelector(ns) );
109 fCutMin.push_back( other.GetCutMin(ns) );
110 fCutMax.push_back( other.GetCutMax(ns) );
111 fCutDoMin.push_back( other.GetCutDoMin(ns) );
112 fCutDoMax.push_back( other.GetCutDoMax(ns) );
113 }
114 fCutNeve = other.GetCutNeve();
115 fPurity = other.GetPurity();
116 }
117}
118
119//_______________________________________________________________________
121{
122 // evaluate event using the cut
123
124 // Loop over all cuts
125 Int_t sel;
126 Double_t val;
127 Bool_t done=kFALSE;
128 Bool_t minOK, cutOK=kFALSE;
129 UInt_t nc=0;
130 while (!done) {
131 sel = fSelector[nc];
132 val = eve.GetValue(sel);
133 minOK = (fCutDoMin[nc] ? (val>fCutMin[nc]):kTRUE); // min cut ok
134 cutOK = (minOK ? ((fCutDoMax[nc] ? (val<fCutMax[nc]):kTRUE)) : kFALSE); // cut ok
135 nc++;
136 done = ((!cutOK) || (nc==fSelector.size())); // done if
137 }
138 // return ( cutOK ? 1.0: 0.0 );
139 return cutOK;
140}
141
142//_______________________________________________________________________
144{
145 // set the number of cuts
146 fSelector.clear();
147 fCutMin.clear();
148 fCutMax.clear();
149 fCutDoMin.clear();
150 fCutDoMax.clear();
151 //
152 fSelector.resize(nc);
153 fCutMin.resize(nc);
154 fCutMax.resize(nc);
155 fCutDoMin.resize(nc);
156 fCutDoMax.resize(nc);
157}
158
159#endif
int Int_t
Definition: RtypesCore.h:45
char Char_t
Definition: RtypesCore.h:33
unsigned int UInt_t
Definition: RtypesCore.h:46
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Definition: Event.cxx:236
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
A class describing a 'rule cut'.
Definition: RuleCut.h:36
std::vector< UInt_t > fSelector
Definition: RuleCut.h:88
Double_t GetPurity() const
Definition: RuleCut.h:79
void SetSelector(Int_t i, UInt_t s)
Definition: RuleCut.h:65
MsgLogger * fLogger
Definition: RuleCut.h:97
UInt_t GetNvars() const
Definition: RuleCut.h:72
std::vector< Double_t > fCutMax
Definition: RuleCut.h:90
MsgLogger & Log() const
Definition: RuleCut.h:98
RuleCut()
empty constructor
Definition: RuleCut.cxx:51
virtual ~RuleCut()
destructor
Definition: RuleCut.cxx:61
std::vector< Double_t > fCutMin
Definition: RuleCut.h:89
void SetCutDoMin(Int_t i, Bool_t v)
Definition: RuleCut.h:68
Double_t GetCutMin(Int_t is) const
Definition: RuleCut.h:74
RuleCut(const RuleCut &other)
Definition: RuleCut.h:44
void SetCutMin(Int_t i, Double_t v)
Definition: RuleCut.h:66
UInt_t GetSelector(Int_t is) const
Definition: RuleCut.h:73
Double_t fCutNeve
Definition: RuleCut.h:93
Double_t GetCutNeve() const
Definition: RuleCut.h:78
Char_t GetCutDoMin(Int_t is) const
Definition: RuleCut.h:76
Double_t fPurity
Definition: RuleCut.h:94
Char_t GetCutDoMax(Int_t is) const
Definition: RuleCut.h:77
UInt_t GetNcuts() const
get number of cuts
Definition: RuleCut.cxx:164
void SetNeve(Double_t n)
Definition: RuleCut.h:63
void MakeCuts(const std::vector< const TMVA::Node * > &nodes)
Construct the cuts from the given array of nodes.
Definition: RuleCut.cxx:69
Bool_t EvalEvent(const Event &eve)
Definition: RuleCut.h:120
void SetCutMax(Int_t i, Double_t v)
Definition: RuleCut.h:67
Double_t GetCutMax(Int_t is) const
Definition: RuleCut.h:75
std::vector< Char_t > fCutDoMax
Definition: RuleCut.h:92
Bool_t GetCutRange(Int_t sel, Double_t &rmin, Double_t &rmax, Bool_t &dormin, Bool_t &dormax) const
get cut range for a given selector
Definition: RuleCut.cxx:176
void Copy(const RuleCut &other)
Definition: RuleCut.h:103
void SetNvars(UInt_t nc)
Definition: RuleCut.h:143
std::vector< Char_t > fCutDoMin
Definition: RuleCut.h:91
void SetPurity(Double_t ssb)
Definition: RuleCut.h:64
void SetCutDoMax(Int_t i, Bool_t v)
Definition: RuleCut.h:69
const Int_t n
Definition: legend1.C:16
static constexpr double s
static constexpr double ns
create variable transformations