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