Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:54

0001 // Tree.h
0002 
0003 #ifndef L1Trigger_L1TMuonEndCap_emtf_Tree
0004 #define L1Trigger_L1TMuonEndCap_emtf_Tree
0005 
0006 #include <list>
0007 #include "Node.h"
0008 #include "TXMLEngine.h"
0009 #include "CondFormats/L1TObjects/interface/L1TMuonEndCapForest.h"
0010 
0011 namespace emtf {
0012 
0013   //class Node;
0014 
0015   class Tree {
0016   public:
0017     Tree();
0018     Tree(std::vector<std::vector<Event*>>& cEvents);
0019     ~Tree();
0020 
0021     Tree(const Tree& tree);
0022     Tree& operator=(const Tree& tree);
0023     Tree(Tree&& tree);
0024 
0025     void setRootNode(Node* sRootNode);
0026     Node* getRootNode();
0027 
0028     void setTerminalNodes(std::list<Node*>& sTNodes);
0029     std::list<Node*>& getTerminalNodes();
0030 
0031     int getNumTerminalNodes();
0032 
0033     void buildTree(int nodeLimit);
0034     void calcError();
0035     void filterEvents(std::vector<Event*>& tEvents);
0036     void filterEventsRecursive(Node* node);
0037     Node* filterEvent(Event* e);
0038     Node* filterEventRecursive(Node* node, Event* e);
0039 
0040     void saveToXML(const char* filename);
0041     void saveToXMLRecursive(TXMLEngine* xml, Node* node, XMLNodePointer_t np);
0042     void addXMLAttributes(TXMLEngine* xml, Node* node, XMLNodePointer_t np);
0043 
0044     void loadFromXML(const char* filename);
0045     void loadFromXMLRecursive(TXMLEngine* xml, XMLNodePointer_t node, Node* tnode);
0046     void loadFromCondPayload(const L1TMuonEndCapForest::DTree& tree);
0047     void loadFromCondPayloadRecursive(const L1TMuonEndCapForest::DTree& tree,
0048                                       const L1TMuonEndCapForest::DTreeNode& node,
0049                                       Node* tnode);
0050 
0051     void rankVariables(std::vector<double>& v);
0052     void rankVariablesRecursive(Node* node, std::vector<double>& v);
0053 
0054     void getSplitValues(std::vector<std::vector<double>>& v);
0055     void getSplitValuesRecursive(Node* node, std::vector<std::vector<double>>& v);
0056 
0057     double getBoostWeight(void) const { return boostWeight; }
0058     void setBoostWeight(double wgt) { boostWeight = wgt; }
0059 
0060   private:
0061     Node* rootNode;
0062     std::list<Node*> terminalNodes;
0063     int numTerminalNodes;
0064     double rmsError;
0065     double boostWeight;
0066     unsigned xmlVersion;  // affects only XML loading part, save uses an old format and looses the boostWeight
0067 
0068     // this is the main recursive workhorse function that compensates for Nodes being non-copyable
0069     Node* copyFrom(const Node* local_root);  // no garantees if throws in the process
0070     // a dumb DFS tree traversal
0071     void findLeafs(Node* local_root, std::list<Node*>& tn);
0072   };
0073 
0074 }  // namespace emtf
0075 
0076 #endif