CMS 3D CMS Logo

L1TMuonEndCapForestESProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <memory>
3 
8 
11 
18 
19 using namespace std;
20 
21 // class declaration
22 
24 public:
27 
28  typedef std::shared_ptr<L1TMuonEndCapForest> ReturnType;
29 
30  ReturnType produce(const L1TMuonEndCapForestRcd&);
31 
32 private:
34  string bdtXMLDir;
35 
37 };
38 
39 // constructor
40 
42 {
43  setWhatProduced(this);
44 
45  ptLUTVersion = iConfig.getParameter<int>("PtAssignVersion");
46  bdtXMLDir = iConfig.getParameter<string>("bdtXMLDir");
47 }
48 
49 // member functions
50 
52  // original implementation use 0 ptr for non-existing children nodes, return empty cond tree (vector of nodes)
53  if( !node ) return L1TMuonEndCapForest::DTree();
54  // recur on left and then right child
55  L1TMuonEndCapForest::DTree left_subtree = traverse( node->getLeftDaughter() );
56  L1TMuonEndCapForest::DTree right_subtree = traverse( node->getRightDaughter() );
57  // allocate tree
58  L1TMuonEndCapForest::DTree cond_tree(1 + left_subtree.size() + right_subtree.size());
59  // copy the local root node
60  L1TMuonEndCapForest::DTreeNode &local_root = cond_tree[0];
61  local_root.splitVar = node->getSplitVariable();
62  local_root.splitVal = node->getSplitValue();
63  local_root.fitVal = node->getFitValue();
64  // shift children indicies and place the subtrees into the newly allocated tree
65  local_root.ileft = (!left_subtree.empty()?1:0); // left subtree (if exists) is placed right after the root -> index=1
66  transform(left_subtree.cbegin(), // source from
67  left_subtree.cend(), // source till
68  cond_tree.begin() + 1, // destination
69  [] (L1TMuonEndCapForest::DTreeNode cond_node) {
70  // increment indecies only for existing children, left 0 for non-existing
71  if( cond_node.ileft ) cond_node.ileft += 1;
72  if( cond_node.iright) cond_node.iright += 1;
73  return cond_node;
74  }
75  );
76  unsigned int offset = left_subtree.size();
77  local_root.iright = (offset+right_subtree.size() ? 1 + offset : 0); // right subtree is placed after the left one
78  transform(right_subtree.cbegin(), // source from
79  right_subtree.cend(), // source till
80  cond_tree.begin() + 1 + offset, // destination
82  // increment indecies only for existing children, left 0 for non-existing
83  if( cond_node.ileft ) cond_node.ileft += 1 + offset;
84  if( cond_node.iright) cond_node.iright += 1 + offset;
85  return cond_node;
86  }
87  );
88  return cond_tree;
89 }
90 
93 {
94  // piggyback on the PtAssignmentEngine class to read the XMLs in
95  PtAssignmentEngine* pt_assign_engine_;
96  std::unique_ptr<PtAssignmentEngine> pt_assign_engine_2016_;
97  std::unique_ptr<PtAssignmentEngine> pt_assign_engine_2017_;
98 
99  pt_assign_engine_2016_.reset(new PtAssignmentEngine2016());
100  pt_assign_engine_2017_.reset(new PtAssignmentEngine2017());
101 
102  if (ptLUTVersion <= 5) pt_assign_engine_ = pt_assign_engine_2016_.get();
103  else pt_assign_engine_ = pt_assign_engine_2017_.get();
104 
105  pt_assign_engine_->read(ptLUTVersion, bdtXMLDir);
106 
107  // get a hold on the forests; copy to non-const locals
108  std::array<emtf::Forest, 16> forests = pt_assign_engine_->getForests();
109  std::vector<int> allowedModes = pt_assign_engine_->getAllowedModes();
110  // construct empty cond payload
111  std::shared_ptr<L1TMuonEndCapForest> pEMTFForest(new L1TMuonEndCapForest());
112  // pack the forests into the cond payload for each mode
113  pEMTFForest->forest_coll_.resize(0);
114  for (unsigned int i = 0; i < allowedModes.size(); i++) {
115  int mode = allowedModes[i];
116  pEMTFForest->forest_map_[mode] = i;
117  // convert emtf::Forest into the L1TMuonEndCapForest::DForest
118  emtf::Forest& forest = forests.at(mode);
119  // Store boostWeight (initial pT value of tree 0) as an integer: boostWeight x 1 million
120  pEMTFForest->forest_map_[mode+16] = forest.getTree(0)->getBoostWeight() * 1000000;
121  L1TMuonEndCapForest::DForest cond_forest;
122  for (unsigned int j = 0; j < forest.size(); j++)
123  cond_forest.push_back( traverse( forest.getTree(j)->getRootNode() ) );
124  // of course, move has no effect here, but I'll keep it in case move constructor will be provided some day
125  pEMTFForest->forest_coll_.push_back( std::move( cond_forest ) );
126  }
127 
128  return pEMTFForest;
129 }
130 
131 // Define this as a plug-in
Node * getRightDaughter()
Definition: Node.cc:112
T getParameter(std::string const &) const
Node * getLeftDaughter()
Definition: Node.cc:102
const std::array< emtf::Forest, 16 > & getForests(void) const
ReturnType produce(const L1TMuonEndCapForestRcd &)
double getFitValue()
Definition: Node.cc:158
L1TMuonEndCapForestESProducer(const edm::ParameterSet &)
const std::vector< int > & getAllowedModes(void) const
Node * getRootNode()
Definition: Tree.cc:160
L1TMuonEndCapForest::DTree traverse(emtf::Node *tree)
std::shared_ptr< L1TMuonEndCapForest > ReturnType
std::vector< DTree > DForest
double getSplitValue()
Definition: Node.cc:136
std::vector< DTreeNode > DTree
double getBoostWeight(void) const
Definition: Tree.h:56
unsigned int size()
Definition: Forest.cc:143
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
Tree * getTree(unsigned int i)
Definition: Forest.cc:129
int getSplitVariable()
Definition: Node.cc:146
Definition: tree.py:1
void read(int pt_lut_version, const std::string &xml_dir)
def move(src, dest)
Definition: eostools.py:510