Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-15 23:25:03

0001 // L1TGlobalProducer.cc
0002 //author:   Brian Winer - Ohio State
0003 //          Vladimir Rekovic - extend for overlap removal
0004 //          Elisa Fontanesi - extended for three-body correlation conditions
0005 
0006 #include "L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.h"
0007 
0008 // system include files
0009 #include <memory>
0010 #include <iostream>
0011 #include <iomanip>
0012 #include <algorithm>
0013 
0014 #include "FWCore/Utilities/interface/typedefs.h"
0015 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/ESHandle.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0022 #include "FWCore/Utilities/interface/InputTag.h"
0023 #include "DataFormats/Common/interface/RefProd.h"
0024 
0025 #include "L1Trigger/L1TGlobal/interface/GlobalParamsHelper.h"
0026 
0027 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0028 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0029 #include "DataFormats/L1TGlobal/interface/GlobalObjectMapRecord.h"
0030 #include "DataFormats/L1TGlobal/interface/AXOL1TLScore.h"
0031 
0032 #include "L1Trigger/L1TGlobal/interface/TriggerMenu.h"
0033 
0034 #include "TriggerMenuParser.h"
0035 
0036 using namespace l1t;
0037 
0038 void L1TGlobalProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0039   edm::ParameterSetDescription desc;
0040   // These parameters are part of the L1T/HLT interface, avoid changing if possible::
0041   desc.add<edm::InputTag>("MuonInputTag", edm::InputTag(""))
0042       ->setComment("InputTag for Global Muon Trigger (required parameter:  default value is invalid)");
0043   desc.add<edm::InputTag>("MuonShowerInputTag", edm::InputTag(""))
0044       ->setComment("InputTag for Global Muon Shower Trigger (required parameter:  default value is invalid)");
0045   desc.add<edm::InputTag>("EGammaInputTag", edm::InputTag(""))
0046       ->setComment("InputTag for Calo Trigger EGamma (required parameter:  default value is invalid)");
0047   desc.add<edm::InputTag>("TauInputTag", edm::InputTag(""))
0048       ->setComment("InputTag for Calo Trigger Tau (required parameter:  default value is invalid)");
0049   desc.add<edm::InputTag>("JetInputTag", edm::InputTag(""))
0050       ->setComment("InputTag for Calo Trigger Jet (required parameter:  default value is invalid)");
0051   desc.add<edm::InputTag>("EtSumInputTag", edm::InputTag(""))
0052       ->setComment("InputTag for Calo Trigger EtSum (required parameter:  default value is invalid)");
0053   desc.add<edm::InputTag>("EtSumZdcInputTag", edm::InputTag(""))
0054       ->setComment("InputTag for ZDC EtSums Plus and Minus (required parameter:  default value is invalid)");
0055   desc.add<edm::InputTag>("CICADAInputTag", edm::InputTag(""))
0056       ->setComment("InputTag for CICADA Anomaly Detection (required parameter: default value is invalid)");
0057   desc.add<edm::InputTag>("ExtInputTag", edm::InputTag(""))
0058       ->setComment("InputTag for external conditions (not required, but recommend to specify explicitly in config)");
0059   desc.add<edm::InputTag>("AlgoBlkInputTag", edm::InputTag("hltGtStage2Digis"))
0060       ->setComment(
0061           "InputTag for unpacked Algblk (required only if GetPrescaleColumnFromData orRequireMenuToMatchAlgoBlkInput "
0062           "set to true)");
0063   desc.add<bool>("GetPrescaleColumnFromData", false)
0064       ->setComment("Get prescale column from unpacked GlobalAlgBck. Otherwise use value specified in PrescaleSet");
0065   desc.add<bool>("AlgorithmTriggersUnprescaled", false)
0066       ->setComment("not required, but recommend to specify explicitly in config");
0067   desc.add<bool>("RequireMenuToMatchAlgoBlkInput", true)
0068       ->setComment(
0069           "This requires that the L1 menu record to match the menu used to produce the inputed L1 results, should be "
0070           "true when used by the HLT to produce the object map");
0071   desc.add<bool>("AlgorithmTriggersUnmasked", false)
0072       ->setComment("not required, but recommend to specify explicitly in config");
0073 
0074   // switch for muon showers in Run-3
0075   desc.add<bool>("useMuonShowers", false);
0076 
0077   //switch for saving AXO score
0078   desc.add<bool>("produceAXOL1TLScore", false);
0079 
0080   // disables resetting the prescale counters each lumisection (needed for offline)
0081   //  originally, the L1T firmware applied the reset of prescale counters at the end of every LS;
0082   //  this reset was disabled in the L1T firmware starting from run-362658 (November 25th, 2022), see
0083   //  https://github.com/cms-sw/cmssw/pull/37395#issuecomment-1323437044
0084   desc.add<bool>("resetPSCountersEachLumiSec", false);
0085 
0086   // initialise prescale counters with a semi-random value in the range [0, prescale*10^precision - 1];
0087   // if false, the prescale counters are initialised to zero
0088   desc.add<bool>("semiRandomInitialPSCounters", false);
0089 
0090   // These parameters have well defined  default values and are not currently
0091   // part of the L1T/HLT interface.  They can be cleaned up or updated at will:
0092   desc.add<bool>("ProduceL1GtDaqRecord", true);
0093   desc.add<bool>("ProduceL1GtObjectMapRecord", true);
0094   desc.add<int>("EmulateBxInEvent", 1);
0095   desc.add<int>("L1DataBxInEvent", 5);
0096   desc.add<unsigned int>("AlternativeNrBxBoardDaq", 0);
0097   desc.add<int>("BstLengthBytes", -1);
0098   desc.add<unsigned int>("PrescaleSet", 1);
0099   desc.addUntracked<int>("Verbosity", 0);
0100   desc.addUntracked<bool>("PrintL1Menu", false);
0101   desc.add<std::string>("TriggerMenuLuminosity", "startup");
0102   descriptions.add("L1TGlobalProducer", desc);
0103 }
0104 
0105 // constructors
0106 
0107 L1TGlobalProducer::L1TGlobalProducer(const edm::ParameterSet& parSet)
0108     : m_muInputTag(parSet.getParameter<edm::InputTag>("MuonInputTag")),
0109       m_muShowerInputTag(parSet.getParameter<edm::InputTag>("MuonShowerInputTag")),
0110       m_egInputTag(parSet.getParameter<edm::InputTag>("EGammaInputTag")),
0111       m_tauInputTag(parSet.getParameter<edm::InputTag>("TauInputTag")),
0112       m_jetInputTag(parSet.getParameter<edm::InputTag>("JetInputTag")),
0113       m_sumInputTag(parSet.getParameter<edm::InputTag>("EtSumInputTag")),
0114       m_sumZdcInputTag(parSet.getParameter<edm::InputTag>("EtSumZdcInputTag")),
0115       m_CICADAInputTag(parSet.getParameter<edm::InputTag>("CICADAInputTag")),
0116       m_extInputTag(parSet.getParameter<edm::InputTag>("ExtInputTag")),
0117 
0118       m_produceL1GtDaqRecord(parSet.getParameter<bool>("ProduceL1GtDaqRecord")),
0119       m_produceL1GtObjectMapRecord(parSet.getParameter<bool>("ProduceL1GtObjectMapRecord")),
0120 
0121       m_emulateBxInEvent(parSet.getParameter<int>("EmulateBxInEvent")),
0122       m_L1DataBxInEvent(parSet.getParameter<int>("L1DataBxInEvent")),
0123 
0124       m_alternativeNrBxBoardDaq(parSet.getParameter<unsigned int>("AlternativeNrBxBoardDaq")),
0125       m_psBstLengthBytes(parSet.getParameter<int>("BstLengthBytes")),
0126 
0127       m_prescaleSet(parSet.getParameter<unsigned int>("PrescaleSet")),
0128 
0129       m_algorithmTriggersUnprescaled(parSet.getParameter<bool>("AlgorithmTriggersUnprescaled")),
0130       m_algorithmTriggersUnmasked(parSet.getParameter<bool>("AlgorithmTriggersUnmasked")),
0131 
0132       m_verbosity(parSet.getUntrackedParameter<int>("Verbosity")),
0133       m_printL1Menu(parSet.getUntrackedParameter<bool>("PrintL1Menu")),
0134       m_isDebugEnabled(edm::isDebugEnabled()),
0135       m_getPrescaleColumnFromData(parSet.getParameter<bool>("GetPrescaleColumnFromData")),
0136       m_requireMenuToMatchAlgoBlkInput(parSet.getParameter<bool>("RequireMenuToMatchAlgoBlkInput")),
0137       m_algoblkInputTag(parSet.getParameter<edm::InputTag>("AlgoBlkInputTag")),
0138       m_resetPSCountersEachLumiSec(parSet.getParameter<bool>("resetPSCountersEachLumiSec")),
0139       m_semiRandomInitialPSCounters(parSet.getParameter<bool>("semiRandomInitialPSCounters")),
0140       m_useMuonShowers(parSet.getParameter<bool>("useMuonShowers")),
0141       m_produceAXOL1TLScore(parSet.getParameter<bool>("produceAXOL1TLScore")) {
0142   m_egInputToken = consumes(m_egInputTag);
0143   m_tauInputToken = consumes(m_tauInputTag);
0144   m_jetInputToken = consumes(m_jetInputTag);
0145   m_sumInputToken = consumes(m_sumInputTag);
0146   m_sumZdcInputToken = consumes(m_sumZdcInputTag);
0147   m_CICADAInputToken = consumes(m_CICADAInputTag);
0148   m_muInputToken = consumes(m_muInputTag);
0149   if (m_useMuonShowers)
0150     m_muShowerInputToken = consumes(m_muShowerInputTag);
0151   m_extInputToken = consumes(m_extInputTag);
0152   m_l1GtStableParToken = esConsumes<edm::Transition::BeginRun>();
0153   m_l1GtMenuToken = esConsumes<edm::Transition::BeginRun>();
0154 
0155   if (!(m_algorithmTriggersUnprescaled && m_algorithmTriggersUnmasked)) {
0156     m_l1GtPrescaleVetosToken = esConsumes();
0157   }
0158 
0159   if (m_getPrescaleColumnFromData || m_requireMenuToMatchAlgoBlkInput) {
0160     m_algoblkInputToken = consumes(m_algoblkInputTag);
0161   }
0162 
0163   if (m_verbosity) {
0164     LogTrace("L1TGlobalProducer") << "\nInput tag for muon collection from uGMT:         " << m_muInputTag
0165                                   << "\nInput tag for calorimeter jet collections from Cal: " << m_jetInputTag
0166                                   << "\nInput tag for external conditions     :         " << m_extInputTag << std::endl;
0167 
0168     LogTrace("L1TGlobalProducer") << "\nProduce the L1 uGT DAQ readout record:          " << m_produceL1GtDaqRecord
0169                                   << "\nProduce the L1 uGT Object Map record:           "
0170                                   << m_produceL1GtObjectMapRecord << " \n"
0171                                   << "\nNumber of BxInEvent to be emulated:             " << m_emulateBxInEvent << " \n"
0172                                   << "\nAlternative for number of BX in GT DAQ record:   0x" << std::hex
0173                                   << m_alternativeNrBxBoardDaq << " \n"
0174                                   << "\nRun algorithm triggers unprescaled:             "
0175                                   << m_algorithmTriggersUnprescaled
0176                                   << "\nRun algorithm triggers unmasked (all enabled):  " << m_algorithmTriggersUnmasked
0177                                   << "\n"
0178                                   << std::endl;
0179   }
0180 
0181   if ((m_emulateBxInEvent > 0) && ((m_emulateBxInEvent % 2) == 0)) {
0182     m_emulateBxInEvent = m_emulateBxInEvent - 1;
0183 
0184     if (m_verbosity) {
0185       edm::LogWarning("L1TGlobalProducer")
0186           << "\nWARNING: Number of bunch crossing to be emulated rounded to: " << m_emulateBxInEvent
0187           << "\n         The number must be an odd number!\n"
0188           << std::endl;
0189     }
0190   }
0191 
0192   if ((m_L1DataBxInEvent > 0) && ((m_L1DataBxInEvent % 2) == 0)) {
0193     m_L1DataBxInEvent = m_L1DataBxInEvent - 1;
0194 
0195     if (m_verbosity) {
0196       edm::LogWarning("L1TGlobalProducer")
0197           << "\nWARNING: Number of bunch crossing for incoming L1 Data rounded to: " << m_L1DataBxInEvent
0198           << "\n         The number must be an odd number!\n"
0199           << std::endl;
0200     }
0201   } else if (m_L1DataBxInEvent < 0) {
0202     m_L1DataBxInEvent = 1;
0203 
0204     if (m_verbosity) {
0205       edm::LogWarning("L1TGlobalProducer")
0206           << "\nWARNING: Number of bunch crossing for incoming L1 Data was changed to: " << m_L1DataBxInEvent
0207           << "\n         The number must be an odd positive number!\n"
0208           << std::endl;
0209     }
0210   }
0211 
0212   // register products
0213   if (m_produceL1GtDaqRecord) {
0214     produces<GlobalAlgBlkBxCollection>();
0215     //blwEXT produces<GlobalExtBlkBxCollection>();
0216   }
0217 
0218   if (m_produceL1GtObjectMapRecord) {
0219     produces<GlobalObjectMapRecord>();
0220   }
0221 
0222   if (m_produceAXOL1TLScore) {
0223     produces<AXOL1TLScoreBxCollection>("AXOScore");
0224   }
0225 
0226   // create new uGt Board
0227   m_uGtBrd = std::make_unique<GlobalBoard>();
0228   m_uGtBrd->setVerbosity(m_verbosity);
0229   m_uGtBrd->setResetPSCountersEachLumiSec(m_resetPSCountersEachLumiSec);
0230   m_uGtBrd->setSemiRandomInitialPSCounters(m_semiRandomInitialPSCounters);
0231 
0232   m_utml1GtMenu = nullptr;
0233 
0234   m_numberPhysTriggers = 0;
0235   m_numberDaqPartitions = 0;
0236 
0237   m_nrL1Mu = 0;
0238   m_nrL1MuShower = 0;
0239   m_nrL1EG = 0;
0240   m_nrL1Tau = 0;
0241 
0242   m_nrL1Jet = 0;
0243 
0244   m_ifMuEtaNumberBits = 0;
0245   m_ifCaloEtaNumberBits = 0;
0246 
0247   m_totalBxInEvent = 0;
0248 
0249   m_activeBoardsGtDaq = 0;
0250   m_bstLengthBytes = 0;
0251 
0252   //
0253   m_l1GtBMCacheID = 0ULL;
0254   m_l1GtPfAlgoCacheID = 0ULL;
0255   m_l1GtTmAlgoCacheID = 0ULL;
0256   m_l1GtTmVetoAlgoCacheID = 0ULL;
0257 
0258   // Set default, initial, dummy prescale factor table
0259   std::vector<std::vector<double>> temp_prescaleTable;
0260 
0261   temp_prescaleTable.push_back(std::vector<double>());
0262   m_initialPrescaleFactorsAlgoTrig = temp_prescaleTable;
0263 }
0264 
0265 // method called once at the beginning of every Run
0266 void L1TGlobalProducer::beginRun(edm::Run const& iRun, const edm::EventSetup& evSetup) {
0267   // get / update the stable parameters from the EventSetup
0268 
0269   auto const& l1GtStablePar = evSetup.getData(m_l1GtStableParToken);
0270   const GlobalParamsHelper* data = GlobalParamsHelper::readFromEventSetup(&l1GtStablePar);
0271 
0272   // number of bx
0273   m_totalBxInEvent = data->totalBxInEvent();
0274 
0275   // number of physics triggers
0276   m_numberPhysTriggers = data->numberPhysTriggers();
0277 
0278   // number of objects of each type
0279   m_nrL1Mu = data->numberL1Mu();
0280 
0281   // There should be at most 1 muon shower object per BX
0282   // This object contains information for the in-time
0283   // showers and out-of-time showers
0284   if (m_useMuonShowers)
0285     m_nrL1MuShower = 1;
0286 
0287   // EG
0288   m_nrL1EG = data->numberL1EG();
0289 
0290   // jets
0291   m_nrL1Jet = data->numberL1Jet();
0292 
0293   // taus
0294   m_nrL1Tau = data->numberL1Tau();
0295 
0296   if (m_L1DataBxInEvent < 1)
0297     m_L1DataBxInEvent = 1;
0298 
0299   int const minL1DataBxInEvent = (m_L1DataBxInEvent + 1) / 2 - m_L1DataBxInEvent;
0300   int const maxL1DataBxInEvent = (m_L1DataBxInEvent + 1) / 2 - 1;
0301 
0302   // Initialize Board
0303   m_uGtBrd->init(m_numberPhysTriggers,
0304                  m_nrL1Mu,
0305                  m_nrL1MuShower,
0306                  m_nrL1EG,
0307                  m_nrL1Tau,
0308                  m_nrL1Jet,
0309                  minL1DataBxInEvent,
0310                  maxL1DataBxInEvent);
0311 
0312   if (m_emulateBxInEvent < 0) {
0313     m_emulateBxInEvent = m_totalBxInEvent;
0314   }
0315 
0316   if (m_emulateBxInEvent < 1)
0317     m_emulateBxInEvent = 1;
0318 
0319   // get / update the trigger menu from the EventSetup
0320 
0321   // Instantiate Parser
0322   TriggerMenuParser gtParser = TriggerMenuParser();
0323   gtParser.setGtNumberConditionChips(data->numberChips());
0324   gtParser.setGtPinsOnConditionChip(data->pinsOnChip());
0325   gtParser.setGtOrderConditionChip(data->orderOfChip());
0326   gtParser.setGtNumberPhysTriggers(data->numberPhysTriggers());
0327 
0328   // parse menu into emulator classes
0329   m_utml1GtMenu = &(evSetup.getData(m_l1GtMenuToken));
0330   gtParser.parseCondFormats(m_utml1GtMenu);
0331 
0332   // transfer the condition map and algorithm map from parser to L1uGtTriggerMenu
0333   m_l1GtMenu = std::make_unique<TriggerMenu>(gtParser.gtTriggerMenuName(),
0334                                              data->numberChips(),
0335                                              gtParser.vecMuonTemplate(),
0336                                              gtParser.vecMuonShowerTemplate(),
0337                                              gtParser.vecCaloTemplate(),
0338                                              gtParser.vecEnergySumTemplate(),
0339                                              gtParser.vecEnergySumZdcTemplate(),
0340                                              gtParser.vecAXOL1TLTemplate(),
0341                                              gtParser.vecCICADATemplate(),
0342                                              gtParser.vecExternalTemplate(),
0343                                              gtParser.vecCorrelationTemplate(),
0344                                              gtParser.vecCorrelationThreeBodyTemplate(),
0345                                              gtParser.vecCorrelationWithOverlapRemovalTemplate(),
0346                                              gtParser.corMuonTemplate(),
0347                                              gtParser.corCaloTemplate(),
0348                                              gtParser.corEnergySumTemplate());
0349 
0350   m_l1GtMenu->setGtTriggerMenuInterface(gtParser.gtTriggerMenuInterface());
0351   m_l1GtMenu->setGtTriggerMenuImplementation(gtParser.gtTriggerMenuImplementation());
0352   m_l1GtMenu->setGtScaleDbKey(gtParser.gtScaleDbKey());
0353   m_l1GtMenu->setGtScales(gtParser.gtScales());
0354   m_l1GtMenu->setGtTriggerMenuUUID(gtParser.gtTriggerMenuUUID());
0355 
0356   m_l1GtMenu->setGtAlgorithmMap(gtParser.gtAlgorithmMap());
0357   m_l1GtMenu->setGtAlgorithmAliasMap(gtParser.gtAlgorithmAliasMap());
0358 
0359   m_l1GtMenu->buildGtConditionMap();
0360 
0361   int printV = 2;
0362   if (m_printL1Menu)
0363     m_l1GtMenu->print(std::cout, printV);
0364 
0365   // get / update the board maps from the EventSetup
0366   // local cache & check on cacheIdentifier
0367 
0368   /*   *** Drop L1GtBoard Maps for now
0369     typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
0370 
0371     unsigned long long l1GtBMCacheID = evSetup.get<L1GtBoardMapsRcd>().cacheIdentifier();
0372 */
0373 
0374   /*  ** Drop board mapping for now
0375     if (m_l1GtBMCacheID != l1GtBMCacheID) {
0376 
0377         edm::ESHandle< L1GtBoardMaps > l1GtBM;
0378         evSetup.get< L1GtBoardMapsRcd >().get( l1GtBM );
0379         m_l1GtBM = l1GtBM.product();
0380 
0381         m_l1GtBMCacheID = l1GtBMCacheID;
0382 
0383     }
0384    
0385 
0386     // TODO need changes in CondFormats to cache the maps
0387     const std::vector<L1GtBoard>& boardMaps = m_l1GtBM->gtBoardMaps();
0388 */
0389 
0390   // get / update the trigger mask from the EventSetup
0391   // local cache & check on cacheIdentifier
0392 
0393   /*  **** For now Leave out Masks  *****
0394     unsigned long long l1GtTmAlgoCacheID =
0395         evSetup.get<L1GtTriggerMaskAlgoTrigRcd>().cacheIdentifier();
0396 
0397     if (m_l1GtTmAlgoCacheID != l1GtTmAlgoCacheID) {
0398 
0399         edm::ESHandle< L1GtTriggerMask > l1GtTmAlgo;
0400         evSetup.get< L1GtTriggerMaskAlgoTrigRcd >().get( l1GtTmAlgo );
0401         m_l1GtTmAlgo = l1GtTmAlgo.product();
0402 
0403         m_triggerMaskAlgoTrig = m_l1GtTmAlgo->gtTriggerMask();
0404 
0405         m_l1GtTmAlgoCacheID = l1GtTmAlgoCacheID;
0406 
0407     }
0408 */
0409 
0410   /*  **** For now Leave out Veto Masks  *****
0411     unsigned long long l1GtTmVetoAlgoCacheID =
0412         evSetup.get<L1GtTriggerMaskVetoAlgoTrigRcd>().cacheIdentifier();
0413 
0414     if (m_l1GtTmVetoAlgoCacheID != l1GtTmVetoAlgoCacheID) {
0415 
0416         edm::ESHandle< L1GtTriggerMask > l1GtTmVetoAlgo;
0417         evSetup.get< L1GtTriggerMaskVetoAlgoTrigRcd >().get( l1GtTmVetoAlgo );
0418         m_l1GtTmVetoAlgo = l1GtTmVetoAlgo.product();
0419 
0420         m_triggerMaskVetoAlgoTrig = m_l1GtTmVetoAlgo->gtTriggerMask();
0421 
0422         m_l1GtTmVetoAlgoCacheID = l1GtTmVetoAlgoCacheID;
0423 
0424     }
0425 */
0426 
0427   // initialise Trigger Conditions
0428   m_uGtBrd->initTriggerConditions(evSetup, m_l1GtMenu.get(), m_nrL1Mu, m_nrL1MuShower, m_nrL1EG, m_nrL1Tau, m_nrL1Jet);
0429 }
0430 
0431 // method called to produce the data
0432 void L1TGlobalProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSetup) {
0433   if (m_requireMenuToMatchAlgoBlkInput) {
0434     auto const& uGtAlgBlk = iEvent.get(m_algoblkInputToken);
0435     if (uGtAlgBlk.size() >= 1) {
0436       if (uGtAlgBlk[0].getL1FirmwareUUID() != static_cast<int>(m_utml1GtMenu->getFirmwareUuidHashed())) {
0437         throw cms::Exception("ConditionsError")
0438             << " Error L1 menu loaded in via conditions does not match the L1 actually run "
0439             << uGtAlgBlk[0].getL1FirmwareUUID() << " vs " << m_utml1GtMenu->getFirmwareUuidHashed()
0440             << ". This means that the mapping of the names to the bits may be incorrect. Please check the "
0441                "L1TUtmTriggerMenuRcd record supplied. Unless you know what you are doing, do not simply disable this "
0442                "check via the config as this a major error and the indication of something very wrong";
0443       }
0444     }
0445   }
0446 
0447   // get / update the prescale factors from the EventSetup
0448 
0449   // Only get event record if not unprescaled and not unmasked
0450   if (not(m_algorithmTriggersUnprescaled and m_algorithmTriggersUnmasked)) {
0451     auto const& l1GtPrescalesFractVetoes = evSetup.getData(m_l1GtPrescaleVetosToken);
0452     m_l1GtPrescalesVetosFract = PrescalesVetosFractHelper::readFromEventSetup(&l1GtPrescalesFractVetoes);
0453 
0454     m_prescaleFactorsAlgoTrig = &(m_l1GtPrescalesVetosFract->prescaleTable());
0455     m_triggerMaskVetoAlgoTrig = &(m_l1GtPrescalesVetosFract->triggerMaskVeto());
0456 
0457     // get prescale column from unpacked data
0458     if (m_getPrescaleColumnFromData) {
0459       auto const uGtAlgBlk = iEvent.getHandle(m_algoblkInputToken);
0460       if (uGtAlgBlk.isValid() && !uGtAlgBlk->isEmpty(0)) {
0461         m_prescaleSet = static_cast<unsigned int>(uGtAlgBlk->at(0, 0).getPreScColumn());
0462       } else {
0463         m_prescaleSet = 1;
0464         edm::LogError("L1TGlobalProduce") << "Could not find valid algo block. Setting prescale column to 1";
0465       }
0466     }
0467   } else {
0468     // Set Prescale factors to initial dummy values
0469     m_prescaleSet = 0;
0470     m_prescaleFactorsAlgoTrig = &m_initialPrescaleFactorsAlgoTrig;
0471     m_triggerMaskAlgoTrig = &m_initialTriggerMaskAlgoTrig;
0472     m_triggerMaskVetoAlgoTrig = &m_initialTriggerMaskVetoAlgoTrig;
0473   }
0474 
0475   // ******  Board Maps Need to be redone....hard code for now ******
0476   // loop over blocks in the GT DAQ record receiving data, count them if they are active
0477   // all board type are defined in CondFormats/L1TObjects/L1GtFwd
0478   // &
0479   // set the active flag for each object type received from GMT and GCT
0480   // all objects in the GT system
0481 
0482   //
0483   bool receiveMu = true;
0484   bool receiveMuShower = true;
0485   bool receiveEG = true;
0486   bool receiveTau = true;
0487   bool receiveJet = true;
0488   bool receiveEtSums = true;
0489   bool receiveEtSumsZdc = true;
0490   bool receiveCICADA = true;
0491   bool receiveExt = true;
0492 
0493   /*  *** Boards need redefining *****
0494     for (CItBoardMaps
0495             itBoard = boardMaps.begin();
0496             itBoard != boardMaps.end(); ++itBoard) {
0497 
0498         int iPosition = itBoard->gtPositionDaqRecord();
0499         if (iPosition > 0) {
0500 
0501             int iActiveBit = itBoard->gtBitDaqActiveBoards();
0502             bool activeBoard = false;
0503 
0504             if (iActiveBit >= 0) {
0505                 activeBoard = m_activeBoardsGtDaq & (1 << iActiveBit);
0506             }
0507 
0508             // use board if: in the record, but not in ActiveBoardsMap (iActiveBit < 0)
0509             //               in the record and ActiveBoardsMap, and active
0510             if ((iActiveBit < 0) || activeBoard) {
0511 
0512 // ******  Decide what board manipulation (if any we want here)
0513 
0514             }
0515         }
0516 
0517     }
0518 */
0519 
0520   int const minEmulBxInEvent = (m_emulateBxInEvent + 1) / 2 - m_emulateBxInEvent;
0521   int const maxEmulBxInEvent = (m_emulateBxInEvent + 1) / 2 - 1;
0522 
0523   // Produce the Output Records for the GT
0524   std::unique_ptr<GlobalAlgBlkBxCollection> uGtAlgRecord(
0525       new GlobalAlgBlkBxCollection(0, minEmulBxInEvent, maxEmulBxInEvent));
0526 
0527   // * produce the GlobalObjectMapRecord
0528   std::unique_ptr<GlobalObjectMapRecord> gtObjectMapRecord(new GlobalObjectMapRecord());
0529 
0530   std::unique_ptr<AXOL1TLScoreBxCollection> uGtAXOScoreRecord(nullptr);
0531   if (m_produceAXOL1TLScore) {
0532     uGtAXOScoreRecord = std::make_unique<AXOL1TLScoreBxCollection>();
0533   }
0534 
0535   // fill the boards not depending on the BxInEvent in the L1 GT DAQ record
0536   // GMT, PSB and FDL depend on BxInEvent
0537 
0538   // fill in emulator the same bunch crossing (12 bits - hardwired number of bits...)
0539   // and the same local bunch crossing for all boards
0540   int bxCross = iEvent.bunchCrossing();
0541   uint16_t bxCrossHw = 0;
0542   if ((bxCross & 0xFFF) == bxCross) {
0543     bxCrossHw = static_cast<uint16_t>(bxCross);
0544   } else {
0545     bxCrossHw = 0;  // Bx number too large, set to 0!
0546     if (m_verbosity) {
0547       LogDebug("L1TGlobalProducer") << "\nBunch cross number [hex] = " << std::hex << bxCross
0548                                     << "\n  larger than 12 bits. Set to 0! \n"
0549                                     << std::dec << std::endl;
0550     }
0551   }
0552   LogDebug("L1TGlobalProducer") << "HW BxCross " << bxCrossHw << std::endl;
0553 
0554   // get the prescale factor from the configuration for now
0555   // prescale set index counts from zero
0556   unsigned int pfAlgoSetIndex = m_prescaleSet;
0557 
0558   auto max = (*m_prescaleFactorsAlgoTrig).size() - 1;
0559   if (pfAlgoSetIndex > max) {
0560     edm::LogWarning("L1TGlobalProducer") << "\nAttempting to access prescale algo set: " << m_prescaleSet
0561                                          << "\nNumber of prescale algo sets available: 0.." << max
0562                                          << "Setting former to latter." << std::endl;
0563     pfAlgoSetIndex = max;
0564   }
0565 
0566   const std::vector<double>& prescaleFactorsAlgoTrig = (*m_prescaleFactorsAlgoTrig).at(pfAlgoSetIndex);
0567 
0568   // For now, set masks according to prescale value of 0
0569   m_initialTriggerMaskAlgoTrig.clear();
0570   for (unsigned int iAlgo = 0; iAlgo < prescaleFactorsAlgoTrig.size(); iAlgo++) {
0571     unsigned int value = prescaleFactorsAlgoTrig[iAlgo];
0572     value = (value == 0) ? 0 : 1;
0573     m_initialTriggerMaskAlgoTrig.push_back(value);
0574   }
0575   m_triggerMaskAlgoTrig = &m_initialTriggerMaskAlgoTrig;
0576 
0577   const std::vector<unsigned int>& triggerMaskAlgoTrig = *m_triggerMaskAlgoTrig;
0578   const std::vector<int>& triggerMaskVetoAlgoTrig = *m_triggerMaskVetoAlgoTrig;
0579 
0580   LogDebug("L1TGlobalProducer") << "Size of prescale vector" << prescaleFactorsAlgoTrig.size() << std::endl;
0581 
0582   // Load the calorimeter input onto the uGt Board
0583   m_uGtBrd->receiveCaloObjectData(iEvent,
0584                                   m_egInputToken,
0585                                   m_tauInputToken,
0586                                   m_jetInputToken,
0587                                   m_sumInputToken,
0588                                   m_sumZdcInputToken,
0589                                   m_CICADAInputToken,
0590                                   receiveEG,
0591                                   m_nrL1EG,
0592                                   receiveTau,
0593                                   m_nrL1Tau,
0594                                   receiveJet,
0595                                   m_nrL1Jet,
0596                                   receiveEtSums,
0597                                   receiveEtSumsZdc,
0598                                   receiveCICADA);
0599 
0600   m_uGtBrd->receiveMuonObjectData(iEvent, m_muInputToken, receiveMu, m_nrL1Mu);
0601 
0602   if (m_useMuonShowers)
0603     m_uGtBrd->receiveMuonShowerObjectData(iEvent, m_muShowerInputToken, receiveMuShower, m_nrL1MuShower);
0604 
0605   //tell board to save axo scores when running GTL
0606   m_uGtBrd->enableAXOScoreSaving(m_produceAXOL1TLScore);
0607 
0608   m_uGtBrd->receiveExternalData(iEvent, m_extInputToken, receiveExt);
0609 
0610   // loop over BxInEvent
0611   for (int iBxInEvent = minEmulBxInEvent; iBxInEvent <= maxEmulBxInEvent; ++iBxInEvent) {
0612     //  run GTL
0613     LogDebug("L1TGlobalProducer") << "\nL1TGlobalProducer : running GTL  for bx = " << iBxInEvent << "\n" << std::endl;
0614 
0615     //  Run the GTL for this BX
0616     m_uGtBrd->runGTL(iEvent,
0617                      evSetup,
0618                      m_l1GtMenu.get(),
0619                      m_produceL1GtObjectMapRecord,
0620                      iBxInEvent,
0621                      gtObjectMapRecord,
0622                      m_numberPhysTriggers);
0623 
0624     //  run FDL
0625     LogDebug("L1TGlobalProducer") << "\nL1TGlobalProducer : running FDL for bx = " << iBxInEvent << "\n" << std::endl;
0626 
0627     //  Run the Final Decision Logic for this BX
0628     m_uGtBrd->runFDL(iEvent,
0629                      iBxInEvent,
0630                      m_totalBxInEvent,
0631                      m_numberPhysTriggers,
0632                      prescaleFactorsAlgoTrig,
0633                      triggerMaskAlgoTrig,
0634                      triggerMaskVetoAlgoTrig,
0635                      m_algorithmTriggersUnprescaled,
0636                      m_algorithmTriggersUnmasked);
0637 
0638     // Fill in the DAQ Records
0639     if (m_produceL1GtDaqRecord) {
0640       m_uGtBrd->fillAlgRecord(iBxInEvent,
0641                               uGtAlgRecord,
0642                               m_prescaleSet,
0643                               m_l1GtMenu->gtTriggerMenuUUID(),
0644                               m_l1GtMenu->gtTriggerMenuImplementation());
0645     }
0646 
0647     //save scores to score collection
0648     if (m_produceAXOL1TLScore) {
0649       m_uGtBrd->fillAXOScore(iBxInEvent, uGtAXOScoreRecord);
0650     }
0651 
0652   }  //End Loop over Bx
0653 
0654   // Add explicit reset of Board
0655   m_uGtBrd->reset();
0656 
0657   if (m_verbosity && m_isDebugEnabled) {
0658     std::ostringstream myCoutStream;
0659 
0660     for (int bx = minEmulBxInEvent; bx < maxEmulBxInEvent; bx++) {
0661       /// Needs error checking that something exists at this bx.
0662       (uGtAlgRecord->at(bx, 0)).print(myCoutStream);
0663     }
0664 
0665     LogTrace("L1TGlobalProducer") << "\n The following L1 GT DAQ readout record was produced:\n"
0666                                   << myCoutStream.str() << "\n"
0667                                   << std::endl;
0668 
0669     myCoutStream.str("");
0670     myCoutStream.clear();
0671 
0672     const std::vector<GlobalObjectMap> objMapVec = gtObjectMapRecord->gtObjectMap();
0673 
0674     for (std::vector<GlobalObjectMap>::const_iterator it = objMapVec.begin(); it != objMapVec.end(); ++it) {
0675       (*it).print(myCoutStream);
0676     }
0677 
0678     LogDebug("L1TGlobalProducer") << "Test gtObjectMapRecord in L1TGlobalProducer \n\n"
0679                                   << myCoutStream.str() << "\n\n"
0680                                   << std::endl;
0681 
0682     myCoutStream.str("");
0683     myCoutStream.clear();
0684   }
0685 
0686   // register products
0687   if (m_produceL1GtDaqRecord) {
0688     iEvent.put(std::move(uGtAlgRecord));
0689   }
0690 
0691   if (m_produceL1GtObjectMapRecord) {
0692     iEvent.put(std::move(gtObjectMapRecord));
0693   }
0694 
0695   if (m_produceAXOL1TLScore) {
0696     iEvent.put(std::move(uGtAXOScoreRecord), "AXOScore");
0697   }
0698 }
0699 
0700 //define this as a plug-in
0701 #include "FWCore/PluginManager/interface/ModuleDef.h"
0702 #include "FWCore/Framework/interface/MakerMacros.h"
0703 #include <cstdint>
0704 DEFINE_FWK_MODULE(L1TGlobalProducer);