25 #include <ext/hash_map>
72 m_firstEvLumiSegment(
true),
100 delete m_candL1EtSum;
101 delete m_candL1External;
121 m_candL1Mu->setBXRange(m_bxFirst_, m_bxLast_);
122 m_candL1EG->setBXRange(m_bxFirst_, m_bxLast_);
123 m_candL1Tau->setBXRange(m_bxFirst_, m_bxLast_);
124 m_candL1Jet->setBXRange(m_bxFirst_, m_bxLast_);
125 m_candL1EtSum->setBXRange(m_bxFirst_, m_bxLast_);
126 m_candL1External->setBXRange(m_bxFirst_, m_bxLast_);
130 LogDebug(
"L1TGlobal") <<
"\t Initializing Board with bxFirst = " << m_bxFirst_ <<
", bxLast = " << m_bxLast_
140 const bool receiveEG,
142 const bool receiveTau,
144 const bool receiveJet,
146 const bool receiveEtSums) {
148 LogDebug(
"L1TGlobal") <<
"\n**** Board receiving Calo Data "
158 iEvent.getByToken(egInputToken, egData);
162 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::EGamma> with input tag "
164 <<
"\nrequested in configuration, but not found in the event.\n"
169 for (
int i = egData->getFirstBX();
i <= egData->getLastBX(); ++
i) {
171 if (i < m_bxFirst_ || i > m_bxLast_)
176 for (std::vector<l1t::EGamma>::const_iterator eg = egData->begin(
i); eg != egData->end(
i); ++eg) {
178 (*m_candL1EG).push_back(
i, &(*eg));
180 edm::LogWarning(
"L1TGlobal") <<
" Too many EG (" << nObj <<
") for uGT Configuration maxEG =" << nrL1EG
183 LogDebug(
"L1TGlobal") <<
"EG Pt " << eg->hwPt() <<
" Eta " << eg->hwEta() <<
" Phi " << eg->hwPhi()
184 <<
" Qual " << eg->hwQual() <<
" Iso " << eg->hwIso() << std::endl;
196 iEvent.getByToken(tauInputToken, tauData);
200 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::Tau> with input tag "
202 <<
"\nrequested in configuration, but not found in the event.\n"
207 for (
int i = tauData->getFirstBX();
i <= tauData->getLastBX(); ++
i) {
209 if (i < m_bxFirst_ || i > m_bxLast_)
214 for (std::vector<l1t::Tau>::const_iterator
tau = tauData->begin(
i);
tau != tauData->end(
i); ++
tau) {
215 if (nObj < nrL1Tau) {
216 (*m_candL1Tau).push_back(
i, &(*
tau));
218 LogTrace(
"L1TGlobal") <<
" Too many Tau (" << nObj <<
") for uGT Configuration maxTau =" << nrL1Tau
222 LogDebug(
"L1TGlobal") <<
"tau Pt " <<
tau->hwPt() <<
" Eta " <<
tau->hwEta() <<
" Phi " <<
tau->hwPhi()
223 <<
" Qual " <<
tau->hwQual() <<
" Iso " <<
tau->hwIso() << std::endl;
239 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::Jet> with input tag "
241 <<
"\nrequested in configuration, but not found in the event.\n"
248 if (i < m_bxFirst_ || i > m_bxLast_)
254 if (nObj < nrL1Jet) {
255 (*m_candL1Jet).push_back(
i, &(*
jet));
257 edm::LogWarning(
"L1TGlobal") <<
" Too many Jets (" << nObj <<
") for uGT Configuration maxJet =" << nrL1Jet
261 LogDebug(
"L1TGlobal") <<
"Jet Pt " <<
jet->hwPt() <<
" Eta " <<
jet->hwEta() <<
" Phi " <<
jet->hwPhi()
262 <<
" Qual " <<
jet->hwQual() <<
" Iso " <<
jet->hwIso() << std::endl;
273 iEvent.getByToken(sumInputToken, etSumData);
277 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::EtSum> with input tag "
279 <<
"\nrequested in configuration, but not found in the event.\n"
283 for (
int i = etSumData->getFirstBX();
i <= etSumData->getLastBX(); ++
i) {
285 if (i < m_bxFirst_ || i > m_bxLast_)
289 for (std::vector<l1t::EtSum>::const_iterator etsum = etSumData->begin(
i); etsum != etSumData->end(
i); ++etsum) {
290 (*m_candL1EtSum).push_back(
i, &(*etsum));
339 const bool receiveMu,
342 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard receiving muon data = "
352 iEvent.getByToken(muInputToken, muonData);
356 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::Muon> with input tag "
358 <<
"\nrequested in configuration, but not found in the event.\n"
363 for (
int i = muonData->getFirstBX();
i <= muonData->getLastBX(); ++
i) {
365 if (i < m_bxFirst_ || i > m_bxLast_)
370 for (std::vector<l1t::Muon>::const_iterator
mu = muonData->begin(
i);
mu != muonData->end(
i); ++
mu) {
372 (*m_candL1Mu).push_back(
i, &(*
mu));
374 edm::LogWarning(
"L1TGlobal") <<
" Too many Muons (" << nObj <<
") for uGT Configuration maxMu =" << nrL1Mu
378 LogDebug(
"L1TGlobal") <<
"Muon Pt " <<
mu->hwPt() <<
" EtaAtVtx " <<
mu->hwEtaAtVtx() <<
" PhiAtVtx "
379 <<
mu->hwPhiAtVtx() <<
" Qual " <<
mu->hwQual() <<
" Iso " <<
mu->hwIso()
393 const bool receiveExt) {
395 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard receiving external data = "
405 iEvent.getByToken(extInputToken, extData);
409 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<GlobalExtBlk> with input tag "
411 <<
"\nrequested in configuration, but not found in the event.\n"
416 for (
int i = extData->getFirstBX();
i <= extData->getLastBX(); ++
i) {
418 if (i < m_bxFirst_ || i > m_bxLast_)
422 for (std::vector<GlobalExtBlk>::const_iterator
ext = extData->begin(
i);
ext != extData->end(
i); ++
ext) {
423 (*m_candL1External).push_back(
i, &(*
ext));
436 const bool produceL1GtObjectMapRecord,
437 const int iBxInEvent,
438 std::unique_ptr<GlobalObjectMapRecord>& gtObjectMapRecord,
439 const unsigned int numberPhysTriggers,
444 const std::vector<ConditionMap>& conditionMap = m_l1GtMenu->
gtConditionMap();
448 LogDebug(
"L1TGlobal") <<
" L1 Menu Scales -- Set Name: " << scaleSetName << std::endl;
452 m_algInitialOr =
false;
453 m_algPrescaledOr =
false;
454 m_algIntermOr =
false;
455 m_algFinalOr =
false;
456 m_algFinalOrVeto =
false;
458 const std::vector<std::vector<MuonTemplate>>& corrMuon = m_l1GtMenu->
corMuonTemplate();
461 const std::vector<std::vector<CaloTemplate>>& corrCalo = m_l1GtMenu->
corCaloTemplate();
463 const std::vector<std::vector<EnergySumTemplate>>& corrEnergySum = m_l1GtMenu->
corEnergySumTemplate();
465 LogDebug(
"L1TGlobal") <<
"Size corrMuon " << corrMuon.size() <<
"\nSize corrCalo " << corrCalo.size()
466 <<
"\nSize corrSums " << corrEnergySum.size() << std::endl;
473 if (m_conditionResultMaps.size() != conditionMap.size()) {
474 m_conditionResultMaps.clear();
475 m_conditionResultMaps.resize(conditionMap.size());
480 for (std::vector<ConditionMap>::const_iterator itCondOnChip = conditionMap.begin();
481 itCondOnChip != conditionMap.end();
487 for (
CItCond itCond = itCondOnChip->begin(); itCond != itCondOnChip->end(); itCond++) {
489 switch ((itCond->second)->condCategory()) {
492 const int ifMuEtaNumberBits = 0;
501 cMapResults[itCond->first] = muCondition;
503 if (m_verbosity && m_isDebugEnabled) {
504 std::ostringstream myCout;
505 muCondition->
print(myCout);
507 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
514 const int ifCaloEtaNumberBits = 0;
517 new CaloCondition(itCond->second,
this, nrL1EG, nrL1Jet, nrL1Tau, ifCaloEtaNumberBits);
523 cMapResults[itCond->first] = caloCondition;
525 if (m_verbosity && m_isDebugEnabled) {
526 std::ostringstream myCout;
527 caloCondition->
print(myCout);
529 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
540 cMapResults[itCond->first] = eSumCondition;
542 if (m_verbosity && m_isDebugEnabled) {
543 std::ostringstream myCout;
544 eSumCondition->
print(myCout);
546 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
558 cMapResults[itCond->first] = extCondition;
560 if (m_verbosity && m_isDebugEnabled) {
561 std::ostringstream myCout;
562 extCondition->
print(myCout);
564 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
571 const CorrelationTemplate* corrTemplate = static_cast<const CorrelationTemplate*>(itCond->second);
574 const int cond0Ind = corrTemplate->
cond0Index();
575 const int cond1Ind = corrTemplate->
cond1Index();
581 int cond0NrL1Objects = 0;
582 int cond1NrL1Objects = 0;
583 LogDebug(
"L1TGlobal") <<
" cond0NrL1Objects" << cond0NrL1Objects <<
" cond1NrL1Objects " << cond1NrL1Objects
586 switch (cond0Categ) {
588 cond0Condition = &((corrMuon[iChip])[cond0Ind]);
591 cond0Condition = &((corrCalo[iChip])[cond0Ind]);
594 cond0Condition = &((corrEnergySum[iChip])[cond0Ind]);
601 switch (cond1Categ) {
603 cond1Condition = &((corrMuon[iChip])[cond1Ind]);
606 cond1Condition = &((corrCalo[iChip])[cond1Ind]);
609 cond1Condition = &((corrEnergySum[iChip])[cond1Ind]);
622 cMapResults[itCond->first] = correlationCond;
624 if (m_verbosity && m_isDebugEnabled) {
625 std::ostringstream myCout;
626 correlationCond->
print(myCout);
628 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
637 static_cast<const CorrelationThreeBodyTemplate*>(itCond->second);
641 const int cond0Ind = corrTemplate->
cond0Index();
642 const int cond1Ind = corrTemplate->
cond1Index();
643 const int cond2Ind = corrTemplate->
cond2Index();
650 int cond0NrL1Objects = 0;
651 int cond1NrL1Objects = 0;
652 int cond2NrL1Objects = 0;
653 LogDebug(
"L1TGlobal") <<
" cond0NrL1Objects " << cond0NrL1Objects <<
" cond1NrL1Objects "
654 << cond1NrL1Objects <<
" cond2NrL1Objects " << cond2NrL1Objects << std::endl;
656 cond0Condition = &((corrMuon[iChip])[cond0Ind]);
658 LogDebug(
"L1TGlobal") <<
"No muon0 to evaluate three-body correlation condition";
661 cond1Condition = &((corrMuon[iChip])[cond1Ind]);
663 LogDebug(
"L1TGlobal") <<
"No muon1 to evaluate three-body correlation condition";
666 cond2Condition = &((corrMuon[iChip])[cond2Ind]);
668 LogDebug(
"L1TGlobal") <<
"No muon2 to evaluate three-body correlation condition";
675 correlationThreeBodyCond->
setScales(>Scales);
677 cMapResults[itCond->first] = correlationThreeBodyCond;
679 if (m_verbosity && m_isDebugEnabled) {
680 std::ostringstream myCout;
681 correlationThreeBodyCond->
print(myCout);
683 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
691 static_cast<const CorrelationWithOverlapRemovalTemplate*>(itCond->second);
695 const int cond0Ind = corrTemplate->
cond0Index();
696 const int cond1Ind = corrTemplate->
cond1Index();
697 const int cond2Ind = corrTemplate->
cond2Index();
704 int cond0NrL1Objects = 0;
705 int cond1NrL1Objects = 0;
706 int cond2NrL1Objects = 0;
707 LogDebug(
"L1TGlobal") <<
" cond0NrL1Objects" << cond0NrL1Objects <<
" cond1NrL1Objects " << cond1NrL1Objects
708 <<
" cond2NrL1Objects " << cond2NrL1Objects << std::endl;
710 switch (cond0Categ) {
712 cond0Condition = &((corrMuon[iChip])[cond0Ind]);
715 cond0Condition = &((corrCalo[iChip])[cond0Ind]);
718 cond0Condition = &((corrEnergySum[iChip])[cond0Ind]);
725 switch (cond1Categ) {
727 cond1Condition = &((corrMuon[iChip])[cond1Ind]);
730 cond1Condition = &((corrCalo[iChip])[cond1Ind]);
733 cond1Condition = &((corrEnergySum[iChip])[cond1Ind]);
740 switch (cond2Categ) {
742 cond2Condition = &((corrMuon[iChip])[cond2Ind]);
745 cond2Condition = &((corrCalo[iChip])[cond2Ind]);
748 cond2Condition = &((corrEnergySum[iChip])[cond2Ind]);
759 correlationCondWOR->
setScales(>Scales);
762 cMapResults[itCond->first] = correlationCondWOR;
764 if (m_verbosity && m_isDebugEnabled) {
765 std::ostringstream myCout;
766 correlationCondWOR->
print(myCout);
768 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
789 std::vector<GlobalObjectMap> objMapVec;
790 if (produceL1GtObjectMapRecord && (iBxInEvent == 0))
791 objMapVec.reserve(numberPhysTriggers);
793 for (
CItAlgo itAlgo = algorithmMap.begin(); itAlgo != algorithmMap.end(); itAlgo++) {
795 gtAlg.
evaluateAlgorithm((itAlgo->second).algoChipNumber(), m_conditionResultMaps);
797 int algBitNumber = (itAlgo->second).algoBitNumber();
800 LogDebug(
"L1TGlobal") <<
" ===> for iBxInEvent = " << iBxInEvent <<
":\t algBitName = " << itAlgo->first
801 <<
",\t algBitNumber = " << algBitNumber <<
",\t algResult = " << algResult << std::endl;
805 m_uGtAlgBlk.setAlgoDecisionInitial(algBitNumber, algResult);
806 m_algInitialOr =
true;
809 if (m_verbosity && m_isDebugEnabled) {
810 std::ostringstream myCout;
811 (itAlgo->second).
print(myCout);
814 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
818 if (produceL1GtObjectMapRecord && (iBxInEvent == 0)) {
819 std::vector<L1TObjectTypeInCond> otypes;
825 for (
auto imap = conditionMap.begin(); imap != conditionMap.end(); imap++) {
827 auto match = imap->find(iop->tokenName);
829 if (
match != imap->end()) {
835 for (
auto itype =
otype.begin(); itype !=
otype.end(); itype++) {
841 edm::LogWarning(
"L1TGlobal") <<
"\n Failed to find match for operand token " << iop->tokenName <<
"\n";
843 otypes.push_back(
otype);
858 if (m_verbosity && m_isDebugEnabled) {
859 std::ostringstream myCout1;
860 objMap.
print(myCout1);
862 LogTrace(
"L1TGlobal") << myCout1.str() << std::endl;
865 objMapVec.push_back(objMap);
870 if (produceL1GtObjectMapRecord && (iBxInEvent == 0)) {
871 gtObjectMapRecord->swapGtObjectMap(objMapVec);
877 for (std::vector<AlgorithmEvaluation::ConditionEvaluationMap>::iterator itCondOnChip = m_conditionResultMaps.begin();
878 itCondOnChip != m_conditionResultMaps.end();
881 delete itCond->second;
882 itCond->second =
nullptr;
889 const int iBxInEvent,
890 const int totalBxInEvent,
891 const unsigned int numberPhysTriggers,
892 const std::vector<double>& prescaleFactorsAlgoTrig,
893 const std::vector<unsigned int>& triggerMaskAlgoTrig,
894 const std::vector<int>& triggerMaskVetoAlgoTrig,
895 const bool algorithmTriggersUnprescaled,
896 const bool algorithmTriggersUnmasked) {
898 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard apply Final Decision Logic " << std::endl;
904 m_prescaleCounterAlgoTrig.reserve(numberPhysTriggers * totalBxInEvent);
906 for (
int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
907 m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
910 m_currentLumi =
iEvent.luminosityBlock();
914 if (m_firstEvLumiSegment || m_currentLumi !=
iEvent.luminosityBlock()) {
915 m_prescaleCounterAlgoTrig.clear();
916 for (
int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
917 m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
920 m_firstEvLumiSegment =
false;
921 m_currentLumi =
iEvent.luminosityBlock();
926 m_uGtAlgBlk.copyInitialToInterm();
931 if (!algorithmTriggersUnprescaled) {
933 int inBxInEvent = totalBxInEvent / 2 + iBxInEvent;
935 bool temp_algPrescaledOr =
false;
936 bool alreadyReported =
false;
937 for (
unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
938 bool bitValue = m_uGtAlgBlk.getAlgoDecisionInitial(iBit);
941 if (iBit < prescaleFactorsAlgoTrig.size()) {
942 if (prescaleFactorsAlgoTrig.at(iBit) != 1) {
943 (m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit))--;
944 if (m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit) == 0) {
946 m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit) = prescaleFactorsAlgoTrig.at(iBit);
947 temp_algPrescaledOr =
true;
950 m_uGtAlgBlk.setAlgoDecisionInterm(iBit,
false);
955 temp_algPrescaledOr =
true;
958 else if (!alreadyReported) {
959 alreadyReported =
true;
960 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: algoBit >= prescaleFactorsAlgoTrig.size() in bx " << iBxInEvent
966 m_algPrescaledOr = temp_algPrescaledOr;
970 m_algPrescaledOr = m_algInitialOr;
976 m_uGtAlgBlk.copyIntermToFinal();
978 if (!algorithmTriggersUnmasked) {
979 bool temp_algFinalOr =
false;
980 bool alreadyReported =
false;
981 for (
unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
982 bool bitValue = m_uGtAlgBlk.getAlgoDecisionInterm(iBit);
986 bool isMasked =
false;
987 if (iBit < triggerMaskAlgoTrig.size())
988 isMasked = (triggerMaskAlgoTrig.at(iBit) == 0);
989 else if (!alreadyReported) {
990 alreadyReported =
true;
991 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: algoBit >= triggerMaskAlgoTrig.size() in bx " << iBxInEvent
995 bool passMask = (bitValue && !isMasked);
998 temp_algFinalOr =
true;
1000 m_uGtAlgBlk.setAlgoDecisionFinal(iBit,
false);
1003 if (triggerMaskVetoAlgoTrig.at(iBit) == 1)
1004 m_algFinalOrVeto =
true;
1008 m_algIntermOr = temp_algFinalOr;
1011 m_algIntermOr = m_algPrescaledOr;
1016 m_algFinalOr = (m_algIntermOr & !m_algFinalOrVeto);
1021 std::unique_ptr<GlobalAlgBlkBxCollection>& uGtAlgRecord,
1026 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard fill DAQ Records for bx= " << iBxInEvent << std::endl;
1030 m_uGtAlgBlk.setbxInEventNr((iBxInEvent & 0xF));
1031 m_uGtAlgBlk.setPreScColumn(prescaleSet);
1032 m_uGtAlgBlk.setL1MenuUUID(menuUUID);
1033 m_uGtAlgBlk.setL1FirmwareUUID(firmwareUUID);
1035 m_uGtAlgBlk.setFinalORVeto(m_algFinalOrVeto);
1036 m_uGtAlgBlk.setFinalORPreVeto(m_algIntermOr);
1037 m_uGtAlgBlk.setFinalOR(m_algFinalOr);
1039 uGtAlgRecord->push_back(iBxInEvent, m_uGtAlgBlk);
1048 m_uGtAlgBlk.reset();
1050 m_gtlDecisionWord.reset();
1051 m_gtlAlgorithmOR.reset();
1056 m_candL1Mu->clear();
1057 m_candL1Mu->setBXRange(m_bxFirst_, m_bxLast_);
1062 m_candL1EG->clear();
1063 m_candL1Tau->clear();
1064 m_candL1Jet->clear();
1065 m_candL1EtSum->clear();
1067 m_candL1EG->setBXRange(m_bxFirst_, m_bxLast_);
1068 m_candL1Tau->setBXRange(m_bxFirst_, m_bxLast_);
1069 m_candL1Jet->setBXRange(m_bxFirst_, m_bxLast_);
1070 m_candL1EtSum->setBXRange(m_bxFirst_, m_bxLast_);
1074 m_candL1External->clear();
1075 m_candL1External->setBXRange(m_bxFirst_, m_bxLast_);
1080 LogTrace(
"L1TGlobal") <<
"\nl1t::L1GlobalTrigger: uGMT data received for BxInEvent = " << iBxInEvent << std::endl;
1082 int nrL1Mu = m_candL1Mu->size(iBxInEvent);
1083 LogTrace(
"L1TGlobal") <<
"Number of GMT muons = " << nrL1Mu <<
"\n" << std::endl;
1085 LogTrace(
"L1TGlobal") << std::endl;