Logo ROOT   6.16/01
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 "Rtypes.h"
41
42#include "TMVA/Version.h"
43
44namespace TMVA {
45
46 class Node;
47 class Event;
48 class BinaryTree;
49
50 std::ostream& operator<<( std::ostream& os, const Node& node );
51 std::ostream& operator<<( std::ostream& os, const Node* node );
52
53 // a class used to identify a Node; (needed for recursive reading from text file)
54 // (currently it is NOT UNIQUE... but could eventually made it
55 // a node in the tree structure
56 class Node {
57
58 // output operator for a node
59 friend std::ostream& operator << (std::ostream& os, const Node& node);
60 // output operator with a pointer to the node (which still prints the node itself)
61 friend std::ostream& operator << (std::ostream& os, const Node* node);
62
63 public:
64
65 // constructor of a node
66 Node();
67
68 // constructor of a daughter node as a daughter of 'p'
69 Node( Node* p, char pos );
70
71 // copy constructor
72 Node( const Node &n );
73
74 // destructor
75 virtual ~Node();
76
77 virtual Node* CreateNode() const = 0;
78
79 // test event if i{ descends the tree at this node to the right
80 virtual Bool_t GoesRight( const Event& ) const = 0;
81 // test event if it descends the tree at this node to the left
82
83 virtual Bool_t GoesLeft ( const Event& ) const = 0;
84 // test event if it is equal to the event that "makes the node" (just for the "search tree"
85
86 // return pointer to the left/right daughter or parent node
87 inline virtual Node* GetLeft () const { return fLeft; }
88 inline virtual Node* GetRight () const { return fRight; }
89 inline virtual Node* GetParent() const { return fParent; }
90
91 // set pointer to the left/right daughter or parent node
92 inline virtual void SetLeft (Node* l) { fLeft = l;}
93 inline virtual void SetRight (Node* r) { fRight = r;}
94 inline virtual void SetParent(Node* p) { fParent = p;}
95
96 //recursively go through the part of the tree below this node and count all daughters
98
99 // printout of the node
100 virtual void Print( std::ostream& os ) const = 0;
101
102 // recursive printout of the node and it daughters
103 virtual void PrintRec ( std::ostream& os ) const = 0;
104
105 void* AddXMLTo(void* parent) const;
106 void ReadXML(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE );
107 virtual void AddAttributesToNode(void* node) const = 0;
108 virtual void AddContentToNode(std::stringstream& s) const = 0;
109
110 // Set depth, layer of the where the node is within the tree, seen from the top (root)
112
113 // Return depth, layer of the where the node is within the tree, seen from the top (root)
114 UInt_t GetDepth() const {return fDepth;}
115
116 // set node position, i.e, the node is a left (l) or right (r) daughter
117 void SetPos(char s) {fPos=s;}
118
119 // Return the node position, i.e, the node is a left (l) or right (r) daughter
120 char GetPos() const {return fPos;}
121
122 // Return the pointer to the Parent tree to which the Node belongs
123 virtual TMVA::BinaryTree* GetParentTree() const {return fParentTree;}
124
125 // set the pointer to the Parent Tree to which the Node belongs
127
128 int GetCount();
129
130 virtual Bool_t ReadDataRecord( std::istream&, UInt_t tmva_Version_Code = TMVA_VERSION_CODE ) = 0;
131 virtual void ReadAttributes(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE ) = 0;
132 virtual void ReadContent(std::stringstream& s) =0;
133
134 protected:
135
136 Node* fParent; // the previous (parent) node
137 Node* fLeft; // pointers to the two "daughter" nodes
138 Node* fRight; // pointers to the two "daughter" nodes
139
140 char fPos; // position, i.e. it is a left (l) or right (r) daughter
141 UInt_t fDepth; // depth of the node within the tree (seen from root node)
142
143 BinaryTree* fParentTree; // pointer to the parent tree to which the Node belongs
144 private:
145
146 static Int_t fgCount; // counter of all nodes present.. for debug.. to spot memory leaks...
147
148 public:
149 ClassDef(Node,0); // Node for the BinarySearch or Decision Trees
150 };
151
152} // namespace TMVA
153
154#endif
155
ROOT::R::TRInterface & r
Definition: Object.C:4
#define d(i)
Definition: RSha256.hxx:102
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:324
#define TMVA_VERSION_CODE
Definition: Version.h:47
Base class for BinarySearch and Decision Trees.
Definition: BinaryTree.h:62
Node for the BinarySearch or Decision Trees.
Definition: Node.h:56
static Int_t fgCount
Definition: Node.h:146
virtual void ReadContent(std::stringstream &s)=0
virtual void ReadAttributes(void *node, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)=0
Node * fLeft
Definition: Node.h:137
virtual void Print(std::ostream &os) const =0
char fPos
Definition: Node.h:140
virtual Node * GetLeft() const
Definition: Node.h:87
virtual Node * GetParent() const
Definition: Node.h:89
Node * fParent
Definition: Node.h:136
virtual TMVA::BinaryTree * GetParentTree() const
Definition: Node.h:123
virtual void PrintRec(std::ostream &os) const =0
virtual Node * CreateNode() const =0
virtual void SetRight(Node *r)
Definition: Node.h:93
char GetPos() const
Definition: Node.h:120
virtual Bool_t GoesLeft(const Event &) const =0
virtual void SetLeft(Node *l)
Definition: Node.h:92
virtual void AddContentToNode(std::stringstream &s) const =0
void SetPos(char s)
Definition: Node.h:117
virtual void SetParentTree(TMVA::BinaryTree *t)
Definition: Node.h:126
void * AddXMLTo(void *parent) const
add attributes to XML
Definition: Node.cxx:147
virtual Bool_t ReadDataRecord(std::istream &, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)=0
int GetCount()
returns the global number of instantiated nodes
Definition: Node.cxx:106
Int_t CountMeAndAllDaughters() const
recursively go through the part of the tree below this node and count all daughters
Definition: Node.cxx:114
void SetDepth(UInt_t d)
Definition: Node.h:111
virtual void SetParent(Node *p)
Definition: Node.h:94
UInt_t fDepth
Definition: Node.h:141
virtual Bool_t GoesRight(const Event &) const =0
virtual ~Node()
node destructor
Definition: Node.cxx:98
friend std::ostream & operator<<(std::ostream &os, const Node &node)
Node()
Definition: Node.cxx:51
Node * fRight
Definition: Node.h:138
UInt_t GetDepth() const
Definition: Node.h:114
virtual void AddAttributesToNode(void *node) const =0
virtual Node * GetRight() const
Definition: Node.h:88
void ReadXML(void *node, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)
read attributes from XML
Definition: Node.cxx:163
BinaryTree * fParentTree
Definition: Node.h:143
const Int_t n
Definition: legend1.C:16
static constexpr double s
Abstract ClassifierFactory template that handles arbitrary types.
std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
auto * l
Definition: textangle.C:4