CMS 3D CMS Logo

L1MuBMExtrapolationUnit.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuBMExtrapolationUnit
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 
41 
44 
45 using namespace std;
46 
47 // --------------------------------
48 // class L1MuBMExtrapolationUnit
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 L1MuBMSEU(sp,ext,startAddress);
72  if ( L1MuBMTFConfig::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  const L1TMuonBarrelParamsRcd& bmtfParamsRcd = c.get<L1TMuonBarrelParamsRcd>();
106  bmtfParamsRcd.get(bmtfParamsHandle);
107  const L1TMuonBarrelParams& bmtfParams = *bmtfParamsHandle.product();
108  pars = bmtfParams.l1mudttfparams;
109 
110  SEUmap::const_iterator iter;
111  for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
112 
113  pair<int,int> ext_pair = which_ext(((*iter).second)->ext());
114  int start = ext_pair.first;
115 
116  const L1MuBMTrackSegPhi* ts = nullptr;
117 
118  //get start track segment
119  ts = m_sp.data()->getTSphi(start, ((*iter).second)->tsId() );
120 
121  if ( ts != nullptr && !ts->empty() ) {
122  ((*iter).second)->load(ts);
123  ((*iter).second)->run(c);
124  }
125 
126  }
127 
128  //
129  // use EX21 to cross-check EX12
130  //
131  bool run_21 = pars.get_soc_run_21(m_sp.id().wheel(), m_sp.id().sector());
132  if ( L1MuBMTFConfig::getUseEX21() || run_21 ) {
133 
134  // search for EX12 + EX21 single extrapolation units
135  for ( unsigned int startAdr = 0; startAdr < 2; startAdr++ ) {
136 
137  bitset<12> extab12 = this->getEXTable( EX12, startAdr );
138  bitset<12> extab21 = this->getEXTable( EX21, startAdr );
139 
140  for ( int eux = 0; eux < 12; eux++ ) {
141  if ( extab12.test(eux) && !extab21.test(eux) ) {
142  reset(EX12,startAdr,eux);
143  if ( L1MuBMTFConfig::Debug(6) ) {
144  SEUId seuid = make_pair(EX12, startAdr);
145  L1MuBMSEU* SEU12 = m_SEUs[seuid];
146  cout << " EX12 - EX21 mismatch : "
147  << " EX12 : " << extab12 << " , "
148  << " EX21 : " << extab21 << endl
149  << " Cancel: " << SEU12->ext()
150  << " start addr = " << SEU12->tsId()
151  << " target addr = " << eux << endl;
152  }
153  }
154  }
155 
156  }
157  }
158 
159 }
160 
161 
162 //
163 // reset Extrapolation Unit
164 //
166 
167  SEUmap::const_iterator iter;
168  for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
169  ((*iter).second)->reset();
170  }
171 
172 }
173 
174 
175 //
176 // reset a single extrapolation
177 //
178 void L1MuBMExtrapolationUnit::reset(Extrapolation ext, unsigned int startAdr, unsigned int relAdr) {
179 
180  // assert( startAdr >= 0 && startAdr <= 3 );
181  // assert( relAdr >= 0 && relAdr <= 12 );
182 
183  SEUId seuid = make_pair(ext, startAdr);
184  SEUmap::const_iterator iter = m_SEUs.find(seuid);
185  if ( iter != m_SEUs.end() ) ((*iter).second)->reset(relAdr);
186 
187 }
188 
189 
190 //
191 // get extrapolation address from ERS
192 //
193 unsigned short int L1MuBMExtrapolationUnit::getAddress(Extrapolation ext, unsigned int startAdr, int id) const {
194 
195  // get extrapolation address from ERS
196  // startAdr = 0, 1 : own wheel
197  // startAdr = 2, 3 : next wheel neighbour
198 
199  // assert( startAdr >= 0 && startAdr <= 3 );
200  // assert( id == 0 || id == 1 );
201 
202  unsigned short int address = 15;
203 
204  SEUId seuid = make_pair(ext, startAdr);
205  SEUmap::const_iterator iter = m_SEUs.find(seuid);
206  if ( iter != m_SEUs.end() ) address = ((*iter).second)->ers()->address(id);
207 
208  return address;
209 
210 }
211 
212 
213 //
214 // get extrapolation quality from ERS
215 //
216 unsigned short int L1MuBMExtrapolationUnit::getQuality(Extrapolation ext, unsigned int startAdr, int id) const {
217 
218  // get extrapolation quality from ERS
219  // startAdr = 0, 1 : own wheel
220  // startAdr = 2, 3 : next wheel neighbour
221 
222  // assert( startAdr >= 0 && startAdr <= 3 );
223  // assert( id == 0 || id == 1 );
224 
225  unsigned short int quality = 0;
226 
227  SEUId seuid = make_pair(ext, startAdr);
228  SEUmap::const_iterator iter = m_SEUs.find(seuid);
229  if ( iter != m_SEUs.end() ) quality = ((*iter).second)->ers()->quality(id);
230 
231  return quality;
232 
233 }
234 
235 
236 //
237 // get Extrapolator table for a given SEU
238 //
239 const bitset<12>& L1MuBMExtrapolationUnit::getEXTable(Extrapolation ext, unsigned int startAdr) const {
240 
241  // startAdr = 0, 1 : own wheel
242  // startAdr = 2, 3 : next wheel neighbour
243 
244  // assert( startAdr >= 0 && startAdr <= 3 );
245 
246  SEUId seuid = make_pair(ext, startAdr);
247  return m_SEUs[seuid]->exTable();
248 
249 }
250 
251 
252 //
253 // get Quality Sorter table for a given SEU
254 //
255 const bitset<12>& L1MuBMExtrapolationUnit::getQSTable(Extrapolation ext, unsigned int startAdr) const {
256 
257  // startAdr = 0, 1 : own wheel
258  // startAdr = 2, 3 : next wheel neighbour
259 
260  // assert( startAdr >= 0 && startAdr <= 3 );
261 
262  SEUId seuid = make_pair(ext, startAdr);
263  return m_SEUs[seuid]->qsTable();
264 
265 }
266 
267 
268 //
269 // get number of successful extrapolations
270 //
272 
273  int number = 0;
274  SEUmap::const_iterator iter;
275  for ( iter = m_SEUs.begin(); iter != m_SEUs.end(); iter++ ) {
276  number += ((*iter).second)->numberOfExt();
277  }
278 
279  return number;
280 
281 }
282 
283 
284 //
285 // print all successful extrapolations
286 //
288 
289  SEUmap::const_iterator iter_seu;
290 
291  if ( level == 0 ) {
292  for ( iter_seu = m_SEUs.begin(); iter_seu != m_SEUs.end(); iter_seu++ ) {
293  vector<L1MuBMEUX*> vec_eux = ((*iter_seu).second)->eux();
294  vector<L1MuBMEUX*>::const_iterator iter_eux;
295  for ( iter_eux = vec_eux.begin();
296  iter_eux != vec_eux.end(); iter_eux++ ) {
297  if ( (*iter_eux)->result() ) {
298  cout << ((*iter_seu).second)->ext() << " "
299  << ((*iter_seu).second)->tsId() << " "
300  << (*iter_eux)->id() << endl;
301  cout << "start : " << *(*iter_eux)->ts().first << endl;
302  cout << "target : " << *(*iter_eux)->ts().second << endl;
303  cout << "result : " << "quality = " << (*iter_eux)->quality() << '\t'
304  << "address = " << (*iter_eux)->address() << endl;
305  }
306  }
307  }
308  }
309 
310  //
311  // print all results from Extrapolator and Quality Sorter
312  //
313  if ( level == 1 ) {
314  cout << "Results from Extrapolator and Quality Sorter of " << m_sp.id()
315  << " : \n" << endl;
316 
317  cout << " EXT QSU " << endl;
318  cout << " S E U 11 11 " << endl;
319  cout << " 109876543210 109876543210 " << endl;
320  cout << "-------------------------------------" << endl;
321  for ( iter_seu = m_SEUs.begin(); iter_seu != m_SEUs.end(); iter_seu++ ) {
322 
323  cout << ((*iter_seu).second)->ext() << "_ "
324  << ((*iter_seu).second)->tsId() << ": "
325  << ((*iter_seu).second)->exTable() << " "
326  << ((*iter_seu).second)->qsTable() << endl;
327 
328  }
329 
330  cout << endl;
331  }
332 
333 }
334 
335 
336 // static
337 
338 //
339 // get station of start and target track segment for a given extrapolation
340 //
342 
343  int source = 0;
344  int target = 0;
345 
346  // assert( ext >= 0 && ext < MAX_EXT );
347 
348  switch ( ext ) {
349  case EX12 : { source = 1; target = 2; break; }
350  case EX13 : { source = 1; target = 3; break; }
351  case EX14 : { source = 1; target = 4; break; }
352  case EX21 : { source = 1; target = 2; break; }
353  case EX23 : { source = 2; target = 3; break; }
354  case EX24 : { source = 2; target = 4; break; }
355  case EX34 : { source = 3; target = 4; break; }
356  case EX15 : { source = 1; target = 3; break; }
357  case EX25 : { source = 2; target = 3; break; }
358  default : { source = 1; target = 2; break; }
359  }
360 
361  return pair<int,int>(source,target);
362 
363 }
Extrapolation ext() const
return extrapolation type
Definition: L1MuBMSEU.h:80
Definition: start.py:1
static std::pair< int, int > which_ext(Extrapolation ext)
return station of start and target track segment for a given extrapolation
L1MuDTTFParameters l1mudttfparams
static bool getUseEX21()
~L1MuBMExtrapolationUnit() override
destructor
int sector() const
return sector number
void reset() override
reset Extrapolation Unit
unsigned short int getQuality(Extrapolation ext, unsigned int startAdr, int id) const
get extrapolation quality from a given ERS
virtual void run()
run processor logic
void get(HolderT &iHolder) const
const int MAX_EXT
unsigned short int getAddress(Extrapolation ext, unsigned int startAdr, int id) const
get extrapolation address from a given ERS
const std::bitset< 12 > & getQSTable(Extrapolation ext, unsigned int startAdr) const
get Quality Sorter table for a given SEU
const L1MuBMSectorProcessor & m_sp
unsigned int tsId() const
return start track segment identifier (relative address)
Definition: L1MuBMSEU.h:83
Extrapolation
int numberOfExt() const
return number of successful extrapolations
const L1MuBMSecProcId & id() const
return Sector Processor identifier
std::pair< Extrapolation, unsigned int > SEUId
void print(int level=0) const
print all successful extrapolations
def load(fileName)
Definition: svgfig.py:546
static bool Debug()
bool get_soc_run_21(int wh, int sc) const
const TSPhivector & getTSphi() const
get all track segments from the buffer
const L1MuBMDataBuffer * data() const
return pointer to Data Buffer
T get() const
Definition: EventSetup.h:63
const std::bitset< 12 > & getEXTable(Extrapolation ext, unsigned int startAdr) const
get Extrapolator table for a given SEU
L1MuBMExtrapolationUnit(const L1MuBMSectorProcessor &)
constructor
Definition: memstream.h:15
edm::ESHandle< L1TMuonBarrelParams > bmtfParamsHandle
T const * product() const
Definition: ESHandle.h:86
static std::string const source
Definition: EdmProvDump.cc:43
bool empty() const
is it an empty phi track segment?
int wheel() const
return wheel number