Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:49

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, NodeID                                                          *
0008  *                                             *
0009  *                                                                                *
0010  * Description:                                                                   *
0011  *      Node for the BinarySearch                                                 *
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  *      LAPP, Annecy, France                                                      *
0023  *                                                                                *
0024  * Redistribution and use in source and binary forms, with or without             *
0025  * modification, are permitted according to the terms listed in LICENSE           *
0026  * (see tmva/doc/LICENSE)                                          *
0027  **********************************************************************************/
0028 
0029 #ifndef ROOT_TMVA_BinarySearchTreeNode
0030 #define ROOT_TMVA_BinarySearchTreeNode
0031 
0032 //////////////////////////////////////////////////////////////////////////
0033 //                                                                      //
0034 // BinarySearchTreeNode                                                 //
0035 //                                                                      //
0036 // Node for the BinarySearch  Tree                                      //
0037 //                                                                      //
0038 //////////////////////////////////////////////////////////////////////////
0039 
0040 #include <iosfwd>
0041 #include <vector>
0042 #include <string>
0043 #include <sstream>
0044 #include "Rtypes.h"
0045 
0046 #include "TMVA/Node.h"
0047 
0048 namespace TMVA {
0049 
0050    class Event;
0051 
0052    // a class used to identify a Node; (needed for recursive reading from text file)
0053    // (currently it is NOT UNIQUE... but could eventually made it
0054    // a node in the tree structure
0055    class BinarySearchTreeNode : public Node  {
0056 
0057    public:
0058 
0059       // constructor of a node for the search tree
0060       BinarySearchTreeNode( const Event* e = nullptr, UInt_t signalClass=0 );
0061 
0062       // constructor of a daughter node as a daughter of 'p'
0063       BinarySearchTreeNode( BinarySearchTreeNode* parent, char pos );
0064 
0065       // copy constructor
0066       BinarySearchTreeNode ( const BinarySearchTreeNode &n,
0067                              BinarySearchTreeNode* parent = nullptr);
0068 
0069       // destructor
0070       virtual ~BinarySearchTreeNode ();
0071 
0072       virtual Node* CreateNode() const { return new BinarySearchTreeNode(); }
0073 
0074       // test event if it descends the tree at this node to the right
0075       virtual Bool_t GoesRight( const Event& ) const;
0076       // test event if it descends the tree at this node to the left
0077 
0078       virtual Bool_t GoesLeft ( const Event& ) const;
0079       // test event if it is equal to the event that "makes the node" (just for the "search tree"
0080 
0081       virtual Bool_t EqualsMe ( const Event& ) const;
0082 
0083       /// set index of variable used for discrimination at this node
0084       inline void SetSelector( Short_t i) { fSelector = i; }
0085       /// return index of variable used for discrimination at this node
0086       inline Short_t GetSelector() const { return fSelector; }
0087 
0088       const std::vector<Float_t> & GetEventV() const { return fEventV; }
0089       Float_t                      GetWeight() const { return fWeight; }
0090       UInt_t                       GetClass()  const { return fClass; }
0091 
0092       const std::vector<Float_t> & GetTargets() const { return fTargets; }
0093 
0094 
0095       // printout of the node
0096       virtual void Print( std::ostream& os ) const;
0097 
0098       // recursive printout of the node and it daughters
0099       virtual void PrintRec( std::ostream& os ) const;
0100 
0101       virtual void AddAttributesToNode(void* node) const;
0102       virtual void AddContentToNode(std::stringstream& s) const;
0103 
0104       // Read the data block
0105       virtual Bool_t ReadDataRecord( std::istream& is, UInt_t tmva_Version_Code = TMVA_VERSION_CODE );
0106       virtual void ReadAttributes(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE );
0107       virtual void ReadContent(std::stringstream& s);
0108 
0109    private:
0110       std::vector<Float_t> fEventV;
0111       std::vector<Float_t> fTargets;
0112 
0113       Float_t     fWeight;
0114       UInt_t      fClass;
0115 
0116       Short_t     fSelector;       ///< index of variable used in node selection (decision tree)
0117 
0118       ClassDef(BinarySearchTreeNode,0); ///< Node for the BinarySearchTree
0119    };
0120 
0121 } // namespace TMVA
0122 
0123 #endif