CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/L1Trigger/GlobalCaloTrigger/src/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 "L1Trigger/GlobalCaloTrigger/interface/L1GctJetFinderBase.h"
00006 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetLeafCard.h"
00007 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetSorter.h"
00008 
00009 //DEFINE STATICS
00010 const int L1GctWheelJetFpga::MAX_JETS_OUT = 4;
00011 const unsigned int L1GctWheelJetFpga::MAX_LEAF_CARDS = 3;
00012 const unsigned int L1GctWheelJetFpga::MAX_JETS_PER_LEAF = L1GctJetLeafCard::MAX_JET_FINDERS * L1GctJetFinderBase::MAX_JETS_OUT;
00013 const int L1GctWheelJetFpga::MAX_JETS_IN = L1GctWheelJetFpga::MAX_LEAF_CARDS * L1GctWheelJetFpga::MAX_JETS_PER_LEAF;
00014 
00015 L1GctWheelJetFpga::L1GctWheelJetFpga(int id,
00016                                      std::vector<L1GctJetLeafCard*> inputLeafCards) :
00017   L1GctProcessor(),
00018   m_id(id),
00019   m_inputLeafCards(inputLeafCards),
00020   m_centralJetSorter(new L1GctJetSorter()),
00021   m_forwardJetSorter(new L1GctJetSorter()),
00022   m_tauJetSorter(new L1GctJetSorter()),
00023   m_inputJets(MAX_JETS_IN),
00024   m_rawCentralJets(MAX_JETS_IN),
00025   m_rawForwardJets(MAX_JETS_IN),
00026   m_rawTauJets(MAX_JETS_IN),
00027   m_inputHx(MAX_LEAF_CARDS),
00028   m_inputHy(MAX_LEAF_CARDS),
00029   m_inputHfSums(MAX_LEAF_CARDS),
00030   m_centralJets(MAX_JETS_OUT),
00031   m_forwardJets(MAX_JETS_OUT),
00032   m_tauJets(MAX_JETS_OUT),
00033   m_outputHx(0), m_outputHy(0), m_outputHfSums(),
00034   m_outputHxPipe(), m_outputHyPipe()
00035 {
00036   if (checkSetup()) {
00037 
00038     setupJetsVectors(0);  //Initialises all the jet vectors with jets of the correct type.
00039 
00040   } else {
00041     if (m_verbose) {
00042       edm::LogError("L1GctSetupError") << "L1GctWheelJetFpga has been incorrectly constructed";
00043     }
00044   }
00045 }
00046 
00047 bool L1GctWheelJetFpga::checkSetup() const
00048 {
00049   bool result=true;
00050   
00051   //Check object construction is ok
00052   if(m_id < 0 || m_id > 1)
00053     {
00054       result = false;
00055       if (m_verbose) {
00056         edm::LogWarning("L1GctSetupError")
00057           << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id << " has been incorrectly constructed!\n"
00058           << "ID number should be between the range of 0 to 1\n";
00059       }
00060     } 
00061   
00062   if(m_inputLeafCards.size() != MAX_LEAF_CARDS)
00063     {
00064       result = false;
00065       if (m_verbose) {
00066         edm::LogWarning("L1GctSetupError")
00067           << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id << " has been incorrectly constructed!\n"
00068           << "This class needs " << MAX_LEAF_CARDS << " jet leaf card pointers, yet only " << m_inputLeafCards.size()
00069           << " leaf card pointers are present.\n";
00070       }
00071     }
00072   
00073   for(unsigned int i = 0; i < MAX_LEAF_CARDS; ++i)
00074     {
00075       if(m_inputLeafCards.at(i) == 0)
00076         {
00077           result = false;
00078           if (m_verbose) {
00079             edm::LogWarning("L1GctSetupError")
00080               << "L1GctWheelJetFpga::L1GctWheelJetFpga() : Wheel Jet FPGA ID " << m_id << " has been incorrectly constructed!\n"
00081               << "Leaf card pointer " << i << " has not been set!\n";
00082           }
00083         }
00084     }
00085   return result;
00086 }
00087 
00088 L1GctWheelJetFpga::~L1GctWheelJetFpga()
00089 {
00090   if (m_centralJetSorter != 0) delete m_centralJetSorter;
00091   if (m_forwardJetSorter != 0) delete m_forwardJetSorter;
00092   if (m_tauJetSorter != 0)     delete m_tauJetSorter;
00093 }
00094 
00095 std::ostream& operator << (std::ostream& os, const L1GctWheelJetFpga& fpga)
00096 {
00097   using std::endl;
00098   os << "===L1GctWheelJetFPGA===" << endl;
00099   os << "ID = " << fpga.m_id << endl;
00100   os << "No of Input Leaf Cards " << fpga.m_inputLeafCards.size() << endl;
00101   for(unsigned i=0; i < fpga.m_inputLeafCards.size(); i++)
00102     {
00103       os << "InputLeafCard* " << i << " = " << fpga.m_inputLeafCards.at(i) << endl;
00104     } 
00105 //   os << "No. of Input Jets " << fpga.m_inputJets.size() << endl;
00106 //   for(unsigned i=0; i < fpga.m_inputJets.size(); i++)
00107 //     {
00108 //       os << fpga.m_inputJets.at(i);
00109 //     } 
00110 //   os << "No. of raw central Jets " << fpga.m_rawCentralJets.size() << endl;
00111 //   for(unsigned i=0; i < fpga.m_rawCentralJets.size(); i++)
00112 //     {
00113 //       os << fpga.m_rawCentralJets.at(i);
00114 //     } 
00115 //   os << "No. of raw forward Jets " << fpga.m_rawForwardJets.size() << endl;
00116 //   for(unsigned i=0; i < fpga.m_rawForwardJets.size(); i++)
00117 //     {
00118 //       os << fpga.m_rawForwardJets.at(i);
00119 //     } 
00120 //   os << "No. of raw tau Jets " << fpga.m_rawTauJets.size() << endl;
00121 //   for(unsigned i=0; i < fpga.m_rawTauJets.size(); i++)
00122 //     {
00123 //       os << fpga.m_rawTauJets.at(i);
00124 //     } 
00125 //   os << "No. of output central Jets " << fpga.m_centralJets.size() << endl;
00126 //   for(unsigned i=0; i < fpga.m_centralJets.size(); i++)
00127 //     {
00128 //       os << fpga.m_centralJets.at(i);
00129 //     } 
00130 //   os << "No. of output forward Jets " << fpga.m_forwardJets.size() << endl;
00131 //   for(unsigned i=0; i < fpga.m_forwardJets.size(); i++)
00132 //     {
00133 //       os << fpga.m_forwardJets.at(i);
00134 //     } 
00135 //   os << "No. of output tau Jets " << fpga.m_tauJets.size() << endl;
00136 //   for(unsigned i=0; i < fpga.m_tauJets.size(); i++)
00137 //     {
00138 //       os << fpga.m_tauJets.at(i);
00139 //     }
00140   os << endl;
00141   return os;
00142 }       
00143 
00144 void L1GctWheelJetFpga::resetProcessor()
00145 {
00146   for (unsigned int i=0; i<MAX_LEAF_CARDS; ++i)
00147   {
00148     m_inputHx.at(i).reset();
00149     m_inputHy.at(i).reset();
00150     m_inputHfSums.at(i).reset();
00151   }
00152   m_outputHx.reset();
00153   m_outputHy.reset();
00154   m_outputHfSums.reset();
00155 }
00156 
00157 void L1GctWheelJetFpga::setupObjects()
00158 {
00159   setupJetsVectors(static_cast<int16_t>(bxAbs()));
00160 }
00161 
00162 void L1GctWheelJetFpga::resetPipelines()
00163 {
00164   m_outputHxPipe.reset(numOfBx());
00165   m_outputHyPipe.reset(numOfBx());
00166 }
00167 
00168 void L1GctWheelJetFpga::fetchInput()
00169 {
00170   if (checkSetup()) {
00171     //Get Jets
00172     for(unsigned short iLeaf = 0; iLeaf < MAX_LEAF_CARDS; ++iLeaf)
00173       {
00174         if (m_inputLeafCards.at(iLeaf) != 0) {  //check that the pointers have been set up!
00175 
00176           storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsA(), iLeaf, 0);
00177           storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsB(), iLeaf, L1GctJetFinderBase::MAX_JETS_OUT);
00178           storeJets(m_inputLeafCards.at(iLeaf)->getOutputJetsC(), iLeaf, 2*L1GctJetFinderBase::MAX_JETS_OUT);
00179         
00180           // Deal with the Ht inputs
00181           m_inputHx.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHx();
00182           m_inputHy.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHy();
00183 
00184           // Deal with the Hf tower sum inputs
00185           m_inputHfSums.at(iLeaf) = m_inputLeafCards.at(iLeaf)->getOutputHfSums();
00186         }
00187       }
00188   }
00189 }
00190 
00191 void L1GctWheelJetFpga::process()
00192 {
00193   if (checkSetup()) {
00194     classifyJets();
00195 
00196     m_centralJetSorter->setJets(m_rawCentralJets);
00197     m_forwardJetSorter->setJets(m_rawForwardJets);
00198     m_tauJetSorter->setJets(m_rawTauJets);
00199 
00200     m_rawCentralJets = m_centralJetSorter->getSortedJets();
00201     m_rawForwardJets = m_forwardJetSorter->getSortedJets();
00202     m_rawTauJets     = m_tauJetSorter->getSortedJets();
00203 
00204     for(unsigned short iJet = 0; iJet < MAX_JETS_OUT; ++iJet)
00205       {
00206         m_centralJets.at(iJet) = m_rawCentralJets.at(iJet);
00207         m_forwardJets.at(iJet) = m_rawForwardJets.at(iJet);
00208         m_tauJets.at(iJet) = m_rawTauJets.at(iJet);
00209       }
00210 
00211     //Ht processing
00212     m_outputHx = m_inputHx.at(0) + m_inputHx.at(1) + m_inputHx.at(2);
00213     m_outputHy = m_inputHy.at(0) + m_inputHy.at(1) + m_inputHy.at(2);
00214 
00215     //Hf tower sums processing
00216     m_outputHfSums = m_inputHfSums.at(0) + m_inputHfSums.at(1) + m_inputHfSums.at(2);
00217 
00218     m_outputHxPipe.store( m_outputHx, bxRel());
00219     m_outputHyPipe.store( m_outputHy, bxRel());
00220   }
00221     
00222 }
00223 
00224 void L1GctWheelJetFpga::setInputJet(int i, L1GctJetCand jet)
00225 {
00226   if(i >=0 && i < MAX_JETS_IN)
00227     {
00228       m_inputJets.at(i) =  jet;
00229     }
00230   else
00231     {
00232       if (m_verbose) {
00233         edm::LogError("L1GctInputError")
00234           << "L1GctWheelJetFpga::setInputJet() : In WheelJetFpga ID  " << m_id << ", inputted jet candidate " 
00235           << i << " is outside input index range of 0 to " << (MAX_JETS_IN-1) << "\n";
00236       }
00237     }
00238 }
00239 
00241 std::vector< L1GctInternHtMiss > L1GctWheelJetFpga::getInternalHtMiss() const
00242 {
00243 
00244   std::vector< L1GctInternHtMiss > result;
00245   for (int bx=0; bx<numOfBx(); bx++) {
00246     result.push_back( L1GctInternHtMiss::emulatorMissHtx( m_outputHxPipe.contents.at(bx).value(),
00247                                                           m_outputHxPipe.contents.at(bx).overFlow(),
00248                                                           static_cast<int16_t> (bx-bxMin()) ) );
00249     result.push_back( L1GctInternHtMiss::emulatorMissHty( m_outputHyPipe.contents.at(bx).value(),
00250                                                           m_outputHyPipe.contents.at(bx).overFlow(),
00251                                                           static_cast<int16_t> (bx-bxMin()) ) );
00252   }
00253   return result;
00254 }
00255 
00256 void L1GctWheelJetFpga::storeJets(JetVector jets, unsigned short iLeaf, unsigned short offset)
00257 {
00258   for(unsigned short iJet = 0; iJet < L1GctJetFinderBase::MAX_JETS_OUT; ++iJet)
00259     {
00260       m_inputJets.at(iLeaf*MAX_JETS_PER_LEAF + offset + iJet) = jets.at(iJet);
00261     }
00262 }
00263 
00264 void L1GctWheelJetFpga::classifyJets()
00265 {
00266   JetVector::iterator currentJet;  
00267   
00268   unsigned short pos=0;
00269   // In the case of two jets of equal rank, the sort will take the lower priority.
00270   // This corresponds to the lower position in the array. In order to mimic the hardware
00271   // behaviour, the order of jets from the input leaf cards is maintained here.
00272   for(currentJet = m_inputJets.begin(); currentJet != m_inputJets.end(); ++currentJet, ++pos)
00273     {
00274       if (!currentJet->empty()) {
00275         if(currentJet->isForward())  //forward jet
00276           {
00277             m_rawForwardJets.at(pos) = *currentJet;
00278           }
00279         else
00280           {
00281             if(currentJet->isCentral())  //central non-tau jet.
00282               {
00283                 m_rawCentralJets.at(pos) = *currentJet;
00284               }
00285             else  //must be central tau-jet
00286               {
00287                 if(currentJet->isTau())
00288                   {
00289                     m_rawTauJets.at(pos) = *currentJet;
00290                   }
00291                 else
00292                   { //shouldn't get here!
00293                     if (m_verbose) {
00294                       edm::LogWarning("L1GctProcessingError")
00295                         << "Unclassified jet found by WheelJetFpga id " << m_id
00296                         << ". Jet details follow." << std::endl << *currentJet << std::endl;
00297                     }
00298                   }
00299               }
00300           }
00301       }
00302     }
00303 }
00304 
00305 void L1GctWheelJetFpga::setupJetsVectors(const int16_t bx)
00306 {
00307   // Create empty jet candidates with the three different combinations
00308   // of flags, corresponding to central, forward and tau jets
00309   L1GctJetCand tempCen(0, 0, 0, false, false, (uint16_t) 0, (uint16_t) 0, bx);
00310   L1GctJetCand tempTau(0, 0, 0, true,  false, (uint16_t) 0, (uint16_t) 0, bx);
00311   L1GctJetCand tempFwd(0, 0, 0, false, true,  (uint16_t) 0, (uint16_t) 0, bx);
00312 
00313   // Initialize the jet vectors with copies of the appropriate empty jet type
00314   m_rawCentralJets.assign(MAX_JETS_IN, tempCen);
00315   m_rawTauJets.assign    (MAX_JETS_IN, tempTau);
00316   m_rawForwardJets.assign(MAX_JETS_IN, tempFwd);
00317 
00318   m_centralJets.assign(MAX_JETS_OUT, tempCen);
00319   m_tauJets.assign    (MAX_JETS_OUT, tempTau);
00320   m_forwardJets.assign(MAX_JETS_OUT, tempFwd);
00321 }