File indexing completed on 2024-04-06 12:19:52
0001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetFinalStage.h"
0002 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
0003 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetSorter.h"
0004
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006
0007 using std::endl;
0008 using std::ostream;
0009
0010
0011 const unsigned int L1GctJetFinalStage::MAX_WHEEL_FPGAS = 2;
0012 const int L1GctJetFinalStage::MAX_JETS_IN = L1GctJetFinalStage::MAX_WHEEL_FPGAS * L1GctWheelJetFpga::MAX_JETS_OUT;
0013 const int L1GctJetFinalStage::MAX_JETS_OUT = 4;
0014
0015 L1GctJetFinalStage::L1GctJetFinalStage(const std::vector<L1GctWheelJetFpga*>& wheelFpgas)
0016 : L1GctProcessor(),
0017 m_wheelFpgas(wheelFpgas),
0018 m_centralJetSorter(new L1GctJetSorter()),
0019 m_forwardJetSorter(new L1GctJetSorter()),
0020 m_tauJetSorter(new L1GctJetSorter()),
0021 m_inputCentralJets(MAX_JETS_IN),
0022 m_inputForwardJets(MAX_JETS_IN),
0023 m_inputTauJets(MAX_JETS_IN),
0024 m_centralJets(MAX_JETS_OUT),
0025 m_forwardJets(MAX_JETS_OUT),
0026 m_tauJets(MAX_JETS_OUT),
0027 m_setupOk(true) {
0028 if (m_wheelFpgas.size() != MAX_WHEEL_FPGAS) {
0029 m_setupOk = false;
0030 if (m_verbose) {
0031 edm::LogWarning("L1GctSetupError")
0032 << "L1GctJetFinalStage::L1GctJetFinalStage() : Jet Final Stage instance has been incorrectly constructed!\n"
0033 << "This class needs " << MAX_WHEEL_FPGAS << " wheel jet FPGA pointers, yet only " << m_wheelFpgas.size()
0034 << " wheel jet FPGA pointers are present.\n";
0035 }
0036 }
0037
0038 for (unsigned int i = 0; i < MAX_WHEEL_FPGAS; ++i) {
0039 if (m_wheelFpgas.at(i) == nullptr) {
0040 m_setupOk = false;
0041 if (m_verbose) {
0042 edm::LogWarning("L1GctSetupError")
0043 << "L1GctJetFinalStage::L1GctJetFinalStage() : Jet Final Stage instance has been incorrectly constructed!\n"
0044 << "Wheel jet FPGA pointer " << i << " has not been set!\n";
0045 }
0046 }
0047 }
0048 if (!m_setupOk && m_verbose) {
0049 edm::LogError("L1GctSetupError") << "L1GctJetFinalStage has been incorrectly constructed";
0050 }
0051 }
0052
0053 L1GctJetFinalStage::~L1GctJetFinalStage() {
0054 if (m_centralJetSorter != nullptr)
0055 delete m_centralJetSorter;
0056 if (m_forwardJetSorter != nullptr)
0057 delete m_forwardJetSorter;
0058 if (m_tauJetSorter != nullptr)
0059 delete m_tauJetSorter;
0060 }
0061
0062 std::ostream& operator<<(std::ostream& os, const L1GctJetFinalStage& fpga) {
0063 os << "===L1GctJetFinalStage===" << endl;
0064 os << "No. of Wheel Jet FPGAs " << fpga.m_wheelFpgas.size() << std::endl;
0065 for (unsigned i = 0; i < fpga.m_wheelFpgas.size(); i++) {
0066 os << "WheelJetFpga* " << i << " = " << fpga.m_wheelFpgas.at(i) << endl;
0067 }
0068 os << "No. of input central Jets " << fpga.m_inputCentralJets.size() << std::endl;
0069 for (unsigned i = 0; i < fpga.m_inputCentralJets.size(); i++) {
0070 os << fpga.m_inputCentralJets.at(i);
0071 }
0072 os << "No. of input forward Jets " << fpga.m_inputForwardJets.size() << std::endl;
0073 for (unsigned i = 0; i < fpga.m_inputForwardJets.size(); i++) {
0074 os << fpga.m_inputForwardJets.at(i);
0075 }
0076 os << "No. of raw tau Jets " << fpga.m_inputTauJets.size() << std::endl;
0077 for (unsigned i = 0; i < fpga.m_inputTauJets.size(); i++) {
0078 os << fpga.m_inputTauJets.at(i);
0079 }
0080 os << "No. of output central Jets " << fpga.m_centralJets.contents.size() << std::endl;
0081 for (unsigned i = 0; i < fpga.m_centralJets.contents.size(); i++) {
0082 os << fpga.m_centralJets.contents.at(i);
0083 }
0084 os << "No. of output forward Jets " << fpga.m_forwardJets.contents.size() << std::endl;
0085 for (unsigned i = 0; i < fpga.m_forwardJets.contents.size(); i++) {
0086 os << fpga.m_forwardJets.contents.at(i);
0087 }
0088 os << "No. of output tau Jets " << fpga.m_tauJets.contents.size() << std::endl;
0089 for (unsigned i = 0; i < fpga.m_tauJets.contents.size(); i++) {
0090 os << fpga.m_tauJets.contents.at(i);
0091 }
0092 os << endl;
0093 return os;
0094 }
0095
0096 void L1GctJetFinalStage::resetProcessor() {
0097
0098 m_inputCentralJets.clear();
0099 m_inputForwardJets.clear();
0100 m_inputTauJets.clear();
0101
0102 m_inputCentralJets.resize(MAX_JETS_IN);
0103 m_inputForwardJets.resize(MAX_JETS_IN);
0104 m_inputTauJets.resize(MAX_JETS_IN);
0105 }
0106
0107 void L1GctJetFinalStage::resetPipelines() {
0108 m_centralJets.reset(numOfBx());
0109 m_forwardJets.reset(numOfBx());
0110 m_tauJets.reset(numOfBx());
0111 }
0112
0113 void L1GctJetFinalStage::fetchInput() {
0114 if (m_setupOk) {
0115
0116
0117 for (unsigned short iWheel = 0; iWheel < MAX_WHEEL_FPGAS; ++iWheel) {
0118 storeJets(m_inputCentralJets, m_wheelFpgas.at(iWheel)->getCentralJets(), iWheel);
0119 storeJets(m_inputForwardJets, m_wheelFpgas.at(iWheel)->getForwardJets(), iWheel);
0120 storeJets(m_inputTauJets, m_wheelFpgas.at(iWheel)->getTauJets(), iWheel);
0121 }
0122 }
0123 }
0124
0125 void L1GctJetFinalStage::process() {
0126 if (m_setupOk) {
0127
0128 m_centralJetSorter->setJets(m_inputCentralJets);
0129 m_forwardJetSorter->setJets(m_inputForwardJets);
0130 m_tauJetSorter->setJets(m_inputTauJets);
0131
0132 m_centralJets.store(m_centralJetSorter->getSortedJets(), bxRel());
0133 m_forwardJets.store(m_forwardJetSorter->getSortedJets(), bxRel());
0134 m_tauJets.store(m_tauJetSorter->getSortedJets(), bxRel());
0135 }
0136 }
0137
0138 void L1GctJetFinalStage::setInputCentralJet(int i, const L1GctJetCand& jet) {
0139 if (((jet.isCentral() && jet.bx() == bxAbs()) || jet.empty()) && (i >= 0 && i < MAX_JETS_IN)) {
0140 m_inputCentralJets.at(i) = jet;
0141 }
0142 }
0143
0144 void L1GctJetFinalStage::setInputForwardJet(int i, const L1GctJetCand& jet) {
0145 if (((jet.isForward() && jet.bx() == bxAbs()) || jet.empty()) && (i >= 0 && i < MAX_JETS_IN)) {
0146 m_inputForwardJets.at(i) = jet;
0147 }
0148 }
0149
0150 void L1GctJetFinalStage::setInputTauJet(int i, const L1GctJetCand& jet) {
0151 if (((jet.isTau() && jet.bx() == bxAbs()) || jet.empty()) && (i >= 0 && i < MAX_JETS_IN)) {
0152 m_inputTauJets.at(i) = jet;
0153 }
0154 }
0155
0156 void L1GctJetFinalStage::storeJets(JetVector& storageVector, const JetVector& jets, unsigned short iWheel) {
0157 for (unsigned short iJet = 0; iJet < L1GctWheelJetFpga::MAX_JETS_OUT; ++iJet) {
0158 if (jets.at(iJet).bx() == bxAbs()) {
0159 storageVector.at((iWheel * L1GctWheelJetFpga::MAX_JETS_OUT) + iJet) = jets.at(iJet);
0160 }
0161 }
0162 }