CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1MuDTPtaLut.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuDTPtaLut
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 //
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 L1MuDTPtaLut
46 //---------------------------------
47 
48 //----------------
49 // Constructors --
50 //----------------
51 
53  pta_lut(0),
54  pta_threshold(MAX_PTASSMETH/2) {
55 
56  pta_lut.reserve(MAX_PTASSMETH);
57  pta_threshold.reserve(MAX_PTASSMETH/2);
58  setPrecision();
59 
60  // if ( load() != 0 ) {
61  // cout << "Can not open files to load pt-assignment look-up tables for DTTrackFinder!" << endl;
62  // }
63 
64  // if ( L1MuDTTFConfig::Debug(6) ) print();
65 
66 }
67 
68 
69 //--------------
70 // Destructor --
71 //--------------
72 
74 
75  vector<LUT>::iterator iter;
76  for ( iter = pta_lut.begin(); iter != pta_lut.end(); iter++ ) {
77  (*iter).clear();
78  }
79 
80  pta_lut.clear();
81  pta_threshold.clear();
82 
83 }
84 
85 
86 //--------------
87 // Operations --
88 //--------------
89 
90 //
91 // reset pt-assignment look-up tables
92 //
94 
95  pta_lut.clear();
96  pta_threshold.clear();
97 
98 }
99 
100 
101 //
102 // load pt-assignment look-up tables
103 //
105 
106  // get directory name
107  string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
108  string pta_dir = "L1TriggerData/DTTrackFinder/Ass/";
109  string pta_str = "";
110 
111  // precision : in the look-up tables the following precision is used :
112  // phi ...12 bits (address) and pt ...5 bits
113  // now convert phi and phib to the required precision
114 
115  int sh_phi = 12 - nbit_phi;
116 
117  // loop over all pt-assignment methods
118  for ( int pam = 0; pam < MAX_PTASSMETH; pam++ ) {
119  switch ( pam ) {
120  case PT12L : { pta_str = "pta12l"; break; }
121  case PT12H : { pta_str = "pta12h"; break; }
122  case PT13L : { pta_str = "pta13l"; break; }
123  case PT13H : { pta_str = "pta13h"; break; }
124  case PT14L : { pta_str = "pta14l"; break; }
125  case PT14H : { pta_str = "pta14h"; break; }
126  case PT23L : { pta_str = "pta23l"; break; }
127  case PT23H : { pta_str = "pta23h"; break; }
128  case PT24L : { pta_str = "pta24l"; break; }
129  case PT24H : { pta_str = "pta24h"; break; }
130  case PT34L : { pta_str = "pta34l"; break; }
131  case PT34H : { pta_str = "pta34h"; break; }
132  case PT12LO : { pta_str = "pta12l_ovl"; break; }
133  case PT12HO : { pta_str = "pta12h_ovl"; break; }
134  case PT13LO : { pta_str = "pta13l_ovl"; break; }
135  case PT13HO : { pta_str = "pta13h_ovl"; break; }
136  case PT14LO : { pta_str = "pta14l_ovl"; break; }
137  case PT14HO : { pta_str = "pta14h_ovl"; break; }
138  case PT23LO : { pta_str = "pta23l_ovl"; break; }
139  case PT23HO : { pta_str = "pta23h_ovl"; break; }
140  case PT24LO : { pta_str = "pta24l_ovl"; break; }
141  case PT24HO : { pta_str = "pta24h_ovl"; break; }
142  case PT34LO : { pta_str = "pta34l_ovl"; break; }
143  case PT34HO : { pta_str = "pta34h_ovl"; break; }
144  case PT15LO : { pta_str = "pta15l_ovl"; break; }
145  case PT15HO : { pta_str = "pta15h_ovl"; break; }
146  case PT25LO : { pta_str = "pta25l_ovl"; break; }
147  case PT25HO : { pta_str = "pta25h_ovl"; break; }
148  }
149 
150  // assemble file name
151  edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + pta_dir + pta_str + ".lut"));
152  string pta_file = lut_f.fullPath();
153 
154  // open file
155  L1TriggerLutFile file(pta_file);
156  if ( file.open() != 0 ) return -1;
157  // if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
158  // << file.getName() << endl;
159 
160  // get the right shift factor
161  int shift = sh_phi;
162  int adr_old = -2048 >> shift;
163 
164  LUT tmplut;
165 
166  int number = -1;
167  int sum_pt = 0;
168 
169  if ( file.good() ) {
170  int threshold = file.readInteger();
171  pta_threshold[pam/2] = threshold;
172  }
173 
174  // read values and shift to correct precision
175  while ( file.good() ) {
176 
177  int adr = (file.readInteger()) >> shift;
178  int pt = file.readInteger();
179 
180  number++;
181 
182  if ( adr != adr_old ) {
183  tmplut.insert(make_pair( adr_old, (sum_pt/number) ));
184 
185  adr_old = adr;
186  number = 0;
187  sum_pt = 0;
188  }
189 
190  sum_pt += pt;
191 
192  if ( !file.good() ) file.close();
193 
194  }
195 
196  file.close();
197  pta_lut.push_back(tmplut);
198  }
199  return 0;
200 
201 }
202 
203 
204 //
205 // print pt-assignment look-up tables
206 //
207 void L1MuDTPtaLut::print() const {
208 
209  cout << endl;
210  cout << "L1 barrel Track Finder Pt-Assignment look-up tables :" << endl;
211  cout << "=====================================================" << endl;
212  cout << endl;
213  cout << "Precision : " << endl;
214  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
215 
216  // loop over all pt-assignment methods
217  for ( int pam = 0; pam < MAX_PTASSMETH; pam++ ) {
218 
219  cout << endl;
220  cout << "Pt-Assignment Method : " << static_cast<PtAssMethod>(pam) << endl;
221  cout << "============================" << endl;
222  cout << endl;
223 
224  cout << "\t Threshold : " << getPtLutThreshold(pam/2) << endl << endl;
225 
226  int maxbits = nbit_phi;
227 
228  cout << " address";
229  for ( int i = 0; i < maxbits; i++ ) cout << ' ';
230  cout << " value" << endl;
231  for ( int i = 0; i < maxbits; i++ ) cout << '-';
232  cout << "-------------------------" << endl;
233 
234  LUT::const_iterator iter = pta_lut[pam].begin();
235  while ( iter != pta_lut[pam].end() ) {
236  int address = (*iter).first;
237  int value = (*iter).second;
238 
239  DTTFBitArray<12> b_address(static_cast<unsigned>(abs(address)));
240  DTTFBitArray<5> b_value(static_cast<unsigned>(abs(value)));
241 
242  if ( address < 0 ) b_address.twoComplement();
243 
244  cout.setf(ios::right,ios::adjustfield);
245  cout << " " << setbase(10) << setw(5) << address << " (";
246  for ( int i = maxbits-1; i >= 0; i-- ) cout << b_address[i];
247  cout << ") " << setw(3) << value << " (";
248  b_value.print();
249  cout << ")" << endl;
250 
251  iter++;
252  }
253 
254  }
255 
256  cout << endl;
257 
258 }
259 
260 
261 //
262 // get pt value for a given address
263 //
264 int L1MuDTPtaLut::getPt(int pta_ind, int address) const {
265 
266  LUT::const_iterator iter = pta_lut[pta_ind].find(address);
267  if ( iter != pta_lut[pta_ind].end() ) {
268  return (*iter).second;
269  }
270  else {
271  cerr << "PtaLut::getPt : can not find address " << address << endl;
272  return 0;
273  }
274 
275 }
276 
277 
278 //
279 // get pt-assignment LUT threshold
280 //
281 int L1MuDTPtaLut::getPtLutThreshold(int pta_ind) const {
282 
283  if ( pta_ind >= 0 && pta_ind < MAX_PTASSMETH/2 ) {
284  return pta_threshold[pta_ind];
285  }
286  else {
287  cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
288  return 0;
289  }
290 
291 }
292 
293 
294 //
295 // set precision for look-up tables
296 //
298 
299  nbit_phi = 12;
300 
301 }
std::vector< LUT > pta_lut
Definition: L1MuDTPtaLut.h:74
std::vector< int > pta_threshold
Definition: L1MuDTPtaLut.h:75
int i
Definition: DBlmapReader.cc:9
int getPt(int pta_ind, int address) const
get pt-value for a given address
std::ostream & print(std::ostream &o=std::cout) const
Definition: DTTFBitArray.h:345
int load()
load pt-assignment look-up tables
char * address
Definition: mlp_lapack.h:14
void reset()
reset pt-assignment look-up tables
Definition: L1MuDTPtaLut.cc:93
void print() const
print pt-assignment look-up tables
DTTFBitArray< N > twoComplement() const
Definition: DTTFBitArray.h:500
virtual ~L1MuDTPtaLut()
destructor
Definition: L1MuDTPtaLut.cc:73
bool good()
return status of file stream
#define abs(x)
Definition: mlp_lapack.h:159
void setPrecision()
set precision for look-up tables
void close()
close file
L1MuDTPtaLut()
constructor
Definition: L1MuDTPtaLut.cc:52
#define end
Definition: vmac.h:38
std::map< short, short, std::less< short > > LUT
Definition: L1MuDTPtaLut.h:72
int readInteger()
read one integer from file
unsigned short int nbit_phi
Definition: L1MuDTPtaLut.h:77
static unsigned int const shift
tuple cout
Definition: gather_cfg.py:121
int getPtLutThreshold(int pta_ind) const
get pt-assignment LUT threshold
std::string fullPath() const
Definition: FileInPath.cc:171
int open()
open file
const int MAX_PTASSMETH
PtAssMethod