Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-06 04:27:03

0001 #include "L1Trigger/L1TMuonEndCap/interface/ConditionHelper.h"
0002 
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 #include "FWCore/Framework/interface/ConsumesCollector.h"
0005 
0006 #include "CondFormats/L1TObjects/interface/L1TMuonEndCapParams.h"
0007 #include "CondFormats/DataRecord/interface/L1TMuonEndCapParamsRcd.h"
0008 
0009 #include "CondFormats/L1TObjects/interface/L1TMuonEndCapForest.h"
0010 #include "CondFormats/DataRecord/interface/L1TMuonEndCapForestRcd.h"
0011 
0012 #include "L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngine.h"
0013 
0014 ConditionHelper::ConditionHelper(edm::ConsumesCollector iC)
0015     : params_cache_id_(0ULL), forest_cache_id_(0ULL), paramsToken_(iC.esConsumes()), forestToken_(iC.esConsumes()) {}
0016 
0017 ConditionHelper::~ConditionHelper() {}
0018 
0019 void ConditionHelper::checkAndUpdateConditions(const edm::EventSetup& iSetup) {
0020   bool new_params = false;
0021   bool new_forests = false;
0022 
0023   // Pull configuration from the EventSetup
0024   auto params_setup = iSetup.get<L1TMuonEndCapParamsRcd>();
0025   if (params_setup.cacheIdentifier() != params_cache_id_) {
0026     params_ = params_setup.getHandle(paramsToken_);
0027 
0028     // with the magic above you can use params_->fwVersion to change emulator's behavior
0029     // ...
0030 
0031     // reset cache id
0032     params_cache_id_ = params_setup.cacheIdentifier();
0033     new_params = true;
0034   }
0035 
0036   // Pull pt LUT from the EventSetup
0037   auto forest_setup = iSetup.get<L1TMuonEndCapForestRcd>();
0038   if (forest_setup.cacheIdentifier() != forest_cache_id_) {
0039     forest_ = forest_setup.getHandle(forestToken_);
0040 
0041     // at this point we want to reload the newly pulled pT LUT
0042     // ...
0043 
0044     // reset cache id
0045     forest_cache_id_ = forest_setup.cacheIdentifier();
0046     new_forests = true;
0047   }
0048 
0049   bool new_conditions = (new_params || new_forests);
0050   if (new_conditions) {
0051     edm::LogInfo("L1T") << "EMTF updating conditions: pc_lut_ver: " << get_pc_lut_version()
0052                         << " pt_lut_ver: " << get_pt_lut_version() << " fw_ver: " << get_fw_version();
0053   }
0054 
0055   // Debug
0056   //edm::LogWarning("L1T") << "EMTF new conditions? Yes (1) or no (0)? -- " << new_conditions << std::endl;
0057   //edm::LogWarning("L1T") << "EMTF updating conditions: pc_lut_ver: " << get_pc_lut_version() << " pt_lut_ver: " << get_pt_lut_version() << " fw_ver: " << get_fw_version();
0058 }
0059 
0060 unsigned int ConditionHelper::get_fw_version() const {
0061   // std::cout << "    - Getting firmware version from ConditionHelper: version = " << params_->firmwareVersion_ << std::endl;
0062   return params_->firmwareVersion_;
0063 }
0064 
0065 unsigned int ConditionHelper::get_pt_lut_version() const {
0066   // std::cout << "    - Getting pT LUT version from ConditionHelper: version = " << (params_->PtAssignVersion_ & 0xff);
0067   // std::cout << " (lowest bits of " << params_->PtAssignVersion_ << ")" << std::endl;
0068   if (params_->firmwareVersion_ < 50000)  // for 2016
0069     return 5;
0070   return (params_->PtAssignVersion_ & 0xff);  // Version indicated by first two bytes
0071 }
0072 
0073 unsigned int ConditionHelper::get_pc_lut_version() const {
0074   // "PhiMatchWindowSt1" arbitrarily re-mapped to Primitive conversion (PC LUT) version
0075   // because of rigid CondFormats naming conventions - AWB 02.06.17
0076   // std::cout << "    - Getting proper PC LUT version from ConditionHelper: version = " << params_->PhiMatchWindowSt1_ << std::endl;
0077   // return params_->PhiMatchWindowSt1_;
0078   // Hack until we figure out why the database is returning "0" for 2017 data - AWB 04.08.17
0079   // std::cout << "    - Getting hacked PC LUT version from ConditionHelper: version = " << (params_->firmwareVersion_ >= 50000) << std::endl;
0080   if (params_->firmwareVersion_ < 50000) {  // For 2016
0081     return 0;
0082   } else if (params_->firmwareVersion_ < 1537467271) {  // From the beginning of 2017
0083     return 1;                                           // Corresponding to FW timestamps before Sept. 20, 2018
0084   } else if (params_->firmwareVersion_ <
0085              1664468309) {  // Corresponds to September 29, 2022. The firmware was deployed on October 6, 2022.
0086     return 2;               // Starting September 26, 2018 with run 323556 (data only, not in MC)
0087   } else if (params_->firmwareVersion_ <
0088              1687686338) {  // Corresponds to June 25, 2023. The firmware was deployed on June 26, 2023.
0089     return 3;               // Starting October 6, 2022 with run 359924 (data only, not in MC)
0090   } else if (params_->firmwareVersion_ <
0091              1716282790) {  // Corresponds to May 21, 2024. The firmware was deployed on May 28, 2024.
0092     return 4;               // Starting July 1, 2023 with run 369675 (data only, not in MC)
0093   } else {
0094     return 5;  // Starting May 28, 2024 with run 381316 (data only, not in MC)
0095   }
0096 }
0097 
0098 unsigned int ConditionHelper::get_pc_lut_version_unchecked() const {
0099   // See comment in get_pc_lut_version()
0100   return params_->PhiMatchWindowSt1_;
0101 }