CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/L1Trigger/GlobalCaloTrigger/src/L1GctElectronSorter.cc

Go to the documentation of this file.
00001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctElectronSorter.h"
00002 #include <algorithm>
00003 
00004 L1GctElectronSorter::L1GctElectronSorter(int nInputs, bool iso):
00005   L1GctProcessor(),
00006   m_id(nInputs),
00007   m_isolation(iso),
00008   m_inputCands(nInputs*4),
00009   m_outputCands(4)
00010 {}  
00011 
00012 L1GctElectronSorter::~L1GctElectronSorter()
00013 {
00014 }
00015 
00016 // clear buffers
00017 void L1GctElectronSorter::resetProcessor() {
00018   m_inputCands.clear();
00019   m_inputCands.resize(m_id*4);
00020 
00021   m_outputCands.clear();
00022   m_outputCands.resize(4);
00023 }
00024 
00028 void L1GctElectronSorter::setupObjects() {
00031   L1CaloEmCand temp;
00032   temp.setBx(bxAbs());
00033   m_inputCands.assign(m_id*4, temp);
00034 }
00035 
00036 // get the input data
00037 void L1GctElectronSorter::fetchInput() {
00038   // This does nothing, assume the input candidates get pushed in
00039 }
00040 
00041 //Process sorts the electron candidates after rank and stores the highest four (in the outputCands vector)
00042 void L1GctElectronSorter::process() {
00043 
00044   //Convert from caloEmCand to gctEmCand and make temporary copy of data
00045   std::vector<prioritisedEmCand> data(m_inputCands.size());
00046   // Assign a "priority" for sorting - this assumes the candidates
00047   // have already been filled in "priority order"
00048   for (unsigned i=0; i<m_inputCands.size(); i++) {
00049     prioritisedEmCand c(m_inputCands.at(i), i);
00050     data.at(i) = c;
00051   }
00052 
00053   //Then sort it
00054   sort(data.begin(),data.end(),rank_gt());
00055 
00056   //Copy data to output buffer
00057   for(int i = 0; i<4; i++){
00058     m_outputCands.at(i) = data.at(i).emCand;
00059   }
00060 }
00061 
00062 void L1GctElectronSorter::setInputEmCand(const L1CaloEmCand& cand){
00063   // Fills the candidates in "priority order"
00064   // The lowest numbered RCT crate in each FPGA has highest priority.
00065   // We distinguish the two FPGAs on a leaf card by the number of inputs.
00066   // FPGA U1 has 5 inputs (crates 4-8) and FPGA U2 has 4 inputs (crates 0-3).
00067   // Within a crate the four input candidates are arranged in the order
00068   // that they arrive on the cable, using the index() method.
00069   unsigned crate = cand.rctCrate();
00070   unsigned input = ( (m_id==4) ? (crate%9) : (crate%9 - 4) );
00071   unsigned i = input*4 + (3-cand.index());
00072   if (m_inputCands.at(i).rank()==0) {
00073     m_inputCands.at(i) = cand;
00074   }
00075 }
00076 
00077 std::ostream& operator<<(std::ostream& s, const L1GctElectronSorter& ems) {
00078   s << "===L1GctElectronSorter===" << std::endl;
00079   s << "Algo type = " << ems.m_isolation << std::endl;
00080   s << "No of Electron Input Candidates = " << ems.m_inputCands.size()<< std::endl;
00081   s << "No of Electron Output Candidates = " << ems.m_outputCands.size()<< std::endl;
00082   return s;
00083 }
00084