CMS 3D CMS Logo

PtAssignmentEngine.cc
Go to the documentation of this file.
2 
3 #include <cassert>
4 #include <iostream>
5 #include <sstream>
6 
7 #include "helper.h" // assert_no_abort
8 
9 
11  allowedModes_({3,5,9,6,10,12,7,11,13,14,15}),
12  forests_(),
13  ptlut_reader_(),
14  ptLUTVersion_(0xFFFFFFFF)
15 {
16 
17 }
18 
20 
21 }
22 
23 // Called by "produce" in plugins/L1TMuonEndCapForestESProducer.cc
24 // Runs over local XMLs if we are not running from the database
25 // void PtAssignmentEngine::read(const std::string& xml_dir, const unsigned xml_nTrees) {
26 void PtAssignmentEngine::read(int pt_lut_version, const std::string& xml_dir) {
27 
28  std::string xml_dir_full = "L1Trigger/L1TMuonEndCap/data/pt_xmls/" + xml_dir;
29  unsigned xml_nTrees = 64; // 2016 XMLs
30  if (pt_lut_version >= 6)
31  xml_nTrees = 400; // First 2017 XMLs
32 
33  std::cout << "EMTF emulator: attempting to read " << xml_nTrees << " pT LUT XMLs from local directory" << std::endl;
34  std::cout << xml_dir_full << std::endl;
35  std::cout << "Non-standard operation; if it fails, now you know why" << std::endl;
36 
37  for (unsigned i = 0; i < allowedModes_.size(); ++i) {
38  int mode = allowedModes_.at(i); // For 2016, maps to "mode_inv"
39  std::stringstream ss;
40  ss << xml_dir_full << "/" << mode;
41  forests_.at(mode).loadForestFromXML(ss.str().c_str(), xml_nTrees);
42  }
43 
44  return;
45 }
46 
47 void PtAssignmentEngine::load(int pt_lut_version, const L1TMuonEndCapForest *payload) {
48  if (ptLUTVersion_ == pt_lut_version) return;
49  ptLUTVersion_ = pt_lut_version;
50 
51  edm::LogInfo("L1T") << "EMTF using pt_lut_ver: " << pt_lut_version;
52 
53  for (unsigned i = 0; i < allowedModes_.size(); ++i) {
54  int mode = allowedModes_.at(i);
55 
56  L1TMuonEndCapForest::DForestMap::const_iterator index = payload->forest_map_.find(mode); // associates mode to index
57  if (index == payload->forest_map_.end()) continue;
58 
59  forests_.at(mode).loadFromCondPayload(payload->forest_coll_[index->second]);
60 
61  double boostWeight_ = payload->forest_map_.find(mode+16)->second / 1000000.;
62  // std::cout << "Loaded forest for mode " << mode << " with boostWeight_ = " << boostWeight_ << std::endl;
63  // std::cout << " * ptLUTVersion_ = " << ptLUTVersion_ << std::endl;
64  forests_.at(mode).getTree(0)->setBoostWeight( boostWeight_ );
65 
66  if (not(boostWeight_ == 0 || ptLUTVersion_ >= 6)) // Check that XMLs and pT LUT version are consistent
67  { edm::LogError("L1T") << "boostWeight_ = " << boostWeight_ << ", ptLUTVersion_ = " << ptLUTVersion_; return; }
68  // Will catch user trying to run with Global Tag settings on 2017 data, rather than fakeEmtfParams. - AWB 08.06.17
69 
70  // // Code below can be used to save out trees in XML format
71  // for (int t = 0; t < 64; t++) {
72  // emtf::Tree* tree = forests_.at(mode).getTree(t);
73  // std::stringstream ss;
74  // ss << mode << "/" << t << ".xml";
75  // tree->saveToXML( ss.str().c_str() );
76  // }
77 
78  }
79 
80  return;
81 }
82 
84  int verbose,
85  bool readPtLUTFile, bool fixMode15HighPt,
86  bool bug9BitDPhi, bool bugMode7CLCT, bool bugNegPt
87 ) {
88  verbose_ = verbose;
89 
90  readPtLUTFile_ = readPtLUTFile;
91  fixMode15HighPt_ = fixMode15HighPt;
92  bug9BitDPhi_ = bug9BitDPhi;
93  bugMode7CLCT_ = bugMode7CLCT;
94  bugNegPt_ = bugNegPt;
95 
97 }
98 
100  if (readPtLUTFile_) {
101  std::stringstream ss;
102  // Hardcoded - this 2 GB LUT file does not exist in CMSSW
103  ss << "/afs/cern.ch/work/a/abrinke1/public/EMTF/PtAssign2017/LUTs/2017_06_07/LUT_v07_07June17.dat";
104  std::string lut_full_path = ss.str();
105  ptlut_reader_.read(lut_full_path);
106  }
107 }
108 
110  static const PtAssignmentEngineAux instance;
111  return instance;
112 }
113 
114 float PtAssignmentEngine::calculate_pt(const address_t& address) const {
115  float pt = 0.;
116 
117  if (readPtLUTFile_) {
118  pt = calculate_pt_lut(address);
119  } else {
120  pt = calculate_pt_xml(address);
121  }
122 
123  return pt;
124 }
125 
127  float pt = 0.;
128 
129  pt = calculate_pt_xml(track);
130 
131  return pt;
132 }
133 
134 float PtAssignmentEngine::calculate_pt_lut(const address_t& address) const {
135  // LUT outputs 'gmt_pt', so need to convert back to 'xmlpt'
136  int gmt_pt = ptlut_reader_.lookup(address);
137  float pt = aux().getPtFromGMTPt(gmt_pt);
138  float xmlpt = pt;
139  xmlpt *= unscale_pt(pt);
140 
141  return xmlpt;
142 }
143 
virtual float calculate_pt_xml(const address_t &address) const
virtual float calculate_pt(const address_t &address) const
void read(const std::string &lut_full_path)
Definition: PtLUTReader.cc:21
const PtAssignmentEngineAux & aux() const
static PFTauRenderPlugin instance
void configure(int verbose, bool readPtLUTFile, bool fixMode15HighPt, bool bug9BitDPhi, bool bugMode7CLCT, bool bugNegPt)
void load(int pt_lut_version, const L1TMuonEndCapForest *payload)
static int verbose
virtual float calculate_pt_lut(const address_t &address) const
std::array< emtf::Forest, 16 > forests_
virtual float unscale_pt(const float pt, const int mode=15) const =0
std::vector< int > allowedModes_
float getPtFromGMTPt(int gmt_pt) const
void read(int pt_lut_version, const std::string &xml_dir)
content_t lookup(const address_t &address) const
Definition: PtLUTReader.cc:67