CMS 3D CMS Logo

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