24 #include <ext/hash_map>
68 m_firstEvLumiSegment(
true),
97 delete m_candL1External;
117 m_candL1Mu->setBXRange(m_bxFirst_, m_bxLast_);
118 m_candL1EG->setBXRange(m_bxFirst_, m_bxLast_);
119 m_candL1Tau->setBXRange(m_bxFirst_, m_bxLast_);
120 m_candL1Jet->setBXRange(m_bxFirst_, m_bxLast_);
121 m_candL1EtSum->setBXRange(m_bxFirst_, m_bxLast_);
122 m_candL1External->setBXRange(m_bxFirst_, m_bxLast_);
126 LogDebug(
"L1TGlobal") <<
"\t Initializing Board with bxFirst = " << m_bxFirst_ <<
", bxLast = " << m_bxLast_
136 const bool receiveEG,
138 const bool receiveTau,
140 const bool receiveJet,
142 const bool receiveEtSums) {
144 LogDebug(
"L1TGlobal") <<
"\n**** Board receiving Calo Data "
154 iEvent.getByToken(egInputToken, egData);
158 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::EGamma> with input tag "
160 <<
"\nrequested in configuration, but not found in the event.\n"
165 for (
int i = egData->getFirstBX();
i <= egData->getLastBX(); ++
i) {
167 if (i < m_bxFirst_ || i > m_bxLast_)
172 for (std::vector<l1t::EGamma>::const_iterator eg = egData->begin(
i); eg != egData->end(
i); ++eg) {
174 (*m_candL1EG).push_back(
i, &(*eg));
176 edm::LogWarning(
"L1TGlobal") <<
" Too many EG (" << nObj <<
") for uGT Configuration maxEG =" << nrL1EG
179 LogDebug(
"L1TGlobal") <<
"EG Pt " << eg->hwPt() <<
" Eta " << eg->hwEta() <<
" Phi " << eg->hwPhi()
180 <<
" Qual " << eg->hwQual() <<
" Iso " << eg->hwIso() << std::endl;
192 iEvent.getByToken(tauInputToken, tauData);
196 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::Tau> with input tag "
198 <<
"\nrequested in configuration, but not found in the event.\n"
203 for (
int i = tauData->getFirstBX();
i <= tauData->getLastBX(); ++
i) {
205 if (i < m_bxFirst_ || i > m_bxLast_)
210 for (std::vector<l1t::Tau>::const_iterator
tau = tauData->begin(
i);
tau != tauData->end(
i); ++
tau) {
211 if (nObj < nrL1Tau) {
212 (*m_candL1Tau).push_back(
i, &(*
tau));
214 LogTrace(
"L1TGlobal") <<
" Too many Tau (" << nObj <<
") for uGT Configuration maxTau =" << nrL1Tau
218 LogDebug(
"L1TGlobal") <<
"tau Pt " <<
tau->hwPt() <<
" Eta " <<
tau->hwEta() <<
" Phi " <<
tau->hwPhi()
219 <<
" Qual " <<
tau->hwQual() <<
" Iso " <<
tau->hwIso() << std::endl;
235 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::Jet> with input tag "
237 <<
"\nrequested in configuration, but not found in the event.\n"
244 if (i < m_bxFirst_ || i > m_bxLast_)
250 if (nObj < nrL1Jet) {
251 (*m_candL1Jet).push_back(
i, &(*
jet));
253 edm::LogWarning(
"L1TGlobal") <<
" Too many Jets (" << nObj <<
") for uGT Configuration maxJet =" << nrL1Jet
257 LogDebug(
"L1TGlobal") <<
"Jet Pt " <<
jet->hwPt() <<
" Eta " <<
jet->hwEta() <<
" Phi " <<
jet->hwPhi()
258 <<
" Qual " <<
jet->hwQual() <<
" Iso " <<
jet->hwIso() << std::endl;
269 iEvent.getByToken(sumInputToken, etSumData);
273 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::EtSum> with input tag "
275 <<
"\nrequested in configuration, but not found in the event.\n"
279 for (
int i = etSumData->getFirstBX();
i <= etSumData->getLastBX(); ++
i) {
281 if (i < m_bxFirst_ || i > m_bxLast_)
285 for (std::vector<l1t::EtSum>::const_iterator etsum = etSumData->begin(
i); etsum != etSumData->end(
i); ++etsum) {
286 (*m_candL1EtSum).push_back(
i, &(*etsum));
335 const bool receiveMu,
338 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard receiving muon data = "
348 iEvent.getByToken(muInputToken, muonData);
352 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::Muon> with input tag "
354 <<
"\nrequested in configuration, but not found in the event.\n"
359 for (
int i = muonData->getFirstBX();
i <= muonData->getLastBX(); ++
i) {
361 if (i < m_bxFirst_ || i > m_bxLast_)
366 for (std::vector<l1t::Muon>::const_iterator
mu = muonData->begin(
i);
mu != muonData->end(
i); ++
mu) {
368 (*m_candL1Mu).push_back(
i, &(*
mu));
370 edm::LogWarning(
"L1TGlobal") <<
" Too many Muons (" << nObj <<
") for uGT Configuration maxMu =" << nrL1Mu
374 LogDebug(
"L1TGlobal") <<
"Muon Pt " <<
mu->hwPt() <<
" EtaAtVtx " <<
mu->hwEtaAtVtx() <<
" PhiAtVtx "
375 <<
mu->hwPhiAtVtx() <<
" Qual " <<
mu->hwQual() <<
" Iso " <<
mu->hwIso()
389 const bool receiveExt) {
391 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard receiving external data = "
401 iEvent.getByToken(extInputToken, extData);
405 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<GlobalExtBlk> with input tag "
407 <<
"\nrequested in configuration, but not found in the event.\n"
412 for (
int i = extData->getFirstBX();
i <= extData->getLastBX(); ++
i) {
414 if (i < m_bxFirst_ || i > m_bxLast_)
418 for (std::vector<GlobalExtBlk>::const_iterator
ext = extData->begin(
i);
ext != extData->end(
i); ++
ext) {
419 (*m_candL1External).push_back(
i, &(*
ext));
432 const bool produceL1GtObjectMapRecord,
433 const int iBxInEvent,
434 std::unique_ptr<GlobalObjectMapRecord>& gtObjectMapRecord,
435 const unsigned int numberPhysTriggers,
440 const std::vector<ConditionMap>& conditionMap = m_l1GtMenu->
gtConditionMap();
444 LogDebug(
"L1TGlobal") <<
" L1 Menu Scales -- Set Name: " << scaleSetName << std::endl;
448 m_algInitialOr =
false;
449 m_algPrescaledOr =
false;
450 m_algIntermOr =
false;
451 m_algFinalOr =
false;
452 m_algFinalOrVeto =
false;
454 const std::vector<std::vector<MuonTemplate>>& corrMuon = m_l1GtMenu->
corMuonTemplate();
457 const std::vector<std::vector<CaloTemplate>>& corrCalo = m_l1GtMenu->
corCaloTemplate();
459 const std::vector<std::vector<EnergySumTemplate>>& corrEnergySum = m_l1GtMenu->
corEnergySumTemplate();
461 LogDebug(
"L1TGlobal") <<
"Size corrMuon " << corrMuon.size() <<
"\nSize corrCalo " << corrCalo.size()
462 <<
"\nSize corrSums " << corrEnergySum.size() << std::endl;
469 if (m_conditionResultMaps.size() != conditionMap.size()) {
470 m_conditionResultMaps.clear();
471 m_conditionResultMaps.resize(conditionMap.size());
476 for (std::vector<ConditionMap>::const_iterator itCondOnChip = conditionMap.begin();
477 itCondOnChip != conditionMap.end();
483 for (
CItCond itCond = itCondOnChip->begin(); itCond != itCondOnChip->end(); itCond++) {
485 switch ((itCond->second)->condCategory()) {
488 const int ifMuEtaNumberBits = 0;
497 cMapResults[itCond->first] = muCondition;
499 if (m_verbosity && m_isDebugEnabled) {
500 std::ostringstream myCout;
501 muCondition->
print(myCout);
503 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
510 const int ifCaloEtaNumberBits = 0;
513 new CaloCondition(itCond->second,
this, nrL1EG, nrL1Jet, nrL1Tau, ifCaloEtaNumberBits);
519 cMapResults[itCond->first] = caloCondition;
521 if (m_verbosity && m_isDebugEnabled) {
522 std::ostringstream myCout;
523 caloCondition->
print(myCout);
525 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
536 cMapResults[itCond->first] = eSumCondition;
538 if (m_verbosity && m_isDebugEnabled) {
539 std::ostringstream myCout;
540 eSumCondition->
print(myCout);
542 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
554 cMapResults[itCond->first] = extCondition;
556 if (m_verbosity && m_isDebugEnabled) {
557 std::ostringstream myCout;
558 extCondition->
print(myCout);
560 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
567 const CorrelationTemplate* corrTemplate = static_cast<const CorrelationTemplate*>(itCond->second);
570 const int cond0Ind = corrTemplate->
cond0Index();
571 const int cond1Ind = corrTemplate->
cond1Index();
577 int cond0NrL1Objects = 0;
578 int cond1NrL1Objects = 0;
579 LogDebug(
"L1TGlobal") <<
" cond0NrL1Objects" << cond0NrL1Objects <<
" cond1NrL1Objects " << cond1NrL1Objects
582 switch (cond0Categ) {
584 cond0Condition = &((corrMuon[iChip])[cond0Ind]);
587 cond0Condition = &((corrCalo[iChip])[cond0Ind]);
590 cond0Condition = &((corrEnergySum[iChip])[cond0Ind]);
597 switch (cond1Categ) {
599 cond1Condition = &((corrMuon[iChip])[cond1Ind]);
602 cond1Condition = &((corrCalo[iChip])[cond1Ind]);
605 cond1Condition = &((corrEnergySum[iChip])[cond1Ind]);
618 cMapResults[itCond->first] = correlationCond;
620 if (m_verbosity && m_isDebugEnabled) {
621 std::ostringstream myCout;
622 correlationCond->
print(myCout);
624 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
633 static_cast<const CorrelationWithOverlapRemovalTemplate*>(itCond->second);
637 const int cond0Ind = corrTemplate->
cond0Index();
638 const int cond1Ind = corrTemplate->
cond1Index();
639 const int cond2Ind = corrTemplate->
cond2Index();
646 int cond0NrL1Objects = 0;
647 int cond1NrL1Objects = 0;
648 int cond2NrL1Objects = 0;
649 LogDebug(
"L1TGlobal") <<
" cond0NrL1Objects" << cond0NrL1Objects <<
" cond1NrL1Objects " << cond1NrL1Objects
650 <<
" cond2NrL1Objects " << cond2NrL1Objects << std::endl;
652 switch (cond0Categ) {
654 cond0Condition = &((corrMuon[iChip])[cond0Ind]);
657 cond0Condition = &((corrCalo[iChip])[cond0Ind]);
660 cond0Condition = &((corrEnergySum[iChip])[cond0Ind]);
667 switch (cond1Categ) {
669 cond1Condition = &((corrMuon[iChip])[cond1Ind]);
672 cond1Condition = &((corrCalo[iChip])[cond1Ind]);
675 cond1Condition = &((corrEnergySum[iChip])[cond1Ind]);
682 switch (cond2Categ) {
684 cond2Condition = &((corrMuon[iChip])[cond2Ind]);
687 cond2Condition = &((corrCalo[iChip])[cond2Ind]);
690 cond2Condition = &((corrEnergySum[iChip])[cond2Ind]);
701 correlationCondWOR->
setScales(>Scales);
704 cMapResults[itCond->first] = correlationCondWOR;
706 if (m_verbosity && m_isDebugEnabled) {
707 std::ostringstream myCout;
708 correlationCondWOR->
print(myCout);
710 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
731 std::vector<GlobalObjectMap> objMapVec;
732 if (produceL1GtObjectMapRecord && (iBxInEvent == 0))
733 objMapVec.reserve(numberPhysTriggers);
735 for (
CItAlgo itAlgo = algorithmMap.begin(); itAlgo != algorithmMap.end(); itAlgo++) {
737 gtAlg.
evaluateAlgorithm((itAlgo->second).algoChipNumber(), m_conditionResultMaps);
739 int algBitNumber = (itAlgo->second).algoBitNumber();
742 LogDebug(
"L1TGlobal") <<
" ===> for iBxInEvent = " << iBxInEvent <<
":\t algBitName = " << itAlgo->first
743 <<
",\t algBitNumber = " << algBitNumber <<
",\t algResult = " << algResult << std::endl;
747 m_uGtAlgBlk.setAlgoDecisionInitial(algBitNumber, algResult);
748 m_algInitialOr =
true;
751 if (m_verbosity && m_isDebugEnabled) {
752 std::ostringstream myCout;
753 (itAlgo->second).
print(myCout);
756 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
760 if (produceL1GtObjectMapRecord && (iBxInEvent == 0)) {
761 std::vector<L1TObjectTypeInCond> otypes;
767 for (
auto imap = conditionMap.begin(); imap != conditionMap.end(); imap++) {
769 auto match = imap->find(iop->tokenName);
771 if (
match != imap->end()) {
777 for (
auto itype =
otype.begin(); itype !=
otype.end(); itype++) {
783 edm::LogWarning(
"L1TGlobal") <<
"\n Failed to find match for operand token " << iop->tokenName <<
"\n";
785 otypes.push_back(
otype);
800 if (m_verbosity && m_isDebugEnabled) {
801 std::ostringstream myCout1;
802 objMap.
print(myCout1);
804 LogTrace(
"L1TGlobal") << myCout1.str() << std::endl;
807 objMapVec.push_back(objMap);
812 if (produceL1GtObjectMapRecord && (iBxInEvent == 0)) {
813 gtObjectMapRecord->swapGtObjectMap(objMapVec);
819 for (std::vector<AlgorithmEvaluation::ConditionEvaluationMap>::iterator itCondOnChip = m_conditionResultMaps.begin();
820 itCondOnChip != m_conditionResultMaps.end();
823 delete itCond->second;
824 itCond->second =
nullptr;
831 const int iBxInEvent,
832 const int totalBxInEvent,
833 const unsigned int numberPhysTriggers,
834 const std::vector<double>& prescaleFactorsAlgoTrig,
835 const std::vector<unsigned int>& triggerMaskAlgoTrig,
836 const std::vector<int>& triggerMaskVetoAlgoTrig,
837 const bool algorithmTriggersUnprescaled,
838 const bool algorithmTriggersUnmasked) {
840 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard apply Final Decision Logic " << std::endl;
846 m_prescaleCounterAlgoTrig.reserve(numberPhysTriggers * totalBxInEvent);
848 for (
int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
849 m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
852 m_currentLumi =
iEvent.luminosityBlock();
856 if (m_firstEvLumiSegment || m_currentLumi !=
iEvent.luminosityBlock()) {
857 m_prescaleCounterAlgoTrig.clear();
858 for (
int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
859 m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
862 m_firstEvLumiSegment =
false;
863 m_currentLumi =
iEvent.luminosityBlock();
868 m_uGtAlgBlk.copyInitialToInterm();
873 if (!algorithmTriggersUnprescaled) {
875 int inBxInEvent = totalBxInEvent / 2 + iBxInEvent;
877 bool temp_algPrescaledOr =
false;
878 bool alreadyReported =
false;
879 for (
unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
880 bool bitValue = m_uGtAlgBlk.getAlgoDecisionInitial(iBit);
883 if (iBit < prescaleFactorsAlgoTrig.size()) {
884 if (prescaleFactorsAlgoTrig.at(iBit) != 1) {
885 (m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit))--;
886 if (m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit) == 0) {
888 m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit) = prescaleFactorsAlgoTrig.at(iBit);
889 temp_algPrescaledOr =
true;
892 m_uGtAlgBlk.setAlgoDecisionInterm(iBit,
false);
897 temp_algPrescaledOr =
true;
900 else if (!alreadyReported) {
901 alreadyReported =
true;
902 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: algoBit >= prescaleFactorsAlgoTrig.size() in bx " << iBxInEvent
908 m_algPrescaledOr = temp_algPrescaledOr;
912 m_algPrescaledOr = m_algInitialOr;
918 m_uGtAlgBlk.copyIntermToFinal();
920 if (!algorithmTriggersUnmasked) {
921 bool temp_algFinalOr =
false;
922 bool alreadyReported =
false;
923 for (
unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
924 bool bitValue = m_uGtAlgBlk.getAlgoDecisionInterm(iBit);
928 bool isMasked =
false;
929 if (iBit < triggerMaskAlgoTrig.size())
930 isMasked = (triggerMaskAlgoTrig.at(iBit) == 0);
931 else if (!alreadyReported) {
932 alreadyReported =
true;
933 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: algoBit >= triggerMaskAlgoTrig.size() in bx " << iBxInEvent
937 bool passMask = (bitValue && !isMasked);
940 temp_algFinalOr =
true;
942 m_uGtAlgBlk.setAlgoDecisionFinal(iBit,
false);
945 if (triggerMaskVetoAlgoTrig.at(iBit) == 1)
946 m_algFinalOrVeto =
true;
950 m_algIntermOr = temp_algFinalOr;
953 m_algIntermOr = m_algPrescaledOr;
958 m_algFinalOr = (m_algIntermOr & !m_algFinalOrVeto);
963 std::unique_ptr<GlobalAlgBlkBxCollection>& uGtAlgRecord,
968 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard fill DAQ Records for bx= " << iBxInEvent << std::endl;
972 m_uGtAlgBlk.setbxInEventNr((iBxInEvent & 0xF));
973 m_uGtAlgBlk.setPreScColumn(prescaleSet);
974 m_uGtAlgBlk.setL1MenuUUID(menuUUID);
975 m_uGtAlgBlk.setL1FirmwareUUID(firmwareUUID);
977 m_uGtAlgBlk.setFinalORVeto(m_algFinalOrVeto);
978 m_uGtAlgBlk.setFinalORPreVeto(m_algIntermOr);
979 m_uGtAlgBlk.setFinalOR(m_algFinalOr);
981 uGtAlgRecord->push_back(iBxInEvent, m_uGtAlgBlk);
992 m_gtlDecisionWord.reset();
993 m_gtlAlgorithmOR.reset();
999 m_candL1Mu->setBXRange(m_bxFirst_, m_bxLast_);
1004 m_candL1EG->clear();
1005 m_candL1Tau->clear();
1006 m_candL1Jet->clear();
1007 m_candL1EtSum->clear();
1009 m_candL1EG->setBXRange(m_bxFirst_, m_bxLast_);
1010 m_candL1Tau->setBXRange(m_bxFirst_, m_bxLast_);
1011 m_candL1Jet->setBXRange(m_bxFirst_, m_bxLast_);
1012 m_candL1EtSum->setBXRange(m_bxFirst_, m_bxLast_);
1016 m_candL1External->clear();
1017 m_candL1External->setBXRange(m_bxFirst_, m_bxLast_);
1022 LogTrace(
"L1TGlobal") <<
"\nl1t::L1GlobalTrigger: uGMT data received for BxInEvent = " << iBxInEvent << std::endl;
1024 int nrL1Mu = m_candL1Mu->size(iBxInEvent);
1025 LogTrace(
"L1TGlobal") <<
"Number of GMT muons = " << nrL1Mu <<
"\n" << std::endl;
1027 LogTrace(
"L1TGlobal") << std::endl;