Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-12-02 10:36:18

0001 /**
0002  * \class GlobalBoard
0003  *
0004  *
0005  * Description: Global Trigger Logic board, see header file for details.
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *
0010  * \author: M. Fierro            - HEPHY Vienna - ORCA version
0011  * \author: Vasile Mihai Ghete   - HEPHY Vienna - CMSSW version
0012  * \author: Vladimir Rekovic     - add correlation with overlap removal cases
0013  *                               - fractional prescales
0014  * \author: Elisa Fontanesi      - extended for three-body correlation conditions
0015  *
0016  * $Date$
0017  * $Revision$
0018  *
0019  */
0020 
0021 // this class header
0022 #include "L1Trigger/L1TGlobal/interface/GlobalBoard.h"
0023 
0024 // user include files
0025 #include "DataFormats/L1TGlobal/interface/GlobalObjectMap.h"
0026 #include "L1Trigger/L1TGlobal/interface/TriggerMenu.h"
0027 #include "L1Trigger/L1TGlobal/interface/GlobalAlgorithm.h"
0028 
0029 #include "L1Trigger/L1TGlobal/interface/MuonTemplate.h"
0030 #include "L1Trigger/L1TGlobal/interface/MuonShowerTemplate.h"
0031 #include "L1Trigger/L1TGlobal/interface/CaloTemplate.h"
0032 #include "L1Trigger/L1TGlobal/interface/EnergySumTemplate.h"
0033 #include "L1Trigger/L1TGlobal/interface/ExternalTemplate.h"
0034 #include "L1Trigger/L1TGlobal/interface/CorrelationTemplate.h"
0035 #include "L1Trigger/L1TGlobal/interface/CorrelationThreeBodyTemplate.h"
0036 #include "L1Trigger/L1TGlobal/interface/CorrelationWithOverlapRemovalTemplate.h"
0037 #include "L1Trigger/L1TGlobal/interface/GlobalCondition.h"
0038 #include "L1Trigger/L1TGlobal/interface/CorrCondition.h"
0039 #include "L1Trigger/L1TGlobal/interface/CorrWithOverlapRemovalCondition.h"
0040 
0041 #include "L1Trigger/L1TGlobal/interface/ConditionEvaluation.h"
0042 #include "L1Trigger/L1TGlobal/interface/AlgorithmEvaluation.h"
0043 
0044 // Conditions for uGt
0045 #include "L1Trigger/L1TGlobal/interface/MuCondition.h"
0046 #include "L1Trigger/L1TGlobal/interface/MuonShowerCondition.h"
0047 #include "L1Trigger/L1TGlobal/interface/CaloCondition.h"
0048 #include "L1Trigger/L1TGlobal/interface/EnergySumCondition.h"
0049 #include "L1Trigger/L1TGlobal/interface/ExternalCondition.h"
0050 #include "L1Trigger/L1TGlobal/interface/CorrCondition.h"
0051 #include "L1Trigger/L1TGlobal/interface/CorrThreeBodyCondition.h"
0052 #include "L1Trigger/L1TGlobal/interface/CorrWithOverlapRemovalCondition.h"
0053 
0054 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0055 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0056 
0057 // constructor
0058 l1t::GlobalBoard::GlobalBoard()
0059     : m_candL1Mu(new BXVector<const l1t::Muon*>),
0060       m_candL1MuShower(new BXVector<const l1t::MuonShower*>),
0061       m_candL1EG(new BXVector<const l1t::L1Candidate*>),
0062       m_candL1Tau(new BXVector<const l1t::L1Candidate*>),
0063       m_candL1Jet(new BXVector<const l1t::L1Candidate*>),
0064       m_candL1EtSum(new BXVector<const l1t::EtSum*>),
0065       m_candL1External(new BXVector<const GlobalExtBlk*>),
0066       m_currentLumi(0),
0067       m_isDebugEnabled(edm::isDebugEnabled()) {
0068   m_uGtAlgBlk.reset();
0069 
0070   m_gtlAlgorithmOR.reset();
0071   m_gtlDecisionWord.reset();
0072 
0073   m_prescaleCounterAlgoTrig.clear();
0074 
0075   // initialize cached IDs
0076   m_l1GtMenuCacheID = 0ULL;
0077   m_l1CaloGeometryCacheID = 0ULL;
0078   m_l1MuTriggerScalesCacheID = 0ULL;
0079 
0080   // Counter for number of events board sees
0081   m_boardEventCount = 0;
0082 
0083   // Need to expand use with more than one uGt GlobalBoard for now assume 1
0084   m_uGtBoardNumber = 0;
0085   m_uGtFinalBoard = true;
0086 }
0087 
0088 // destructor
0089 l1t::GlobalBoard::~GlobalBoard() {
0090   //reset();  //why would we need a reset?
0091   delete m_candL1Mu;
0092   delete m_candL1MuShower;
0093   delete m_candL1EG;
0094   delete m_candL1Tau;
0095   delete m_candL1Jet;
0096   delete m_candL1EtSum;
0097   delete m_candL1External;
0098 
0099   //    delete m_gtEtaPhiConversions;
0100 }
0101 
0102 // operations
0103 void l1t::GlobalBoard::setBxFirst(int bx) { m_bxFirst_ = bx; }
0104 
0105 void l1t::GlobalBoard::setBxLast(int bx) { m_bxLast_ = bx; }
0106 
0107 void l1t::GlobalBoard::init(const int numberPhysTriggers,
0108                             const int nrL1Mu,
0109                             const int nrL1MuShower,
0110                             const int nrL1EG,
0111                             const int nrL1Tau,
0112                             const int nrL1Jet,
0113                             int bxFirst,
0114                             int bxLast) {
0115   setBxFirst(bxFirst);
0116   setBxLast(bxLast);
0117 
0118   m_candL1Mu->setBXRange(m_bxFirst_, m_bxLast_);
0119   m_candL1MuShower->setBXRange(m_bxFirst_, m_bxLast_);
0120   m_candL1EG->setBXRange(m_bxFirst_, m_bxLast_);
0121   m_candL1Tau->setBXRange(m_bxFirst_, m_bxLast_);
0122   m_candL1Jet->setBXRange(m_bxFirst_, m_bxLast_);
0123   m_candL1EtSum->setBXRange(m_bxFirst_, m_bxLast_);
0124   m_candL1External->setBXRange(m_bxFirst_, m_bxLast_);
0125 
0126   m_uGtAlgBlk.reset();
0127 
0128   LogDebug("L1TGlobal") << "\t Initializing Board with bxFirst = " << m_bxFirst_ << ", bxLast = " << m_bxLast_;
0129 }
0130 
0131 // receive data from Calorimeter
0132 void l1t::GlobalBoard::receiveCaloObjectData(const edm::Event& iEvent,
0133                                              const edm::EDGetTokenT<BXVector<l1t::EGamma>>& egInputToken,
0134                                              const edm::EDGetTokenT<BXVector<l1t::Tau>>& tauInputToken,
0135                                              const edm::EDGetTokenT<BXVector<l1t::Jet>>& jetInputToken,
0136                                              const edm::EDGetTokenT<BXVector<l1t::EtSum>>& sumInputToken,
0137                                              const bool receiveEG,
0138                                              const int nrL1EG,
0139                                              const bool receiveTau,
0140                                              const int nrL1Tau,
0141                                              const bool receiveJet,
0142                                              const int nrL1Jet,
0143                                              const bool receiveEtSums) {
0144   if (m_verbosity) {
0145     LogDebug("L1TGlobal") << "\n**** Board receiving Calo Data ";
0146     //<<  "\n     from input tag " << caloInputTag << "\n"
0147   }
0148 
0149   resetCalo();
0150 
0151   // get data from Calorimeter
0152   if (receiveEG) {
0153     edm::Handle<BXVector<l1t::EGamma>> egData;
0154     iEvent.getByToken(egInputToken, egData);
0155 
0156     if (!egData.isValid()) {
0157       if (m_verbosity) {
0158         edm::LogWarning("L1TGlobal") << "\nWarning: BXVector<l1t::EGamma> with input tag "
0159                                      //<< caloInputTag
0160                                      << "\nrequested in configuration, but not found in the event.\n";
0161       }
0162     } else {
0163       // bx in EG data
0164       for (int i = egData->getFirstBX(); i <= egData->getLastBX(); ++i) {
0165         // Prevent from pushing back bx that is outside of allowed range
0166         if (i < m_bxFirst_ || i > m_bxLast_)
0167           continue;
0168 
0169         //Loop over EG in this bx
0170         int nObj = 0;
0171         for (std::vector<l1t::EGamma>::const_iterator eg = egData->begin(i); eg != egData->end(i); ++eg) {
0172           if (nObj < nrL1EG) {
0173             (*m_candL1EG).push_back(i, &(*eg));
0174           } else {
0175             edm::LogWarning("L1TGlobal") << " Too many EG (" << nObj << ") for uGT Configuration maxEG =" << nrL1EG;
0176           }
0177           LogDebug("L1TGlobal") << "EG  Pt " << eg->hwPt() << " Eta  " << eg->hwEta() << " Phi " << eg->hwPhi()
0178                                 << "  Qual " << eg->hwQual() << "  Iso " << eg->hwIso();
0179 
0180           nObj++;
0181         }  //end loop over EG in bx
0182       }    //end loop over bx
0183 
0184     }  //end if over valid EG data
0185 
0186   }  //end if ReveiveEG data
0187 
0188   if (receiveTau) {
0189     edm::Handle<BXVector<l1t::Tau>> tauData;
0190     iEvent.getByToken(tauInputToken, tauData);
0191 
0192     if (!tauData.isValid()) {
0193       if (m_verbosity) {
0194         edm::LogWarning("L1TGlobal") << "\nWarning: BXVector<l1t::Tau> with input tag "
0195                                      //<< caloInputTag
0196                                      << "\nrequested in configuration, but not found in the event.\n";
0197       }
0198     } else {
0199       // bx in tau data
0200       for (int i = tauData->getFirstBX(); i <= tauData->getLastBX(); ++i) {
0201         // Prevent from pushing back bx that is outside of allowed range
0202         if (i < m_bxFirst_ || i > m_bxLast_)
0203           continue;
0204 
0205         //Loop over tau in this bx
0206         int nObj = 0;
0207         for (std::vector<l1t::Tau>::const_iterator tau = tauData->begin(i); tau != tauData->end(i); ++tau) {
0208           if (nObj < nrL1Tau) {
0209             (*m_candL1Tau).push_back(i, &(*tau));
0210           } else {
0211             LogTrace("L1TGlobal") << " Too many Tau (" << nObj << ") for uGT Configuration maxTau =" << nrL1Tau;
0212           }
0213 
0214           LogDebug("L1TGlobal") << "tau  Pt " << tau->hwPt() << " Eta  " << tau->hwEta() << " Phi " << tau->hwPhi()
0215                                 << "  Qual " << tau->hwQual() << "  Iso " << tau->hwIso();
0216           nObj++;
0217 
0218         }  //end loop over tau in bx
0219       }    //end loop over bx
0220 
0221     }  //end if over valid tau data
0222 
0223   }  //end if ReveiveTau data
0224 
0225   if (receiveJet) {
0226     edm::Handle<BXVector<l1t::Jet>> jetData;
0227     iEvent.getByToken(jetInputToken, jetData);
0228 
0229     if (!jetData.isValid()) {
0230       if (m_verbosity) {
0231         edm::LogWarning("L1TGlobal") << "\nWarning: BXVector<l1t::Jet> with input tag "
0232                                      //<< caloInputTag
0233                                      << "\nrequested in configuration, but not found in the event.\n";
0234       }
0235     } else {
0236       // bx in jet data
0237       for (int i = jetData->getFirstBX(); i <= jetData->getLastBX(); ++i) {
0238         // Prevent from pushing back bx that is outside of allowed range
0239         if (i < m_bxFirst_ || i > m_bxLast_)
0240           continue;
0241 
0242         //Loop over jet in this bx
0243         int nObj = 0;
0244         for (std::vector<l1t::Jet>::const_iterator jet = jetData->begin(i); jet != jetData->end(i); ++jet) {
0245           if (nObj < nrL1Jet) {
0246             (*m_candL1Jet).push_back(i, &(*jet));
0247           } else {
0248             edm::LogWarning("L1TGlobal") << " Too many Jets (" << nObj << ") for uGT Configuration maxJet =" << nrL1Jet;
0249           }
0250 
0251           LogDebug("L1TGlobal") << "Jet  Pt " << jet->hwPt() << " Eta  " << jet->hwEta() << " Phi " << jet->hwPhi()
0252                                 << "  Qual " << jet->hwQual() << "  Iso " << jet->hwIso();
0253           nObj++;
0254         }  //end loop over jet in bx
0255       }    //end loop over bx
0256 
0257     }  //end if over valid jet data
0258 
0259   }  //end if ReveiveJet data
0260 
0261   if (receiveEtSums) {
0262     edm::Handle<BXVector<l1t::EtSum>> etSumData;
0263     iEvent.getByToken(sumInputToken, etSumData);
0264 
0265     if (!etSumData.isValid()) {
0266       if (m_verbosity) {
0267         edm::LogWarning("L1TGlobal") << "\nWarning: BXVector<l1t::EtSum> with input tag "
0268                                      //<< caloInputTag
0269                                      << "\nrequested in configuration, but not found in the event.\n";
0270       }
0271     } else {
0272       for (int i = etSumData->getFirstBX(); i <= etSumData->getLastBX(); ++i) {
0273         // Prevent from pushing back bx that is outside of allowed range
0274         if (i < m_bxFirst_ || i > m_bxLast_)
0275           continue;
0276 
0277         //Loop over jet in this bx
0278         for (std::vector<l1t::EtSum>::const_iterator etsum = etSumData->begin(i); etsum != etSumData->end(i); ++etsum) {
0279           (*m_candL1EtSum).push_back(i, &(*etsum));
0280 
0281           /*  In case we need to split these out
0282               switch ( etsum->getType() ) {
0283              case l1t::EtSum::EtSumType::kMissingEt:
0284                {
0285              //(*m_candETM).push_back(i,&(*etsum));
0286              LogDebug("L1TGlobal") << "ETM:  Pt " << etsum->hwPt() <<  " Phi " << etsum->hwPhi();
0287                }
0288                break; 
0289              case l1t::EtSum::EtSumType::kMissingHt:
0290                {
0291              //(*m_candHTM).push_back(i,&(*etsum));
0292              LogDebug("L1TGlobal") << "HTM:  Pt " << etsum->hwPt() <<  " Phi " << etsum->hwPhi();
0293                }
0294                break;            
0295              case l1t::EtSum::EtSumType::kTotalEt:
0296                {
0297              //(*m_candETT).push_back(i,&(*etsum));
0298              LogDebug("L1TGlobal") << "ETT:  Pt " << etsum->hwPt();
0299                }
0300                break;            
0301              case l1t::EtSum::EtSumType::kTotalHt:
0302                {
0303              //(*m_candHTT).push_back(i,&(*etsum));
0304              LogDebug("L1TGlobal") << "HTT:  Pt " << etsum->hwPt();
0305                }
0306                break;
0307              case l1t::EtSum::EtSumType::kTowerCount:
0308                {
0309              //(*m_candTowerCount).push_back(i,&(*etsum));
0310              LogDebug("L1TGlobal") << "TowerCount: " << etsum->hwPt();
0311                }
0312                break;
0313              default:
0314                LogDebug("L1TGlobal") << "Default encounted ";
0315                break;
0316           }
0317 */
0318 
0319         }  //end loop over jet in bx
0320       }    //end loop over Bx
0321     }
0322   }
0323 }
0324 
0325 // receive data from Global Muon Trigger
0326 void l1t::GlobalBoard::receiveMuonObjectData(const edm::Event& iEvent,
0327                                              const edm::EDGetTokenT<BXVector<l1t::Muon>>& muInputToken,
0328                                              const bool receiveMu,
0329                                              const int nrL1Mu) {
0330   if (m_verbosity) {
0331     LogDebug("L1TGlobal") << "\n**** GlobalBoard receiving muon data = ";
0332     //<< "\n     from input tag " << muInputTag << "\n"
0333   }
0334 
0335   resetMu();
0336 
0337   // get data from Global Muon Trigger
0338   if (receiveMu) {
0339     edm::Handle<BXVector<l1t::Muon>> muonData;
0340     iEvent.getByToken(muInputToken, muonData);
0341 
0342     if (!muonData.isValid()) {
0343       if (m_verbosity) {
0344         edm::LogWarning("L1TGlobal") << "\nWarning: BXVector<l1t::Muon> with input tag "
0345                                      //<< muInputTag
0346                                      << "\nrequested in configuration, but not found in the event.\n";
0347       }
0348     } else {
0349       // bx in muon data
0350       for (int i = muonData->getFirstBX(); i <= muonData->getLastBX(); ++i) {
0351         // Prevent from pushing back bx that is outside of allowed range
0352         if (i < m_bxFirst_ || i > m_bxLast_)
0353           continue;
0354 
0355         //Loop over Muons in this bx
0356         int nObj = 0;
0357         for (std::vector<l1t::Muon>::const_iterator mu = muonData->begin(i); mu != muonData->end(i); ++mu) {
0358           if (nObj < nrL1Mu) {
0359             (*m_candL1Mu).push_back(i, &(*mu));
0360           } else {
0361             edm::LogWarning("L1TGlobal") << " Too many Muons (" << nObj << ") for uGT Configuration maxMu =" << nrL1Mu;
0362           }
0363 
0364           LogDebug("L1TGlobal") << "Muon  Pt " << mu->hwPt() << " EtaAtVtx  " << mu->hwEtaAtVtx() << " PhiAtVtx "
0365                                 << mu->hwPhiAtVtx() << "  Qual " << mu->hwQual() << "  Iso " << mu->hwIso();
0366           nObj++;
0367         }  //end loop over muons in bx
0368       }    //end loop over bx
0369 
0370     }  //end if over valid muon data
0371 
0372   }  //end if ReveiveMuon data
0373 }
0374 
0375 // receive muon shower data from Global Muon Trigger
0376 void l1t::GlobalBoard::receiveMuonShowerObjectData(const edm::Event& iEvent,
0377                                                    const edm::EDGetTokenT<BXVector<l1t::MuonShower>>& muShowerInputToken,
0378                                                    const bool receiveMuShower,
0379                                                    const int nrL1MuShower) {
0380   // get data from Global Muon Trigger
0381   if (receiveMuShower) {
0382     edm::Handle<BXVector<l1t::MuonShower>> muonData;
0383     iEvent.getByToken(muShowerInputToken, muonData);
0384 
0385     if (!muonData.isValid()) {
0386       if (m_verbosity) {
0387         edm::LogWarning("L1TGlobal") << "\nWarning: BXVector<l1t::MuonShower> with input tag "
0388                                      << "\nrequested in configuration, but not found in the event.\n";
0389       }
0390     } else {
0391       //Loop over Muon Showers in this bx
0392       int nObj = 0;
0393       for (auto mu = muonData->begin(0); mu != muonData->end(0); ++mu) {
0394         if (nObj < nrL1MuShower) {
0395           /* Important here to split up the single object into 4 separate MuonShower
0396              bits for the global board. This is because the UTM library considers those bits separate as well
0397            */
0398           l1t::MuonShower mus0;
0399           l1t::MuonShower mus1;
0400           l1t::MuonShower musOutOfTime0;
0401           l1t::MuonShower musOutOfTime1;
0402 
0403           mus0.setMus0(mu->mus0());
0404           mus1.setMus1(mu->mus1());
0405           musOutOfTime0.setMusOutOfTime0(mu->musOutOfTime0());
0406           musOutOfTime1.setMusOutOfTime1(mu->musOutOfTime1());
0407 
0408           (*m_candL1MuShower).push_back(0, &mus0);
0409           (*m_candL1MuShower).push_back(0, &mus1);
0410           (*m_candL1MuShower).push_back(0, &musOutOfTime0);
0411           (*m_candL1MuShower).push_back(0, &musOutOfTime1);
0412         } else {
0413           edm::LogWarning("L1TGlobal") << " Too many Muon Showers (" << nObj
0414                                        << ") for uGT Configuration maxMuShower =" << nrL1MuShower;
0415         }
0416         nObj++;
0417       }  //end loop over muon showers in bx
0418     }    //end if over valid muon shower data
0419   }      //end if ReveiveMuonShower data
0420 }
0421 
0422 // receive data from Global External Conditions
0423 void l1t::GlobalBoard::receiveExternalData(const edm::Event& iEvent,
0424                                            const edm::EDGetTokenT<BXVector<GlobalExtBlk>>& extInputToken,
0425                                            const bool receiveExt) {
0426   if (m_verbosity) {
0427     LogDebug("L1TGlobal") << "\n**** GlobalBoard receiving external data = ";
0428     //<< "\n     from input tag " << muInputTag << "\n"
0429   }
0430 
0431   resetExternal();
0432 
0433   // get data from Global Muon Trigger
0434   if (receiveExt) {
0435     edm::Handle<BXVector<GlobalExtBlk>> extData;
0436     iEvent.getByToken(extInputToken, extData);
0437 
0438     if (!extData.isValid()) {
0439       if (m_verbosity) {
0440         edm::LogWarning("L1TGlobal") << "\nWarning: BXVector<GlobalExtBlk> with input tag "
0441                                      //<< muInputTag
0442                                      << "\nrequested in configuration, but not found in the event.\n";
0443       }
0444     } else {
0445       // bx in muon data
0446       for (int i = extData->getFirstBX(); i <= extData->getLastBX(); ++i) {
0447         // Prevent from pushing back bx that is outside of allowed range
0448         if (i < m_bxFirst_ || i > m_bxLast_)
0449           continue;
0450 
0451         //Loop over ext in this bx
0452         for (std::vector<GlobalExtBlk>::const_iterator ext = extData->begin(i); ext != extData->end(i); ++ext) {
0453           (*m_candL1External).push_back(i, &(*ext));
0454         }  //end loop over ext in bx
0455       }    //end loop over bx
0456 
0457     }  //end if over valid ext data
0458 
0459   }  //end if ReveiveExt data
0460 }
0461 
0462 // run GTL
0463 void l1t::GlobalBoard::runGTL(const edm::Event&,
0464                               const edm::EventSetup& evSetup,
0465                               const TriggerMenu* m_l1GtMenu,
0466                               const bool produceL1GtObjectMapRecord,
0467                               const int iBxInEvent,
0468                               std::unique_ptr<GlobalObjectMapRecord>& gtObjectMapRecord,
0469                               const unsigned int numberPhysTriggers,
0470                               const int nrL1Mu,
0471                               const int nrL1MuShower,
0472                               const int nrL1EG,
0473                               const int nrL1Tau,
0474                               const int nrL1Jet) {
0475   const std::vector<ConditionMap>& conditionMap = m_l1GtMenu->gtConditionMap();
0476   const AlgorithmMap& algorithmMap = m_l1GtMenu->gtAlgorithmMap();
0477   const GlobalScales& gtScales = m_l1GtMenu->gtScales();
0478   const std::string scaleSetName = gtScales.getScalesName();
0479   LogDebug("L1TGlobal") << " L1 Menu Scales -- Set Name: " << scaleSetName;
0480 
0481   // Reset AlgBlk for this bx
0482   m_uGtAlgBlk.reset();
0483   m_algInitialOr = false;
0484   m_algPrescaledOr = false;
0485   m_algIntermOr = false;
0486   m_algFinalOr = false;
0487   m_algFinalOrVeto = false;
0488 
0489   const std::vector<std::vector<MuonTemplate>>& corrMuon = m_l1GtMenu->corMuonTemplate();
0490 
0491   // Comment out for now
0492   const std::vector<std::vector<CaloTemplate>>& corrCalo = m_l1GtMenu->corCaloTemplate();
0493 
0494   const std::vector<std::vector<EnergySumTemplate>>& corrEnergySum = m_l1GtMenu->corEnergySumTemplate();
0495 
0496   LogDebug("L1TGlobal") << "Size corrMuon " << corrMuon.size() << "\nSize corrCalo " << corrCalo.size()
0497                         << "\nSize corrSums " << corrEnergySum.size();
0498 
0499   // loop over condition maps (one map per condition chip)
0500   // then loop over conditions in the map
0501   // save the results in temporary maps
0502 
0503   // never happens in production but at first event...
0504   if (m_conditionResultMaps.size() != conditionMap.size()) {
0505     m_conditionResultMaps.clear();
0506     m_conditionResultMaps.resize(conditionMap.size());
0507   }
0508 
0509   int iChip = -1;
0510 
0511   for (std::vector<ConditionMap>::const_iterator itCondOnChip = conditionMap.begin();
0512        itCondOnChip != conditionMap.end();
0513        itCondOnChip++) {
0514     iChip++;
0515 
0516     AlgorithmEvaluation::ConditionEvaluationMap& cMapResults = m_conditionResultMaps[iChip];
0517 
0518     for (CItCond itCond = itCondOnChip->begin(); itCond != itCondOnChip->end(); itCond++) {
0519       // evaluate condition
0520       switch ((itCond->second)->condCategory()) {
0521         case CondMuon: {
0522           // BLW Not sure what to do with this for now
0523           const int ifMuEtaNumberBits = 0;
0524 
0525           MuCondition* muCondition = new MuCondition(itCond->second, this, nrL1Mu, ifMuEtaNumberBits);
0526 
0527           muCondition->setVerbosity(m_verbosity);
0528 
0529           muCondition->evaluateConditionStoreResult(iBxInEvent);
0530 
0531           // BLW COmment out for now
0532           cMapResults[itCond->first] = muCondition;
0533 
0534           if (m_verbosity && m_isDebugEnabled) {
0535             std::ostringstream myCout;
0536             muCondition->print(myCout);
0537 
0538             LogTrace("L1TGlobal") << myCout.str();
0539           }
0540           //delete muCondition;
0541 
0542         } break;
0543         case CondMuonShower: {
0544           MuonShowerCondition* muShowerCondition = new MuonShowerCondition(itCond->second, this, nrL1MuShower);
0545 
0546           muShowerCondition->setVerbosity(m_verbosity);
0547 
0548           muShowerCondition->evaluateConditionStoreResult(iBxInEvent);
0549 
0550           cMapResults[itCond->first] = muShowerCondition;
0551 
0552           if (m_verbosity && m_isDebugEnabled) {
0553             std::ostringstream myCout;
0554             muShowerCondition->print(myCout);
0555 
0556             edm::LogWarning("L1TGlobal") << "MuonShowerCondition " << myCout.str();
0557           }
0558           //delete muShowerCondition;
0559 
0560         } break;
0561         case CondCalo: {
0562           // BLW Not sure w hat to do with this for now
0563           const int ifCaloEtaNumberBits = 0;
0564 
0565           CaloCondition* caloCondition =
0566               new CaloCondition(itCond->second, this, nrL1EG, nrL1Jet, nrL1Tau, ifCaloEtaNumberBits);
0567 
0568           caloCondition->setVerbosity(m_verbosity);
0569 
0570           caloCondition->evaluateConditionStoreResult(iBxInEvent);
0571 
0572           cMapResults[itCond->first] = caloCondition;
0573 
0574           if (m_verbosity && m_isDebugEnabled) {
0575             std::ostringstream myCout;
0576             caloCondition->print(myCout);
0577 
0578             LogTrace("L1TGlobal") << myCout.str();
0579           }
0580           //                    delete caloCondition;
0581 
0582         } break;
0583         case CondEnergySum: {
0584           EnergySumCondition* eSumCondition = new EnergySumCondition(itCond->second, this);
0585 
0586           eSumCondition->setVerbosity(m_verbosity);
0587           eSumCondition->evaluateConditionStoreResult(iBxInEvent);
0588 
0589           cMapResults[itCond->first] = eSumCondition;
0590 
0591           if (m_verbosity && m_isDebugEnabled) {
0592             std::ostringstream myCout;
0593             eSumCondition->print(myCout);
0594 
0595             LogTrace("L1TGlobal") << myCout.str();
0596           }
0597           //                    delete eSumCondition;
0598 
0599         } break;
0600 
0601         case CondExternal: {
0602           ExternalCondition* extCondition = new ExternalCondition(itCond->second, this);
0603 
0604           extCondition->setVerbosity(m_verbosity);
0605           extCondition->evaluateConditionStoreResult(iBxInEvent);
0606 
0607           cMapResults[itCond->first] = extCondition;
0608 
0609           if (m_verbosity && m_isDebugEnabled) {
0610             std::ostringstream myCout;
0611             extCondition->print(myCout);
0612 
0613             LogTrace("L1TGlobal") << myCout.str();
0614           }
0615           //                    delete extCondition;
0616 
0617         } break;
0618         case CondCorrelation: {
0619           // get first the sub-conditions
0620           const CorrelationTemplate* corrTemplate = static_cast<const CorrelationTemplate*>(itCond->second);
0621           const GtConditionCategory cond0Categ = corrTemplate->cond0Category();
0622           const GtConditionCategory cond1Categ = corrTemplate->cond1Category();
0623           const int cond0Ind = corrTemplate->cond0Index();
0624           const int cond1Ind = corrTemplate->cond1Index();
0625 
0626           const GlobalCondition* cond0Condition = nullptr;
0627           const GlobalCondition* cond1Condition = nullptr;
0628 
0629           // maximum number of objects received for evaluation of l1t::Type1s condition
0630           int cond0NrL1Objects = 0;
0631           int cond1NrL1Objects = 0;
0632           LogDebug("L1TGlobal") << " cond0NrL1Objects" << cond0NrL1Objects << "  cond1NrL1Objects  "
0633                                 << cond1NrL1Objects;
0634 
0635           switch (cond0Categ) {
0636             case CondMuon: {
0637               cond0Condition = &((corrMuon[iChip])[cond0Ind]);
0638             } break;
0639             case CondCalo: {
0640               cond0Condition = &((corrCalo[iChip])[cond0Ind]);
0641             } break;
0642             case CondEnergySum: {
0643               cond0Condition = &((corrEnergySum[iChip])[cond0Ind]);
0644             } break;
0645             default: {
0646               // do nothing, should not arrive here
0647             } break;
0648           }
0649 
0650           switch (cond1Categ) {
0651             case CondMuon: {
0652               cond1Condition = &((corrMuon[iChip])[cond1Ind]);
0653             } break;
0654             case CondCalo: {
0655               cond1Condition = &((corrCalo[iChip])[cond1Ind]);
0656             } break;
0657             case CondEnergySum: {
0658               cond1Condition = &((corrEnergySum[iChip])[cond1Ind]);
0659             } break;
0660             default: {
0661               // do nothing, should not arrive here
0662             } break;
0663           }
0664 
0665           CorrCondition* correlationCond = new CorrCondition(itCond->second, cond0Condition, cond1Condition, this);
0666 
0667           correlationCond->setVerbosity(m_verbosity);
0668           correlationCond->setScales(&gtScales);
0669           correlationCond->evaluateConditionStoreResult(iBxInEvent);
0670 
0671           cMapResults[itCond->first] = correlationCond;
0672 
0673           if (m_verbosity && m_isDebugEnabled) {
0674             std::ostringstream myCout;
0675             correlationCond->print(myCout);
0676 
0677             LogTrace("L1TGlobal") << myCout.str();
0678           }
0679 
0680           //        delete correlationCond;
0681 
0682         } break;
0683         case CondCorrelationThreeBody: {
0684           // get first the sub-conditions
0685           const CorrelationThreeBodyTemplate* corrTemplate =
0686               static_cast<const CorrelationThreeBodyTemplate*>(itCond->second);
0687           const GtConditionCategory cond0Categ = corrTemplate->cond0Category();
0688           const GtConditionCategory cond1Categ = corrTemplate->cond1Category();
0689           const GtConditionCategory cond2Categ = corrTemplate->cond2Category();
0690           const int cond0Ind = corrTemplate->cond0Index();
0691           const int cond1Ind = corrTemplate->cond1Index();
0692           const int cond2Ind = corrTemplate->cond2Index();
0693 
0694           const GlobalCondition* cond0Condition = nullptr;
0695           const GlobalCondition* cond1Condition = nullptr;
0696           const GlobalCondition* cond2Condition = nullptr;
0697 
0698           // maximum number of objects received for evaluation of l1t::Type1s condition
0699           int cond0NrL1Objects = 0;
0700           int cond1NrL1Objects = 0;
0701           int cond2NrL1Objects = 0;
0702           LogDebug("L1TGlobal") << "  cond0NrL1Objects  " << cond0NrL1Objects << "  cond1NrL1Objects  "
0703                                 << cond1NrL1Objects << "  cond2NrL1Objects  " << cond2NrL1Objects;
0704           if (cond0Categ == CondMuon) {
0705             cond0Condition = &((corrMuon[iChip])[cond0Ind]);
0706           } else {
0707             LogDebug("L1TGlobal") << "No muon0 to evaluate three-body correlation condition";
0708           }
0709           if (cond1Categ == CondMuon) {
0710             cond1Condition = &((corrMuon[iChip])[cond1Ind]);
0711           } else {
0712             LogDebug("L1TGlobal") << "No muon1 to evaluate three-body correlation condition";
0713           }
0714           if (cond2Categ == CondMuon) {
0715             cond2Condition = &((corrMuon[iChip])[cond2Ind]);
0716           } else {
0717             LogDebug("L1TGlobal") << "No muon2 to evaluate three-body correlation condition";
0718           }
0719 
0720           CorrThreeBodyCondition* correlationThreeBodyCond =
0721               new CorrThreeBodyCondition(itCond->second, cond0Condition, cond1Condition, cond2Condition, this);
0722 
0723           correlationThreeBodyCond->setVerbosity(m_verbosity);
0724           correlationThreeBodyCond->setScales(&gtScales);
0725           correlationThreeBodyCond->evaluateConditionStoreResult(iBxInEvent);
0726           cMapResults[itCond->first] = correlationThreeBodyCond;
0727 
0728           if (m_verbosity && m_isDebugEnabled) {
0729             std::ostringstream myCout;
0730             correlationThreeBodyCond->print(myCout);
0731 
0732             LogTrace("L1TGlobal") << myCout.str();
0733           }
0734           //              delete correlationThreeBodyCond;
0735         } break;
0736 
0737         case CondCorrelationWithOverlapRemoval: {
0738           // get first the sub-conditions
0739           const CorrelationWithOverlapRemovalTemplate* corrTemplate =
0740               static_cast<const CorrelationWithOverlapRemovalTemplate*>(itCond->second);
0741           const GtConditionCategory cond0Categ = corrTemplate->cond0Category();
0742           const GtConditionCategory cond1Categ = corrTemplate->cond1Category();
0743           const GtConditionCategory cond2Categ = corrTemplate->cond2Category();
0744           const int cond0Ind = corrTemplate->cond0Index();
0745           const int cond1Ind = corrTemplate->cond1Index();
0746           const int cond2Ind = corrTemplate->cond2Index();
0747 
0748           const GlobalCondition* cond0Condition = nullptr;
0749           const GlobalCondition* cond1Condition = nullptr;
0750           const GlobalCondition* cond2Condition = nullptr;
0751 
0752           // maximum number of objects received for evaluation of l1t::Type1s condition
0753           int cond0NrL1Objects = 0;
0754           int cond1NrL1Objects = 0;
0755           int cond2NrL1Objects = 0;
0756           LogDebug("L1TGlobal") << " cond0NrL1Objects" << cond0NrL1Objects << "  cond1NrL1Objects  " << cond1NrL1Objects
0757                                 << "  cond2NrL1Objects  " << cond2NrL1Objects;
0758 
0759           switch (cond0Categ) {
0760             case CondMuon: {
0761               cond0Condition = &((corrMuon[iChip])[cond0Ind]);
0762             } break;
0763             case CondCalo: {
0764               cond0Condition = &((corrCalo[iChip])[cond0Ind]);
0765             } break;
0766             case CondEnergySum: {
0767               cond0Condition = &((corrEnergySum[iChip])[cond0Ind]);
0768             } break;
0769             default: {
0770               // do nothing, should not arrive here
0771             } break;
0772           }
0773 
0774           switch (cond1Categ) {
0775             case CondMuon: {
0776               cond1Condition = &((corrMuon[iChip])[cond1Ind]);
0777             } break;
0778             case CondCalo: {
0779               cond1Condition = &((corrCalo[iChip])[cond1Ind]);
0780             } break;
0781             case CondEnergySum: {
0782               cond1Condition = &((corrEnergySum[iChip])[cond1Ind]);
0783             } break;
0784             default: {
0785               // do nothing, should not arrive here
0786             } break;
0787           }
0788 
0789           switch (cond2Categ) {
0790             case CondMuon: {
0791               cond2Condition = &((corrMuon[iChip])[cond2Ind]);
0792             } break;
0793             case CondCalo: {
0794               cond2Condition = &((corrCalo[iChip])[cond2Ind]);
0795             } break;
0796             case CondEnergySum: {
0797               cond2Condition = &((corrEnergySum[iChip])[cond2Ind]);
0798             } break;
0799             default: {
0800               // do nothing, should not arrive here
0801             } break;
0802           }
0803 
0804           CorrWithOverlapRemovalCondition* correlationCondWOR =
0805               new CorrWithOverlapRemovalCondition(itCond->second, cond0Condition, cond1Condition, cond2Condition, this);
0806 
0807           correlationCondWOR->setVerbosity(m_verbosity);
0808           correlationCondWOR->setScales(&gtScales);
0809           correlationCondWOR->evaluateConditionStoreResult(iBxInEvent);
0810 
0811           cMapResults[itCond->first] = correlationCondWOR;
0812 
0813           if (m_verbosity && m_isDebugEnabled) {
0814             std::ostringstream myCout;
0815             correlationCondWOR->print(myCout);
0816 
0817             LogTrace("L1TGlobal") << myCout.str();
0818           }
0819 
0820           //        delete correlationCondWOR;
0821 
0822         } break;
0823         case CondNull: {
0824           // do nothing
0825 
0826         } break;
0827         default: {
0828           // do nothing
0829 
0830         } break;
0831       }
0832     }
0833   }
0834 
0835   // loop over algorithm map
0836   /// DMP Start debugging here
0837   // empty vector for object maps - filled during loop
0838   std::vector<GlobalObjectMap> objMapVec;
0839   if (produceL1GtObjectMapRecord && (iBxInEvent == 0))
0840     objMapVec.reserve(numberPhysTriggers);
0841 
0842   for (CItAlgo itAlgo = algorithmMap.begin(); itAlgo != algorithmMap.end(); itAlgo++) {
0843     AlgorithmEvaluation gtAlg(itAlgo->second);
0844     gtAlg.evaluateAlgorithm((itAlgo->second).algoChipNumber(), m_conditionResultMaps);
0845 
0846     int algBitNumber = (itAlgo->second).algoBitNumber();
0847     bool algResult = gtAlg.gtAlgoResult();
0848 
0849     LogDebug("L1TGlobal") << " ===> for iBxInEvent = " << iBxInEvent << ":\t algBitName = " << itAlgo->first
0850                           << ",\t algBitNumber = " << algBitNumber << ",\t algResult = " << algResult;
0851 
0852     if (algResult) {
0853       //            m_gtlAlgorithmOR.set(algBitNumber);
0854       m_uGtAlgBlk.setAlgoDecisionInitial(algBitNumber, algResult);
0855       m_algInitialOr = true;
0856     }
0857 
0858     if (m_verbosity && m_isDebugEnabled) {
0859       std::ostringstream myCout;
0860       (itAlgo->second).print(myCout);
0861       gtAlg.print(myCout);
0862 
0863       LogTrace("L1TGlobal") << myCout.str();
0864     }
0865 
0866     // object maps only for BxInEvent = 0
0867     if (produceL1GtObjectMapRecord && (iBxInEvent == 0)) {
0868       std::vector<L1TObjectTypeInCond> otypes;
0869       for (auto iop = gtAlg.operandTokenVector().begin(); iop != gtAlg.operandTokenVector().end(); ++iop) {
0870         //cout << "INFO:  operand name:  " << iop->tokenName << "\n";
0871         int myChip = -1;
0872         int found = 0;
0873         L1TObjectTypeInCond otype;
0874         for (auto imap = conditionMap.begin(); imap != conditionMap.end(); imap++) {
0875           myChip++;
0876           auto match = imap->find(iop->tokenName);
0877 
0878           if (match != imap->end()) {
0879             found = 1;
0880             //cout << "DEBUG: found match for " << iop->tokenName << " at " << match->first << "\n";
0881 
0882             otype = match->second->objectType();
0883 
0884             for (auto itype = otype.begin(); itype != otype.end(); itype++) {
0885               //cout << "type:  " << *itype << "\n";
0886             }
0887           }
0888         }
0889         if (!found) {
0890           edm::LogWarning("L1TGlobal") << "\n Failed to find match for operand token " << iop->tokenName << "\n";
0891         } else {
0892           otypes.push_back(otype);
0893         }
0894       }
0895 
0896       // set object map
0897       GlobalObjectMap objMap;
0898 
0899       objMap.setAlgoName(itAlgo->first);
0900       objMap.setAlgoBitNumber(algBitNumber);
0901       objMap.setAlgoGtlResult(algResult);
0902       objMap.swapOperandTokenVector(gtAlg.operandTokenVector());
0903       objMap.swapCombinationVector(gtAlg.gtAlgoCombinationVector());
0904       // gtAlg is empty now...
0905       objMap.swapObjectTypeVector(otypes);
0906 
0907       if (m_verbosity && m_isDebugEnabled) {
0908         std::ostringstream myCout1;
0909         objMap.print(myCout1);
0910 
0911         LogTrace("L1TGlobal") << myCout1.str();
0912       }
0913 
0914       objMapVec.push_back(objMap);
0915     }
0916   }
0917 
0918   // object maps only for BxInEvent = 0
0919   if (produceL1GtObjectMapRecord && (iBxInEvent == 0)) {
0920     gtObjectMapRecord->swapGtObjectMap(objMapVec);
0921   }
0922 
0923   // loop over condition maps (one map per condition chip)
0924   // then loop over conditions in the map
0925   // delete the conditions created with new, zero pointer, do not clear map, keep the vector as is...
0926   for (std::vector<AlgorithmEvaluation::ConditionEvaluationMap>::iterator itCondOnChip = m_conditionResultMaps.begin();
0927        itCondOnChip != m_conditionResultMaps.end();
0928        itCondOnChip++) {
0929     for (AlgorithmEvaluation::ItEvalMap itCond = itCondOnChip->begin(); itCond != itCondOnChip->end(); itCond++) {
0930       delete itCond->second;
0931       itCond->second = nullptr;
0932     }
0933   }
0934 }
0935 
0936 // run GTL
0937 void l1t::GlobalBoard::runFDL(const edm::Event& iEvent,
0938                               const int iBxInEvent,
0939                               const int totalBxInEvent,
0940                               const unsigned int numberPhysTriggers,
0941                               const std::vector<double>& prescaleFactorsAlgoTrig,
0942                               const std::vector<unsigned int>& triggerMaskAlgoTrig,
0943                               const std::vector<int>& triggerMaskVetoAlgoTrig,
0944                               const bool algorithmTriggersUnprescaled,
0945                               const bool algorithmTriggersUnmasked) {
0946   if (m_verbosity) {
0947     LogDebug("L1TGlobal") << "\n**** GlobalBoard apply Final Decision Logic ";
0948   }
0949 
0950   // update and clear prescales at the beginning of the luminosity segment
0951   if (m_prescaleCounterAlgoTrig.empty() or
0952       (m_currentLumi != iEvent.luminosityBlock() and m_resetPSCountersEachLumiSec)) {
0953     m_prescaleCounterAlgoTrig.clear();
0954     m_prescaleCounterAlgoTrig.reserve(totalBxInEvent);
0955     auto const& prescaleCountersAlgoTrig =
0956         m_semiRandomInitialPSCounters ? prescaleCountersWithSemirandomInitialCounter(prescaleFactorsAlgoTrig, iEvent)
0957                                       : prescaleCounters(prescaleFactorsAlgoTrig);
0958     for (int iBxInEvent = 0; iBxInEvent < totalBxInEvent; ++iBxInEvent) {
0959       m_prescaleCounterAlgoTrig.push_back(prescaleCountersAlgoTrig);
0960     }
0961 
0962     m_currentLumi = iEvent.luminosityBlock();
0963   }
0964 
0965   // Copy Algorithm bits to Prescaled word
0966   // Prescaling and Masking done below if requested.
0967   m_uGtAlgBlk.copyInitialToInterm();
0968 
0969   // -------------------------------------------
0970   //      Apply Prescales or skip if turned off
0971   // -------------------------------------------
0972   if (!algorithmTriggersUnprescaled) {
0973     // iBxInEvent is ... -2 -1 0 1 2 ... while counters are 0 1 2 3 4 ...
0974     int const inBxInEvent = totalBxInEvent / 2 + iBxInEvent;
0975 
0976     bool temp_algPrescaledOr = false;
0977     bool alreadyReported = false;
0978     for (unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
0979       bool const bitValue = m_uGtAlgBlk.getAlgoDecisionInitial(iBit);
0980       if (bitValue) {
0981         // Make sure algo bit in range, warn otherwise
0982         if (iBit < prescaleFactorsAlgoTrig.size()) {
0983           if (prescaleFactorsAlgoTrig.at(iBit) != 1) {
0984             bool const triggered = m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit).accept();
0985             if (triggered) {
0986               temp_algPrescaledOr = true;
0987             } else {
0988               // change bit to false in prescaled word and final decision word
0989               m_uGtAlgBlk.setAlgoDecisionInterm(iBit, false);
0990             }  //if Prescale counter reached zero
0991           }    //if prescale factor is not 1 (ie. no prescale)
0992           else {
0993             temp_algPrescaledOr = true;
0994           }
0995         }  // require bit in range
0996         else if (!alreadyReported) {
0997           alreadyReported = true;
0998           edm::LogWarning("L1TGlobal") << "\nWarning: algoBit >= prescaleFactorsAlgoTrig.size() in bx " << iBxInEvent;
0999         }
1000       }  //if algo bit is set true
1001     }    //loop over alg bits
1002 
1003     m_algPrescaledOr = temp_algPrescaledOr;  //temp
1004 
1005   } else {
1006     // Since not Prescaling just take OR of Initial Work
1007     m_algPrescaledOr = m_algInitialOr;
1008 
1009   }  //if we are going to apply prescales.
1010 
1011   // Copy Algorithm bits fron Prescaled word to Final Word
1012   // Masking done below if requested.
1013   m_uGtAlgBlk.copyIntermToFinal();
1014 
1015   if (!algorithmTriggersUnmasked) {
1016     bool temp_algFinalOr = false;
1017     bool alreadyReported = false;
1018     for (unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
1019       const bool bitValue = m_uGtAlgBlk.getAlgoDecisionInterm(iBit);
1020 
1021       if (bitValue) {
1022         //bool isMasked = ( triggerMaskAlgoTrig.at(iBit) == 0 );
1023         bool isMasked = false;
1024         if (iBit < triggerMaskAlgoTrig.size())
1025           isMasked = (triggerMaskAlgoTrig.at(iBit) == 0);
1026         else if (!alreadyReported) {
1027           alreadyReported = true;
1028           edm::LogWarning("L1TGlobal") << "\nWarning: algoBit >= triggerMaskAlgoTrig.size() in bx " << iBxInEvent;
1029         }
1030 
1031         bool const passMask = (bitValue && !isMasked);
1032 
1033         if (passMask)
1034           temp_algFinalOr = true;
1035         else
1036           m_uGtAlgBlk.setAlgoDecisionFinal(iBit, false);
1037 
1038         // Check if veto mask is true, if it is, set the event veto flag.
1039         if (triggerMaskVetoAlgoTrig.at(iBit) == 1)
1040           m_algFinalOrVeto = true;
1041       }
1042     }
1043 
1044     m_algIntermOr = temp_algFinalOr;
1045 
1046   } else {
1047     m_algIntermOr = m_algPrescaledOr;
1048 
1049   }  ///if we are masking.
1050 
1051   // Set FinalOR for this board
1052   m_algFinalOr = (m_algIntermOr & !m_algFinalOrVeto);
1053 }
1054 
1055 // Fill DAQ Record
1056 void l1t::GlobalBoard::fillAlgRecord(int iBxInEvent,
1057                                      std::unique_ptr<GlobalAlgBlkBxCollection>& uGtAlgRecord,
1058                                      int prescaleSet,
1059                                      int menuUUID,
1060                                      int firmwareUUID) {
1061   if (m_verbosity) {
1062     LogDebug("L1TGlobal") << "\n**** GlobalBoard fill DAQ Records for bx= " << iBxInEvent;
1063   }
1064 
1065   // Set header information
1066   m_uGtAlgBlk.setbxInEventNr((iBxInEvent & 0xF));
1067   m_uGtAlgBlk.setPreScColumn(prescaleSet);
1068   m_uGtAlgBlk.setL1MenuUUID(menuUUID);
1069   m_uGtAlgBlk.setL1FirmwareUUID(firmwareUUID);
1070 
1071   m_uGtAlgBlk.setFinalORVeto(m_algFinalOrVeto);
1072   m_uGtAlgBlk.setFinalORPreVeto(m_algIntermOr);
1073   m_uGtAlgBlk.setFinalOR(m_algFinalOr);
1074 
1075   uGtAlgRecord->push_back(iBxInEvent, m_uGtAlgBlk);
1076 }
1077 
1078 // clear GTL
1079 void l1t::GlobalBoard::reset() {
1080   resetMu();
1081   resetMuonShower();
1082   resetCalo();
1083   resetExternal();
1084 
1085   m_uGtAlgBlk.reset();
1086 
1087   m_gtlDecisionWord.reset();
1088   m_gtlAlgorithmOR.reset();
1089 }
1090 
1091 // clear muon
1092 void l1t::GlobalBoard::resetMu() {
1093   m_candL1Mu->clear();
1094   m_candL1Mu->setBXRange(m_bxFirst_, m_bxLast_);
1095 }
1096 
1097 // clear muon shower
1098 void l1t::GlobalBoard::resetMuonShower() {
1099   m_candL1MuShower->clear();
1100   m_candL1MuShower->setBXRange(m_bxFirst_, m_bxLast_);
1101 }
1102 
1103 // clear calo
1104 void l1t::GlobalBoard::resetCalo() {
1105   m_candL1EG->clear();
1106   m_candL1Tau->clear();
1107   m_candL1Jet->clear();
1108   m_candL1EtSum->clear();
1109 
1110   m_candL1EG->setBXRange(m_bxFirst_, m_bxLast_);
1111   m_candL1Tau->setBXRange(m_bxFirst_, m_bxLast_);
1112   m_candL1Jet->setBXRange(m_bxFirst_, m_bxLast_);
1113   m_candL1EtSum->setBXRange(m_bxFirst_, m_bxLast_);
1114 }
1115 
1116 void l1t::GlobalBoard::resetExternal() {
1117   m_candL1External->clear();
1118   m_candL1External->setBXRange(m_bxFirst_, m_bxLast_);
1119 }
1120 
1121 // print Global Muon Trigger data received
1122 void l1t::GlobalBoard::printGmtData(const int iBxInEvent) const {
1123   LogTrace("L1TGlobal") << "\nl1t::L1GlobalTrigger: uGMT data received for BxInEvent = " << iBxInEvent;
1124 
1125   int nrL1Mu = m_candL1Mu->size(iBxInEvent);
1126   LogTrace("L1TGlobal") << "Number of GMT muons = " << nrL1Mu << "\n";
1127 }
1128 
1129 // initialize prescale counters to zero
1130 std::vector<l1t::GlobalBoard::PrescaleCounter> l1t::GlobalBoard::prescaleCounters(
1131     std::vector<double> const& prescaleFactorsAlgoTrig) {
1132   std::vector<PrescaleCounter> out;
1133   out.reserve(prescaleFactorsAlgoTrig.size());
1134   for (size_t iAlgo = 0; iAlgo < prescaleFactorsAlgoTrig.size(); ++iAlgo) {
1135     out.emplace_back(prescaleFactorsAlgoTrig[iAlgo]);
1136   }
1137   return out;
1138 }
1139 
1140 // initialises prescale counters with a semi-random value in the range [0, prescale*10^precision - 1]
1141 std::vector<l1t::GlobalBoard::PrescaleCounter> l1t::GlobalBoard::prescaleCountersWithSemirandomInitialCounter(
1142     std::vector<double> const& prescaleFactorsAlgoTrig, edm::Event const& iEvent) {
1143   // pick a (semi)random number seeding based on run, lumi, event numbers,
1144   // this leads to different (semi)random numbers for different streams,
1145   // reminder: different streams have different initial event number
1146   std::srand(iEvent.id().run());
1147   std::srand(std::rand() + iEvent.id().luminosityBlock());
1148   std::srand(std::rand() + iEvent.id().event());
1149   int const semirandom = std::rand();
1150 
1151   std::vector<PrescaleCounter> out;
1152   out.reserve(prescaleFactorsAlgoTrig.size());
1153 
1154   for (size_t iAlgo = 0; iAlgo < prescaleFactorsAlgoTrig.size(); ++iAlgo) {
1155     out.emplace_back(prescaleFactorsAlgoTrig[iAlgo]);
1156     // initialise trigger_counter to a (semi)random integer
1157     // between 0 and prescale_count - 1 (both inclusive)
1158     // (this only changes the behaviour of triggers with PS > 1)
1159     auto& prescaleCounter = out.back();
1160     if (prescaleCounter.prescale_count > 0) {
1161       prescaleCounter.trigger_counter = semirandom % prescaleCounter.prescale_count;
1162     }
1163   }
1164 
1165   return out;
1166 }
1167 
1168 // return decision of PrescalCounter, and update its internal counter
1169 bool l1t::GlobalBoard::PrescaleCounter::accept() {
1170   trigger_counter += m_singlestep;
1171 
1172   if (prescale_count == 0 or trigger_counter < prescale_count)
1173     return false;
1174 
1175   trigger_counter -= prescale_count;
1176 
1177   return true;
1178 }