Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:15:07

0001 /**
0002  * \class L1GlobalTriggerRecordProducer
0003  * 
0004  * 
0005  * Description: L1GlobalTriggerRecord producer.  
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *   
0010  * \author: Vasile Mihai Ghete - HEPHY Vienna 
0011  * 
0012  *
0013  */
0014 
0015 // this class header
0016 #include "EventFilter/L1GlobalTriggerRawToDigi/interface/L1GlobalTriggerRecordProducer.h"
0017 
0018 // system include files
0019 #include <iostream>
0020 
0021 // user include files
0022 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerRecord.h"
0023 
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/Utilities/interface/InputTag.h"
0026 
0027 #include "FWCore/Framework/interface/EventSetup.h"
0028 #include "FWCore/Framework/interface/ESHandle.h"
0029 
0030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0031 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0032 
0033 // constructor(s)
0034 L1GlobalTriggerRecordProducer::L1GlobalTriggerRecordProducer(const edm::ParameterSet& parSet) {
0035   produces<L1GlobalTriggerRecord>();
0036 
0037   // input tag for DAQ GT record
0038   m_l1GtReadoutRecordTag =
0039       consumes<L1GlobalTriggerReadoutRecord>(parSet.getParameter<edm::InputTag>("L1GtReadoutRecordTag"));
0040 
0041   LogDebug("L1GlobalTriggerRecordProducer").log([&parSet](auto& l) {
0042     l << "\nInput tag for L1 GT DAQ record:             " << parSet.getParameter<edm::InputTag>("L1GtReadoutRecordTag");
0043   });
0044   /// EventSetup Token for l1GtTriggerMaskAlgo
0045   m_l1GtTmAlgoToken = esConsumes<L1GtTriggerMask, L1GtTriggerMaskAlgoTrigRcd>();
0046 
0047   ///  EventSetupToken for L1GtTriggerMaskTech
0048   m_l1GtTmTechToken = esConsumes<L1GtTriggerMask, L1GtTriggerMaskTechTrigRcd>();
0049 
0050   // initialize cached IDs
0051 
0052   m_l1GtTmAlgoCacheID = 0ULL;
0053   m_l1GtTmTechCacheID = 0ULL;
0054 }
0055 
0056 // destructor
0057 L1GlobalTriggerRecordProducer::~L1GlobalTriggerRecordProducer() {
0058   // empty
0059 }
0060 
0061 // member functions
0062 
0063 // method called to produce the data
0064 void L1GlobalTriggerRecordProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSetup) {
0065   // produce the L1GlobalTriggerRecord
0066   std::unique_ptr<L1GlobalTriggerRecord> gtRecord(new L1GlobalTriggerRecord());
0067 
0068   // get L1GlobalTriggerReadoutRecord
0069   edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecord;
0070   iEvent.getByToken(m_l1GtReadoutRecordTag, gtReadoutRecord);
0071 
0072   if (!gtReadoutRecord.isValid()) {
0073     LogDebug("L1GlobalTriggerRecordProducer").log([this](auto& l) {
0074       l << "\n\n Error: no L1GlobalTriggerReadoutRecord found with input tag ";
0075       edm::ProductLabels labels;
0076       labelsForToken(m_l1GtReadoutRecordTag, labels);
0077       l << labels.module << " " << labels.productInstance << " " << labels.process
0078         << "\n Returning empty L1GlobalTriggerRecord.\n\n";
0079     });
0080     iEvent.put(std::move(gtRecord));
0081     return;
0082   }
0083 
0084   //
0085   cms_uint16_t gtFinalOR = gtReadoutRecord->finalOR();
0086   int physicsDaqPartition = 0;
0087   bool gtDecision = static_cast<bool>(gtFinalOR & (1 << physicsDaqPartition));
0088 
0089   DecisionWord algoDecisionWord = gtReadoutRecord->decisionWord();
0090   TechnicalTriggerWord techDecisionWord = gtReadoutRecord->technicalTriggerWord();
0091 
0092   // get / update the trigger mask from the EventSetup
0093   // local cache & check on cacheIdentifier
0094 
0095   unsigned long long l1GtTmAlgoCacheID = evSetup.get<L1GtTriggerMaskAlgoTrigRcd>().cacheIdentifier();
0096 
0097   if (m_l1GtTmAlgoCacheID != l1GtTmAlgoCacheID) {
0098     edm::ESHandle<L1GtTriggerMask> l1GtTmAlgo = evSetup.getHandle(m_l1GtTmAlgoToken);
0099     m_l1GtTmAlgo = l1GtTmAlgo.product();
0100 
0101     m_triggerMaskAlgoTrig = m_l1GtTmAlgo->gtTriggerMask();
0102 
0103     m_l1GtTmAlgoCacheID = l1GtTmAlgoCacheID;
0104   }
0105 
0106   unsigned long long l1GtTmTechCacheID = evSetup.get<L1GtTriggerMaskTechTrigRcd>().cacheIdentifier();
0107 
0108   if (m_l1GtTmTechCacheID != l1GtTmTechCacheID) {
0109     edm::ESHandle<L1GtTriggerMask> l1GtTmTech = evSetup.getHandle(m_l1GtTmTechToken);
0110     m_l1GtTmTech = l1GtTmTech.product();
0111 
0112     m_triggerMaskTechTrig = m_l1GtTmTech->gtTriggerMask();
0113 
0114     m_l1GtTmTechCacheID = l1GtTmTechCacheID;
0115   }
0116 
0117   /// set global decision, decision word and technical trigger word
0118   /// for bunch cross with L1Accept (BxInEvent = 0) before applying the masks
0119   gtRecord->setDecisionWordBeforeMask(algoDecisionWord);
0120   gtRecord->setTechnicalTriggerWordBeforeMask(techDecisionWord);
0121 
0122   // mask the required bits for DAQ partition 0 (Physics Partition)
0123 
0124   int iDaq = 0;
0125 
0126   // algorithm trigger mask
0127 
0128   int iBit = -1;  // bit counter
0129 
0130   for (std::vector<bool>::iterator itBit = algoDecisionWord.begin(); itBit != algoDecisionWord.end(); ++itBit) {
0131     iBit++;
0132 
0133     int triggerMaskAlgoTrigBit = m_triggerMaskAlgoTrig[iBit] & (1 << iDaq);
0134     //LogTrace("L1GlobalTriggerFDL")
0135     //<< "\nAlgorithm trigger bit: " << iBit
0136     //<< " mask = " << triggerMaskAlgoTrigBit
0137     //<< " DAQ partition " << iDaq
0138     //<< std::endl;
0139 
0140     if (triggerMaskAlgoTrigBit) {
0141       *itBit = false;
0142 
0143       //LogTrace("L1GlobalTriggerFDL")
0144       //<< "\nMasked algorithm trigger: " << iBit << ". Result set to false"
0145       //<< std::endl;
0146     }
0147   }
0148 
0149   // mask the technical trigger
0150 
0151   iBit = -1;  // bit counter
0152 
0153   for (std::vector<bool>::iterator itBit = techDecisionWord.begin(); itBit != techDecisionWord.end(); ++itBit) {
0154     iBit++;
0155 
0156     int triggerMaskTechTrigBit = m_triggerMaskTechTrig[iBit] & (1 << iDaq);
0157     //LogTrace("L1GlobalTriggerFDL")
0158     //<< "\nTechnical trigger bit: " << iBit
0159     //<< " mask = " << triggerMaskTechTrigBit
0160     //<< " DAQ partition " << iDaq
0161     //<< std::endl;
0162 
0163     if (triggerMaskTechTrigBit) {
0164       *itBit = false;
0165 
0166       //LogTrace("L1GlobalTriggerFDL")
0167       //<< "\nMasked technical trigger: " << iBit << ". Result set to false"
0168       //<< std::endl;
0169     }
0170   }
0171 
0172   // set global decision, decision word and technical trigger word
0173   // for bunch cross with L1Accept (BxInEvent = 0) after applying the trigger masks
0174   gtRecord->setDecision(gtDecision);
0175   gtRecord->setDecisionWord(algoDecisionWord);
0176   gtRecord->setTechnicalTriggerWord(techDecisionWord);
0177 
0178   // get/set index of the set of prescale factors
0179   unsigned int pfIndexTech = static_cast<unsigned int>((gtReadoutRecord->gtFdlWord()).gtPrescaleFactorIndexTech());
0180   unsigned int pfIndexAlgo = static_cast<unsigned int>((gtReadoutRecord->gtFdlWord()).gtPrescaleFactorIndexAlgo());
0181 
0182   gtRecord->setGtPrescaleFactorIndexTech(pfIndexTech);
0183   gtRecord->setGtPrescaleFactorIndexAlgo(pfIndexAlgo);
0184 
0185   if (edm::isDebugEnabled()) {
0186     std::ostringstream myCoutStream;
0187     gtRecord->print(myCoutStream);
0188     LogTrace("L1GlobalTriggerRecordProducer") << "\n The following L1 GT record was produced.\n"
0189                                               << myCoutStream.str() << "\n"
0190                                               << std::endl;
0191   }
0192 
0193   // put records into event
0194   iEvent.put(std::move(gtRecord));
0195 }
0196 
0197 // static class members