Logo ROOT   6.12/07
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 namespace TMVA {
30 
31  class Node;
32  class MsgLogger;
33 
34  class RuleCut {
35 
36  public:
37 
38  // main constructor
39  RuleCut( const std::vector< const TMVA::Node * > & nodes );
40 
41  // copy constructor
42  RuleCut( const RuleCut & other ) : fLogger(0) { Copy( other ); }
43 
44  // empty constructor
45  RuleCut();
46 
47  // destructor
48  virtual ~RuleCut();
49 
50  // evaluate an event
51  inline Bool_t EvalEvent( const Event &eve );
52 
53  // get cut range for a given selector
54  Bool_t GetCutRange(Int_t sel,Double_t &rmin, Double_t &rmax, Bool_t &dormin, Bool_t &dormax) const;
55 
56  // number of cuts
57  UInt_t GetNcuts() const;
58 
59  // set members
60  inline void SetNvars( UInt_t nc );
61  void SetNeve( Double_t n ) { fCutNeve = n; }
62  void SetPurity( Double_t ssb ) { fPurity = ssb; }
63  void SetSelector( Int_t i, UInt_t s ) { fSelector[i] = s; }
64  void SetCutMin( Int_t i, Double_t v ) { fCutMin[i] = v; }
65  void SetCutMax( Int_t i, Double_t v ) { fCutMax[i] = v; }
66  void SetCutDoMin( Int_t i, Bool_t v ) { fCutDoMin[i] = v; }
67  void SetCutDoMax( Int_t i, Bool_t v ) { fCutDoMax[i] = v; }
68 
69  // accessors
70  UInt_t GetNvars() const { return fSelector.size(); }
71  UInt_t GetSelector(Int_t is) const { return fSelector[is]; }
72  Double_t GetCutMin(Int_t is) const { return fCutMin[is]; }
73  Double_t GetCutMax(Int_t is) const { return fCutMax[is]; }
74  Char_t GetCutDoMin(Int_t is) const { return fCutDoMin[is]; }
75  Char_t GetCutDoMax(Int_t is) const { return fCutDoMax[is]; }
76  Double_t GetCutNeve() const { return fCutNeve; }
77  Double_t GetPurity() const { return fPurity; }
78 
79  private:
80  // copy
81  inline void Copy( const RuleCut & other);
82 
83  // make the cuts from the array of nodes
84  void MakeCuts( const std::vector< const TMVA::Node * > & nodes );
85 
86  std::vector<UInt_t> fSelector; // array of selectors (expressions)
87  std::vector<Double_t> fCutMin; // array of lower limits
88  std::vector<Double_t> fCutMax; // array of upper limits
89  std::vector<Char_t> fCutDoMin; // array of usage flags for lower limits <--- stores boolean
90  std::vector<Char_t> fCutDoMax; // array of usage flags for upper limits <--- stores boolean
91  Double_t fCutNeve; // N(events) after cut (possibly weighted)
92  Double_t fPurity; // S/(S+B) on training data
93 
94 
95  mutable MsgLogger* fLogger; // message logger
96  MsgLogger& Log() const { return *fLogger; }
97  };
98 }
99 
100 //_______________________________________________________________________
101 inline void TMVA::RuleCut::Copy( const TMVA::RuleCut & other )
102 {
103  // copy from another
104  if (&other != this) {
105  for (UInt_t ns=0; ns<other.GetNvars(); ns++) {
106  fSelector.push_back( other.GetSelector(ns) );
107  fCutMin.push_back( other.GetCutMin(ns) );
108  fCutMax.push_back( other.GetCutMax(ns) );
109  fCutDoMin.push_back( other.GetCutDoMin(ns) );
110  fCutDoMax.push_back( other.GetCutDoMax(ns) );
111  }
112  fCutNeve = other.GetCutNeve();
113  fPurity = other.GetPurity();
114  }
115 }
116 
117 //_______________________________________________________________________
119 {
120  // evaluate event using the cut
121 
122  // Loop over all cuts
123  Int_t sel;
124  Double_t val;
125  Bool_t done=kFALSE;
126  Bool_t minOK, cutOK=kFALSE;
127  UInt_t nc=0;
128  while (!done) {
129  sel = fSelector[nc];
130  val = eve.GetValue(sel);
131  minOK = (fCutDoMin[nc] ? (val>fCutMin[nc]):kTRUE); // min cut ok
132  cutOK = (minOK ? ((fCutDoMax[nc] ? (val<fCutMax[nc]):kTRUE)) : kFALSE); // cut ok
133  nc++;
134  done = ((!cutOK) || (nc==fSelector.size())); // done if
135  }
136  // return ( cutOK ? 1.0: 0.0 );
137  return cutOK;
138 }
139 
140 //_______________________________________________________________________
142 {
143  // set the number of cuts
144  fSelector.clear();
145  fCutMin.clear();
146  fCutMax.clear();
147  fCutDoMin.clear();
148  fCutDoMax.clear();
149  //
150  fSelector.resize(nc);
151  fCutMin.resize(nc);
152  fCutMax.resize(nc);
153  fCutDoMin.resize(nc);
154  fCutDoMax.resize(nc);
155 }
156 
157 #endif
RuleCut(const RuleCut &other)
Definition: RuleCut.h:42
Double_t fPurity
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 SetCutMax(Int_t i, Double_t v)
Definition: RuleCut.h:65
MsgLogger * fLogger
Definition: RuleCut.h:95
void SetPurity(Double_t ssb)
Definition: RuleCut.h:62
Double_t GetPurity() const
Definition: RuleCut.h:77
UInt_t GetNvars() const
Definition: RuleCut.h:70
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t GetCutMin(Int_t is) const
Definition: RuleCut.h:72
void SetNvars(UInt_t nc)
Definition: RuleCut.h:141
Bool_t EvalEvent(const Event &eve)
Definition: RuleCut.h:118
std::vector< Double_t > fCutMax
Definition: RuleCut.h:88
std::vector< Char_t > fCutDoMin
Definition: RuleCut.h:89
void SetCutMin(Int_t i, Double_t v)
Definition: RuleCut.h:64
MsgLogger & Log() const
Definition: RuleCut.h:96
Char_t GetCutDoMin(Int_t is) const
Definition: RuleCut.h:74
void SetCutDoMin(Int_t i, Bool_t v)
Definition: RuleCut.h:66
RuleCut()
empty constructor
Definition: RuleCut.cxx:51
void SetSelector(Int_t i, UInt_t s)
Definition: RuleCut.h:63
Char_t GetCutDoMax(Int_t is) const
Definition: RuleCut.h:75
std::vector< Char_t > fCutDoMax
Definition: RuleCut.h:90
std::vector< UInt_t > fSelector
Definition: RuleCut.h:86
A class describing a &#39;rule cut&#39;.
Definition: RuleCut.h:34
UInt_t GetNcuts() const
get number of cuts
Definition: RuleCut.cxx:164
SVector< double, 2 > v
Definition: Dict.h:5
unsigned int UInt_t
Definition: RtypesCore.h:42
void Copy(const RuleCut &other)
Definition: RuleCut.h:101
const Bool_t kFALSE
Definition: RtypesCore.h:88
Float_t GetValue(UInt_t ivar) const
return value of i&#39;th variable
Definition: Event.cxx:237
void SetCutDoMax(Int_t i, Bool_t v)
Definition: RuleCut.h:67
double Double_t
Definition: RtypesCore.h:55
void SetNeve(Double_t n)
Definition: RuleCut.h:61
static constexpr double s
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
void MakeCuts(const std::vector< const TMVA::Node * > &nodes)
Construct the cuts from the given array of nodes.
Definition: RuleCut.cxx:69
UInt_t GetSelector(Int_t is) const
Definition: RuleCut.h:71
char Char_t
Definition: RtypesCore.h:29
Abstract ClassifierFactory template that handles arbitrary types.
Double_t GetCutMax(Int_t is) const
Definition: RuleCut.h:73
std::vector< Double_t > fCutMin
Definition: RuleCut.h:87
virtual ~RuleCut()
destructor
Definition: RuleCut.cxx:61
Double_t GetCutNeve() const
Definition: RuleCut.h:76
const Bool_t kTRUE
Definition: RtypesCore.h:87
static constexpr double ns
const Int_t n
Definition: legend1.C:16
Double_t fCutNeve
Definition: RuleCut.h:91