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 {
17  public:
18  Tree();
19  Tree(std::vector< std::vector<Event*> >& cEvents);
20  ~Tree();
21 
22  Tree(const Tree &tree);
23  Tree& operator=(const Tree &tree);
24  Tree(Tree && tree);
25 
26  void setRootNode(Node *sRootNode);
27  Node* getRootNode();
28 
29  void setTerminalNodes(std::list<Node*>& sTNodes);
30  std::list<Node*>& getTerminalNodes();
31 
32  int getNumTerminalNodes();
33 
34  void buildTree(int nodeLimit);
35  void calcError();
36  void filterEvents(std::vector<Event*>& tEvents);
37  void filterEventsRecursive(Node* node);
39  Node* filterEventRecursive(Node* node, Event* e);
40 
41  void saveToXML(const char* filename);
42  void saveToXMLRecursive(TXMLEngine* xml, Node* node, XMLNodePointer_t np);
43  void addXMLAttributes(TXMLEngine* xml, Node* node, XMLNodePointer_t np);
44 
45  void loadFromXML(const char* filename);
46  void loadFromXMLRecursive(TXMLEngine* xml, XMLNodePointer_t node, Node* tnode);
49 
50  void rankVariables(std::vector<double>& v);
51  void rankVariablesRecursive(Node* node, std::vector<double>& v);
52 
53  void getSplitValues(std::vector<std::vector<double>>& v);
54  void getSplitValuesRecursive(Node* node, std::vector<std::vector<double>>& v);
55 
56  double getBoostWeight(void) const { return boostWeight; }
57  void setBoostWeight(double wgt) { boostWeight = wgt; }
58 
59  private:
61  std::list<Node*> terminalNodes;
63  double rmsError;
64  double boostWeight;
65  unsigned xmlVersion; // affects only XML loading part, save uses an old format and looses the boostWeight
66 
67  // this is the main recursive workhorse function that compensates for Nodes being non-copyable
68  Node* copyFrom(const Node *local_root); // no garantees if throws in the process
69  // a dumb DFS tree traversal
70  void findLeafs(Node *local_root, std::list<Node*> &tn);
71 };
72 
73 } // end of emtf namespace
74 
75 #endif
Node * filterEventRecursive(Node *node, Event *e)
Definition: Tree.cc:311
std::list< Node * > terminalNodes
Definition: Tree.h:61
void buildTree(int nodeLimit)
Definition: Tree.cc:204
void getSplitValues(std::vector< std::vector< double >> &v)
Definition: Tree.cc:397
Tree()
Definition: Tree.cc:30
void loadFromXMLRecursive(TXMLEngine *xml, XMLNodePointer_t node, Node *tnode)
Definition: Tree.cc:517
double rmsError
Definition: Tree.h:63
int getNumTerminalNodes()
Definition: Tree.cc:179
void addXMLAttributes(TXMLEngine *xml, Node *node, XMLNodePointer_t np)
Definition: Tree.cc:418
Node * getRootNode()
Definition: Tree.cc:160
void loadFromCondPayloadRecursive(const L1TMuonEndCapForest::DTree &tree, const L1TMuonEndCapForest::DTreeNode &node, Node *tnode)
Definition: Tree.cc:597
Definition: Event.h:15
Tree & operator=(const Tree &tree)
Definition: Tree.cc:78
void setTerminalNodes(std::list< Node * > &sTNodes)
Definition: Tree.cc:167
void findLeafs(Node *local_root, std::list< Node * > &tn)
Definition: Tree.cc:125
int np
Definition: AMPTWrapper.h:33
void setBoostWeight(double wgt)
Definition: Tree.h:57
void loadFromCondPayload(const L1TMuonEndCapForest::DTree &tree)
Definition: Tree.cc:587
void rankVariables(std::vector< double > &v)
Definition: Tree.cc:359
void rankVariablesRecursive(Node *node, std::vector< double > &v)
Definition: Tree.cc:326
void saveToXMLRecursive(TXMLEngine *xml, Node *node, XMLNodePointer_t np)
Definition: Tree.cc:455
std::vector< DTreeNode > DTree
std::list< Node * > & getTerminalNodes()
Definition: Tree.cc:172
Node * copyFrom(const Node *local_root)
Definition: Tree.cc:96
double getBoostWeight(void) const
Definition: Tree.h:56
void filterEventsRecursive(Node *node)
Definition: Tree.cc:281
int numTerminalNodes
Definition: Tree.h:62
void calcError()
Definition: Tree.cc:188
double boostWeight
Definition: Tree.h:64
Node * filterEvent(Event *e)
Definition: Tree.cc:299
void loadFromXML(const char *filename)
Definition: Tree.cc:477
void saveToXML(const char *filename)
Definition: Tree.cc:429
Node * rootNode
Definition: Tree.h:60
unsigned xmlVersion
Definition: Tree.h:65
Definition: tree.py:1
void filterEvents(std::vector< Event * > &tEvents)
Definition: Tree.cc:265
void setRootNode(Node *sRootNode)
Definition: Tree.cc:155
void getSplitValuesRecursive(Node *node, std::vector< std::vector< double >> &v)
Definition: Tree.cc:367
~Tree()
Definition: Tree.cc:55