CMS 3D CMS Logo

L1MuDTExtLut.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuDTExtLut
4 //
5 // Description: Look-up tables for extrapolation
6 //
7 //
8 // $Date: 2009/05/13 06:36:48 $
9 // $Revision: 1.6 $
10 //
11 // Author :
12 // N. Neumeister CERN EP
13 // J. Troconiz UAM Madrid
14 //
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 
33 //-------------------------------
34 // Collaborating Class Headers --
35 //-------------------------------
36 
41 
42 using namespace std;
43 
44 // --------------------------------
45 // class L1MuDTExtLut
46 //---------------------------------
47 
48 //----------------
49 // Constructors --
50 //----------------
51 
53  ext_lut.reserve(MAX_EXT);
54  setPrecision();
55  // if ( load() != 0 ) {
56  // cout << "Can not open files to load extrapolation look-up tables for DTTrackFinder!" << endl;
57  // }
58 
59  // if ( L1MuDTTFConfig::Debug(6) ) print();
60 }
61 
62 //--------------
63 // Destructor --
64 //--------------
65 
67  typedef vector<LUT>::iterator LI;
68  for (LI iter = ext_lut.begin(); iter != ext_lut.end(); iter++) {
69  (*iter).low.clear();
70  (*iter).high.clear();
71  }
72 
73  ext_lut.clear();
74 }
75 
76 //--------------
77 // Operations --
78 //--------------
79 
80 //
81 // reset extrapolation look-up tables
82 //
83 void L1MuDTExtLut::reset() { ext_lut.clear(); }
84 
85 //
86 // load extrapolation look-up tables
87 //
89  // get directory name
90  string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
91  string ext_dir = "L1TriggerData/DTTrackFinder/Ext/";
92  string ext_str = "";
93 
94  // precision : in the look-up tables the following precision is used :
95  // phi ...12 bits (low, high), phib ...10 bits (address)
96  // now convert phi and phib to the required precision
97 
98  int sh_phi = 12 - nbit_phi;
99  int sh_phib = 10 - nbit_phib;
100 
101  // loop over all extrapolations
102  for (int ext = 0; ext < MAX_EXT; ext++) {
103  switch (ext) {
104  case EX12:
105  ext_str = "ext12";
106  break;
107  case EX13:
108  ext_str = "ext13";
109  break;
110  case EX14:
111  ext_str = "ext14";
112  break;
113  case EX21:
114  ext_str = "ext21";
115  break;
116  case EX23:
117  ext_str = "ext23";
118  break;
119  case EX24:
120  ext_str = "ext24";
121  break;
122  case EX34:
123  ext_str = "ext34";
124  break;
125  case EX15:
126  ext_str = "ext15";
127  break;
128  case EX16:
129  ext_str = "ext16";
130  break;
131  case EX25:
132  ext_str = "ext25";
133  break;
134  case EX26:
135  ext_str = "ext26";
136  break;
137  case EX56:
138  ext_str = "ext56";
139  break;
140  }
141 
142  // assemble file name
143  edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + ext_dir + ext_str + ".lut"));
144  string ext_file = lut_f.fullPath();
145 
146  // open file
147  L1TriggerLutFile file(ext_file);
148  if (file.open() != 0)
149  return -1;
150  // if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
151  // << file.getName() << endl;
152 
153  LUT tmplut;
154 
155  int number = -1;
156  int adr_old = -512 >> sh_phib;
157  int sum_low = 0;
158  int sum_high = 0;
159 
160  // read values and shift to correct precision
161  while (file.good()) {
162  int adr = (file.readInteger()) >> sh_phib; // address (phib)
163  int low = (file.readInteger()); // low value (phi)
164  int high = (file.readInteger()); // high value (phi)
165 
166  number++;
167 
168  if (adr != adr_old) {
169  tmplut.low[adr_old] = sum_low >> sh_phi;
170  tmplut.high[adr_old] = sum_high >> sh_phi;
171 
172  adr_old = adr;
173  number = 0;
174  sum_low = 0;
175  sum_high = 0;
176  }
177 
178  if (number == 0)
179  sum_low = low;
180  if (number == 0)
181  sum_high = high;
182 
183  if (!file.good())
184  file.close();
185  }
186 
187  file.close();
188  ext_lut.push_back(tmplut);
189  }
190  return 0;
191 }
192 
193 //
194 // print extrapolation look-up tables
195 //
196 void L1MuDTExtLut::print() const {
197  cout << endl;
198  cout << "L1 barrel Track Finder Extrapolation look-up tables :" << endl;
199  cout << "=====================================================" << endl;
200  cout << endl;
201  cout << "Precision : " << endl;
202  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
203  cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
204 
205  // loop over all extrapolations
206  for (int ext = 0; ext < MAX_EXT; ext++) {
207  cout << endl;
208  cout << "Extrapolation : " << static_cast<Extrapolation>(ext) << endl;
209  cout << "====================" << endl;
210  cout << endl;
211 
212  cout << " address";
213  for (int i = 0; i < nbit_phib; i++)
214  cout << ' ';
215  cout << " low-value";
216  for (int i = 0; i < nbit_phi; i++)
217  cout << ' ';
218  cout << " high-value " << endl;
219  for (int i = 0; i < 2 * nbit_phi + nbit_phib; i++)
220  cout << '-';
221  cout << "---------------------------------" << endl;
222 
223  LUT::LUTmap::const_iterator iter = ext_lut[ext].low.begin();
224  LUT::LUTmap::const_iterator iter1;
225  while (iter != ext_lut[ext].low.end()) {
226  int address = (*iter).first;
227  int low = (*iter).second;
228  iter1 = ext_lut[ext].high.find(address);
229  int high = (*iter1).second;
230 
231  DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
232  DTTFBitArray<12> b_low(static_cast<unsigned>(abs(low)));
233  DTTFBitArray<12> b_high(static_cast<unsigned>(abs(high)));
234 
235  if (address < 0)
236  b_address.twoComplement();
237  if (low < 0)
238  b_low.twoComplement();
239  if (high < 0)
240  b_high.twoComplement();
241 
242  cout.setf(ios::right, ios::adjustfield);
243  cout << " " << setbase(10) << setw(5) << address << " (";
244  for (int i = nbit_phib - 1; i >= 0; i--)
245  cout << b_address[i];
246  cout << ") " << setw(5) << low << " (";
247  for (int i = nbit_phi - 1; i >= 0; i--)
248  cout << b_low[i];
249  cout << ") " << setw(5) << high << " (";
250  for (int i = nbit_phi - 1; i >= 0; i--)
251  cout << b_high[i];
252  cout << ") " << endl;
253 
254  iter++;
255  }
256  }
257 
258  cout << endl;
259 }
260 
261 //
262 // get low_value for a given address
263 //
264 int L1MuDTExtLut::getLow(int ext_ind, int address) const {
265  LUT::LUTmap::const_iterator iter = ext_lut[ext_ind].low.find(address);
266  if (iter != ext_lut[ext_ind].low.end()) {
267  return (*iter).second;
268  } else {
269  cerr << "ExtLut::getLow : can not find address " << address << endl;
270  return 99999;
271  }
272 }
273 
274 //
275 // get high_value for a given address
276 //
277 int L1MuDTExtLut::getHigh(int ext_ind, int address) const {
278  LUT::LUTmap::const_iterator iter = ext_lut[ext_ind].high.find(address);
279  if (iter != ext_lut[ext_ind].high.end()) {
280  return (*iter).second;
281  } else {
282  cerr << "ExtLut::getHigh : can not find address " << address << endl;
283  return 99999;
284  }
285 }
286 
287 //
288 // set precision for Look-up tables
289 //
291  nbit_phi = 12;
292  nbit_phib = 10;
293 }
std::string fullPath() const
Definition: FileInPath.cc:161
int getLow(int ext_ind, int address) const
get low_value for a given address
helper class for look-up tables
Definition: L1MuDTExtLut.h:42
L1MuDTExtLut()
constructor
Definition: L1MuDTExtLut.cc:52
int load()
load extrapolation look-up tables
Definition: L1MuDTExtLut.cc:88
void print() const
print extrapolation look-up tables
const int MAX_EXT
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Extrapolation
void reset()
reset extrapolation look-up tables
Definition: L1MuDTExtLut.cc:83
int getHigh(int ext_ind, int address) const
get high_value for a given address
void setPrecision()
set precision for look-up tables
DTTFBitArray< N > twoComplement() const
Definition: DTTFBitArray.h:507
virtual ~L1MuDTExtLut()
destructor
Definition: L1MuDTExtLut.cc:66
Definition: memstream.h:15