Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:44

0001 /** \class HLTLevel1Activity
0002  *
0003  *  
0004  *  This class is an EDFilter
0005  *  that checks if there was any L1 activity
0006  *  It can be configured to
0007  *    - look at different bunch crossings
0008  *    - use or ignore the L1 trigger mask
0009  *    - only look at a subset of the L1 bits
0010  * 
0011  *
0012  *  \author Andrea Bocci
0013  *
0014  */
0015 
0016 #include <vector>
0017 
0018 #include "FWCore/Framework/interface/Frameworkfwd.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/stream/EDFilter.h"
0021 #include "FWCore/Framework/interface/ESWatcher.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0025 #include "FWCore/Utilities/interface/InputTag.h"
0026 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskTechTrigRcd.h"
0027 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"
0028 
0029 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0030 
0031 // FIXME: these should come form the L1 configuration at runtime
0032 #define PHYSICS_BITS_SIZE 128
0033 #define TECHNICAL_BITS_SIZE 64
0034 
0035 //
0036 // class declaration
0037 //
0038 
0039 class HLTLevel1Activity : public edm::stream::EDFilter<> {
0040 public:
0041   explicit HLTLevel1Activity(const edm::ParameterSet &);
0042   ~HLTLevel1Activity() override;
0043   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0044   bool filter(edm::Event &, edm::EventSetup const &) final;
0045 
0046 private:
0047   edm::InputTag m_gtReadoutRecordTag;
0048   edm::EDGetTokenT<L1GlobalTriggerReadoutRecord> m_gtReadoutRecordToken;
0049   std::vector<int> m_bunchCrossings;
0050   std::vector<bool> m_selectPhysics;
0051   std::vector<bool> m_selectTechnical;
0052   std::vector<bool> m_maskedPhysics;
0053   std::vector<bool> m_maskedTechnical;
0054   unsigned int m_daqPartitions;
0055   bool m_ignoreL1Mask;
0056   bool m_invert;
0057 
0058   edm::ESWatcher<L1GtTriggerMaskAlgoTrigRcd> m_watchPhysicsMask;
0059   edm::ESWatcher<L1GtTriggerMaskTechTrigRcd> m_watchTechnicalMask;
0060 };
0061 
0062 #include "FWCore/Framework/interface/EventSetup.h"
0063 #include "FWCore/Framework/interface/ESHandle.h"
0064 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0065 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
0066 
0067 //
0068 // constructors and destructor
0069 //
0070 HLTLevel1Activity::HLTLevel1Activity(const edm::ParameterSet &config)
0071     : m_gtReadoutRecordTag(config.getParameter<edm::InputTag>("L1GtReadoutRecordTag")),
0072       m_gtReadoutRecordToken(consumes<L1GlobalTriggerReadoutRecord>(m_gtReadoutRecordTag)),
0073       m_bunchCrossings(config.getParameter<std::vector<int>>("bunchCrossings")),
0074       m_selectPhysics(PHYSICS_BITS_SIZE),
0075       m_selectTechnical(TECHNICAL_BITS_SIZE),
0076       m_maskedPhysics(PHYSICS_BITS_SIZE),
0077       m_maskedTechnical(TECHNICAL_BITS_SIZE),
0078       m_daqPartitions(config.getParameter<unsigned int>("daqPartitions")),
0079       m_ignoreL1Mask(config.getParameter<bool>("ignoreL1Mask")),
0080       m_invert(config.getParameter<bool>("invert")) {
0081   unsigned long long low = config.getParameter<unsigned long long>("physicsLoBits");
0082   unsigned long long high = config.getParameter<unsigned long long>("physicsHiBits");
0083   unsigned long long tech = config.getParameter<unsigned long long>("technicalBits");
0084   for (unsigned int i = 0; i < 64; i++) {
0085     m_selectPhysics[i] = low & (0x01ULL << (unsigned long long)i);
0086     m_maskedPhysics[i] = low & (0x01ULL << (unsigned long long)i);
0087   }
0088   for (unsigned int i = 0; i < 64; i++) {
0089     m_selectPhysics[i + 64] = high & (0x01ULL << (unsigned long long)i);
0090     m_maskedPhysics[i + 64] = high & (0x01ULL << (unsigned long long)i);
0091   }
0092   for (unsigned int i = 0; i < 64; i++) {
0093     m_selectTechnical[i] = tech & (0x01ULL << (unsigned long long)i);
0094     m_maskedTechnical[i] = tech & (0x01ULL << (unsigned long long)i);
0095   }
0096 }
0097 
0098 HLTLevel1Activity::~HLTLevel1Activity() = default;
0099 
0100 void HLTLevel1Activity::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0101   edm::ParameterSetDescription desc;
0102   desc.add<edm::InputTag>("L1GtReadoutRecordTag", edm::InputTag("hltGtDigis"));
0103   desc.add<std::vector<int>>("bunchCrossings", {0, -1, 1});
0104   desc.add<unsigned int>("daqPartitions", 1);
0105   desc.add<bool>("ignoreL1Mask", false);
0106   desc.add<bool>("invert", false);
0107   desc.add<unsigned long long int>("physicsLoBits", 0x0000000000000001LL);  // bit 0
0108   desc.add<unsigned long long int>("physicsHiBits", 0x0000000000040000LL);  // bit 64 + 18 = 82
0109   desc.add<unsigned long long int>("technicalBits", 0x0000000000000001LL);  // bit 0
0110   descriptions.add("hltLevel1Activity", desc);
0111 }
0112 
0113 //
0114 // member functions
0115 //
0116 
0117 // ------------ method called to produce the data  ------------
0118 bool HLTLevel1Activity::filter(edm::Event &event, edm::EventSetup const &setup) {
0119   /*
0120   // apply L1 mask to the physics bits
0121   //  - mask & partition == part. --> fully masked
0122   //  - mask & partition == 0x00  --> fully unmasked
0123   //  - mask & partition != part. --> unmasked in some partitions, consider as unmasked
0124   if (not m_ignoreL1Mask and m_watchPhysicsMask.check(setup)) {
0125     edm::ESHandle<L1GtTriggerMask> h_mask;
0126     setup.get<L1GtTriggerMaskAlgoTrigRcd>().get(h_mask);
0127     const std::vector<unsigned int> & mask = h_mask->gtTriggerMask();
0128     for (unsigned int i = 0; i < PHYSICS_BITS_SIZE; ++i)
0129       m_maskedPhysics[i] = m_selectPhysics[i] and ((mask[i] & m_daqPartitions) != m_daqPartitions);
0130   }
0131   
0132   // apply L1 mask to the technical bits
0133   //  - mask & partition == part. --> fully masked
0134   //  - mask & partition == 0x00  --> fully unmasked
0135   //  - mask & partition != part. --> unmasked in some partitions, consider as unmasked
0136   if (not m_ignoreL1Mask and m_watchTechnicalMask.check(setup)) {
0137     edm::ESHandle<L1GtTriggerMask> h_mask;
0138     setup.get<L1GtTriggerMaskTechTrigRcd>().get(h_mask);
0139     const std::vector<unsigned int> & mask = h_mask->gtTriggerMask();
0140     for (unsigned int i = 0; i < TECHNICAL_BITS_SIZE; ++i)
0141       m_maskedTechnical[i] = m_selectTechnical[i] and ((mask[i] & m_daqPartitions) != m_daqPartitions);
0142   }
0143 
0144   // access the L1 decisions
0145   edm::Handle<L1GlobalTriggerReadoutRecord> h_gtReadoutRecord;
0146   event.getByToken(m_gtReadoutRecordToken, h_gtReadoutRecord);
0147 
0148   // compare the results with the requested bits, and return true as soon as the first match is found
0149   for (int bx : m_bunchCrossings) {
0150     const std::vector<bool> & physics = h_gtReadoutRecord->decisionWord(bx);
0151     if (physics.size() != PHYSICS_BITS_SIZE)
0152       // error in L1 results
0153       return m_invert;
0154     for (unsigned int i = 0; i < PHYSICS_BITS_SIZE; ++i)
0155       if (m_maskedPhysics[i] and physics[i])
0156         return not m_invert;
0157     const std::vector<bool> & technical = h_gtReadoutRecord->technicalTriggerWord(bx);
0158     if (technical.size() != TECHNICAL_BITS_SIZE)
0159       // error in L1 results
0160       return m_invert;
0161     for (unsigned int i = 0; i < TECHNICAL_BITS_SIZE; ++i)
0162       if (m_maskedTechnical[i] and technical[i])
0163         return not m_invert;
0164   }
0165  
0166   return m_invert; 
0167   */
0168   return false;
0169 }
0170 
0171 // define as a framework plugin
0172 #include "FWCore/Framework/interface/MakerMacros.h"
0173 DEFINE_FWK_MODULE(HLTLevel1Activity);