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_.reset(new PtAssignmentEngine2016());
101  pt_assign_engine_2017_.reset(new 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
L1TMuonEndCapForestESProducer::L1TMuonEndCapForestESProducer
L1TMuonEndCapForestESProducer(const edm::ParameterSet &)
Definition: L1TMuonEndCapForestESProducer.cc:41
mps_fire.i
i
Definition: mps_fire.py:355
ESHandle.h
PtAssignmentEngine::getAllowedModes
const std::vector< int > & getAllowedModes(void) const
Definition: PtAssignmentEngine.h:26
L1TMuonEndCapForestESProducer::~L1TMuonEndCapForestESProducer
~L1TMuonEndCapForestESProducer() override
Definition: L1TMuonEndCapForestESProducer.cc:26
tree
Definition: tree.py:1
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
emtf::Node::getRightDaughter
Node * getRightDaughter()
Definition: Node.cc:90
PtAssignmentEngine
Definition: PtAssignmentEngine.h:16
ESProducer.h
L1TMuonEndCapForestRcd.h
L1TMuonEndCapForestESProducer::ptLUTVersion
int ptLUTVersion
Definition: L1TMuonEndCapForestESProducer.cc:33
L1TMuonEndCapForestESProducer
Definition: L1TMuonEndCapForestESProducer.cc:23
PtAssignmentEngine::getForests
const std::array< emtf::Forest, 16 > & getForests(void) const
Definition: PtAssignmentEngine.h:25
emtf::Tree::getBoostWeight
double getBoostWeight(void) const
Definition: Tree.h:57
emtf::Forest::size
unsigned int size()
Definition: Forest.cc:127
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
L1TMuonEndCapForestRcd
Definition: L1TMuonEndCapForestRcd.h:11
PtAssignmentEngine2017
Definition: PtAssignmentEngine2017.h:7
emtf::Forest::getTree
Tree * getTree(unsigned int i)
Definition: Forest.cc:114
L1TMuonEndCapForest::DTreeNode
Definition: L1TMuonEndCapForest.h:17
Forest.h
L1TMuonEndCapForest.h
L1TMuonEndCapForestESProducer::traverse
L1TMuonEndCapForest::DTree traverse(emtf::Node *tree)
Definition: L1TMuonEndCapForestESProducer.cc:50
ESProducts.h
L1TMuonEndCapForestESProducer::ReturnType
std::unique_ptr< L1TMuonEndCapForest > ReturnType
Definition: L1TMuonEndCapForestESProducer.cc:28
PtAssignmentEngine2017.h
emtf::Tree::getRootNode
Node * getRootNode()
Definition: Tree.cc:155
edm::ParameterSet
Definition: ParameterSet.h:36
Node.h
PtAssignmentEngine2016.h
L1TMuonEndCapForest::DTree
std::vector< DTreeNode > DTree
Definition: L1TMuonEndCapForest.h:31
fakeEmtfParams_empty_cff.bdtXMLDir
bdtXMLDir
Definition: fakeEmtfParams_empty_cff.py:44
emtf::Node::getSplitVariable
int getSplitVariable()
Definition: Node.cc:106
emtf::Node::getLeftDaughter
Node * getLeftDaughter()
Definition: Node.cc:86
emtf::Forest
Definition: Forest.h:12
Tree.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
L1TMuonEndCapForest::DForest
std::vector< DTree > DForest
Definition: L1TMuonEndCapForest.h:32
ModuleFactory.h
PtAssignmentEngine::read
void read(int pt_lut_version, const std::string &xml_dir)
Definition: PtAssignmentEngine.cc:14
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
emtf::Node::getFitValue
double getFitValue()
Definition: Node.cc:112
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
emtf::Node::getSplitValue
double getSplitValue()
Definition: Node.cc:102
emtf::Node
Definition: Node.h:12
PtAssignmentEngine2016
Definition: PtAssignmentEngine2016.h:7
L1TMuonEndCapForestESProducer::bdtXMLDir
string bdtXMLDir
Definition: L1TMuonEndCapForestESProducer.cc:34
edm::ESProducer
Definition: ESProducer.h:101
PtAssignmentEngine.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
L1TMuonEndCapForest::DTreeNode::splitVar
int splitVar
Definition: L1TMuonEndCapForest.h:23
L1TMuonEndCapForestESProducer::produce
ReturnType produce(const L1TMuonEndCapForestRcd &)
Definition: L1TMuonEndCapForestESProducer.cc:94