Logo ROOT  
Reference Guide
Node.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Classes: Node *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Node for the BinarySearch or Decision Trees *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
16  * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
17  * *
18  * Copyright (c) 2005: *
19  * CERN, Switzerland *
20  * U. of Victoria, Canada *
21  * MPI-K Heidelberg, Germany *
22  * *
23  * Redistribution and use in source and binary forms, with or without *
24  * modification, are permitted according to the terms listed in LICENSE *
25  * (http://tmva.sourceforge.net/LICENSE) *
26  **********************************************************************************/
27 
28 #ifndef ROOT_TMVA_Node
29 #define ROOT_TMVA_Node
30 
31 //////////////////////////////////////////////////////////////////////////
32 // //
33 // Node //
34 // //
35 // Node base class for the BinarySearch or Decision Trees Nodes //
36 // //
37 //////////////////////////////////////////////////////////////////////////
38 
39 #include <iosfwd>
40 #include <string>
41 #include <sstream>
42 
43 #include "Rtypes.h"
44 #include "TMVA/Version.h"
45 
46 namespace TMVA {
47 
48  class Node;
49  class Event;
50  class BinaryTree;
51 
52  std::ostream& operator<<( std::ostream& os, const Node& node );
53  std::ostream& operator<<( std::ostream& os, const Node* node );
54 
55  // a class used to identify a Node; (needed for recursive reading from text file)
56  // (currently it is NOT UNIQUE... but could eventually made it
57  // a node in the tree structure
58  class Node {
59 
60  // output operator for a node
61  friend std::ostream& operator << (std::ostream& os, const Node& node);
62  // output operator with a pointer to the node (which still prints the node itself)
63  friend std::ostream& operator << (std::ostream& os, const Node* node);
64 
65  public:
66 
67  // constructor of a node
68  Node();
69 
70  // constructor of a daughter node as a daughter of 'p'
71  Node( Node* p, char pos );
72 
73  // copy constructor
74  Node( const Node &n );
75 
76  // destructor
77  virtual ~Node();
78 
79  virtual Node* CreateNode() const = 0;
80 
81  // test event if i{ descends the tree at this node to the right
82  virtual Bool_t GoesRight( const Event& ) const = 0;
83  // test event if it descends the tree at this node to the left
84 
85  virtual Bool_t GoesLeft ( const Event& ) const = 0;
86  // test event if it is equal to the event that "makes the node" (just for the "search tree"
87 
88  // return pointer to the left/right daughter or parent node
89  inline virtual Node* GetLeft () const { return fLeft; }
90  inline virtual Node* GetRight () const { return fRight; }
91  inline virtual Node* GetParent() const { return fParent; }
92 
93  // set pointer to the left/right daughter or parent node
94  inline virtual void SetLeft (Node* l) { fLeft = l;}
95  inline virtual void SetRight (Node* r) { fRight = r;}
96  inline virtual void SetParent(Node* p) { fParent = p;}
97 
98  //recursively go through the part of the tree below this node and count all daughters
100 
101  // printout of the node
102  virtual void Print( std::ostream& os ) const = 0;
103 
104  // recursive printout of the node and it daughters
105  virtual void PrintRec ( std::ostream& os ) const = 0;
106 
107  void* AddXMLTo(void* parent) const;
108  void ReadXML(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE );
109  virtual void AddAttributesToNode(void* node) const = 0;
110  virtual void AddContentToNode(std::stringstream& s) const = 0;
111 
112  // Set depth, layer of the where the node is within the tree, seen from the top (root)
114 
115  // Return depth, layer of the where the node is within the tree, seen from the top (root)
116  UInt_t GetDepth() const {return fDepth;}
117 
118  // set node position, i.e, the node is a left (l) or right (r) daughter
119  void SetPos(char s) {fPos=s;}
120 
121  // Return the node position, i.e, the node is a left (l) or right (r) daughter
122  char GetPos() const {return fPos;}
123 
124  // Return the pointer to the Parent tree to which the Node belongs
125  virtual TMVA::BinaryTree* GetParentTree() const {return fParentTree;}
126 
127  // set the pointer to the Parent Tree to which the Node belongs
129 
130  int GetCount();
131 
132  virtual Bool_t ReadDataRecord( std::istream&, UInt_t tmva_Version_Code = TMVA_VERSION_CODE ) = 0;
133  virtual void ReadAttributes(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE ) = 0;
134  virtual void ReadContent(std::stringstream& s) =0;
135 
136  protected:
137 
138  Node* fParent; // the previous (parent) node
139  Node* fLeft; // pointers to the two "daughter" nodes
140  Node* fRight; // pointers to the two "daughter" nodes
141 
142  char fPos; // position, i.e. it is a left (l) or right (r) daughter
143  UInt_t fDepth; // depth of the node within the tree (seen from root node)
144 
145  BinaryTree* fParentTree; // pointer to the parent tree to which the Node belongs
146  private:
147 
148  static Int_t fgCount; // counter of all nodes present.. for debug.. to spot memory leaks...
149 
150  public:
151  ClassDef(Node,0); // Node for the BinarySearch or Decision Trees
152  };
153 
154 } // namespace TMVA
155 
156 #endif
157 
l
auto * l
Definition: textangle.C:4
TMVA::Node::ReadContent
virtual void ReadContent(std::stringstream &s)=0
n
const Int_t n
Definition: legend1.C:16
TMVA::Node::~Node
virtual ~Node()
node destructor
Definition: Node.cxx:98
TMVA::Node::SetParent
virtual void SetParent(Node *p)
Definition: Node.h:96
TMVA::Node::AddXMLTo
void * AddXMLTo(void *parent) const
add attributes to XML
Definition: Node.cxx:147
TMVA::Node::SetDepth
void SetDepth(UInt_t d)
Definition: Node.h:113
TMVA::Node::fParent
Node * fParent
Definition: Node.h:138
TMVA::Node::CountMeAndAllDaughters
Int_t CountMeAndAllDaughters() const
recursively go through the part of the tree below this node and count all daughters
Definition: Node.cxx:114
TMVA::Node::GetRight
virtual Node * GetRight() const
Definition: Node.h:90
r
ROOT::R::TRInterface & r
Definition: Object.C:4
TMVA::Node::GetDepth
UInt_t GetDepth() const
Definition: Node.h:116
TMVA::Node::AddAttributesToNode
virtual void AddAttributesToNode(void *node) const =0
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
TMVA::Node::GetParent
virtual Node * GetParent() const
Definition: Node.h:91
TMVA::Node::operator<<
friend std::ostream & operator<<(std::ostream &os, const Node &node)
TMVA::operator<<
std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
TMVA::Node::SetParentTree
virtual void SetParentTree(TMVA::BinaryTree *t)
Definition: Node.h:128
TMVA::Node::fPos
char fPos
Definition: Node.h:142
TMVA::Node::GoesRight
virtual Bool_t GoesRight(const Event &) const =0
TMVA::Node
Node for the BinarySearch or Decision Trees.
Definition: Node.h:58
bool
Version.h
TMVA::Node::fDepth
UInt_t fDepth
Definition: Node.h:143
TMVA::Node::ReadXML
void ReadXML(void *node, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)
read attributes from XML
Definition: Node.cxx:163
TMVA::Node::CreateNode
virtual Node * CreateNode() const =0
TMVA::Node::Node
Node()
Definition: Node.cxx:51
TMVA::Node::SetLeft
virtual void SetLeft(Node *l)
Definition: Node.h:94
TMVA::BinaryTree
Base class for BinarySearch and Decision Trees.
Definition: BinaryTree.h:62
TMVA::Node::Print
virtual void Print(std::ostream &os) const =0
TMVA::Node::ReadDataRecord
virtual Bool_t ReadDataRecord(std::istream &, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)=0
TMVA::Node::GoesLeft
virtual Bool_t GoesLeft(const Event &) const =0
TMVA::Node::GetCount
int GetCount()
returns the global number of instantiated nodes
Definition: Node.cxx:106
TMVA::Node::GetLeft
virtual Node * GetLeft() const
Definition: Node.h:89
unsigned int
TMVA::Node::fParentTree
BinaryTree * fParentTree
Definition: Node.h:145
TMVA::Node::fRight
Node * fRight
Definition: Node.h:140
TMVA::Node::ReadAttributes
virtual void ReadAttributes(void *node, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)=0
TMVA_VERSION_CODE
#define TMVA_VERSION_CODE
Definition: Version.h:47
TMVA::Event
Definition: Event.h:51
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
d
#define d(i)
Definition: RSha256.hxx:102
TMVA::Node::fLeft
Node * fLeft
Definition: Node.h:139
TMVA::Node::PrintRec
virtual void PrintRec(std::ostream &os) const =0
TMVA::Node::AddContentToNode
virtual void AddContentToNode(std::stringstream &s) const =0
TMVA::Node::SetRight
virtual void SetRight(Node *r)
Definition: Node.h:95
TMVA::Node::SetPos
void SetPos(char s)
Definition: Node.h:119
Rtypes.h
TMVA::Node::GetPos
char GetPos() const
Definition: Node.h:122
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
int
TMVA::Node::fgCount
static Int_t fgCount
Definition: Node.h:148
TMVA::Node::GetParentTree
virtual TMVA::BinaryTree * GetParentTree() const
Definition: Node.h:125