CMS 3D CMS Logo

L1MuGMTSorter.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuGMTSorter
4 //
5 // Description: GMT Muon Sorter
6 //
7 //
8 //
9 // Author :
10 // N. Neumeister CERN EP
11 //
12 // Migrated to CMSSW:
13 // I. Mikulec
14 //
15 //--------------------------------------------------
16 
17 //-----------------------
18 // This Class's Header --
19 //-----------------------
20 
22 
23 //---------------
24 // C++ Headers --
25 //---------------
26 
27 #include <iostream>
28 #include <algorithm>
29 #include <functional>
30 
31 //-------------------------------
32 // Collaborating Class Headers --
33 //-------------------------------
34 
43 
45 
46 // --------------------------------
47 // class L1MuGMTSorter
48 //---------------------------------
49 
50 //----------------
51 // Constructors --
52 //----------------
53 
55  m_gmt(gmt), m_MuonCands() {
56 
57  m_MuonCands.reserve(4);
58 
59 }
60 
61 
62 //--------------
63 // Destructor --
64 //--------------
65 
67 
68 }
69 
70 
71 //--------------
72 // Operations --
73 //--------------
74 
75 //
76 // run GMT Sorter
77 //
79 
80  std::vector<L1MuGMTExtendedCand*> mycands;
81  std::vector<L1MuGMTExtendedCand*> my_brl_cands;
82 
83  std::vector<L1MuGMTExtendedCand*>::const_iterator iter;
84 
85  // get muon candidates from barrel Merger
86  const std::vector<L1MuGMTExtendedCand*>& brl_cands = m_gmt.Merger(0)->Cands();
87  iter = brl_cands.begin();
88  while ( iter != brl_cands.end() ) {
89  if ( *iter && !(*iter)->empty() ) {
90  my_brl_cands.push_back((*iter));
91  }
92  iter++;
93  }
94  // sort by rank
97  stable_sort( my_brl_cands.begin(), my_brl_cands.end(), rankFunction );
98 
99  // copy best four of brl to main sorter
100  iter = my_brl_cands.begin();
101  int count=0;
102  while ( iter != my_brl_cands.end() && (count<4) ) {
103  if ( *iter && !(*iter)->empty() ) {
104  mycands.push_back((*iter));
105  m_gmt.DebugBlockForFill()->SetBrlGMTCands( count, **iter) ;
106  m_gmt.currentReadoutRecord()->setGMTBrlCand ( count, **iter );
107  count++;
108  }
109  iter++;
110  }
111 
112 
113  std::vector<L1MuGMTExtendedCand*> my_fwd_cands;
114 
115  // get muon candidates from forward Merger
116  const std::vector<L1MuGMTExtendedCand*>& fwd_cands = m_gmt.Merger(1)->Cands();
117  iter = fwd_cands.begin();
118  while ( iter != fwd_cands.end() ) {
119  if ( *iter && !(*iter)->empty() ) {
120  my_fwd_cands.push_back((*iter));
121  }
122  iter++;
123  }
124  // sort by rank
125  stable_sort( my_fwd_cands.begin(), my_fwd_cands.end(), rankFunction );
126 
127 
128  // copy best four of fwd to main sorter
129  iter = my_fwd_cands.begin();
130  count=0;
131  while ( iter != my_fwd_cands.end() && (count<4) ) {
132  if ( *iter && !(*iter)->empty() ) {
133  mycands.push_back((*iter));
134  m_gmt.DebugBlockForFill()->SetFwdGMTCands( count, **iter) ;
135  m_gmt.currentReadoutRecord()->setGMTFwdCand ( count, **iter );
136  count++;
137  }
138  iter++;
139  }
140 
141 
142  // print input data
143  if ( L1MuGMTConfig::Debug(5) ) {
144  edm::LogVerbatim("GMT_Sorter_info") << "GMT Sorter input: "
145  << mycands.size();
146  std::vector<L1MuGMTExtendedCand*>::const_iterator iter;
147  for ( iter = mycands.begin(); iter != mycands.end(); iter++ ) {
148  if (*iter ) (*iter)->print();
149  }
150  }
151 
152  // sort by rank
153  stable_sort( mycands.begin(), mycands.end(), rankFunction );
154 
155  // copy the best 4 candidates
156  int number_of_cands = 0;
157  std::vector<L1MuGMTExtendedCand*>::const_iterator iter1 = mycands.begin();
158  while ( iter1 != mycands.end() ) {
159  if ( *iter1 && number_of_cands < 4 ) {
160  m_MuonCands.push_back(*iter1);
161  m_gmt.currentReadoutRecord()->setGMTCand ( number_of_cands, **iter1 );
162  number_of_cands++;
163  }
164  iter1++;
165  }
166 
167 }
168 
169 
170 //
171 // reset GMT Sorter
172 //
174 
175  std::vector<const L1MuGMTExtendedCand*>::iterator iter;
176  for ( iter = m_MuonCands.begin(); iter != m_MuonCands.end(); iter++ ) {
177  *iter = nullptr;
178  }
179  m_MuonCands.clear();
180 
181 }
182 
183 
184 //
185 // print GMT sorter results
186 //
188 
189  edm::LogVerbatim("GMT_Sorter_info") << " ";
190  edm::LogVerbatim("GMT_Sorter_info") << "Muon candidates found by the L1 Global Muon Trigger : "
191  << numberOfCands();
192  std::vector<const L1MuGMTExtendedCand*>::const_iterator iter = m_MuonCands.begin();
193  while ( iter != m_MuonCands.end() ) {
194  if ( *iter ) (*iter)->print();
195  iter++;
196  }
197  edm::LogVerbatim("GMT_Sorter_info") << " ";
198 
199 }
200 
201 
202 
203 
204 
205 
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
void setGMTBrlCand(int nr, L1MuGMTExtendedCand const &cand)
set GMT barrel candidate
L1MuGMTSorter(const L1MuGlobalMuonTrigger &)
constructor
virtual void reset()
reset Sorter
void setGMTFwdCand(int nr, L1MuGMTExtendedCand const &cand)
set GMT forward candidate
std::vector< const L1MuGMTExtendedCand * > m_MuonCands
Definition: L1MuGMTSorter.h:69
virtual ~L1MuGMTSorter()
destructor
void SetBrlGMTCands(int idx, L1MuGMTExtendedCand const &cand)
Set brl GMT Cands.
virtual void run()
run Sorter
U second(std::pair< T, U > const &p)
static bool Debug()
const L1MuGMTMerger * Merger(int id) const
return pointer to Merger
void print()
print results after sorting
static bool compareRank(const L1MuGMTExtendedCand *first, const L1MuGMTExtendedCand *second)
define a rank for muon candidates
void SetFwdGMTCands(int idx, L1MuGMTExtendedCand const &cand)
Set fwd GMT Cands.
const std::vector< L1MuGMTExtendedCand * > & Cands() const
return std::vector with all muon candidates
Definition: L1MuGMTMerger.h:84
void setGMTCand(int nr, L1MuGMTExtendedCand const &cand)
set GMT candidate (does not store rank)
L1MuGMTDebugBlock * DebugBlockForFill() const
for debug: return the debug block (in order to fill it)
int numberOfCands() const
return number of found muon candidates after sorter
Definition: L1MuGMTSorter.h:61
const L1MuGlobalMuonTrigger & m_gmt
Definition: L1MuGMTSorter.h:68
L1MuGMTReadoutRecord * currentReadoutRecord() const
return a reference to the current record in the ring buffer