CMS 3D CMS Logo

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