CMS 3D CMS Logo

L1GctWheelJetFpga.cc

Go to the documentation of this file.
00001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "CondFormats/L1TObjects/interface/L1GctJetCounterSetup.h"
00006 
00007 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctJetCounts.h"
00008 
00009 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetFinderBase.h"
00010 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetLeafCard.h"
00011 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetSorter.h"
00012 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetCounter.h"
00013 
00014 //DEFINE STATICS
00015 const int L1GctWheelJetFpga::MAX_JETS_OUT = 4;
00016 const unsigned int L1GctWheelJetFpga::MAX_LEAF_CARDS = 3;
00017 const unsigned int L1GctWheelJetFpga::MAX_JETS_PER_LEAF = L1GctJetLeafCard::MAX_JET_FINDERS * L1GctJetFinderBase::MAX_JETS_OUT;
00018 const int L1GctWheelJetFpga::MAX_JETS_IN = L1GctWheelJetFpga::MAX_LEAF_CARDS * L1GctWheelJetFpga::MAX_JETS_PER_LEAF;
00019 const unsigned int L1GctWheelJetFpga::N_JET_COUNTERS = std::min(L1GctJetCounterSetup::MAX_JET_COUNTERS,
00020                                                                 L1GctJetCounts::MAX_TRUE_COUNTS);
00021 
00022 
00023 L1GctWheelJetFpga::L1GctWheelJetFpga(int id,
00024                                      std::vector<L1GctJetLeafCard*> inputLeafCards) :
00025   L1GctProcessor(),
00026   m_id(id),
00027   m_inputLeafCards(inputLeafCards),
00028   m_centralJetSorter(new L1GctJetSorter()),
00029   m_forwardJetSorter(new L1GctJetSorter()),
00030   m_tauJetSorter(new L1GctJetSorter()),
00031   m_jetCounters(N_JET_COUNTERS),
00032   m_inputJets(MAX_JETS_IN),
00033   m_rawCentralJets(MAX_JETS_IN),
00034   m_rawForwardJets(MAX_JETS_IN),
00035   m_rawTauJets(MAX_JETS_IN),
00036   m_inputHt(MAX_LEAF_CARDS),
00037   m_inputHx(MAX_LEAF_CARDS),
00038   m_inputHy(MAX_LEAF_CARDS),
00039   m_inputHfSums(MAX_LEAF_CARDS),
00040   m_centralJets(MAX_JETS_OUT),
00041   m_forwardJets(MAX_JETS_OUT),
00042   m_tauJets(MAX_JETS_OUT),
00043   m_outputHt(0), m_outputHx(0), m_outputHy(0), m_outputHfSums(),
00044   m_outputJc(N_JET_COUNTERS)
00045 {
00046   if (checkSetup()) {
00047 
00048     setupJetsVectors(0);  //Initialises all the jet vectors with jets of the correct type.
00049 
00050     // Initalise the jetCounters with null jetCounterLuts
00051     for (unsigned int i=0; i < N_JET_COUNTERS; i++) {
00052       m_jetCounters.at(i) = new L1GctJetCounter(((100*m_id)+i), m_inputLeafCards);
00053     }
00054   } else {
00055     if (m_verbose) {
00056       edm::LogError("L1GctSetupError") << "L1GctWheelJetFpga has been incorrectly constructed";
00057     }
00058   }
00059 }
00060 
00061 bool L1GctWheelJetFpga::checkSetup() const
00062 {
00063   bool result=true;
00064   
00065   //Check object construction is ok
00066   if(m_id < 0 || m_id > 1)
00067     {
00068       result = false;
00069       if (m_verbose) {
00070         edm::LogWarning("L1GctSetupError")
00071           << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id << " has been incorrectly constructed!\n"
00072           << "ID number should be between the range of 0 to 1\n";
00073       }
00074     } 
00075   
00076   if(m_inputLeafCards.size() != MAX_LEAF_CARDS)
00077     {
00078       result = false;
00079       if (m_verbose) {
00080         edm::LogWarning("L1GctSetupError")
00081           << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id << " has been incorrectly constructed!\n"
00082           << "This class needs " << MAX_LEAF_CARDS << " jet leaf card pointers, yet only " << m_inputLeafCards.size()
00083           << " leaf card pointers are present.\n";
00084       }
00085     }
00086   
00087   for(unsigned int i = 0; i < MAX_LEAF_CARDS; ++i)
00088     {
00089       if(m_inputLeafCards.at(i) == 0)
00090         {
00091           result = false;
00092           if (m_verbose) {
00093             edm::LogWarning("L1GctSetupError")
00094               << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id << " has been incorrectly constructed!\n"
00095               << "Leaf card pointer " << i << " has not been set!\n";
00096           }
00097         }
00098     }
00099   for (unsigned i=0; i < N_JET_COUNTERS; i++) {
00100     if (m_jetCounters.at(i) != 0) result &= m_jetCounters.at(i)->setupOk();
00101   } 
00102   return result;
00103 }
00104 
00105 L1GctWheelJetFpga::~L1GctWheelJetFpga()
00106 {
00107   if (m_centralJetSorter != 0) delete m_centralJetSorter;
00108   if (m_forwardJetSorter != 0) delete m_forwardJetSorter;
00109   if (m_tauJetSorter != 0)     delete m_tauJetSorter;
00110   for (unsigned int i=0; i < N_JET_COUNTERS; i++) {
00111     if (m_jetCounters.at(i) != 0) delete m_jetCounters.at(i);
00112   }
00113 }
00114 
00115 std::ostream& operator << (std::ostream& os, const L1GctWheelJetFpga& fpga)
00116 {
00117   using std::endl;
00118   os << "===L1GctWheelJetFPGA===" << endl;
00119   os << "ID = " << fpga.m_id << endl;
00120   os << "No of Input Leaf Cards " << fpga.m_inputLeafCards.size() << endl;
00121   for(unsigned i=0; i < fpga.m_inputLeafCards.size(); i++)
00122     {
00123       os << "InputLeafCard* " << i << " = " << fpga.m_inputLeafCards.at(i) << endl;
00124     } 
00125 //   os << "No. of Input Jets " << fpga.m_inputJets.size() << endl;
00126 //   for(unsigned i=0; i < fpga.m_inputJets.size(); i++)
00127 //     {
00128 //       os << fpga.m_inputJets.at(i);
00129 //     } 
00130   os << "Input Ht " << endl;
00131   for(unsigned i=0; i < fpga.m_inputHt.size(); i++)
00132     {
00133       os << (fpga.m_inputHt.at(i)) << endl;
00134     } 
00135 //   os << "No. of raw central Jets " << fpga.m_rawCentralJets.size() << endl;
00136 //   for(unsigned i=0; i < fpga.m_rawCentralJets.size(); i++)
00137 //     {
00138 //       os << fpga.m_rawCentralJets.at(i);
00139 //     } 
00140 //   os << "No. of raw forward Jets " << fpga.m_rawForwardJets.size() << endl;
00141 //   for(unsigned i=0; i < fpga.m_rawForwardJets.size(); i++)
00142 //     {
00143 //       os << fpga.m_rawForwardJets.at(i);
00144 //     } 
00145 //   os << "No. of raw tau Jets " << fpga.m_rawTauJets.size() << endl;
00146 //   for(unsigned i=0; i < fpga.m_rawTauJets.size(); i++)
00147 //     {
00148 //       os << fpga.m_rawTauJets.at(i);
00149 //     } 
00150   os << "Output Ht " << fpga.m_outputHt << endl;
00151   os << "Output Jet count " << endl;
00152   for(unsigned i=0; i < fpga.m_outputJc.size(); i++)
00153     {
00154       os << "Jet count " << i << ": " << fpga.m_outputJc.at(i) << endl;
00155     } 
00156 //   os << "No. of output central Jets " << fpga.m_centralJets.size() << endl;
00157 //   for(unsigned i=0; i < fpga.m_centralJets.size(); i++)
00158 //     {
00159 //       os << fpga.m_centralJets.at(i);
00160 //     } 
00161 //   os << "No. of output forward Jets " << fpga.m_forwardJets.size() << endl;
00162 //   for(unsigned i=0; i < fpga.m_forwardJets.size(); i++)
00163 //     {
00164 //       os << fpga.m_forwardJets.at(i);
00165 //     } 
00166 //   os << "No. of output tau Jets " << fpga.m_tauJets.size() << endl;
00167 //   for(unsigned i=0; i < fpga.m_tauJets.size(); i++)
00168 //     {
00169 //       os << fpga.m_tauJets.at(i);
00170 //     }
00171   os << "Jet counters:" << endl; 
00172   for (unsigned int i=0; i < L1GctWheelJetFpga::N_JET_COUNTERS; i++) {
00173     os << *fpga.m_jetCounters.at(i) << endl;
00174   }
00175   os << endl;
00176   return os;
00177 }       
00178 
00180 void L1GctWheelJetFpga::reset() {
00181   L1GctProcessor::reset();
00182   for (unsigned int i=0; i<N_JET_COUNTERS; ++i)
00183   {
00184     m_jetCounters.at(i)->reset();
00185   }
00186 }
00187 
00189 void L1GctWheelJetFpga::setBxRange(const int firstBx, const int numberOfBx) {
00190   L1GctProcessor::setBxRange(firstBx, numberOfBx);
00191   for (unsigned int i=0; i<N_JET_COUNTERS; ++i)
00192   {
00193     m_jetCounters.at(i)->setBxRange(firstBx, numberOfBx);
00194   }
00195 }
00196 
00197 void L1GctWheelJetFpga::setNextBx(const int bx) {
00198   L1GctProcessor::setNextBx(bx);
00199   for (unsigned int i=0; i<N_JET_COUNTERS; ++i)
00200   {
00201     m_jetCounters.at(i)->setNextBx(bx);
00202   }
00203 }
00204 
00205 void L1GctWheelJetFpga::resetProcessor()
00206 {
00207   for (unsigned int i=0; i<MAX_LEAF_CARDS; ++i)
00208   {
00209     m_inputHt.at(i).reset();
00210     m_inputHx.at(i).reset();
00211     m_inputHy.at(i).reset();
00212     m_inputHfSums.at(i).reset();
00213   }
00214   m_outputHt.reset();
00215   m_outputHx.reset();
00216   m_outputHy.reset();
00217   m_outputHfSums.reset();
00218   for (unsigned int i=0; i<N_JET_COUNTERS; ++i)
00219   {
00220     m_outputJc.at(i).reset();
00221   }
00222 }
00223 
00224 void L1GctWheelJetFpga::setupObjects()
00225 {
00226   setupJetsVectors(static_cast<int16_t>(bxAbs()));
00227 }
00228 
00229 void L1GctWheelJetFpga::fetchInput()
00230 {
00231   if (checkSetup()) {
00232     //Get Jets
00233     for(unsigned short iLeaf = 0; iLeaf < MAX_LEAF_CARDS; ++iLeaf)
00234       {
00235         if (m_inputLeafCards.at(iLeaf) != 0) {  //check that the pointers have been set up!
00236 
00237           storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsA(), iLeaf, 0);
00238           storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsB(), iLeaf, L1GctJetFinderBase::MAX_JETS_OUT);
00239           storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsC(), iLeaf, 2*L1GctJetFinderBase::MAX_JETS_OUT);
00240         
00241           // Deal with the Ht inputs
00242           m_inputHt.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHt();
00243           m_inputHx.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHx();
00244           m_inputHy.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHy();
00245 
00246           // Deal with the Hf tower sum inputs
00247           m_inputHfSums.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHfSums();
00248         }
00249       }
00250     // Deal with the jet counters
00251     for (unsigned int i=0; i<N_JET_COUNTERS; i++) {
00252       // m_jetCounters.at(i)->fetchInput();
00253       //==============================================
00254       // For efficiency, provide our own list of jets to 
00255       // all the jet counters instead of allowing them
00256       // to fetch the jets from the jetfinder outputs
00257 
00258       m_jetCounters.at(i)->setJets(m_inputJets);
00259 
00260       //==============================================
00261     }
00262   }
00263 }
00264 
00265 void L1GctWheelJetFpga::process()
00266 {
00267   if (checkSetup()) {
00268     classifyJets();
00269 
00270     m_centralJetSorter->setJets(m_rawCentralJets);
00271     m_forwardJetSorter->setJets(m_rawForwardJets);
00272     m_tauJetSorter->setJets(m_rawTauJets);
00273 
00274     m_rawCentralJets = m_centralJetSorter->getSortedJets();
00275     m_rawForwardJets = m_forwardJetSorter->getSortedJets();
00276     m_rawTauJets     = m_tauJetSorter->getSortedJets();
00277 
00278     for(unsigned short iJet = 0; iJet < MAX_JETS_OUT; ++iJet)
00279       {
00280         m_centralJets.at(iJet) = m_rawCentralJets.at(iJet);
00281         m_forwardJets.at(iJet) = m_rawForwardJets.at(iJet);
00282         m_tauJets.at(iJet) = m_rawTauJets.at(iJet);
00283       }
00284 
00285     //Ht processing
00286     m_outputHt = m_inputHt.at(0) + m_inputHt.at(1) + m_inputHt.at(2);
00287     m_outputHx = m_inputHx.at(0) + m_inputHx.at(1) + m_inputHx.at(2);
00288     m_outputHy = m_inputHy.at(0) + m_inputHy.at(1) + m_inputHy.at(2);
00289 
00290     //Hf tower sums processing
00291     m_outputHfSums = m_inputHfSums.at(0) + m_inputHfSums.at(1) + m_inputHfSums.at(2);
00292 
00293     //Jet count processing
00294     for (unsigned int i=0; i<N_JET_COUNTERS; i++) {
00295       m_jetCounters.at(i)->process();
00296       m_outputJc.at(i) = m_jetCounters.at(i)->getValue();
00297     }
00298   }
00299     
00300 }
00301 
00302 void L1GctWheelJetFpga::setInputJet(int i, L1GctJetCand jet)
00303 {
00304   if(i >=0 && i < MAX_JETS_IN)
00305     {
00306       m_inputJets.at(i) =  jet;
00307     }
00308   else
00309     {
00310       if (m_verbose) {
00311         edm::LogError("L1GctInputError")
00312           << "L1GctWheelJetFpga::setInputJet() : In WheelJetFpga ID  " << m_id << ", inputted jet candidate " 
00313           << i << " is outside input index range of 0 to " << (MAX_JETS_IN-1) << "\n";
00314       }
00315     }
00316 }
00317 
00318 void L1GctWheelJetFpga::setInputHt (int i, unsigned ht)
00319 {   
00320   if(i >= 0 && i < static_cast<int>(MAX_LEAF_CARDS))
00321     {
00322       m_inputHt.at(i).setValue(ht);
00323     }
00324   else
00325     {
00326       if (m_verbose) {
00327         edm::LogError("L1GctInputError")
00328           << "L1GctWheelJetFpga::setInputHt() : In WheelJetFpga ID  " << m_id << ", inputted Ht value " 
00329           << i << " is outside input index range of 0 to " << (MAX_LEAF_CARDS-1) << "\n";
00330       }
00331     }
00332 } 
00333 
00334 void L1GctWheelJetFpga::storeJets(JetVector jets, unsigned short iLeaf, unsigned short offset)
00335 {
00336   for(unsigned short iJet = 0; iJet < L1GctJetFinderBase::MAX_JETS_OUT; ++iJet)
00337     {
00338       m_inputJets.at(iLeaf*MAX_JETS_PER_LEAF + offset + iJet) = jets.at(iJet);
00339     }
00340 }
00341 
00342 void L1GctWheelJetFpga::classifyJets()
00343 {
00344   JetVector::iterator currentJet;  
00345   
00346   unsigned short pos=0;
00347   // In the case of two jets of equal rank, the sort will take the lower priority.
00348   // This corresponds to the lower position in the array. In order to mimic the hardware
00349   // behaviour, the order of jets from the input leaf cards is maintained here.
00350   for(currentJet = m_inputJets.begin(); currentJet != m_inputJets.end(); ++currentJet, ++pos)
00351     {
00352       if (!currentJet->empty()) {
00353         if(currentJet->isForward())  //forward jet
00354           {
00355             m_rawForwardJets.at(pos) = *currentJet;
00356           }
00357         else
00358           {
00359             if(currentJet->isCentral())  //central non-tau jet.
00360               {
00361                 m_rawCentralJets.at(pos) = *currentJet;
00362               }
00363             else  //must be central tau-jet
00364               {
00365                 if(currentJet->isTau())
00366                   {
00367                     m_rawTauJets.at(pos) = *currentJet;
00368                   }
00369                 else
00370                   { //shouldn't get here!
00371                     if (m_verbose) {
00372                       edm::LogWarning("L1GctProcessingError")
00373                         << "Unclassified jet found by WheelJetFpga id " << m_id
00374                         << ". Jet details follow." << std::endl << *currentJet << std::endl;
00375                     }
00376                   }
00377               }
00378           }
00379       }
00380     }
00381 }
00382 
00383 void L1GctWheelJetFpga::setupJetsVectors(const int16_t bx)
00384 {
00385   // Create empty jet candidates with the three different combinations
00386   // of flags, corresponding to central, forward and tau jets
00387   L1GctJetCand tempCen(0, 0, 0, false, false, (uint16_t) 0, (uint16_t) 0, bx);
00388   L1GctJetCand tempTau(0, 0, 0, true,  false, (uint16_t) 0, (uint16_t) 0, bx);
00389   L1GctJetCand tempFwd(0, 0, 0, false, true,  (uint16_t) 0, (uint16_t) 0, bx);
00390 
00391   // Initialize the jet vectors with copies of the appropriate empty jet type
00392   m_rawCentralJets.assign(MAX_JETS_IN, tempCen);
00393   m_rawTauJets.assign    (MAX_JETS_IN, tempTau);
00394   m_rawForwardJets.assign(MAX_JETS_IN, tempFwd);
00395 
00396   m_centralJets.assign(MAX_JETS_OUT, tempCen);
00397   m_tauJets.assign    (MAX_JETS_OUT, tempTau);
00398   m_forwardJets.assign(MAX_JETS_OUT, tempFwd);
00399 }

Generated on Tue Jun 9 17:40:11 2009 for CMSSW by  doxygen 1.5.4