Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-26 03:56:09

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