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