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