Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:59

0001 #include <array>
0002 #include <cassert>
0003 #include <memory>
0004 #include <vector>
0005 
0006 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/one/EDFilter.h"
0010 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 
0013 class L1GTPrescaler : public edm::one::EDFilter<> {
0014 public:
0015   L1GTPrescaler(edm::ParameterSet const &config);
0016 
0017   bool filter(edm::Event &event, edm::EventSetup const &setup) override;
0018 
0019   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0020 
0021 private:
0022   const edm::EDGetTokenT<L1GlobalTriggerReadoutRecord> m_l1ResultsToken;
0023   const std::array<double, 128> m_algoPrescales;
0024   const std::array<double, 64> m_techPrescales;
0025   std::array<unsigned int, 128> m_algoCounters;
0026   std::array<unsigned int, 64> m_techCounters;
0027 };
0028 
0029 L1GTPrescaler::L1GTPrescaler(edm::ParameterSet const &config)
0030     : m_l1ResultsToken(consumes<L1GlobalTriggerReadoutRecord>(config.getParameter<edm::InputTag>("l1Results"))),
0031       m_algoPrescales(config.getParameter<std::array<double, 128>>("l1AlgoPrescales")),
0032       m_techPrescales(config.getParameter<std::array<double, 64>>("l1TechPrescales")) {
0033   m_algoCounters.fill(0);
0034   m_techCounters.fill(0);
0035   produces<L1GlobalTriggerReadoutRecord>();
0036 }
0037 
0038 bool L1GTPrescaler::filter(edm::Event &event, edm::EventSetup const &setup) {
0039   edm::Handle<L1GlobalTriggerReadoutRecord> handle;
0040   event.getByToken(m_l1ResultsToken, handle);
0041   auto algoWord = handle->decisionWord();          // make a copy of the L1 algo results
0042   auto techWord = handle->technicalTriggerWord();  // make a copy of the L1 tech results
0043   bool finalOr = false;
0044 
0045   for (unsigned int i = 0; i < 128; ++i) {
0046     if (m_algoPrescales[i] == 0) {
0047       // mask this trigger: reset the bit
0048       algoWord[i] = false;
0049     } else if (algoWord[i]) {
0050       // prescale this trigger
0051       ++m_algoCounters[i];
0052       if (std::fmod(m_algoCounters[i], m_algoPrescales[i]) < 1)
0053         // the prescale is successful, keep the bit set
0054         finalOr = true;
0055       else
0056         // the prescale failed, reset the bit
0057         algoWord[i] = false;
0058     }
0059   }
0060   for (unsigned int i = 0; i < 64; ++i) {
0061     if (m_techPrescales[i] == 0) {
0062       // mask this trigger: reset the bit
0063       techWord[i] = false;
0064     } else if (techWord[i]) {
0065       ++m_techCounters[i];
0066       if (std::fmod(m_techCounters[i], m_techPrescales[i]) < 1)
0067         // the prescale is successful, keep the bit set
0068         finalOr = true;
0069       else
0070         // the prescale failed, reset the bit
0071         techWord[i] = false;
0072     }
0073   }
0074 
0075   // make a copy of the L1GlobalTriggerReadoutRecord, and set the new decisions
0076   std::unique_ptr<L1GlobalTriggerReadoutRecord> result(new L1GlobalTriggerReadoutRecord(*handle));
0077   result->setDecisionWord(algoWord);
0078   result->setTechnicalTriggerWord(techWord);
0079   result->setDecision(finalOr);
0080   event.put(std::move(result));
0081 
0082   return finalOr;
0083 }
0084 
0085 void L1GTPrescaler::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0086   edm::ParameterSetDescription desc;
0087   desc.add<edm::InputTag>("l1Results", edm::InputTag("gtDigis"));
0088   desc.add<std::vector<double>>("l1AlgoPrescales", std::vector<double>(128, 1));
0089   desc.add<std::vector<double>>("l1TechPrescales", std::vector<double>(64, 1));
0090   descriptions.add("l1GTPrescaler", desc);
0091 }
0092 
0093 // register as a framework plugin
0094 #include "FWCore/Framework/interface/MakerMacros.h"
0095 DEFINE_FWK_MODULE(L1GTPrescaler);