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 }
PtAssignmentEngine::fixMode15HighPt_
bool fixMode15HighPt_
Definition: PtAssignmentEngine.h:57
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
PtAssignmentEngine::calculate_pt
virtual float calculate_pt(const address_t &address) const
Definition: PtAssignmentEngine.cc:100
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
PtAssignmentEngine::bug9BitDPhi_
bool bug9BitDPhi_
Definition: PtAssignmentEngine.h:58
PtAssignmentEngine::calculate_pt_lut
virtual float calculate_pt_lut(const address_t &address) const
Definition: PtAssignmentEngine.cc:120
gather_cfg.cout
cout
Definition: gather_cfg.py:144
PtAssignmentEngine::ptLUTVersion_
int ptLUTVersion_
Definition: PtAssignmentEngine.h:56
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
PtAssignmentEngine::configure_details
void configure_details()
Definition: PtAssignmentEngine.cc:85
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
PtAssignmentEngine::~PtAssignmentEngine
virtual ~PtAssignmentEngine()
Definition: PtAssignmentEngine.cc:9
PtAssignmentEngine::configure
void configure(int verbose, bool readPtLUTFile, bool fixMode15HighPt, bool bug9BitDPhi, bool bugMode7CLCT, bool bugNegPt)
Definition: PtAssignmentEngine.cc:72
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
PtAssignmentEngineAux
Definition: PtAssignmentEngineAux.h:13
PtLUTReader::lookup
content_t lookup(const address_t &address) const
Definition: PtLUTReader.cc:60
PtAssignmentEngine::bugMode7CLCT_
bool bugMode7CLCT_
Definition: PtAssignmentEngine.h:58
PtAssignmentEngine::address_t
uint64_t address_t
Definition: PtAssignmentEngine.h:21
PtAssignmentEngine::ptlut_reader_
PtLUTReader ptlut_reader_
Definition: PtAssignmentEngine.h:52
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
jets_cff.payload
payload
Definition: jets_cff.py:32
l1t::EMTFTrack
Definition: EMTFTrack.h:42
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PtAssignmentEngine::calculate_pt_xml
virtual float calculate_pt_xml(const address_t &address) const
Definition: PtAssignmentEngine.h:46
PtAssignmentEngine::forests_
std::array< emtf::Forest, 16 > forests_
Definition: PtAssignmentEngine.h:51
PtAssignmentEngine::load
void load(int pt_lut_version, const L1TMuonEndCapForest *payload)
Definition: PtAssignmentEngine.cc:34
PtAssignmentEngineAux::getPtFromGMTPt
float getPtFromGMTPt(int gmt_pt) const
Definition: PtAssignmentEngineAux.cc:40
PtAssignmentEngine::unscale_pt
virtual float unscale_pt(const float pt, const int mode=15) const =0
PtAssignmentEngine::aux
const PtAssignmentEngineAux & aux() const
Definition: PtAssignmentEngine.cc:95
PtAssignmentEngine::readPtLUTFile_
bool readPtLUTFile_
Definition: PtAssignmentEngine.h:57
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
PtAssignmentEngine::allowedModes_
std::vector< int > allowedModes_
Definition: PtAssignmentEngine.h:50
PtAssignmentEngine::read
void read(int pt_lut_version, const std::string &xml_dir)
Definition: PtAssignmentEngine.cc:14
PtAssignmentEngine::bugNegPt_
bool bugNegPt_
Definition: PtAssignmentEngine.h:58
L1TMuonEndCapForest
Definition: L1TMuonEndCapForest.h:15
PtAssignmentEngine::PtAssignmentEngine
PtAssignmentEngine()
Definition: PtAssignmentEngine.cc:6
PtAssignmentEngine::verbose_
int verbose_
Definition: PtAssignmentEngine.h:54
emtf_assert
#define emtf_assert(expr)
Definition: DebugTools.h:18
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
PtAssignmentEngine.h
PtLUTReader::read
void read(const std::string &lut_full_path)
Definition: PtLUTReader.cc:13