Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:16

0001 //-------------------------------------------------
0002 //
0003 //   Class: L1MuGMTSorter
0004 //
0005 //   Description: GMT Muon Sorter
0006 //
0007 //
0008 //
0009 //   Author :
0010 //   N. Neumeister             CERN EP
0011 //
0012 //   Migrated to CMSSW:
0013 //   I. Mikulec
0014 //
0015 //--------------------------------------------------
0016 
0017 //-----------------------
0018 // This Class's Header --
0019 //-----------------------
0020 
0021 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTSorter.h"
0022 
0023 //---------------
0024 // C++ Headers --
0025 //---------------
0026 
0027 #include <iostream>
0028 #include <algorithm>
0029 #include <functional>
0030 
0031 //-------------------------------
0032 // Collaborating Class Headers --
0033 //-------------------------------
0034 
0035 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTConfig.h"
0036 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMatrix.h"
0037 #include "L1Trigger/GlobalMuonTrigger/interface/L1MuGlobalMuonTrigger.h"
0038 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTPSB.h"
0039 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMerger.h"
0040 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTExtendedCand.h"
0041 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutRecord.h"
0042 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTDebugBlock.h"
0043 
0044 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0045 
0046 // --------------------------------
0047 //       class L1MuGMTSorter
0048 //---------------------------------
0049 
0050 //----------------
0051 // Constructors --
0052 //----------------
0053 
0054 L1MuGMTSorter::L1MuGMTSorter(const L1MuGlobalMuonTrigger& gmt) : m_gmt(gmt), m_MuonCands() { m_MuonCands.reserve(4); }
0055 
0056 //--------------
0057 // Destructor --
0058 //--------------
0059 
0060 L1MuGMTSorter::~L1MuGMTSorter() {}
0061 
0062 //--------------
0063 // Operations --
0064 //--------------
0065 
0066 //
0067 // run GMT Sorter
0068 //
0069 void L1MuGMTSorter::run() {
0070   std::vector<L1MuGMTExtendedCand*> mycands;
0071   std::vector<L1MuGMTExtendedCand*> my_brl_cands;
0072 
0073   std::vector<L1MuGMTExtendedCand*>::const_iterator iter;
0074 
0075   // get muon candidates from barrel Merger
0076   const std::vector<L1MuGMTExtendedCand*>& brl_cands = m_gmt.Merger(0)->Cands();
0077   iter = brl_cands.begin();
0078   while (iter != brl_cands.end()) {
0079     if (*iter && !(*iter)->empty()) {
0080       my_brl_cands.push_back((*iter));
0081     }
0082     iter++;
0083   }
0084   // sort by rank
0085   std::function<bool(const L1MuGMTExtendedCand* first, const L1MuGMTExtendedCand* second)> rankFunction{
0086       L1MuGMTExtendedCand::compareRank};
0087   stable_sort(my_brl_cands.begin(), my_brl_cands.end(), rankFunction);
0088 
0089   // copy best four of brl to main sorter
0090   iter = my_brl_cands.begin();
0091   int count = 0;
0092   while (iter != my_brl_cands.end() && (count < 4)) {
0093     if (*iter && !(*iter)->empty()) {
0094       mycands.push_back((*iter));
0095       m_gmt.DebugBlockForFill()->SetBrlGMTCands(count, **iter);
0096       m_gmt.currentReadoutRecord()->setGMTBrlCand(count, **iter);
0097       count++;
0098     }
0099     iter++;
0100   }
0101 
0102   std::vector<L1MuGMTExtendedCand*> my_fwd_cands;
0103 
0104   // get muon candidates from forward Merger
0105   const std::vector<L1MuGMTExtendedCand*>& fwd_cands = m_gmt.Merger(1)->Cands();
0106   iter = fwd_cands.begin();
0107   while (iter != fwd_cands.end()) {
0108     if (*iter && !(*iter)->empty()) {
0109       my_fwd_cands.push_back((*iter));
0110     }
0111     iter++;
0112   }
0113   // sort by rank
0114   stable_sort(my_fwd_cands.begin(), my_fwd_cands.end(), rankFunction);
0115 
0116   // copy best four of fwd to main sorter
0117   iter = my_fwd_cands.begin();
0118   count = 0;
0119   while (iter != my_fwd_cands.end() && (count < 4)) {
0120     if (*iter && !(*iter)->empty()) {
0121       mycands.push_back((*iter));
0122       m_gmt.DebugBlockForFill()->SetFwdGMTCands(count, **iter);
0123       m_gmt.currentReadoutRecord()->setGMTFwdCand(count, **iter);
0124       count++;
0125     }
0126     iter++;
0127   }
0128 
0129   // print input data
0130   if (L1MuGMTConfig::Debug(5)) {
0131     edm::LogVerbatim("GMT_Sorter_info") << "GMT Sorter input: " << mycands.size();
0132     std::vector<L1MuGMTExtendedCand*>::const_iterator iter;
0133     for (iter = mycands.begin(); iter != mycands.end(); iter++) {
0134       if (*iter)
0135         (*iter)->print();
0136     }
0137   }
0138 
0139   // sort by rank
0140   stable_sort(mycands.begin(), mycands.end(), rankFunction);
0141 
0142   // copy the best 4 candidates
0143   int number_of_cands = 0;
0144   std::vector<L1MuGMTExtendedCand*>::const_iterator iter1 = mycands.begin();
0145   while (iter1 != mycands.end()) {
0146     if (*iter1 && number_of_cands < 4) {
0147       m_MuonCands.push_back(*iter1);
0148       m_gmt.currentReadoutRecord()->setGMTCand(number_of_cands, **iter1);
0149       number_of_cands++;
0150     }
0151     iter1++;
0152   }
0153 }
0154 
0155 //
0156 // reset GMT Sorter
0157 //
0158 void L1MuGMTSorter::reset() {
0159   std::vector<const L1MuGMTExtendedCand*>::iterator iter;
0160   for (iter = m_MuonCands.begin(); iter != m_MuonCands.end(); iter++) {
0161     *iter = nullptr;
0162   }
0163   m_MuonCands.clear();
0164 }
0165 
0166 //
0167 // print GMT sorter results
0168 //
0169 void L1MuGMTSorter::print() {
0170   edm::LogVerbatim("GMT_Sorter_info") << " ";
0171   edm::LogVerbatim("GMT_Sorter_info") << "Muon candidates found by the L1 Global Muon Trigger : " << numberOfCands();
0172   std::vector<const L1MuGMTExtendedCand*>::const_iterator iter = m_MuonCands.begin();
0173   while (iter != m_MuonCands.end()) {
0174     if (*iter)
0175       (*iter)->print();
0176     iter++;
0177   }
0178   edm::LogVerbatim("GMT_Sorter_info") << " ";
0179 }