CMS 3D CMS Logo

Tree.h
Go to the documentation of this file.
1 // Tree.h
2 
3 #ifndef L1Trigger_L1TMuonEndCap_emtf_Tree
4 #define L1Trigger_L1TMuonEndCap_emtf_Tree
5 
6 #include <list>
7 #include "Node.h"
8 #include "TXMLEngine.h"
10 
11 namespace emtf {
12 
13  //class Node;
14 
15  class Tree {
16  public:
17  Tree();
18  Tree(std::vector<std::vector<Event*>>& cEvents);
19  ~Tree();
20 
21  Tree(const Tree& tree);
22  Tree& operator=(const Tree& tree);
23  Tree(Tree&& tree);
24 
25  void setRootNode(Node* sRootNode);
26  Node* getRootNode();
27 
28  void setTerminalNodes(std::list<Node*>& sTNodes);
29  std::list<Node*>& getTerminalNodes();
30 
31  int getNumTerminalNodes();
32 
33  void buildTree(int nodeLimit);
34  void calcError();
35  void filterEvents(std::vector<Event*>& tEvents);
36  void filterEventsRecursive(Node* node);
39 
40  void saveToXML(const char* filename);
41  void saveToXMLRecursive(TXMLEngine* xml, Node* node, XMLNodePointer_t np);
42  void addXMLAttributes(TXMLEngine* xml, Node* node, XMLNodePointer_t np);
43 
44  void loadFromXML(const char* filename);
45  void loadFromXMLRecursive(TXMLEngine* xml, XMLNodePointer_t node, Node* tnode);
49  Node* tnode);
50 
51  void rankVariables(std::vector<double>& v);
52  void rankVariablesRecursive(Node* node, std::vector<double>& v);
53 
54  void getSplitValues(std::vector<std::vector<double>>& v);
55  void getSplitValuesRecursive(Node* node, std::vector<std::vector<double>>& v);
56 
57  double getBoostWeight(void) const { return boostWeight; }
58  void setBoostWeight(double wgt) { boostWeight = wgt; }
59 
60  private:
62  std::list<Node*> terminalNodes;
64  double rmsError;
65  double boostWeight;
66  unsigned xmlVersion; // affects only XML loading part, save uses an old format and looses the boostWeight
67 
68  // this is the main recursive workhorse function that compensates for Nodes being non-copyable
69  Node* copyFrom(const Node* local_root); // no garantees if throws in the process
70  // a dumb DFS tree traversal
71  void findLeafs(Node* local_root, std::list<Node*>& tn);
72  };
73 
74 } // namespace emtf
75 
76 #endif
Node * filterEventRecursive(Node *node, Event *e)
Definition: Tree.cc:287
std::list< Node * > terminalNodes
Definition: Tree.h:62
void buildTree(int nodeLimit)
Definition: Tree.cc:185
void getSplitValues(std::vector< std::vector< double >> &v)
Definition: Tree.cc:364
Tree()
Definition: Tree.cc:30
void loadFromXMLRecursive(TXMLEngine *xml, XMLNodePointer_t node, Node *tnode)
Definition: Tree.cc:477
double rmsError
Definition: Tree.h:64
int getNumTerminalNodes()
Definition: Tree.cc:165
void addXMLAttributes(TXMLEngine *xml, Node *node, XMLNodePointer_t np)
Definition: Tree.cc:381
Node * getRootNode()
Definition: Tree.cc:155
void loadFromCondPayloadRecursive(const L1TMuonEndCapForest::DTree &tree, const L1TMuonEndCapForest::DTreeNode &node, Node *tnode)
Definition: Tree.cc:560
Definition: Event.h:15
void filterEvents(std::vector< Event *> &tEvents)
Definition: Tree.cc:243
Tree & operator=(const Tree &tree)
Definition: Tree.cc:74
void setTerminalNodes(std::list< Node *> &sTNodes)
Definition: Tree.cc:159
void findLeafs(Node *local_root, std::list< Node *> &tn)
Definition: Tree.cc:124
int np
Definition: AMPTWrapper.h:43
void setBoostWeight(double wgt)
Definition: Tree.h:58
void loadFromCondPayload(const L1TMuonEndCapForest::DTree &tree)
Definition: Tree.cc:550
void rankVariables(std::vector< double > &v)
Definition: Tree.cc:332
void rankVariablesRecursive(Node *node, std::vector< double > &v)
Definition: Tree.cc:300
void saveToXMLRecursive(TXMLEngine *xml, Node *node, XMLNodePointer_t np)
Definition: Tree.cc:415
std::vector< DTreeNode > DTree
std::list< Node * > & getTerminalNodes()
Definition: Tree.cc:161
Node * copyFrom(const Node *local_root)
Definition: Tree.cc:93
void filterEventsRecursive(Node *node)
Definition: Tree.cc:258
int numTerminalNodes
Definition: Tree.h:63
void calcError()
Definition: Tree.cc:171
double boostWeight
Definition: Tree.h:65
Node * filterEvent(Event *e)
Definition: Tree.cc:276
double getBoostWeight(void) const
Definition: Tree.h:57
void loadFromXML(const char *filename)
Definition: Tree.cc:437
void saveToXML(const char *filename)
Definition: Tree.cc:391
Node * rootNode
Definition: Tree.h:61
unsigned xmlVersion
Definition: Tree.h:66
Definition: tree.py:1
void setRootNode(Node *sRootNode)
Definition: Tree.cc:153
void getSplitValuesRecursive(Node *node, std::vector< std::vector< double >> &v)
Definition: Tree.cc:336
~Tree()
Definition: Tree.cc:52