CMS 3D CMS Logo

L1MuBMLUTHandler.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuBMLUTHandler
4 //
5 // Description: Look-up tables for pt assignment
6 //
7 //
8 // $Date: 2010/05/12 23:03:43 $
9 // $Revision: 1.7 $
10 //
11 // Author :
12 // N. Neumeister CERN EP
13 // J. Troconiz UAM Madrid
14 // G. Flouris U. Ioannina
15 //--------------------------------------------------
16 
17 //-----------------------
18 // This Class's Header --
19 //-----------------------
20 
22 
23 //---------------
24 // C++ Headers --
25 //---------------
26 
27 #include <iostream>
28 #include <ostream>
29 #include <iomanip>
30 #include <string>
31 #include <cstdlib>
32 #include <cstdlib> /* std::getenv */
33 
34 //-------------------------------
35 // Collaborating Class Headers --
36 //-------------------------------
37 
41 
42 using namespace std;
43 
44 // --------------------------------
45 // class L1MuBMLUTHandler
46 //---------------------------------
47 
48 //----------------
49 // Constructors --
50 //----------------
51 
52 L1MuBMLUTHandler::L1MuBMLUTHandler(const L1TMuonBarrelParams& l1params) { l1tbmparams = &l1params; }
53 
54 //--------------
55 // Destructor --
56 //--------------
57 
59 
60 //--------------
61 // Operations --
62 //--------------
63 
64 //
65 // print pt-assignment look-up tables
66 //
68  int nbit_phi = l1tbmparams->get_PT_Assignment_nbits_Phi();
69 
70  cout << endl;
71  cout << "L1 barrel Track Finder Pt-Assignment look-up tables :" << endl;
72  cout << "=====================================================" << endl;
73  cout << endl;
74  cout << "Precision : " << endl;
75  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
76 
77  // loop over all pt-assignment methods
78  for (int pam = 0; pam < L1MuBMLUTHandler::MAX_PTASSMETH; pam++) {
79  cout << endl;
80  cout << "Pt-Assignment Method : " << static_cast<L1MuBMLUTHandler::PtAssMethod>(pam) << endl;
81  cout << "============================" << endl;
82  cout << endl;
83 
84  cout << "\t Threshold : " << getPtLutThreshold(pam / 2) << endl << endl;
85 
86  int maxbits = nbit_phi;
87  if (pam >= MAX_PTASSMETHA)
88  maxbits = nbit_phi - 2;
89 
90  cout << " address";
91  for (int i = 0; i < maxbits; i++)
92  cout << ' ';
93  cout << " value" << endl;
94  for (int i = 0; i < maxbits; i++)
95  cout << '-';
96  cout << "-------------------------" << endl;
97  std::vector<L1TMuonBarrelParams::LUT> const& pta_lut = l1tbmparams->pta_lut();
98 
99  L1TMuonBarrelParams::LUT::const_iterator iter = pta_lut[pam].begin();
100  while (iter != pta_lut[pam].end()) {
101  int address = (*iter).first;
102  int value = (*iter).second;
103 
104  DTTFBitArray<12> b_address(static_cast<unsigned>(abs(address)));
105  DTTFBitArray<9> b_value(static_cast<unsigned>(abs(value)));
106 
107  if (address < 0)
108  b_address.twoComplement();
109 
110  cout.setf(ios::right, ios::adjustfield);
111  cout << " " << setbase(10) << setw(9) << address << " (";
112  for (int i = maxbits - 1; i >= 0; i--)
113  cout << b_address[i];
114  cout << ") " << setw(3) << value << " (";
115  b_value.print();
116  cout << ")" << endl;
117 
118  iter++;
119  }
120  }
121 
122  cout << endl;
123 }
124 
125 //
126 // get pt value for a given address
127 //
128 int L1MuBMLUTHandler::getPt(int pta_ind, int address) const {
129  std::vector<L1TMuonBarrelParams::LUT> const& pta_lut = l1tbmparams->pta_lut();
130 
131  L1TMuonBarrelParams::LUT::const_iterator iter = pta_lut[pta_ind].find(address);
132  if (iter != pta_lut[pta_ind].end()) {
133  //std::cout<<"pta_ind "<<pta_ind<<" address "<<address<<" pt "<<(*iter).second<<std::endl;
134 
135  return (*iter).second;
136  } else {
137  cerr << "PtaLut::getPt : can not find address " << address << endl;
138  return 0;
139  }
140 }
141 
142 //
143 // get pt-assignment LUT threshold
144 //
145 int L1MuBMLUTHandler::getPtLutThreshold(int pta_ind) const {
146  std::vector<int> const& pta_threshold = l1tbmparams->pta_threshold();
147  if (pta_ind >= 0 && pta_ind < L1MuBMLUTHandler::MAX_PTASSMETH / 2) {
148  return pta_threshold[pta_ind];
149  } else {
150  cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
151  return 0;
152  }
153 }
154 
155 //
156 // get delta-phi value for a given address
157 //
158 int L1MuBMLUTHandler::getDeltaPhi(int idx, int address) const {
159  std::vector<L1TMuonBarrelParams::LUT> const& phi_lut = l1tbmparams->phi_lut();
160  L1TMuonBarrelParams::LUT::const_iterator iter = phi_lut[idx].find(address);
161  if (iter != phi_lut[idx].end()) {
162  return (*iter).second;
163  } else {
164  cerr << "PhiLut::getDeltaPhi : can not find address " << address << endl;
165  return 0;
166  }
167 }
168 
169 //
170 // get precision for look-up tables
171 //
172 pair<unsigned short, unsigned short> L1MuBMLUTHandler::getPrecision() const {
173  return pair<unsigned short, unsigned short>(l1tbmparams->get_PHI_Assignment_nbits_Phi(),
174  l1tbmparams->get_PHI_Assignment_nbits_PhiB());
175 }
176 
177 // print phi-assignment look-up tables
178 //
180  unsigned short int nbit_phi = l1tbmparams->get_PHI_Assignment_nbits_Phi();
181  unsigned short int nbit_phib = l1tbmparams->get_PHI_Assignment_nbits_PhiB();
182 
183  cout << endl;
184  cout << "L1 barrel Track Finder Phi-Assignment look-up tables :" << endl;
185  cout << "======================================================" << endl;
186  cout << endl;
187  cout << "Precision : " << endl;
188  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
189  cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
190 
191  // loop over all phi-assignment methods
192  for (int idx = 0; idx < 2; idx++) {
193  cout << endl;
194  if (idx == 0)
195  cout << "Phi-Assignment Method : "
196  << "PHI12" << endl;
197  if (idx == 1)
198  cout << "Phi-Assignment Method : "
199  << "PHI42" << endl;
200  cout << "=============================" << endl;
201  cout << endl;
202 
203  cout << " address";
204  for (int i = 0; i < nbit_phib; i++)
205  cout << ' ';
206  cout << " value" << endl;
207  for (int i = 0; i < nbit_phi + nbit_phib; i++)
208  cout << '-';
209  cout << "----------------------" << endl;
210  std::vector<L1TMuonBarrelParams::LUT> const& phi_lut = l1tbmparams->phi_lut();
211 
212  L1TMuonBarrelParams::LUT::const_iterator iter = phi_lut[idx].begin();
213  while (iter != phi_lut[idx].end()) {
214  int address = (*iter).first;
215  int value = (*iter).second;
216 
217  DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
218  DTTFBitArray<12> b_value(static_cast<unsigned>(abs(value)));
219 
220  if (address < 0)
221  b_address.twoComplement();
222  if (value < 0)
223  b_value.twoComplement();
224 
225  cout.setf(ios::right, ios::adjustfield);
226  cout << " " << setbase(10) << setw(5) << address << " (";
227  for (int i = nbit_phib - 1; i >= 0; i--)
228  cout << b_address[i];
229  cout << ") " << setw(5) << value << " (";
230  for (int i = nbit_phi - 1; i >= 0; i--)
231  cout << b_value[i];
232  cout << ") " << endl;
233 
234  iter++;
235  }
236  }
237 
238  cout << endl;
239 }
240 
241 //
242 // get low_value for a given address
243 //
244 int L1MuBMLUTHandler::getLow(int ext_ind, int address) const {
245  std::vector<L1TMuonBarrelParams::LUTParams::extLUT> const& ext_lut = l1tbmparams->ext_lut();
246  L1TMuonBarrelParams::LUT::const_iterator iter = ext_lut[ext_ind].low.find(address);
247  if (iter != ext_lut[ext_ind].low.end()) {
248  return (*iter).second;
249  } else {
250  cerr << "ExtLut::getLow : can not find address " << address << endl;
251  return 99999;
252  }
253 }
254 
255 //
256 // get high_value for a given address
257 //
258 int L1MuBMLUTHandler::getHigh(int ext_ind, int address) const {
259  std::vector<L1TMuonBarrelParams::LUTParams::extLUT> const& ext_lut = l1tbmparams->ext_lut();
260  L1TMuonBarrelParams::LUT::const_iterator iter = ext_lut[ext_ind].high.find(address);
261  if (iter != ext_lut[ext_ind].high.end()) {
262  return (*iter).second;
263  } else {
264  cerr << "ExtLut::getHigh : can not find address " << address << endl;
265  return 99999;
266  }
267 }
268 
269 //
270 // print extrapolation look-up tables
271 //
273  unsigned short int nbit_phi = l1tbmparams->get_PHI_Assignment_nbits_Phi();
274  unsigned short int nbit_phib = l1tbmparams->get_PHI_Assignment_nbits_PhiB();
275  cout << endl;
276  cout << "L1 barrel Track Finder Extrapolation look-up tables :" << endl;
277  cout << "=====================================================" << endl;
278  cout << endl;
279  cout << "Precision : " << endl;
280  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
281  cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
282 
283  // loop over all extrapolations
284  for (int ext = 0; ext < L1MuBMLUTHandler::MAX_EXT; ext++) {
285  cout << endl;
286  cout << "Extrapolation : " << static_cast<L1MuBMLUTHandler::Extrapolation>(ext) << endl;
287  cout << "====================" << endl;
288  cout << endl;
289 
290  cout << " address";
291  for (int i = 0; i < nbit_phib; i++)
292  cout << ' ';
293  cout << " low-value";
294  for (int i = 0; i < nbit_phi; i++)
295  cout << ' ';
296  cout << " high-value " << endl;
297  for (int i = 0; i < 2 * nbit_phi + nbit_phib; i++)
298  cout << '-';
299  cout << "---------------------------------" << endl;
300  std::vector<L1TMuonBarrelParams::LUTParams::extLUT> const& ext_lut = l1tbmparams->ext_lut();
301  L1TMuonBarrelParams::LUT::const_iterator iter = ext_lut[ext].low.begin();
302  L1TMuonBarrelParams::LUT::const_iterator iter1;
303  while (iter != ext_lut[ext].low.end()) {
304  int address = (*iter).first;
305  int low = (*iter).second;
306  iter1 = ext_lut[ext].high.find(address);
307  int high = (*iter1).second;
308 
309  DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
310  DTTFBitArray<12> b_low(static_cast<unsigned>(abs(low)));
311  DTTFBitArray<12> b_high(static_cast<unsigned>(abs(high)));
312 
313  if (address < 0)
314  b_address.twoComplement();
315  if (low < 0)
316  b_low.twoComplement();
317  if (high < 0)
318  b_high.twoComplement();
319 
320  cout.setf(ios::right, ios::adjustfield);
321  cout << " " << setbase(10) << setw(5) << address << " (";
322  for (int i = nbit_phib - 1; i >= 0; i--)
323  cout << b_address[i];
324  cout << ") " << setw(5) << low << " (";
325  for (int i = nbit_phi - 1; i >= 0; i--)
326  cout << b_low[i];
327  cout << ") " << setw(5) << high << " (";
328  for (int i = nbit_phi - 1; i >= 0; i--)
329  cout << b_high[i];
330  cout << ") " << endl;
331 
332  iter++;
333  }
334  }
335 
336  cout << endl;
337 }
virtual ~L1MuBMLUTHandler()
destructor
std::ostream & print(std::ostream &o=std::cout) const
Definition: DTTFBitArray.h:340
void print_pta_lut() const
print pt-assignment look-up tables
const int MAX_PTASSMETH
L1MuBMLUTHandler(const L1TMuonBarrelParams &l1params)
constructor
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: value.py:1
int getPt(int pta_ind, int address) const
get pt-value for a given address
void print_ext_lut() const
print extrapolation look-up tables
int getHigh(int ext_ind, int address) const
get high_value for a given address
int getLow(int ext_ind, int address) const
get low_value for a given address
int getPtLutThreshold(int pta_ind) const
get pt-assignment LUT threshold
int getDeltaPhi(int idx, int address) const
get delta-phi for a given address (bend-angle)
DTTFBitArray< N > twoComplement() const
Definition: DTTFBitArray.h:507
std::pair< unsigned short, unsigned short > getPrecision() const
get precision for look-up tables
void print_phi_lut() const
print phi-assignment look-up tables
Definition: memstream.h:15