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
46namespace 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
ROOT::R::TRInterface & r
Definition: Object.C:4
#define d(i)
Definition: RSha256.hxx:102
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
bool Bool_t
Definition: RtypesCore.h:63
#define ClassDef(name, id)
Definition: Rtypes.h:325
#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:58
static Int_t fgCount
Definition: Node.h:148
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:139
virtual void Print(std::ostream &os) const =0
char fPos
Definition: Node.h:142
virtual Node * GetLeft() const
Definition: Node.h:89
virtual Node * GetParent() const
Definition: Node.h:91
Node * fParent
Definition: Node.h:138
virtual TMVA::BinaryTree * GetParentTree() const
Definition: Node.h:125
virtual void PrintRec(std::ostream &os) const =0
virtual Node * CreateNode() const =0
virtual void SetRight(Node *r)
Definition: Node.h:95
char GetPos() const
Definition: Node.h:122
virtual Bool_t GoesLeft(const Event &) const =0
virtual void SetLeft(Node *l)
Definition: Node.h:94
virtual void AddContentToNode(std::stringstream &s) const =0
void SetPos(char s)
Definition: Node.h:119
virtual void SetParentTree(TMVA::BinaryTree *t)
Definition: Node.h:128
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:113
virtual void SetParent(Node *p)
Definition: Node.h:96
UInt_t fDepth
Definition: Node.h:143
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:140
UInt_t GetDepth() const
Definition: Node.h:116
virtual void AddAttributesToNode(void *node) const =0
virtual Node * GetRight() const
Definition: Node.h:90
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:145
const Int_t n
Definition: legend1.C:16
static constexpr double s
create variable transformations
std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
auto * l
Definition: textangle.C:4