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  using ReturnType = std::unique_ptr<L1TMuonEndCapForest>;
29 
30  ReturnType produce(const L1TMuonEndCapForestRcd&);
31 
32 private:
34  string bdtXMLDir;
35 
37 };
38 
39 // constructor
40 
42  setWhatProduced(this);
43 
44  ptLUTVersion = iConfig.getParameter<int>("PtAssignVersion");
45  bdtXMLDir = iConfig.getParameter<string>("bdtXMLDir");
46 }
47 
48 // member functions
49 
51  // original implementation use 0 ptr for non-existing children nodes, return empty cond tree (vector of nodes)
52  if (!node)
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 =
66  (!left_subtree.empty() ? 1 : 0); // left subtree (if exists) is placed right after the root -> index=1
67  transform(left_subtree.cbegin(), // source from
68  left_subtree.cend(), // source till
69  cond_tree.begin() + 1, // destination
70  [](L1TMuonEndCapForest::DTreeNode cond_node) {
71  // increment indecies only for existing children, left 0 for non-existing
72  if (cond_node.ileft)
73  cond_node.ileft += 1;
74  if (cond_node.iright)
75  cond_node.iright += 1;
76  return cond_node;
77  });
78  unsigned int offset = left_subtree.size();
79  local_root.iright = (offset + right_subtree.size() ? 1 + offset : 0); // right subtree is placed after the left one
80  transform(right_subtree.cbegin(), // source from
81  right_subtree.cend(), // source till
82  cond_tree.begin() + 1 + offset, // destination
84  // increment indecies only for existing children, left 0 for non-existing
85  if (cond_node.ileft)
86  cond_node.ileft += 1 + offset;
87  if (cond_node.iright)
88  cond_node.iright += 1 + offset;
89  return cond_node;
90  });
91  return cond_tree;
92 }
93 
95  // piggyback on the PtAssignmentEngine class to read the XMLs in
96  PtAssignmentEngine* pt_assign_engine_;
97  std::unique_ptr<PtAssignmentEngine> pt_assign_engine_2016_;
98  std::unique_ptr<PtAssignmentEngine> pt_assign_engine_2017_;
99 
100  pt_assign_engine_2016_ = std::make_unique<PtAssignmentEngine2016>();
101  pt_assign_engine_2017_ = std::make_unique<PtAssignmentEngine2017>();
102 
103  if (ptLUTVersion <= 5)
104  pt_assign_engine_ = pt_assign_engine_2016_.get();
105  else
106  pt_assign_engine_ = pt_assign_engine_2017_.get();
107 
108  pt_assign_engine_->read(ptLUTVersion, bdtXMLDir);
109 
110  // get a hold on the forests; copy to non-const locals
111  std::array<emtf::Forest, 16> forests = pt_assign_engine_->getForests();
112  std::vector<int> allowedModes = pt_assign_engine_->getAllowedModes();
113  // construct empty cond payload
114  auto pEMTFForest = std::make_unique<L1TMuonEndCapForest>();
115  // pack the forests into the cond payload for each mode
116  pEMTFForest->forest_coll_.resize(0);
117  for (unsigned int i = 0; i < allowedModes.size(); i++) {
118  int mode = allowedModes[i];
119  pEMTFForest->forest_map_[mode] = i;
120  // convert emtf::Forest into the L1TMuonEndCapForest::DForest
121  emtf::Forest& forest = forests.at(mode);
122  // Store boostWeight (initial pT value of tree 0) as an integer: boostWeight x 1 million
123  pEMTFForest->forest_map_[mode + 16] = forest.getTree(0)->getBoostWeight() * 1000000;
124  L1TMuonEndCapForest::DForest cond_forest;
125  for (unsigned int j = 0; j < forest.size(); j++)
126  cond_forest.push_back(traverse(forest.getTree(j)->getRootNode()));
127  // of course, move has no effect here, but I'll keep it in case move constructor will be provided some day
128  pEMTFForest->forest_coll_.push_back(std::move(cond_forest));
129  }
130 
131  return pEMTFForest;
132 }
133 
134 // Define this as a plug-in
Node * getRightDaughter()
Definition: Node.cc:90
Node * getLeftDaughter()
Definition: Node.cc:86
ReturnType produce(const L1TMuonEndCapForestRcd &)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double getFitValue()
Definition: Node.cc:112
L1TMuonEndCapForestESProducer(const edm::ParameterSet &)
Node * getRootNode()
Definition: Tree.cc:155
const std::array< emtf::Forest, 16 > & getForests(void) const
const std::vector< int > & getAllowedModes(void) const
L1TMuonEndCapForest::DTree traverse(emtf::Node *tree)
std::vector< DTree > DForest
std::unique_ptr< L1TMuonEndCapForest > ReturnType
double getSplitValue()
Definition: Node.cc:102
std::vector< DTreeNode > DTree
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
unsigned int size()
Definition: Forest.cc:127
double getBoostWeight(void) const
Definition: Tree.h:57
Tree * getTree(unsigned int i)
Definition: Forest.cc:114
int getSplitVariable()
Definition: Node.cc:106
Definition: tree.py:1
void read(int pt_lut_version, const std::string &xml_dir)
def move(src, dest)
Definition: eostools.py:511
unsigned transform(const HcalDetId &id, unsigned transformCode)