CMS 3D CMS Logo

L1MuBMWedgeSorter.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuBMWedgeSorter
4 //
5 // Description: Wedge Sorter
6 // find the 2 highest rank candidates per wedge
7 //
8 //
9 //
10 // Author :
11 // N. Neumeister CERN EP
12 // J. Troconiz UAM Madrid
13 //
14 //--------------------------------------------------
15 
16 //-----------------------
17 // This Class's Header --
18 //-----------------------
19 
21 
22 //---------------
23 // C++ Headers --
24 //---------------
25 
26 #include <iostream>
27 #include <algorithm>
28 
29 //-------------------------------
30 // Collaborating Class Headers --
31 //-------------------------------
32 
39 
40 using namespace std;
41 
42 // --------------------------------
43 // class L1MuBMWedgeSorter
44 //---------------------------------
45 
46 //----------------
47 // Constructors --
48 //----------------
49 
51  m_tf(tf), m_wsid(id), m_TrackCands(3) {
52 
53  m_TrackCands.reserve(3);
54 
55 }
56 
57 
58 //--------------
59 // Destructor --
60 //--------------
61 
63 
64 }
65 
66 
67 //--------------
68 // Operations --
69 //--------------
70 
71 //
72 // run Wedge Sorter
73 //
75 
76  // get track candidates from Sector Processors
77  vector<L1MuBMTrack*> wedgecands;
78  wedgecands.reserve(12);
79 
80  int sector = m_wsid;
81  for ( int wheel = -3; wheel <= 3; wheel++ ) {
82  if ( wheel == 0 ) continue;
83  L1MuBMSecProcId tmpspid(wheel,sector);
84  for ( int number = 0; number < 2; number++ ) {
85  const L1MuBMTrack* cand = m_tf.sp(tmpspid)->track(number);
86  if ( cand && !cand->empty() ) {
87  // remove tracks which where found in wheel 0 and
88  // which didn't cross wheel boundaries (SP -1)
89  bool reject = false;
90  if ( wheel == -1 ) {
91  reject = true;
92  for ( int stat = 2; stat <= 4; stat++ ) {
93  int adr = cand->address(stat);
94  // check addresses : 0,1,4,5,8,9 (own wheel)
95  if ( adr != 15 ) reject &= ( (adr/2)%2 == 0 );
96  }
97  }
98  if ( !reject ) wedgecands.push_back(const_cast<L1MuBMTrack*>(cand));
99  }
100  }
101  }
102 
103  // print input data
104  if ( L1MuBMTFConfig::Debug(5) ) {
105  cout << "Wedge Sorter " << m_wsid << " input: "
106  << wedgecands.size() << endl;
107  vector<L1MuBMTrack*>::const_iterator iter;
108  for ( iter = wedgecands.begin(); iter != wedgecands.end(); iter++ ) {
109  if (*iter ) (*iter)->print();
110  }
111  }
112 
113  // print input data
114  runCOL(wedgecands);
115 
116  // remove disabled candidates
117  vector<L1MuBMTrack*>::iterator it = wedgecands.begin();
118  while ( it != wedgecands.end() ) {
119  if ( *it && (*it)->empty() ) {
120  wedgecands.erase(it);
121  it = wedgecands.begin(); continue;
122  }
123  it++;
124  }
125 
126  // sort candidates by pt and quality and copy the 2 best candidates
127  partial_sort_copy( wedgecands.begin(), wedgecands.end(),
128  m_TrackCands.begin(), m_TrackCands.end(),
130 
131  if ( L1MuBMTFConfig::Debug(4) ) {
132  cout << "Wedge Sorter " << m_wsid << " output: " << endl;
133  vector<const L1MuBMTrack*>::const_iterator iter;
134  for ( iter = m_TrackCands.begin();
135  iter != m_TrackCands.end(); iter++ ) {
136  if (*iter) (*iter)->print();
137  }
138  }
139 
140 }
141 
142 
143 //
144 // reset Wedge Sorter
145 //
147 
148  vector<const L1MuBMTrack*>::iterator iter;
149  for ( iter = m_TrackCands.begin(); iter != m_TrackCands.end(); iter++ ) {
150  *iter = nullptr;
151  }
152 
153 }
154 
155 
156 //
157 // print candidates found in Wedge Sorter
158 //
160 
161  if ( anyTrack() ) {
162  cout << "Muon candidates found in Wedge Sorter " << m_wsid << " : " << endl;
163  vector<const L1MuBMTrack*>::const_iterator iter = m_TrackCands.begin();
164  while ( iter != m_TrackCands.end() ) {
165  if ( *iter ) cout << *(*iter) << " found in "
166  << (*iter)->spid() << endl;
167  iter++;
168  }
169  }
170 
171 }
172 
173 
174 //
175 // are there any muon candidates?
176 //
178 
179  vector<const L1MuBMTrack*>::const_iterator iter = m_TrackCands.begin();
180  while ( iter != m_TrackCands.end() ) {
181  if ( *iter && !(*iter)->empty() ) return true;
182  iter++;
183  }
184 
185  return false;
186 
187 }
188 
189 
190 //
191 // Cancel Out Logic for Wedge Muon Sorter
192 //
193 void L1MuBMWedgeSorter::runCOL(vector<L1MuBMTrack*>& cands) const {
194 
195  // compare candidates which were found in nearby wheels:
196  // if 2 candidates have at least one track segment in common
197  // disable the one with lower quality;
198  // compare addresses from stations 2, 3 and 4
199 
200  typedef vector<L1MuBMTrack*>::iterator TI;
201  for ( TI iter1 = cands.begin(); iter1 != cands.end(); iter1++ ) {
202  if ( *iter1 == nullptr ) continue;
203  if ( (*iter1)->empty() ) continue;
204  L1MuBMSecProcId sp1 = (*iter1)->spid();
205  int qual1 = (*iter1)->quality();
206  for ( TI iter2 = cands.begin(); iter2 != cands.end(); iter2++ ) {
207  if ( *iter2 == nullptr ) continue;
208  if ( *iter1 == *iter2 ) continue;
209  if ( (*iter2)->empty() ) continue;
210  L1MuBMSecProcId sp2 = (*iter2)->spid();
211  int qual2 = (*iter2)->quality();
212  if ( sp1 == sp2 ) continue;
213  if ( !neighbour(sp1,sp2) ) continue;
214  int adr_shift = ( sp2.wheel() == -1 ) ? 0 : 2;
215  int countTS = 0;
216  for ( int stat = 2; stat <= 4; stat++ ) {
217  int adr1 = (*iter1)->address(stat);
218  int adr2 = (*iter2)->address(stat);
219  if ( adr1 == 15 || adr2 == 15 ) continue;
220  if ( (adr2/2)%2 == 1 ) continue;
221  if ( adr1 == adr2 + adr_shift ) countTS++;
222  }
223  if ( countTS > 0 ) {
224  if ( qual1 < qual2 ) {
225  if ( L1MuBMTFConfig::Debug(5) ) {
226  cout << "Wedge Sorter cancel : "; (*iter1)->print();
227  }
228  (*iter1)->disable();
229  break;
230  }
231  else {
232  if ( L1MuBMTFConfig::Debug(5) ) {
233  cout << "Wedge Sorter cancel : "; (*iter2)->print();
234  }
235  (*iter2)->disable();
236  }
237  }
238  }
239  }
240 
241 }
242 
243 
244 //
245 // find out if two Sector Processors are neighbours in the same wedge
246 //
248  const L1MuBMSecProcId& spid2) {
249 
250  // neighbour definition:
251  // wheel 1 : -2, -1, +1, +1, +2
252  // wheel 2 : -3, -2, -1, +2, +3
253 
254  bool neigh = false;
255 
256  int sector1 = spid1.sector();
257  int wheel1 = spid1.wheel();
258 
259  int sector2 = spid2.sector();
260  int wheel2 = spid2.wheel();
261 
262  if ( sector1 == sector2 ) {
263 
264  if ( ( wheel1 == -2 && wheel2 == -3 ) ||
265  ( wheel1 == -1 && wheel2 == -2 ) ||
266  ( wheel1 == +1 && wheel2 == -1 ) ||
267  ( wheel1 == +1 && wheel2 == +2 ) ||
268  ( wheel1 == +2 && wheel2 == +3 ) ) neigh = true;
269 
270  }
271 
272  return neigh;
273 
274 }
~L1MuBMWedgeSorter() override
destructor
void reset() override
reset Wedge Sorter
std::vector< const L1MuBMTrack * > m_TrackCands
L1MuBMAddressArray address() const
get address-array for this muon candidate
Definition: L1MuBMTrack.h:101
bool anyTrack() const
are there any non-empty muon candidates in the Wedge Sorter?
L1MuBMWedgeSorter(const L1MuBMTrackFinder &, int id)
constructor
int sector() const
return sector number
static bool neighbour(const L1MuBMSecProcId &spid1, const L1MuBMSecProcId &spid2)
find out if two Sector Processors are neighbours in the same wedge
const L1MuBMSectorProcessor * sp(const L1MuBMSecProcId &) const
get a pointer to a Sector Processor
L1MuBMTrack * track(int id) const
return pointer to muon candidate, index [0,1]
const L1MuBMTrackFinder & m_tf
static bool rank(const L1MuBMTrack *first, const L1MuBMTrack *second)
define a rank for muon candidates
Definition: L1MuBMTrack.h:194
static bool Debug()
void print() const
print results after sorting
bool empty() const
is it an empty muon candidate?
Definition: L1MuBMTrack.h:95
void runCOL(std::vector< L1MuBMTrack * > &) const
run the Cancel Out Logic of the wedge sorter
void run() override
run Wedge Sorter
int wheel() const
return wheel number