Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctElectronSorter.h"
0002 #include <algorithm>
0003 
0004 L1GctElectronSorter::L1GctElectronSorter(int nInputs, bool iso)
0005     : L1GctProcessor(), m_id(nInputs), m_isolation(iso), m_inputCands(nInputs * 4), m_outputCands(4) {}
0006 
0007 L1GctElectronSorter::~L1GctElectronSorter() {}
0008 
0009 // clear buffers
0010 void L1GctElectronSorter::resetProcessor() {
0011   m_inputCands.clear();
0012   m_inputCands.resize(m_id * 4);
0013 
0014   m_outputCands.clear();
0015   m_outputCands.resize(4);
0016 }
0017 
0018 /// Initialise inputs with null objects for the correct bunch crossing
0019 /// If no other input candidates "arrive", we have the correct
0020 /// bunch crossing to propagate through the processing.
0021 void L1GctElectronSorter::setupObjects() {
0022   /// Create a null input electron with the right bunch crossing,
0023   /// and fill the input candidates with copies of this.
0024   L1CaloEmCand temp;
0025   temp.setBx(bxAbs());
0026   m_inputCands.assign(m_id * 4, temp);
0027 }
0028 
0029 // get the input data
0030 void L1GctElectronSorter::fetchInput() {
0031   // This does nothing, assume the input candidates get pushed in
0032 }
0033 
0034 //Process sorts the electron candidates after rank and stores the highest four (in the outputCands vector)
0035 void L1GctElectronSorter::process() {
0036   //Convert from caloEmCand to gctEmCand and make temporary copy of data
0037   std::vector<prioritisedEmCand> data(m_inputCands.size());
0038   // Assign a "priority" for sorting - this assumes the candidates
0039   // have already been filled in "priority order"
0040   for (unsigned i = 0; i < m_inputCands.size(); i++) {
0041     prioritisedEmCand c(m_inputCands.at(i), i);
0042     data.at(i) = c;
0043   }
0044 
0045   //Then sort it
0046   sort(data.begin(), data.end(), rankByGt);
0047 
0048   //Copy data to output buffer
0049   for (int i = 0; i < 4; i++) {
0050     m_outputCands.at(i) = data.at(i).emCand;
0051   }
0052 }
0053 
0054 void L1GctElectronSorter::setInputEmCand(const L1CaloEmCand& cand) {
0055   // Fills the candidates in "priority order"
0056   // The lowest numbered RCT crate in each FPGA has highest priority.
0057   // We distinguish the two FPGAs on a leaf card by the number of inputs.
0058   // FPGA U1 has 5 inputs (crates 4-8) and FPGA U2 has 4 inputs (crates 0-3).
0059   // Within a crate the four input candidates are arranged in the order
0060   // that they arrive on the cable, using the index() method.
0061   unsigned crate = cand.rctCrate();
0062   unsigned input = ((m_id == 4) ? (crate % 9) : (crate % 9 - 4));
0063   unsigned i = input * 4 + (3 - cand.index());
0064   if (m_inputCands.at(i).rank() == 0) {
0065     m_inputCands.at(i) = cand;
0066   }
0067 }
0068 
0069 std::ostream& operator<<(std::ostream& s, const L1GctElectronSorter& ems) {
0070   s << "===L1GctElectronSorter===" << std::endl;
0071   s << "Algo type = " << ems.m_isolation << std::endl;
0072   s << "No of Electron Input Candidates = " << ems.m_inputCands.size() << std::endl;
0073   s << "No of Electron Output Candidates = " << ems.m_outputCands.size() << std::endl;
0074   return s;
0075 }