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