File indexing completed on 2022-12-02 10:36:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include "L1Trigger/L1TGlobal/interface/GlobalBoard.h"
0023
0024
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
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
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
0076 m_l1GtMenuCacheID = 0ULL;
0077 m_l1CaloGeometryCacheID = 0ULL;
0078 m_l1MuTriggerScalesCacheID = 0ULL;
0079
0080
0081 m_boardEventCount = 0;
0082
0083
0084 m_uGtBoardNumber = 0;
0085 m_uGtFinalBoard = true;
0086 }
0087
0088
0089 l1t::GlobalBoard::~GlobalBoard() {
0090
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
0100 }
0101
0102
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
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
0147 }
0148
0149 resetCalo();
0150
0151
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
0160 << "\nrequested in configuration, but not found in the event.\n";
0161 }
0162 } else {
0163
0164 for (int i = egData->getFirstBX(); i <= egData->getLastBX(); ++i) {
0165
0166 if (i < m_bxFirst_ || i > m_bxLast_)
0167 continue;
0168
0169
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 }
0182 }
0183
0184 }
0185
0186 }
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
0196 << "\nrequested in configuration, but not found in the event.\n";
0197 }
0198 } else {
0199
0200 for (int i = tauData->getFirstBX(); i <= tauData->getLastBX(); ++i) {
0201
0202 if (i < m_bxFirst_ || i > m_bxLast_)
0203 continue;
0204
0205
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 }
0219 }
0220
0221 }
0222
0223 }
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
0233 << "\nrequested in configuration, but not found in the event.\n";
0234 }
0235 } else {
0236
0237 for (int i = jetData->getFirstBX(); i <= jetData->getLastBX(); ++i) {
0238
0239 if (i < m_bxFirst_ || i > m_bxLast_)
0240 continue;
0241
0242
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 }
0255 }
0256
0257 }
0258
0259 }
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
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
0274 if (i < m_bxFirst_ || i > m_bxLast_)
0275 continue;
0276
0277
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
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319 }
0320 }
0321 }
0322 }
0323 }
0324
0325
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
0333 }
0334
0335 resetMu();
0336
0337
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
0346 << "\nrequested in configuration, but not found in the event.\n";
0347 }
0348 } else {
0349
0350 for (int i = muonData->getFirstBX(); i <= muonData->getLastBX(); ++i) {
0351
0352 if (i < m_bxFirst_ || i > m_bxLast_)
0353 continue;
0354
0355
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 }
0368 }
0369
0370 }
0371
0372 }
0373 }
0374
0375
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
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
0392 int nObj = 0;
0393 for (auto mu = muonData->begin(0); mu != muonData->end(0); ++mu) {
0394 if (nObj < nrL1MuShower) {
0395
0396
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 }
0418 }
0419 }
0420 }
0421
0422
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
0429 }
0430
0431 resetExternal();
0432
0433
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
0442 << "\nrequested in configuration, but not found in the event.\n";
0443 }
0444 } else {
0445
0446 for (int i = extData->getFirstBX(); i <= extData->getLastBX(); ++i) {
0447
0448 if (i < m_bxFirst_ || i > m_bxLast_)
0449 continue;
0450
0451
0452 for (std::vector<GlobalExtBlk>::const_iterator ext = extData->begin(i); ext != extData->end(i); ++ext) {
0453 (*m_candL1External).push_back(i, &(*ext));
0454 }
0455 }
0456
0457 }
0458
0459 }
0460 }
0461
0462
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
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
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
0500
0501
0502
0503
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
0520 switch ((itCond->second)->condCategory()) {
0521 case CondMuon: {
0522
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
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
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
0559
0560 } break;
0561 case CondCalo: {
0562
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
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
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
0616
0617 } break;
0618 case CondCorrelation: {
0619
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
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
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
0662 } break;
0663 }
0664
0665 CorrCondition* correlationCond = new CorrCondition(itCond->second, cond0Condition, cond1Condition, this);
0666
0667 correlationCond->setVerbosity(m_verbosity);
0668 correlationCond->setScales(>Scales);
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
0681
0682 } break;
0683 case CondCorrelationThreeBody: {
0684
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
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(>Scales);
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
0735 } break;
0736
0737 case CondCorrelationWithOverlapRemoval: {
0738
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
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
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
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
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(>Scales);
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
0821
0822 } break;
0823 case CondNull: {
0824
0825
0826 } break;
0827 default: {
0828
0829
0830 } break;
0831 }
0832 }
0833 }
0834
0835
0836
0837
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
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
0867 if (produceL1GtObjectMapRecord && (iBxInEvent == 0)) {
0868 std::vector<L1TObjectTypeInCond> otypes;
0869 for (auto iop = gtAlg.operandTokenVector().begin(); iop != gtAlg.operandTokenVector().end(); ++iop) {
0870
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
0881
0882 otype = match->second->objectType();
0883
0884 for (auto itype = otype.begin(); itype != otype.end(); itype++) {
0885
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
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
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
0919 if (produceL1GtObjectMapRecord && (iBxInEvent == 0)) {
0920 gtObjectMapRecord->swapGtObjectMap(objMapVec);
0921 }
0922
0923
0924
0925
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
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
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
0966
0967 m_uGtAlgBlk.copyInitialToInterm();
0968
0969
0970
0971
0972 if (!algorithmTriggersUnprescaled) {
0973
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
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
0989 m_uGtAlgBlk.setAlgoDecisionInterm(iBit, false);
0990 }
0991 }
0992 else {
0993 temp_algPrescaledOr = true;
0994 }
0995 }
0996 else if (!alreadyReported) {
0997 alreadyReported = true;
0998 edm::LogWarning("L1TGlobal") << "\nWarning: algoBit >= prescaleFactorsAlgoTrig.size() in bx " << iBxInEvent;
0999 }
1000 }
1001 }
1002
1003 m_algPrescaledOr = temp_algPrescaledOr;
1004
1005 } else {
1006
1007 m_algPrescaledOr = m_algInitialOr;
1008
1009 }
1010
1011
1012
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
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
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 }
1050
1051
1052 m_algFinalOr = (m_algIntermOr & !m_algFinalOrVeto);
1053 }
1054
1055
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
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
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
1092 void l1t::GlobalBoard::resetMu() {
1093 m_candL1Mu->clear();
1094 m_candL1Mu->setBXRange(m_bxFirst_, m_bxLast_);
1095 }
1096
1097
1098 void l1t::GlobalBoard::resetMuonShower() {
1099 m_candL1MuShower->clear();
1100 m_candL1MuShower->setBXRange(m_bxFirst_, m_bxLast_);
1101 }
1102
1103
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
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
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
1141 std::vector<l1t::GlobalBoard::PrescaleCounter> l1t::GlobalBoard::prescaleCountersWithSemirandomInitialCounter(
1142 std::vector<double> const& prescaleFactorsAlgoTrig, edm::Event const& iEvent) {
1143
1144
1145
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
1157
1158
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
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 }