Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:53

0001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetFinderBase.h"
0006 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetLeafCard.h"
0007 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetSorter.h"
0008 
0009 //DEFINE STATICS
0010 const int L1GctWheelJetFpga::MAX_JETS_OUT = 4;
0011 const unsigned int L1GctWheelJetFpga::MAX_LEAF_CARDS = 3;
0012 const unsigned int L1GctWheelJetFpga::MAX_JETS_PER_LEAF =
0013     L1GctJetLeafCard::MAX_JET_FINDERS * L1GctJetFinderBase::MAX_JETS_OUT;
0014 const int L1GctWheelJetFpga::MAX_JETS_IN = L1GctWheelJetFpga::MAX_LEAF_CARDS * L1GctWheelJetFpga::MAX_JETS_PER_LEAF;
0015 
0016 L1GctWheelJetFpga::L1GctWheelJetFpga(int id, const std::vector<L1GctJetLeafCard*>& inputLeafCards)
0017     : L1GctProcessor(),
0018       m_id(id),
0019       m_inputLeafCards(inputLeafCards),
0020       m_centralJetSorter(new L1GctJetSorter()),
0021       m_forwardJetSorter(new L1GctJetSorter()),
0022       m_tauJetSorter(new L1GctJetSorter()),
0023       m_inputJets(MAX_JETS_IN),
0024       m_rawCentralJets(MAX_JETS_IN),
0025       m_rawForwardJets(MAX_JETS_IN),
0026       m_rawTauJets(MAX_JETS_IN),
0027       m_inputHx(MAX_LEAF_CARDS),
0028       m_inputHy(MAX_LEAF_CARDS),
0029       m_inputHfSums(MAX_LEAF_CARDS),
0030       m_centralJets(MAX_JETS_OUT),
0031       m_forwardJets(MAX_JETS_OUT),
0032       m_tauJets(MAX_JETS_OUT),
0033       m_outputHx(0),
0034       m_outputHy(0),
0035       m_outputHfSums(),
0036       m_outputHxPipe(),
0037       m_outputHyPipe() {
0038   if (checkSetup()) {
0039     setupJetsVectors(0);  //Initialises all the jet vectors with jets of the correct type.
0040 
0041   } else {
0042     if (m_verbose) {
0043       edm::LogError("L1GctSetupError") << "L1GctWheelJetFpga has been incorrectly constructed";
0044     }
0045   }
0046 }
0047 
0048 bool L1GctWheelJetFpga::checkSetup() const {
0049   bool result = true;
0050 
0051   //Check object construction is ok
0052   if (m_id < 0 || m_id > 1) {
0053     result = false;
0054     if (m_verbose) {
0055       edm::LogWarning("L1GctSetupError") << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id
0056                                          << " has been incorrectly constructed!\n"
0057                                          << "ID number should be between the range of 0 to 1\n";
0058     }
0059   }
0060 
0061   if (m_inputLeafCards.size() != MAX_LEAF_CARDS) {
0062     result = false;
0063     if (m_verbose) {
0064       edm::LogWarning("L1GctSetupError") << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id
0065                                          << " has been incorrectly constructed!\n"
0066                                          << "This class needs " << MAX_LEAF_CARDS
0067                                          << " jet leaf card pointers, yet only " << m_inputLeafCards.size()
0068                                          << " leaf card pointers are present.\n";
0069     }
0070   }
0071 
0072   for (unsigned int i = 0; i < MAX_LEAF_CARDS; ++i) {
0073     if (m_inputLeafCards.at(i) == nullptr) {
0074       result = false;
0075       if (m_verbose) {
0076         edm::LogWarning("L1GctSetupError") << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id
0077                                            << " has been incorrectly constructed!\n"
0078                                            << "Leaf card pointer " << i << " has not been set!\n";
0079       }
0080     }
0081   }
0082   return result;
0083 }
0084 
0085 L1GctWheelJetFpga::~L1GctWheelJetFpga() {
0086   if (m_centralJetSorter != nullptr)
0087     delete m_centralJetSorter;
0088   if (m_forwardJetSorter != nullptr)
0089     delete m_forwardJetSorter;
0090   if (m_tauJetSorter != nullptr)
0091     delete m_tauJetSorter;
0092 }
0093 
0094 std::ostream& operator<<(std::ostream& os, const L1GctWheelJetFpga& fpga) {
0095   using std::endl;
0096   os << "===L1GctWheelJetFPGA===" << endl;
0097   os << "ID = " << fpga.m_id << endl;
0098   os << "No of Input Leaf Cards " << fpga.m_inputLeafCards.size() << endl;
0099   for (unsigned i = 0; i < fpga.m_inputLeafCards.size(); i++) {
0100     os << "InputLeafCard* " << i << " = " << fpga.m_inputLeafCards.at(i) << endl;
0101   }
0102   //   os << "No. of Input Jets " << fpga.m_inputJets.size() << endl;
0103   //   for(unsigned i=0; i < fpga.m_inputJets.size(); i++)
0104   //     {
0105   //       os << fpga.m_inputJets.at(i);
0106   //     }
0107   //   os << "No. of raw central Jets " << fpga.m_rawCentralJets.size() << endl;
0108   //   for(unsigned i=0; i < fpga.m_rawCentralJets.size(); i++)
0109   //     {
0110   //       os << fpga.m_rawCentralJets.at(i);
0111   //     }
0112   //   os << "No. of raw forward Jets " << fpga.m_rawForwardJets.size() << endl;
0113   //   for(unsigned i=0; i < fpga.m_rawForwardJets.size(); i++)
0114   //     {
0115   //       os << fpga.m_rawForwardJets.at(i);
0116   //     }
0117   //   os << "No. of raw tau Jets " << fpga.m_rawTauJets.size() << endl;
0118   //   for(unsigned i=0; i < fpga.m_rawTauJets.size(); i++)
0119   //     {
0120   //       os << fpga.m_rawTauJets.at(i);
0121   //     }
0122   //   os << "No. of output central Jets " << fpga.m_centralJets.size() << endl;
0123   //   for(unsigned i=0; i < fpga.m_centralJets.size(); i++)
0124   //     {
0125   //       os << fpga.m_centralJets.at(i);
0126   //     }
0127   //   os << "No. of output forward Jets " << fpga.m_forwardJets.size() << endl;
0128   //   for(unsigned i=0; i < fpga.m_forwardJets.size(); i++)
0129   //     {
0130   //       os << fpga.m_forwardJets.at(i);
0131   //     }
0132   //   os << "No. of output tau Jets " << fpga.m_tauJets.size() << endl;
0133   //   for(unsigned i=0; i < fpga.m_tauJets.size(); i++)
0134   //     {
0135   //       os << fpga.m_tauJets.at(i);
0136   //     }
0137   os << endl;
0138   return os;
0139 }
0140 
0141 void L1GctWheelJetFpga::resetProcessor() {
0142   for (unsigned int i = 0; i < MAX_LEAF_CARDS; ++i) {
0143     m_inputHx.at(i).reset();
0144     m_inputHy.at(i).reset();
0145     m_inputHfSums.at(i).reset();
0146   }
0147   m_outputHx.reset();
0148   m_outputHy.reset();
0149   m_outputHfSums.reset();
0150 }
0151 
0152 void L1GctWheelJetFpga::setupObjects() { setupJetsVectors(static_cast<int16_t>(bxAbs())); }
0153 
0154 void L1GctWheelJetFpga::resetPipelines() {
0155   m_outputHxPipe.reset(numOfBx());
0156   m_outputHyPipe.reset(numOfBx());
0157 }
0158 
0159 void L1GctWheelJetFpga::fetchInput() {
0160   if (checkSetup()) {
0161     //Get Jets
0162     for (unsigned short iLeaf = 0; iLeaf < MAX_LEAF_CARDS; ++iLeaf) {
0163       if (m_inputLeafCards.at(iLeaf) != nullptr) {  //check that the pointers have been set up!
0164 
0165         storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsA(), iLeaf, 0);
0166         storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsB(), iLeaf, L1GctJetFinderBase::MAX_JETS_OUT);
0167         storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsC(), iLeaf, 2 * L1GctJetFinderBase::MAX_JETS_OUT);
0168 
0169         // Deal with the Ht inputs
0170         m_inputHx.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHx();
0171         m_inputHy.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHy();
0172 
0173         // Deal with the Hf tower sum inputs
0174         m_inputHfSums.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHfSums();
0175       }
0176     }
0177   }
0178 }
0179 
0180 void L1GctWheelJetFpga::process() {
0181   if (checkSetup()) {
0182     classifyJets();
0183 
0184     m_centralJetSorter->setJets(m_rawCentralJets);
0185     m_forwardJetSorter->setJets(m_rawForwardJets);
0186     m_tauJetSorter->setJets(m_rawTauJets);
0187 
0188     m_rawCentralJets = m_centralJetSorter->getSortedJets();
0189     m_rawForwardJets = m_forwardJetSorter->getSortedJets();
0190     m_rawTauJets = m_tauJetSorter->getSortedJets();
0191 
0192     for (unsigned short iJet = 0; iJet < MAX_JETS_OUT; ++iJet) {
0193       m_centralJets.at(iJet) = m_rawCentralJets.at(iJet);
0194       m_forwardJets.at(iJet) = m_rawForwardJets.at(iJet);
0195       m_tauJets.at(iJet) = m_rawTauJets.at(iJet);
0196     }
0197 
0198     //Ht processing
0199     m_outputHx = m_inputHx.at(0) + m_inputHx.at(1) + m_inputHx.at(2);
0200     m_outputHy = m_inputHy.at(0) + m_inputHy.at(1) + m_inputHy.at(2);
0201 
0202     //Hf tower sums processing
0203     m_outputHfSums = m_inputHfSums.at(0) + m_inputHfSums.at(1) + m_inputHfSums.at(2);
0204 
0205     m_outputHxPipe.store(m_outputHx, bxRel());
0206     m_outputHyPipe.store(m_outputHy, bxRel());
0207   }
0208 }
0209 
0210 void L1GctWheelJetFpga::setInputJet(int i, const L1GctJetCand& jet) {
0211   if (i >= 0 && i < MAX_JETS_IN) {
0212     m_inputJets.at(i) = jet;
0213   } else {
0214     if (m_verbose) {
0215       edm::LogError("L1GctInputError") << "L1GctWheelJetFpga::setInputJet() : In WheelJetFpga ID  " << m_id
0216                                        << ", inputted jet candidate " << i << " is outside input index range of 0 to "
0217                                        << (MAX_JETS_IN - 1) << "\n";
0218     }
0219   }
0220 }
0221 
0222 /// get the Et sums in internal component format
0223 std::vector<L1GctInternHtMiss> L1GctWheelJetFpga::getInternalHtMiss() const {
0224   std::vector<L1GctInternHtMiss> result;
0225   for (int bx = 0; bx < numOfBx(); bx++) {
0226     result.push_back(L1GctInternHtMiss::emulatorMissHtx(m_outputHxPipe.contents.at(bx).value(),
0227                                                         m_outputHxPipe.contents.at(bx).overFlow(),
0228                                                         static_cast<int16_t>(bx - bxMin())));
0229     result.push_back(L1GctInternHtMiss::emulatorMissHty(m_outputHyPipe.contents.at(bx).value(),
0230                                                         m_outputHyPipe.contents.at(bx).overFlow(),
0231                                                         static_cast<int16_t>(bx - bxMin())));
0232   }
0233   return result;
0234 }
0235 
0236 void L1GctWheelJetFpga::storeJets(const JetVector& jets, unsigned short iLeaf, unsigned short offset) {
0237   for (unsigned short iJet = 0; iJet < L1GctJetFinderBase::MAX_JETS_OUT; ++iJet) {
0238     m_inputJets.at(iLeaf * MAX_JETS_PER_LEAF + offset + iJet) = jets.at(iJet);
0239   }
0240 }
0241 
0242 void L1GctWheelJetFpga::classifyJets() {
0243   JetVector::iterator currentJet;
0244 
0245   unsigned short pos = 0;
0246   // In the case of two jets of equal rank, the sort will take the lower priority.
0247   // This corresponds to the lower position in the array. In order to mimic the hardware
0248   // behaviour, the order of jets from the input leaf cards is maintained here.
0249   for (currentJet = m_inputJets.begin(); currentJet != m_inputJets.end(); ++currentJet, ++pos) {
0250     if (!currentJet->empty()) {
0251       if (currentJet->isForward())  //forward jet
0252       {
0253         m_rawForwardJets.at(pos) = *currentJet;
0254       } else {
0255         if (currentJet->isCentral())  //central non-tau jet.
0256         {
0257           m_rawCentralJets.at(pos) = *currentJet;
0258         } else  //must be central tau-jet
0259         {
0260           if (currentJet->isTau()) {
0261             m_rawTauJets.at(pos) = *currentJet;
0262           } else {  //shouldn't get here!
0263             if (m_verbose) {
0264               edm::LogWarning("L1GctProcessingError")
0265                   << "Unclassified jet found by WheelJetFpga id " << m_id << ". Jet details follow." << std::endl
0266                   << *currentJet << std::endl;
0267             }
0268           }
0269         }
0270       }
0271     }
0272   }
0273 }
0274 
0275 void L1GctWheelJetFpga::setupJetsVectors(const int16_t bx) {
0276   // Create empty jet candidates with the three different combinations
0277   // of flags, corresponding to central, forward and tau jets
0278   L1GctJetCand tempCen(0, 0, 0, false, false, (uint16_t)0, (uint16_t)0, bx);
0279   L1GctJetCand tempTau(0, 0, 0, true, false, (uint16_t)0, (uint16_t)0, bx);
0280   L1GctJetCand tempFwd(0, 0, 0, false, true, (uint16_t)0, (uint16_t)0, bx);
0281 
0282   // Initialize the jet vectors with copies of the appropriate empty jet type
0283   m_rawCentralJets.assign(MAX_JETS_IN, tempCen);
0284   m_rawTauJets.assign(MAX_JETS_IN, tempTau);
0285   m_rawForwardJets.assign(MAX_JETS_IN, tempFwd);
0286 
0287   m_centralJets.assign(MAX_JETS_OUT, tempCen);
0288   m_tauJets.assign(MAX_JETS_OUT, tempTau);
0289   m_forwardJets.assign(MAX_JETS_OUT, tempFwd);
0290 }