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 
53  // l1tbmparams = &l1params;
54  l1tbmparams = new L1TMuonBarrelParamsAllPublic(l1params);
55 }
56 
57 //--------------
58 // Destructor --
59 //--------------
60 
61 L1MuBMLUTHandler::~L1MuBMLUTHandler() { delete l1tbmparams; }
62 
63 //--------------
64 // Operations --
65 //--------------
66 
67 //
68 // print pt-assignment look-up tables
69 //
71  int nbit_phi = l1tbmparams->get_PT_Assignment_nbits_Phi();
72 
73  cout << endl;
74  cout << "L1 barrel Track Finder Pt-Assignment look-up tables :" << endl;
75  cout << "=====================================================" << endl;
76  cout << endl;
77  cout << "Precision : " << endl;
78  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
79 
80  // loop over all pt-assignment methods
81  for (int pam = 0; pam < L1MuBMLUTHandler::MAX_PTASSMETH; pam++) {
82  cout << endl;
83  cout << "Pt-Assignment Method : " << static_cast<L1MuBMLUTHandler::PtAssMethod>(pam) << endl;
84  cout << "============================" << endl;
85  cout << endl;
86 
87  cout << "\t Threshold : " << getPtLutThreshold(pam / 2) << endl << endl;
88 
89  int maxbits = nbit_phi;
90  if (pam >= MAX_PTASSMETHA)
91  maxbits = nbit_phi - 2;
92 
93  cout << " address";
94  for (int i = 0; i < maxbits; i++)
95  cout << ' ';
96  cout << " value" << endl;
97  for (int i = 0; i < maxbits; i++)
98  cout << '-';
99  cout << "-------------------------" << endl;
100  std::vector<L1TMuonBarrelParams::LUT> pta_lut = l1tbmparams->pta_lut();
101 
102  L1TMuonBarrelParams::LUT::const_iterator iter = pta_lut[pam].begin();
103  while (iter != pta_lut[pam].end()) {
104  int address = (*iter).first;
105  int value = (*iter).second;
106 
107  DTTFBitArray<12> b_address(static_cast<unsigned>(abs(address)));
108  DTTFBitArray<9> b_value(static_cast<unsigned>(abs(value)));
109 
110  if (address < 0)
111  b_address.twoComplement();
112 
113  cout.setf(ios::right, ios::adjustfield);
114  cout << " " << setbase(10) << setw(9) << address << " (";
115  for (int i = maxbits - 1; i >= 0; i--)
116  cout << b_address[i];
117  cout << ") " << setw(3) << value << " (";
118  b_value.print();
119  cout << ")" << endl;
120 
121  iter++;
122  }
123  }
124 
125  cout << endl;
126 }
127 
128 //
129 // get pt value for a given address
130 //
131 int L1MuBMLUTHandler::getPt(int pta_ind, int address) const {
132  std::vector<L1TMuonBarrelParams::LUT> pta_lut = l1tbmparams->pta_lut();
133 
134  L1TMuonBarrelParams::LUT::const_iterator iter = pta_lut[pta_ind].find(address);
135  if (iter != pta_lut[pta_ind].end()) {
136  //std::cout<<"pta_ind "<<pta_ind<<" address "<<address<<" pt "<<(*iter).second<<std::endl;
137 
138  return (*iter).second;
139  } else {
140  cerr << "PtaLut::getPt : can not find address " << address << endl;
141  return 0;
142  }
143 }
144 
145 //
146 // get pt-assignment LUT threshold
147 //
148 int L1MuBMLUTHandler::getPtLutThreshold(int pta_ind) const {
149  std::vector<int> pta_threshold = l1tbmparams->pta_threshold();
150  if (pta_ind >= 0 && pta_ind < L1MuBMLUTHandler::MAX_PTASSMETH / 2) {
151  return pta_threshold[pta_ind];
152  } else {
153  cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
154  return 0;
155  }
156 }
157 
158 //
159 // get delta-phi value for a given address
160 //
161 int L1MuBMLUTHandler::getDeltaPhi(int idx, int address) const {
162  std::vector<L1TMuonBarrelParams::LUT> phi_lut = l1tbmparams->phi_lut();
163  L1TMuonBarrelParams::LUT::const_iterator iter = phi_lut[idx].find(address);
164  if (iter != phi_lut[idx].end()) {
165  return (*iter).second;
166  } else {
167  cerr << "PhiLut::getDeltaPhi : can not find address " << address << endl;
168  return 0;
169  }
170 }
171 
172 //
173 // get precision for look-up tables
174 //
175 pair<unsigned short, unsigned short> L1MuBMLUTHandler::getPrecision() const {
176  return pair<unsigned short, unsigned short>(l1tbmparams->get_PHI_Assignment_nbits_Phi(),
177  l1tbmparams->get_PHI_Assignment_nbits_PhiB());
178 }
179 
180 // print phi-assignment look-up tables
181 //
183  unsigned short int nbit_phi = l1tbmparams->get_PHI_Assignment_nbits_Phi();
184  unsigned short int nbit_phib = l1tbmparams->get_PHI_Assignment_nbits_PhiB();
185 
186  cout << endl;
187  cout << "L1 barrel Track Finder Phi-Assignment look-up tables :" << endl;
188  cout << "======================================================" << endl;
189  cout << endl;
190  cout << "Precision : " << endl;
191  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
192  cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
193 
194  // loop over all phi-assignment methods
195  for (int idx = 0; idx < 2; idx++) {
196  cout << endl;
197  if (idx == 0)
198  cout << "Phi-Assignment Method : "
199  << "PHI12" << endl;
200  if (idx == 1)
201  cout << "Phi-Assignment Method : "
202  << "PHI42" << endl;
203  cout << "=============================" << endl;
204  cout << endl;
205 
206  cout << " address";
207  for (int i = 0; i < nbit_phib; i++)
208  cout << ' ';
209  cout << " value" << endl;
210  for (int i = 0; i < nbit_phi + nbit_phib; i++)
211  cout << '-';
212  cout << "----------------------" << endl;
213  std::vector<L1TMuonBarrelParams::LUT> phi_lut = l1tbmparams->phi_lut();
214 
215  L1TMuonBarrelParams::LUT::const_iterator iter = phi_lut[idx].begin();
216  while (iter != phi_lut[idx].end()) {
217  int address = (*iter).first;
218  int value = (*iter).second;
219 
220  DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
221  DTTFBitArray<12> b_value(static_cast<unsigned>(abs(value)));
222 
223  if (address < 0)
224  b_address.twoComplement();
225  if (value < 0)
226  b_value.twoComplement();
227 
228  cout.setf(ios::right, ios::adjustfield);
229  cout << " " << setbase(10) << setw(5) << address << " (";
230  for (int i = nbit_phib - 1; i >= 0; i--)
231  cout << b_address[i];
232  cout << ") " << setw(5) << value << " (";
233  for (int i = nbit_phi - 1; i >= 0; i--)
234  cout << b_value[i];
235  cout << ") " << endl;
236 
237  iter++;
238  }
239  }
240 
241  cout << endl;
242 }
243 
244 //
245 // get low_value for a given address
246 //
247 int L1MuBMLUTHandler::getLow(int ext_ind, int address) const {
248  std::vector<L1TMuonBarrelParams::LUTParams::extLUT> ext_lut = l1tbmparams->ext_lut();
249  L1TMuonBarrelParams::LUT::const_iterator iter = ext_lut[ext_ind].low.find(address);
250  if (iter != ext_lut[ext_ind].low.end()) {
251  return (*iter).second;
252  } else {
253  cerr << "ExtLut::getLow : can not find address " << address << endl;
254  return 99999;
255  }
256 }
257 
258 //
259 // get high_value for a given address
260 //
261 int L1MuBMLUTHandler::getHigh(int ext_ind, int address) const {
262  std::vector<L1TMuonBarrelParams::LUTParams::extLUT> ext_lut = l1tbmparams->ext_lut();
263  L1TMuonBarrelParams::LUT::const_iterator iter = ext_lut[ext_ind].high.find(address);
264  if (iter != ext_lut[ext_ind].high.end()) {
265  return (*iter).second;
266  } else {
267  cerr << "ExtLut::getHigh : can not find address " << address << endl;
268  return 99999;
269  }
270 }
271 
272 //
273 // print extrapolation look-up tables
274 //
276  unsigned short int nbit_phi = l1tbmparams->get_PHI_Assignment_nbits_Phi();
277  unsigned short int nbit_phib = l1tbmparams->get_PHI_Assignment_nbits_PhiB();
278  cout << endl;
279  cout << "L1 barrel Track Finder Extrapolation look-up tables :" << endl;
280  cout << "=====================================================" << endl;
281  cout << endl;
282  cout << "Precision : " << endl;
283  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
284  cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
285 
286  // loop over all extrapolations
287  for (int ext = 0; ext < L1MuBMLUTHandler::MAX_EXT; ext++) {
288  cout << endl;
289  cout << "Extrapolation : " << static_cast<L1MuBMLUTHandler::Extrapolation>(ext) << endl;
290  cout << "====================" << endl;
291  cout << endl;
292 
293  cout << " address";
294  for (int i = 0; i < nbit_phib; i++)
295  cout << ' ';
296  cout << " low-value";
297  for (int i = 0; i < nbit_phi; i++)
298  cout << ' ';
299  cout << " high-value " << endl;
300  for (int i = 0; i < 2 * nbit_phi + nbit_phib; i++)
301  cout << '-';
302  cout << "---------------------------------" << endl;
303  std::vector<L1TMuonBarrelParams::LUTParams::extLUT> ext_lut = l1tbmparams->ext_lut();
304  L1TMuonBarrelParams::LUT::const_iterator iter = ext_lut[ext].low.begin();
305  L1TMuonBarrelParams::LUT::const_iterator iter1;
306  while (iter != ext_lut[ext].low.end()) {
307  int address = (*iter).first;
308  int low = (*iter).second;
309  iter1 = ext_lut[ext].high.find(address);
310  int high = (*iter1).second;
311 
312  DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
313  DTTFBitArray<12> b_low(static_cast<unsigned>(abs(low)));
314  DTTFBitArray<12> b_high(static_cast<unsigned>(abs(high)));
315 
316  if (address < 0)
317  b_address.twoComplement();
318  if (low < 0)
319  b_low.twoComplement();
320  if (high < 0)
321  b_high.twoComplement();
322 
323  cout.setf(ios::right, ios::adjustfield);
324  cout << " " << setbase(10) << setw(5) << address << " (";
325  for (int i = nbit_phib - 1; i >= 0; i--)
326  cout << b_address[i];
327  cout << ") " << setw(5) << low << " (";
328  for (int i = nbit_phi - 1; i >= 0; i--)
329  cout << b_low[i];
330  cout << ") " << setw(5) << high << " (";
331  for (int i = nbit_phi - 1; i >= 0; i--)
332  cout << b_high[i];
333  cout << ") " << endl;
334 
335  iter++;
336  }
337  }
338 
339  cout << endl;
340 }
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