Back to home page

Project CMSSW displayed by LXR

 
 

    


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 // Called by "produce" in plugins/L1TMuonEndCapForestESProducer.cc
0012 // Runs over local XMLs if we are not running from the database
0013 // void PtAssignmentEngine::read(const std::string& xml_dir, const unsigned xml_nTrees) {
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;  // 2016 XMLs
0017   if (pt_lut_version >= 6)
0018     xml_nTrees = 400;  // First 2017 XMLs
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);  // For 2016, maps to "mode_inv"
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);  // associates mode to index
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     // std::cout << "Loaded forest for mode " << mode << " with boostWeight_ = " << boostWeight_ << std::endl;
0053     // std::cout << "  * ptLUTVersion_ = " << ptLUTVersion_ << std::endl;
0054     forests_.at(mode).getTree(0)->setBoostWeight(boostWeight_);
0055 
0056     emtf_assert(boostWeight_ == 0 || ptLUTVersion_ >= 6);  // Check that XMLs and pT LUT version are consistent
0057 
0058     // Will catch user trying to run with Global Tag settings on 2017 data, rather than fakeEmtfParams. - AWB 08.06.17
0059 
0060     // // Code below can be used to save out trees in XML format
0061     // for (int t = 0; t < 64; t++) {
0062     //   emtf::Tree* tree = forests_.at(mode).getTree(t);
0063     //   std::stringstream ss;
0064     //   ss << mode << "/" << t << ".xml";
0065     //   tree->saveToXML( ss.str().c_str() );
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     // Hardcoded - this 2 GB LUT file does not exist in CMSSW
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   // LUT outputs 'gmt_pt', so need to convert back to 'xmlpt'
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 }