CMS 3D CMS Logo

L1MuDTExtrapolationUnit.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuDTExtrapolationUnit
4 //
5 // Description: Extrapolation Unit
6 //
7 //
8 //
9 // Author :
10 // N. Neumeister CERN EP
11 //
12 //--------------------------------------------------
13 
14 //-----------------------
15 // This Class's Header --
16 //-----------------------
17 
19 
20 //---------------
21 // C++ Headers --
22 //---------------
23 
24 #include <iostream>
25 #include <bitset>
26 #include <cassert>
27 
28 //-------------------------------
29 // Collaborating Class Headers --
30 //-------------------------------
31 
44 
45 using namespace std;
46 
47 // --------------------------------
48 // class L1MuDTExtrapolationUnit
49 //---------------------------------
50 
51 //----------------
52 // Constructors --
53 //----------------
54 
56  m_sp(sp), m_SEUs() {
57 
58  for ( int ext_idx = 0; ext_idx < MAX_EXT; ext_idx++ ) {
59 
60  Extrapolation ext = static_cast<Extrapolation>(ext_idx);
61 
62  if ( ext == EX12 || ext == EX13 || ext == EX14 ||
63  ext == EX21 || ext == EX23 || ext == EX24 || ext == EX34 ) {
64 
65  unsigned int maxaddr = 4;
66 
67  if ( ext == EX12 || ext == EX13 || ext == EX14 ) maxaddr = 2;
68 
69  for ( unsigned int startAddress = 0; startAddress < maxaddr; startAddress++ ) {
70  SEUId id = make_pair(ext, startAddress);
71  m_SEUs[id] = new L1MuDTSEU(sp,ext,startAddress);
72  if ( L1MuDTTFConfig::Debug(6) ) cout << " creating SEU " << ext << " " << startAddress << endl;
73  }
74  }
75  }
76 
77 }
78 
79 
80 //--------------
81 // Destructor --
82 //--------------
83 
85 
86  for ( SEUmap::iterator iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
87  delete (*iter).second;
88  (*iter).second = nullptr;
89  }
90  m_SEUs.clear();
91 
92 }
93 
94 
95 //--------------
96 // Operations --
97 //--------------
98 
99 //
100 // run Extrapolation Unit
101 //
103 
104  c.get< L1MuDTTFParametersRcd >().get( pars );
105 
106  SEUmap::const_iterator iter;
107  for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
108 
109  pair<int,int> ext_pair = which_ext(((*iter).second)->ext());
110  int start = ext_pair.first;
111 
112  const L1MuDTTrackSegPhi* ts = nullptr;
113 
114  //get start track segment
115  ts = m_sp.data()->getTSphi(start, ((*iter).second)->tsId() );
116 
117  if ( ts != nullptr && !ts->empty() ) {
118  ((*iter).second)->load(ts);
119  ((*iter).second)->run(c);
120  }
121 
122  }
123 
124  //
125  // use EX21 to cross-check EX12
126  //
127  bool run_21 = pars->get_soc_run_21(m_sp.id().wheel(), m_sp.id().sector());
128  if ( m_sp.tf().config()->getUseEX21() || run_21 ) {
129 
130  // search for EX12 + EX21 single extrapolation units
131  for ( unsigned int startAdr = 0; startAdr < 2; startAdr++ ) {
132 
133  bitset<12> extab12 = this->getEXTable( EX12, startAdr );
134  bitset<12> extab21 = this->getEXTable( EX21, startAdr );
135 
136  for ( int eux = 0; eux < 12; eux++ ) {
137  if ( extab12.test(eux) && !extab21.test(eux) ) {
138  reset(EX12,startAdr,eux);
139  if ( L1MuDTTFConfig::Debug(6) ) {
140  SEUId seuid = make_pair(EX12, startAdr);
141  L1MuDTSEU* SEU12 = m_SEUs[seuid];
142  cout << " EX12 - EX21 mismatch : "
143  << " EX12 : " << extab12 << " , "
144  << " EX21 : " << extab21 << endl
145  << " Cancel: " << SEU12->ext()
146  << " start addr = " << SEU12->tsId()
147  << " target addr = " << eux << endl;
148  }
149  }
150  }
151 
152  }
153  }
154 
155 }
156 
157 
158 //
159 // reset Extrapolation Unit
160 //
162 
163  SEUmap::const_iterator iter;
164  for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
165  ((*iter).second)->reset();
166  }
167 
168 }
169 
170 
171 //
172 // reset a single extrapolation
173 //
174 void L1MuDTExtrapolationUnit::reset(Extrapolation ext, unsigned int startAdr, unsigned int relAdr) {
175 
176  // assert( startAdr >= 0 && startAdr <= 3 );
177  // assert( relAdr >= 0 && relAdr <= 12 );
178 
179  SEUId seuid = make_pair(ext, startAdr);
180  SEUmap::const_iterator iter = m_SEUs.find(seuid);
181  if ( iter != m_SEUs.end() ) ((*iter).second)->reset(relAdr);
182 
183 }
184 
185 
186 //
187 // get extrapolation address from ERS
188 //
189 unsigned short int L1MuDTExtrapolationUnit::getAddress(Extrapolation ext, unsigned int startAdr, int id) const {
190 
191  // get extrapolation address from ERS
192  // startAdr = 0, 1 : own wheel
193  // startAdr = 2, 3 : next wheel neighbour
194 
195  // assert( startAdr >= 0 && startAdr <= 3 );
196  // assert( id == 0 || id == 1 );
197 
198  unsigned short int address = 15;
199 
200  SEUId seuid = make_pair(ext, startAdr);
201  SEUmap::const_iterator iter = m_SEUs.find(seuid);
202  if ( iter != m_SEUs.end() ) address = ((*iter).second)->ers()->address(id);
203 
204  return address;
205 
206 }
207 
208 
209 //
210 // get extrapolation quality from ERS
211 //
212 unsigned short int L1MuDTExtrapolationUnit::getQuality(Extrapolation ext, unsigned int startAdr, int id) const {
213 
214  // get extrapolation quality from ERS
215  // startAdr = 0, 1 : own wheel
216  // startAdr = 2, 3 : next wheel neighbour
217 
218  // assert( startAdr >= 0 && startAdr <= 3 );
219  // assert( id == 0 || id == 1 );
220 
221  unsigned short int quality = 0;
222 
223  SEUId seuid = make_pair(ext, startAdr);
224  SEUmap::const_iterator iter = m_SEUs.find(seuid);
225  if ( iter != m_SEUs.end() ) quality = ((*iter).second)->ers()->quality(id);
226 
227  return quality;
228 
229 }
230 
231 
232 //
233 // get Extrapolator table for a given SEU
234 //
235 const bitset<12>& L1MuDTExtrapolationUnit::getEXTable(Extrapolation ext, unsigned int startAdr) const {
236 
237  // startAdr = 0, 1 : own wheel
238  // startAdr = 2, 3 : next wheel neighbour
239 
240  // assert( startAdr >= 0 && startAdr <= 3 );
241 
242  SEUId seuid = make_pair(ext, startAdr);
243  return m_SEUs[seuid]->exTable();
244 
245 }
246 
247 
248 //
249 // get Quality Sorter table for a given SEU
250 //
251 const bitset<12>& L1MuDTExtrapolationUnit::getQSTable(Extrapolation ext, unsigned int startAdr) const {
252 
253  // startAdr = 0, 1 : own wheel
254  // startAdr = 2, 3 : next wheel neighbour
255 
256  // assert( startAdr >= 0 && startAdr <= 3 );
257 
258  SEUId seuid = make_pair(ext, startAdr);
259  return m_SEUs[seuid]->qsTable();
260 
261 }
262 
263 
264 //
265 // get number of successful extrapolations
266 //
268 
269  int number = 0;
270  SEUmap::const_iterator iter;
271  for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
272  number += ((*iter).second)->numberOfExt();
273  }
274 
275  return number;
276 
277 }
278 
279 
280 //
281 // print all successful extrapolations
282 //
284 
285  SEUmap::const_iterator iter_seu;
286 
287  if ( level == 0 ) {
288  for ( iter_seu = m_SEUs.begin(); iter_seu != m_SEUs.end(); iter_seu++ ) {
289  vector<L1MuDTEUX*> vec_eux = ((*iter_seu).second)->eux();
290  vector<L1MuDTEUX*>::const_iterator iter_eux;
291  for ( iter_eux = vec_eux.begin();
292  iter_eux != vec_eux.end(); iter_eux++ ) {
293  if ( (*iter_eux)->result() ) {
294  cout << ((*iter_seu).second)->ext() << " "
295  << ((*iter_seu).second)->tsId() << " "
296  << (*iter_eux)->id() << endl;
297  cout << "start : " << *(*iter_eux)->ts().first << endl;
298  cout << "target : " << *(*iter_eux)->ts().second << endl;
299  cout << "result : " << "quality = " << (*iter_eux)->quality() << '\t'
300  << "address = " << (*iter_eux)->address() << endl;
301  }
302  }
303  }
304  }
305 
306  //
307  // print all results from Extrapolator and Quality Sorter
308  //
309  if ( level == 1 ) {
310  cout << "Results from Extrapolator and Quality Sorter of " << m_sp.id()
311  << " : \n" << endl;
312 
313  cout << " EXT QSU " << endl;
314  cout << " S E U 11 11 " << endl;
315  cout << " 109876543210 109876543210 " << endl;
316  cout << "-------------------------------------" << endl;
317  for ( iter_seu = m_SEUs.begin(); iter_seu != m_SEUs.end(); iter_seu++ ) {
318 
319  cout << ((*iter_seu).second)->ext() << "_ "
320  << ((*iter_seu).second)->tsId() << ": "
321  << ((*iter_seu).second)->exTable() << " "
322  << ((*iter_seu).second)->qsTable() << endl;
323 
324  }
325 
326  cout << endl;
327  }
328 
329 }
330 
331 
332 // static
333 
334 //
335 // get station of start and target track segment for a given extrapolation
336 //
338 
339  int source = 0;
340  int target = 0;
341 
342  // assert( ext >= 0 && ext < MAX_EXT );
343 
344  switch ( ext ) {
345  case EX12 : { source = 1; target = 2; break; }
346  case EX13 : { source = 1; target = 3; break; }
347  case EX14 : { source = 1; target = 4; break; }
348  case EX21 : { source = 1; target = 2; break; }
349  case EX23 : { source = 2; target = 3; break; }
350  case EX24 : { source = 2; target = 4; break; }
351  case EX34 : { source = 3; target = 4; break; }
352  case EX15 : { source = 1; target = 3; break; }
353  case EX25 : { source = 2; target = 3; break; }
354  default : { source = 1; target = 2; break; }
355  }
356 
357  return pair<int,int>(source,target);
358 
359 }
Definition: start.py:1
Extrapolation ext() const
return extrapolation type
Definition: L1MuDTSEU.h:80
const std::bitset< 12 > & getEXTable(Extrapolation ext, unsigned int startAdr) const
get Extrapolator table for a given SEU
void reset() override
reset Extrapolation Unit
std::pair< Extrapolation, unsigned int > SEUId
unsigned short int getQuality(Extrapolation ext, unsigned int startAdr, int id) const
get extrapolation quality from a given ERS
void print(int level=0) const
print all successful extrapolations
int sector() const
return sector number
const L1MuDTDataBuffer * data() const
return pointer to Data Buffer
const std::bitset< 12 > & getQSTable(Extrapolation ext, unsigned int startAdr) const
get Quality Sorter table for a given SEU
const L1MuDTSectorProcessor & m_sp
L1MuDTExtrapolationUnit(const L1MuDTSectorProcessor &)
constructor
virtual void run()
run processor logic
const int MAX_EXT
unsigned short int getAddress(Extrapolation ext, unsigned int startAdr, int id) const
get extrapolation address from a given ERS
bool empty() const
is it an empty phi track segment?
bool getUseEX21() const
static bool Debug()
const L1MuDTSecProcId & id() const
return Sector Processor identifier
Extrapolation
~L1MuDTExtrapolationUnit() override
destructor
static std::pair< int, int > which_ext(Extrapolation ext)
return station of start and target track segment for a given extrapolation
const TSPhivector & getTSphi() const
get all track segments from the buffer
def load(fileName)
Definition: svgfig.py:546
const T & get() const
Definition: EventSetup.h:58
static L1MuDTTFConfig * config()
return configuration
edm::ESHandle< L1MuDTTFParameters > pars
bool get_soc_run_21(int wh, int sc) const
int numberOfExt() const
return number of successful extrapolations
const L1MuDTTrackFinder & tf() const
return reference to barrel MTTF
int wheel() const
return wheel number
Definition: memstream.h:15
static std::string const source
Definition: EdmProvDump.cc:43
unsigned int tsId() const
return start track segment identifier (relative address)
Definition: L1MuDTSEU.h:83