23 #include <ext/hash_map>
67 m_firstEvLumiSegment(
true),
96 delete m_candL1External;
116 m_candL1Mu->setBXRange(m_bxFirst_, m_bxLast_);
117 m_candL1EG->setBXRange(m_bxFirst_, m_bxLast_);
118 m_candL1Tau->setBXRange(m_bxFirst_, m_bxLast_);
119 m_candL1Jet->setBXRange(m_bxFirst_, m_bxLast_);
120 m_candL1EtSum->setBXRange(m_bxFirst_, m_bxLast_);
121 m_candL1External->setBXRange(m_bxFirst_, m_bxLast_);
125 LogDebug(
"L1TGlobal") <<
"\t Initializing Board with bxFirst = " << m_bxFirst_ <<
", bxLast = " << m_bxLast_
135 const bool receiveEG,
137 const bool receiveTau,
139 const bool receiveJet,
141 const bool receiveEtSums) {
143 LogDebug(
"L1TGlobal") <<
"\n**** Board receiving Calo Data "
153 iEvent.getByToken(egInputToken, egData);
157 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::EGamma> with input tag "
159 <<
"\nrequested in configuration, but not found in the event.\n"
164 for (
int i = egData->getFirstBX();
i <= egData->getLastBX(); ++
i) {
166 if (i < m_bxFirst_ || i > m_bxLast_)
171 for (std::vector<l1t::EGamma>::const_iterator eg = egData->begin(
i); eg != egData->end(
i); ++eg) {
173 (*m_candL1EG).push_back(
i, &(*eg));
175 edm::LogWarning(
"L1TGlobal") <<
" Too many EG (" << nObj <<
") for uGT Configuration maxEG =" << nrL1EG
178 LogDebug(
"L1TGlobal") <<
"EG Pt " << eg->hwPt() <<
" Eta " << eg->hwEta() <<
" Phi " << eg->hwPhi()
179 <<
" Qual " << eg->hwQual() <<
" Iso " << eg->hwIso() << std::endl;
191 iEvent.getByToken(tauInputToken, tauData);
195 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::Tau> with input tag "
197 <<
"\nrequested in configuration, but not found in the event.\n"
202 for (
int i = tauData->getFirstBX();
i <= tauData->getLastBX(); ++
i) {
204 if (i < m_bxFirst_ || i > m_bxLast_)
209 for (std::vector<l1t::Tau>::const_iterator
tau = tauData->begin(
i);
tau != tauData->end(
i); ++
tau) {
210 if (nObj < nrL1Tau) {
211 (*m_candL1Tau).push_back(
i, &(*
tau));
213 LogTrace(
"L1TGlobal") <<
" Too many Tau (" << nObj <<
") for uGT Configuration maxTau =" << nrL1Tau
217 LogDebug(
"L1TGlobal") <<
"tau Pt " <<
tau->hwPt() <<
" Eta " <<
tau->hwEta() <<
" Phi " <<
tau->hwPhi()
218 <<
" Qual " <<
tau->hwQual() <<
" Iso " <<
tau->hwIso() << std::endl;
234 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::Jet> with input tag "
236 <<
"\nrequested in configuration, but not found in the event.\n"
243 if (i < m_bxFirst_ || i > m_bxLast_)
249 if (nObj < nrL1Jet) {
250 (*m_candL1Jet).push_back(
i, &(*
jet));
252 edm::LogWarning(
"L1TGlobal") <<
" Too many Jets (" << nObj <<
") for uGT Configuration maxJet =" << nrL1Jet
256 LogDebug(
"L1TGlobal") <<
"Jet Pt " <<
jet->hwPt() <<
" Eta " <<
jet->hwEta() <<
" Phi " <<
jet->hwPhi()
257 <<
" Qual " <<
jet->hwQual() <<
" Iso " <<
jet->hwIso() << std::endl;
268 iEvent.getByToken(sumInputToken, etSumData);
272 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::EtSum> with input tag "
274 <<
"\nrequested in configuration, but not found in the event.\n"
278 for (
int i = etSumData->getFirstBX();
i <= etSumData->getLastBX(); ++
i) {
280 if (i < m_bxFirst_ || i > m_bxLast_)
284 for (std::vector<l1t::EtSum>::const_iterator etsum = etSumData->begin(
i); etsum != etSumData->end(
i); ++etsum) {
285 (*m_candL1EtSum).push_back(
i, &(*etsum));
334 const bool receiveMu,
337 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard receiving muon data = "
347 iEvent.getByToken(muInputToken, muonData);
351 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<l1t::Muon> with input tag "
353 <<
"\nrequested in configuration, but not found in the event.\n"
358 for (
int i = muonData->getFirstBX();
i <= muonData->getLastBX(); ++
i) {
360 if (i < m_bxFirst_ || i > m_bxLast_)
365 for (std::vector<l1t::Muon>::const_iterator
mu = muonData->begin(
i);
mu != muonData->end(
i); ++
mu) {
367 (*m_candL1Mu).push_back(
i, &(*
mu));
369 edm::LogWarning(
"L1TGlobal") <<
" Too many Muons (" << nObj <<
") for uGT Configuration maxMu =" << nrL1Mu
373 LogDebug(
"L1TGlobal") <<
"Muon Pt " <<
mu->hwPt() <<
" EtaAtVtx " <<
mu->hwEtaAtVtx() <<
" PhiAtVtx "
374 <<
mu->hwPhiAtVtx() <<
" Qual " <<
mu->hwQual() <<
" Iso " <<
mu->hwIso()
388 const bool receiveExt) {
390 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard receiving external data = "
400 iEvent.getByToken(extInputToken, extData);
404 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: BXVector<GlobalExtBlk> with input tag "
406 <<
"\nrequested in configuration, but not found in the event.\n"
411 for (
int i = extData->getFirstBX();
i <= extData->getLastBX(); ++
i) {
413 if (i < m_bxFirst_ || i > m_bxLast_)
417 for (std::vector<GlobalExtBlk>::const_iterator
ext = extData->begin(
i);
ext != extData->end(
i); ++
ext) {
418 (*m_candL1External).push_back(
i, &(*
ext));
431 const bool produceL1GtObjectMapRecord,
432 const int iBxInEvent,
433 std::unique_ptr<GlobalObjectMapRecord>& gtObjectMapRecord,
434 const unsigned int numberPhysTriggers,
439 const std::vector<ConditionMap>& conditionMap = m_l1GtMenu->
gtConditionMap();
443 LogDebug(
"L1TGlobal") <<
" L1 Menu Scales -- Set Name: " << scaleSetName << std::endl;
447 m_algInitialOr =
false;
448 m_algPrescaledOr =
false;
449 m_algIntermOr =
false;
450 m_algFinalOr =
false;
451 m_algFinalOrVeto =
false;
453 const std::vector<std::vector<MuonTemplate>>& corrMuon = m_l1GtMenu->
corMuonTemplate();
456 const std::vector<std::vector<CaloTemplate>>& corrCalo = m_l1GtMenu->
corCaloTemplate();
458 const std::vector<std::vector<EnergySumTemplate>>& corrEnergySum = m_l1GtMenu->
corEnergySumTemplate();
460 LogDebug(
"L1TGlobal") <<
"Size corrMuon " << corrMuon.size() <<
"\nSize corrCalo " << corrCalo.size()
461 <<
"\nSize corrSums " << corrEnergySum.size() << std::endl;
468 if (m_conditionResultMaps.size() != conditionMap.size()) {
469 m_conditionResultMaps.clear();
470 m_conditionResultMaps.resize(conditionMap.size());
475 for (std::vector<ConditionMap>::const_iterator itCondOnChip = conditionMap.begin();
476 itCondOnChip != conditionMap.end();
482 for (
CItCond itCond = itCondOnChip->begin(); itCond != itCondOnChip->end(); itCond++) {
484 switch ((itCond->second)->condCategory()) {
487 const int ifMuEtaNumberBits = 0;
496 cMapResults[itCond->first] = muCondition;
498 if (m_verbosity && m_isDebugEnabled) {
499 std::ostringstream myCout;
500 muCondition->
print(myCout);
502 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
509 const int ifCaloEtaNumberBits = 0;
512 new CaloCondition(itCond->second,
this, nrL1EG, nrL1Jet, nrL1Tau, ifCaloEtaNumberBits);
518 cMapResults[itCond->first] = caloCondition;
520 if (m_verbosity && m_isDebugEnabled) {
521 std::ostringstream myCout;
522 caloCondition->
print(myCout);
524 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
535 cMapResults[itCond->first] = eSumCondition;
537 if (m_verbosity && m_isDebugEnabled) {
538 std::ostringstream myCout;
539 eSumCondition->
print(myCout);
541 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
553 cMapResults[itCond->first] = extCondition;
555 if (m_verbosity && m_isDebugEnabled) {
556 std::ostringstream myCout;
557 extCondition->
print(myCout);
559 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
566 const CorrelationTemplate* corrTemplate = static_cast<const CorrelationTemplate*>(itCond->second);
569 const int cond0Ind = corrTemplate->
cond0Index();
570 const int cond1Ind = corrTemplate->
cond1Index();
576 int cond0NrL1Objects = 0;
577 int cond1NrL1Objects = 0;
578 LogDebug(
"L1TGlobal") <<
" cond0NrL1Objects" << cond0NrL1Objects <<
" cond1NrL1Objects " << cond1NrL1Objects
581 switch (cond0Categ) {
583 cond0Condition = &((corrMuon[iChip])[cond0Ind]);
586 cond0Condition = &((corrCalo[iChip])[cond0Ind]);
589 cond0Condition = &((corrEnergySum[iChip])[cond0Ind]);
596 switch (cond1Categ) {
598 cond1Condition = &((corrMuon[iChip])[cond1Ind]);
601 cond1Condition = &((corrCalo[iChip])[cond1Ind]);
604 cond1Condition = &((corrEnergySum[iChip])[cond1Ind]);
617 cMapResults[itCond->first] = correlationCond;
619 if (m_verbosity && m_isDebugEnabled) {
620 std::ostringstream myCout;
621 correlationCond->
print(myCout);
623 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
632 static_cast<const CorrelationWithOverlapRemovalTemplate*>(itCond->second);
636 const int cond0Ind = corrTemplate->
cond0Index();
637 const int cond1Ind = corrTemplate->
cond1Index();
638 const int cond2Ind = corrTemplate->
cond2Index();
645 int cond0NrL1Objects = 0;
646 int cond1NrL1Objects = 0;
647 int cond2NrL1Objects = 0;
648 LogDebug(
"L1TGlobal") <<
" cond0NrL1Objects" << cond0NrL1Objects <<
" cond1NrL1Objects " << cond1NrL1Objects
649 <<
" cond2NrL1Objects " << cond2NrL1Objects << std::endl;
651 switch (cond0Categ) {
653 cond0Condition = &((corrMuon[iChip])[cond0Ind]);
656 cond0Condition = &((corrCalo[iChip])[cond0Ind]);
659 cond0Condition = &((corrEnergySum[iChip])[cond0Ind]);
666 switch (cond1Categ) {
668 cond1Condition = &((corrMuon[iChip])[cond1Ind]);
671 cond1Condition = &((corrCalo[iChip])[cond1Ind]);
674 cond1Condition = &((corrEnergySum[iChip])[cond1Ind]);
681 switch (cond2Categ) {
683 cond2Condition = &((corrMuon[iChip])[cond2Ind]);
686 cond2Condition = &((corrCalo[iChip])[cond2Ind]);
689 cond2Condition = &((corrEnergySum[iChip])[cond2Ind]);
700 correlationCondWOR->
setScales(>Scales);
703 cMapResults[itCond->first] = correlationCondWOR;
705 if (m_verbosity && m_isDebugEnabled) {
706 std::ostringstream myCout;
707 correlationCondWOR->
print(myCout);
709 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
730 std::vector<GlobalObjectMap> objMapVec;
731 if (produceL1GtObjectMapRecord && (iBxInEvent == 0))
732 objMapVec.reserve(numberPhysTriggers);
734 for (
CItAlgo itAlgo = algorithmMap.begin(); itAlgo != algorithmMap.end(); itAlgo++) {
736 gtAlg.
evaluateAlgorithm((itAlgo->second).algoChipNumber(), m_conditionResultMaps);
738 int algBitNumber = (itAlgo->second).algoBitNumber();
741 LogDebug(
"L1TGlobal") <<
" ===> for iBxInEvent = " << iBxInEvent <<
":\t algBitName = " << itAlgo->first
742 <<
",\t algBitNumber = " << algBitNumber <<
",\t algResult = " << algResult << std::endl;
746 m_uGtAlgBlk.setAlgoDecisionInitial(algBitNumber, algResult);
747 m_algInitialOr =
true;
750 if (m_verbosity && m_isDebugEnabled) {
751 std::ostringstream myCout;
752 (itAlgo->second).
print(myCout);
755 LogTrace(
"L1TGlobal") << myCout.str() << std::endl;
759 if (produceL1GtObjectMapRecord && (iBxInEvent == 0)) {
760 std::vector<L1TObjectTypeInCond> otypes;
766 for (
auto imap = conditionMap.begin(); imap != conditionMap.end(); imap++) {
768 auto match = imap->find(iop->tokenName);
770 if (
match != imap->end()) {
776 for (
auto itype =
otype.begin(); itype !=
otype.end(); itype++) {
782 edm::LogWarning(
"L1TGlobal") <<
"\n Failed to find match for operand token " << iop->tokenName <<
"\n";
784 otypes.push_back(
otype);
799 if (m_verbosity && m_isDebugEnabled) {
800 std::ostringstream myCout1;
801 objMap.
print(myCout1);
803 LogTrace(
"L1TGlobal") << myCout1.str() << std::endl;
806 objMapVec.push_back(objMap);
811 if (produceL1GtObjectMapRecord && (iBxInEvent == 0)) {
812 gtObjectMapRecord->swapGtObjectMap(objMapVec);
818 for (std::vector<AlgorithmEvaluation::ConditionEvaluationMap>::iterator itCondOnChip = m_conditionResultMaps.begin();
819 itCondOnChip != m_conditionResultMaps.end();
822 delete itCond->second;
823 itCond->second =
nullptr;
830 const int iBxInEvent,
831 const int totalBxInEvent,
832 const unsigned int numberPhysTriggers,
833 const std::vector<int>& prescaleFactorsAlgoTrig,
834 const std::vector<unsigned int>& triggerMaskAlgoTrig,
835 const std::vector<int>& triggerMaskVetoAlgoTrig,
836 const bool algorithmTriggersUnprescaled,
837 const bool algorithmTriggersUnmasked) {
839 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard apply Final Decision Logic " << std::endl;
845 m_prescaleCounterAlgoTrig.reserve(numberPhysTriggers * totalBxInEvent);
847 for (
int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
848 m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
851 m_currentLumi =
iEvent.luminosityBlock();
855 if (m_firstEvLumiSegment || m_currentLumi !=
iEvent.luminosityBlock()) {
856 m_prescaleCounterAlgoTrig.clear();
857 for (
int iBxInEvent = 0; iBxInEvent <= totalBxInEvent; ++iBxInEvent) {
858 m_prescaleCounterAlgoTrig.push_back(prescaleFactorsAlgoTrig);
861 m_firstEvLumiSegment =
false;
862 m_currentLumi =
iEvent.luminosityBlock();
867 m_uGtAlgBlk.copyInitialToInterm();
872 if (!algorithmTriggersUnprescaled) {
874 int inBxInEvent = totalBxInEvent / 2 + iBxInEvent;
876 bool temp_algPrescaledOr =
false;
877 bool alreadyReported =
false;
878 for (
unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
879 bool bitValue = m_uGtAlgBlk.getAlgoDecisionInitial(iBit);
882 if (iBit < prescaleFactorsAlgoTrig.size()) {
883 if (prescaleFactorsAlgoTrig.at(iBit) != 1) {
884 (m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit))--;
885 if (m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit) == 0) {
887 m_prescaleCounterAlgoTrig.at(inBxInEvent).at(iBit) = prescaleFactorsAlgoTrig.at(iBit);
888 temp_algPrescaledOr =
true;
891 m_uGtAlgBlk.setAlgoDecisionInterm(iBit,
false);
896 temp_algPrescaledOr =
true;
899 else if (!alreadyReported) {
900 alreadyReported =
true;
901 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: algoBit >= prescaleFactorsAlgoTrig.size() in bx " << iBxInEvent
907 m_algPrescaledOr = temp_algPrescaledOr;
911 m_algPrescaledOr = m_algInitialOr;
917 m_uGtAlgBlk.copyIntermToFinal();
919 if (!algorithmTriggersUnmasked) {
920 bool temp_algFinalOr =
false;
921 bool alreadyReported =
false;
922 for (
unsigned int iBit = 0; iBit < numberPhysTriggers; ++iBit) {
923 bool bitValue = m_uGtAlgBlk.getAlgoDecisionInterm(iBit);
927 bool isMasked =
false;
928 if (iBit < triggerMaskAlgoTrig.size())
929 isMasked = (triggerMaskAlgoTrig.at(iBit) == 0);
930 else if (!alreadyReported) {
931 alreadyReported =
true;
932 edm::LogWarning(
"L1TGlobal") <<
"\nWarning: algoBit >= triggerMaskAlgoTrig.size() in bx " << iBxInEvent
936 bool passMask = (bitValue && !isMasked);
939 temp_algFinalOr =
true;
941 m_uGtAlgBlk.setAlgoDecisionFinal(iBit,
false);
944 if (triggerMaskVetoAlgoTrig.at(iBit) == 1)
945 m_algFinalOrVeto =
true;
949 m_algIntermOr = temp_algFinalOr;
952 m_algIntermOr = m_algPrescaledOr;
957 m_algFinalOr = (m_algIntermOr & !m_algFinalOrVeto);
962 std::unique_ptr<GlobalAlgBlkBxCollection>& uGtAlgRecord,
967 LogDebug(
"L1TGlobal") <<
"\n**** GlobalBoard fill DAQ Records for bx= " << iBxInEvent << std::endl;
971 m_uGtAlgBlk.setbxInEventNr((iBxInEvent & 0xF));
972 m_uGtAlgBlk.setPreScColumn(prescaleSet);
973 m_uGtAlgBlk.setL1MenuUUID(menuUUID);
974 m_uGtAlgBlk.setL1FirmwareUUID(firmwareUUID);
976 m_uGtAlgBlk.setFinalORVeto(m_algFinalOrVeto);
977 m_uGtAlgBlk.setFinalORPreVeto(m_algIntermOr);
978 m_uGtAlgBlk.setFinalOR(m_algFinalOr);
980 uGtAlgRecord->push_back(iBxInEvent, m_uGtAlgBlk);
991 m_gtlDecisionWord.reset();
992 m_gtlAlgorithmOR.reset();
998 m_candL1Mu->setBXRange(m_bxFirst_, m_bxLast_);
1003 m_candL1EG->clear();
1004 m_candL1Tau->clear();
1005 m_candL1Jet->clear();
1006 m_candL1EtSum->clear();
1008 m_candL1EG->setBXRange(m_bxFirst_, m_bxLast_);
1009 m_candL1Tau->setBXRange(m_bxFirst_, m_bxLast_);
1010 m_candL1Jet->setBXRange(m_bxFirst_, m_bxLast_);
1011 m_candL1EtSum->setBXRange(m_bxFirst_, m_bxLast_);
1015 m_candL1External->clear();
1016 m_candL1External->setBXRange(m_bxFirst_, m_bxLast_);
1021 LogTrace(
"L1TGlobal") <<
"\nl1t::L1GlobalTrigger: uGMT data received for BxInEvent = " << iBxInEvent << std::endl;
1023 int nrL1Mu = m_candL1Mu->size(iBxInEvent);
1024 LogTrace(
"L1TGlobal") <<
"Number of GMT muons = " << nrL1Mu <<
"\n" << std::endl;
1026 LogTrace(
"L1TGlobal") << std::endl;