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