File indexing completed on 2024-04-06 12:20:58
0001 #include "L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngine.h"
0002
0003 #include <iostream>
0004 #include <sstream>
0005
0006 PtAssignmentEngine::PtAssignmentEngine()
0007 : allowedModes_({3, 5, 9, 6, 10, 12, 7, 11, 13, 14, 15}), forests_(), ptlut_reader_(), ptLUTVersion_(0xFFFFFFFF) {}
0008
0009 PtAssignmentEngine::~PtAssignmentEngine() {}
0010
0011
0012
0013
0014 void PtAssignmentEngine::read(int pt_lut_version, const std::string& xml_dir) {
0015 std::string xml_dir_full = "L1Trigger/L1TMuonEndCap/data/pt_xmls/" + xml_dir;
0016 unsigned xml_nTrees = 64;
0017 if (pt_lut_version >= 6)
0018 xml_nTrees = 400;
0019
0020 std::cout << "EMTF emulator: attempting to read " << xml_nTrees << " pT LUT XMLs from local directory" << std::endl;
0021 std::cout << xml_dir_full << std::endl;
0022 std::cout << "Non-standard operation; if it fails, now you know why" << std::endl;
0023
0024 for (unsigned i = 0; i < allowedModes_.size(); ++i) {
0025 int mode = allowedModes_.at(i);
0026 std::stringstream ss;
0027 ss << xml_dir_full << "/" << mode;
0028 forests_.at(mode).loadForestFromXML(ss.str().c_str(), xml_nTrees);
0029 }
0030
0031 return;
0032 }
0033
0034 void PtAssignmentEngine::load(int pt_lut_version, const L1TMuonEndCapForest* payload) {
0035 if (ptLUTVersion_ == pt_lut_version)
0036 return;
0037 ptLUTVersion_ = pt_lut_version;
0038
0039 edm::LogInfo("L1T") << "EMTF using pt_lut_ver: " << pt_lut_version;
0040
0041 for (unsigned i = 0; i < allowedModes_.size(); ++i) {
0042 int mode = allowedModes_.at(i);
0043
0044 L1TMuonEndCapForest::DForestMap::const_iterator index =
0045 payload->forest_map_.find(mode);
0046 if (index == payload->forest_map_.end())
0047 continue;
0048
0049 forests_.at(mode).loadFromCondPayload(payload->forest_coll_[index->second]);
0050
0051 double boostWeight_ = payload->forest_map_.find(mode + 16)->second / 1000000.;
0052
0053
0054 forests_.at(mode).getTree(0)->setBoostWeight(boostWeight_);
0055
0056 emtf_assert(boostWeight_ == 0 || ptLUTVersion_ >= 6);
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 }
0068
0069 return;
0070 }
0071
0072 void PtAssignmentEngine::configure(
0073 int verbose, bool readPtLUTFile, bool fixMode15HighPt, bool bug9BitDPhi, bool bugMode7CLCT, bool bugNegPt) {
0074 verbose_ = verbose;
0075
0076 readPtLUTFile_ = readPtLUTFile;
0077 fixMode15HighPt_ = fixMode15HighPt;
0078 bug9BitDPhi_ = bug9BitDPhi;
0079 bugMode7CLCT_ = bugMode7CLCT;
0080 bugNegPt_ = bugNegPt;
0081
0082 configure_details();
0083 }
0084
0085 void PtAssignmentEngine::configure_details() {
0086 if (readPtLUTFile_) {
0087 std::stringstream ss;
0088
0089 ss << "/afs/cern.ch/work/a/abrinke1/public/EMTF/PtAssign2017/LUTs/2017_06_07/LUT_v07_07June17.dat";
0090 std::string lut_full_path = ss.str();
0091 ptlut_reader_.read(lut_full_path);
0092 }
0093 }
0094
0095 const PtAssignmentEngineAux& PtAssignmentEngine::aux() const {
0096 static const PtAssignmentEngineAux instance;
0097 return instance;
0098 }
0099
0100 float PtAssignmentEngine::calculate_pt(const address_t& address) const {
0101 float pt = 0.;
0102
0103 if (readPtLUTFile_) {
0104 pt = calculate_pt_lut(address);
0105 } else {
0106 pt = calculate_pt_xml(address);
0107 }
0108
0109 return pt;
0110 }
0111
0112 float PtAssignmentEngine::calculate_pt(const EMTFTrack& track) const {
0113 float pt = 0.;
0114
0115 pt = calculate_pt_xml(track);
0116
0117 return pt;
0118 }
0119
0120 float PtAssignmentEngine::calculate_pt_lut(const address_t& address) const {
0121
0122 int gmt_pt = ptlut_reader_.lookup(address);
0123 float pt = aux().getPtFromGMTPt(gmt_pt);
0124 float xmlpt = pt;
0125 xmlpt *= unscale_pt(pt);
0126
0127 return xmlpt;
0128 }