ROOT  6.06/09
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 #ifndef ROOT_TMVA_Event
28 #include "TMVA/Event.h"
29 #endif
30 
31 namespace 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 //_______________________________________________________________________
103 inline 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
Double_t GetPurity() const
Definition: RuleCut.h:79
MsgLogger & Log() const
Definition: RuleCut.h:98
RuleCut(const RuleCut &other)
Definition: RuleCut.h:44
Double_t fPurity
Definition: RuleCut.h:94
void SetCutMax(Int_t i, Double_t v)
Definition: RuleCut.h:67
MsgLogger * fLogger
Definition: RuleCut.h:97
void SetPurity(Double_t ssb)
Definition: RuleCut.h:64
Double_t GetCutMax(Int_t is) const
Definition: RuleCut.h:75
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
void SetNvars(UInt_t nc)
Definition: RuleCut.h:143
Bool_t EvalEvent(const Event &eve)
Definition: RuleCut.h:120
std::vector< Double_t > fCutMax
Definition: RuleCut.h:90
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Definition: Event.cxx:231
std::vector< Char_t > fCutDoMin
Definition: RuleCut.h:91
UInt_t GetSelector(Int_t is) const
Definition: RuleCut.h:73
void SetCutMin(Int_t i, Double_t v)
Definition: RuleCut.h:66
Char_t GetCutDoMax(Int_t is) const
Definition: RuleCut.h:77
Double_t GetCutMin(Int_t is) const
Definition: RuleCut.h:74
void SetCutDoMin(Int_t i, Bool_t v)
Definition: RuleCut.h:68
RuleCut()
empty constructor
Definition: RuleCut.cxx:45
void SetSelector(Int_t i, UInt_t s)
Definition: RuleCut.h:65
UInt_t GetNvars() const
Definition: RuleCut.h:72
std::vector< Char_t > fCutDoMax
Definition: RuleCut.h:92
std::vector< UInt_t > fSelector
Definition: RuleCut.h:88
SVector< double, 2 > v
Definition: Dict.h:5
unsigned int UInt_t
Definition: RtypesCore.h:42
UInt_t GetNcuts() const
get number of cuts
Definition: RuleCut.cxx:158
void Copy(const RuleCut &other)
Definition: RuleCut.h:103
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:170
void SetCutDoMax(Int_t i, Bool_t v)
Definition: RuleCut.h:69
double Double_t
Definition: RtypesCore.h:55
void SetNeve(Double_t n)
Definition: RuleCut.h:63
Char_t GetCutDoMin(Int_t is) const
Definition: RuleCut.h:76
void MakeCuts(const std::vector< const TMVA::Node * > &nodes)
Construct the cuts from the given array of nodes.
Definition: RuleCut.cxx:63
char Char_t
Definition: RtypesCore.h:29
Abstract ClassifierFactory template that handles arbitrary types.
std::vector< Double_t > fCutMin
Definition: RuleCut.h:89
virtual ~RuleCut()
destructor
Definition: RuleCut.cxx:55
Double_t GetCutNeve() const
Definition: RuleCut.h:78
const Bool_t kTRUE
Definition: Rtypes.h:91
const Int_t n
Definition: legend1.C:16
Double_t fCutNeve
Definition: RuleCut.h:93