Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:02

0001 // @(#)root/tmva $Id$
0002 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss
0003 
0004 /**********************************************************************************
0005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
0006  * Package: TMVA                                                                  *
0007  * Classes: Node                                                                  *
0008  *                                             *
0009  *                                                                                *
0010  * Description:                                                                   *
0011  *      Node for the BinarySearch or Decision Trees                               *
0012  *                                                                                *
0013  * Authors (alphabetical):                                                        *
0014  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
0015  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
0016  *      Kai Voss        <Kai.Voss@cern.ch>       - U. of Victoria, Canada         *
0017  *                                                                                *
0018  * Copyright (c) 2005:                                                            *
0019  *      CERN, Switzerland                                                         *
0020  *      U. of Victoria, Canada                                                    *
0021  *      MPI-K Heidelberg, Germany                                                 *
0022  *                                                                                *
0023  * Redistribution and use in source and binary forms, with or without             *
0024  * modification, are permitted according to the terms listed in LICENSE           *
0025  * (see tmva/doc/LICENSE)                                          *
0026  **********************************************************************************/
0027 
0028 #ifndef ROOT_TMVA_Node
0029 #define ROOT_TMVA_Node
0030 
0031 //////////////////////////////////////////////////////////////////////////
0032 //                                                                      //
0033 // Node                                                                 //
0034 //                                                                      //
0035 // Node base class for the BinarySearch or Decision Trees Nodes         //
0036 //                                                                      //
0037 //////////////////////////////////////////////////////////////////////////
0038 
0039 #include <iosfwd>
0040 #include <string>
0041 #include <sstream>
0042 
0043 #include "Rtypes.h"
0044 #include "TMVA/Version.h"
0045 
0046 namespace TMVA {
0047 
0048    class Node;
0049    class Event;
0050    class BinaryTree;
0051 
0052    std::ostream& operator<<( std::ostream& os, const Node& node );
0053    std::ostream& operator<<( std::ostream& os, const Node* node );
0054 
0055    // a class used to identify a Node; (needed for recursive reading from text file)
0056    // (currently it is NOT UNIQUE... but could eventually made it
0057    // a node in the tree structure
0058    class Node {
0059 
0060       // output operator for a node
0061       friend std::ostream& operator << (std::ostream& os, const Node& node);
0062       // output operator with a pointer to the node (which still prints the node itself)
0063       friend std::ostream& operator << (std::ostream& os, const Node* node);
0064 
0065    public:
0066 
0067       // constructor of a node
0068       Node();
0069 
0070       // constructor of a daughter node as a daughter of 'p'
0071       Node( Node* p, char pos );
0072 
0073       // copy constructor
0074       Node( const Node &n );
0075 
0076       // destructor
0077       virtual ~Node();
0078 
0079       virtual Node* CreateNode() const = 0;
0080 
0081       // test event if i{ descends the tree at this node to the right
0082       virtual Bool_t GoesRight( const Event& ) const = 0;
0083       // test event if it descends the tree at this node to the left
0084 
0085       virtual Bool_t GoesLeft ( const Event& ) const = 0;
0086       // test event if it is equal to the event that "makes the node" (just for the "search tree"
0087 
0088       // return pointer to the left/right daughter or parent node
0089       inline virtual Node* GetLeft  () const { return fLeft;   }
0090       inline virtual Node* GetRight () const { return fRight;  }
0091       inline virtual Node* GetParent() const { return fParent; }
0092 
0093       // set pointer to the left/right daughter or parent node
0094       inline virtual void SetLeft  (Node* l) { fLeft   = l;}
0095       inline virtual void SetRight (Node* r) { fRight  = r;}
0096       inline virtual void SetParent(Node* p) { fParent = p;}
0097 
0098       //recursively go through the part of the tree below this node and count all daughters
0099       Int_t  CountMeAndAllDaughters() const;
0100 
0101       // printout of the node
0102       virtual void Print( std::ostream& os ) const = 0;
0103 
0104       // recursive printout of the node and it daughters
0105       virtual void PrintRec ( std::ostream& os ) const = 0;
0106 
0107       void* AddXMLTo(void* parent) const;
0108       void  ReadXML(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE );
0109       virtual void AddAttributesToNode(void* node) const = 0;
0110       virtual void AddContentToNode(std::stringstream& s) const = 0;
0111 
0112       // Set depth, layer of the where the node is within the tree, seen from the top (root)
0113       void SetDepth(UInt_t d){fDepth=d;}
0114 
0115       // Return depth, layer of the where the node is within the tree, seen from the top (root)
0116       UInt_t GetDepth() const {return fDepth;}
0117 
0118       // set node position, i.e, the node is a left (l) or right (r) daughter
0119       void SetPos(char s) {fPos=s;}
0120 
0121       // Return the node position, i.e, the node is a left (l) or right (r) daughter
0122       char GetPos() const {return fPos;}
0123 
0124       // Return the pointer to the Parent tree to which the Node belongs
0125       virtual TMVA::BinaryTree* GetParentTree() const {return fParentTree;}
0126 
0127       // set the pointer to the Parent Tree to which the Node belongs
0128       virtual void SetParentTree(TMVA::BinaryTree* t) {fParentTree = t;}
0129 
0130       int GetCount();
0131 
0132       virtual Bool_t ReadDataRecord( std::istream&, UInt_t tmva_Version_Code = TMVA_VERSION_CODE ) = 0;
0133       virtual void ReadAttributes(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE  ) = 0;
0134       virtual void ReadContent(std::stringstream& s) =0;
0135 
0136    protected:
0137 
0138       Node*   fParent;              ///< the previous (parent) node
0139       Node*   fLeft;                ///< pointers to the two "daughter" nodes
0140       Node*   fRight;               ///< pointers to the two "daughter" nodes
0141 
0142       char    fPos;                 ///< position, i.e. it is a left (l) or right (r) daughter
0143       UInt_t  fDepth;               ///< depth of the node within the tree (seen from root node)
0144 
0145       BinaryTree*  fParentTree;     ///< pointer to the parent tree to which the Node belongs
0146    private:
0147 
0148       static Int_t fgCount;         ///< counter of all nodes present.. for debug.. to spot memory leaks...
0149 
0150    public:
0151       ClassDef(Node,0); // Node for the BinarySearch or Decision Trees
0152    };
0153 
0154 } // namespace TMVA
0155 
0156 #endif
0157