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  assert(number);
184  tmplut.insert(make_pair( adr_old, (sum_pt/number) ));
185 
186  adr_old = adr;
187  number = 0;
188  sum_pt = 0;
189  }
190 
191  sum_pt += pt;
192 
193  if ( !file.good() ) file.close();
194 
195  }
196 
197  file.close();
198  pta_lut.push_back(tmplut);
199  }
200  return 0;
201 
202 }
203 
204 
205 //
206 // print pt-assignment look-up tables
207 //
208 void L1MuDTPtaLut::print() const {
209 
210  cout << endl;
211  cout << "L1 barrel Track Finder Pt-Assignment look-up tables :" << endl;
212  cout << "=====================================================" << endl;
213  cout << endl;
214  cout << "Precision : " << endl;
215  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
216 
217  // loop over all pt-assignment methods
218  for ( int pam = 0; pam < MAX_PTASSMETH; pam++ ) {
219 
220  cout << endl;
221  cout << "Pt-Assignment Method : " << static_cast<PtAssMethod>(pam) << endl;
222  cout << "============================" << endl;
223  cout << endl;
224 
225  cout << "\t Threshold : " << getPtLutThreshold(pam/2) << endl << endl;
226 
227  int maxbits = nbit_phi;
228 
229  cout << " address";
230  for ( int i = 0; i < maxbits; i++ ) cout << ' ';
231  cout << " value" << endl;
232  for ( int i = 0; i < maxbits; i++ ) cout << '-';
233  cout << "-------------------------" << endl;
234 
235  LUT::const_iterator iter = pta_lut[pam].begin();
236  while ( iter != pta_lut[pam].end() ) {
237  int address = (*iter).first;
238  int value = (*iter).second;
239 
240  DTTFBitArray<12> b_address(static_cast<unsigned>(abs(address)));
241  DTTFBitArray<5> b_value(static_cast<unsigned>(abs(value)));
242 
243  if ( address < 0 ) b_address.twoComplement();
244 
245  cout.setf(ios::right,ios::adjustfield);
246  cout << " " << setbase(10) << setw(5) << address << " (";
247  for ( int i = maxbits-1; i >= 0; i-- ) cout << b_address[i];
248  cout << ") " << setw(3) << value << " (";
249  b_value.print();
250  cout << ")" << endl;
251 
252  iter++;
253  }
254 
255  }
256 
257  cout << endl;
258 
259 }
260 
261 
262 //
263 // get pt value for a given address
264 //
265 int L1MuDTPtaLut::getPt(int pta_ind, int address) const {
266 
267  LUT::const_iterator iter = pta_lut[pta_ind].find(address);
268  if ( iter != pta_lut[pta_ind].end() ) {
269  return (*iter).second;
270  }
271  else {
272  cerr << "PtaLut::getPt : can not find address " << address << endl;
273  return 0;
274  }
275 
276 }
277 
278 
279 //
280 // get pt-assignment LUT threshold
281 //
282 int L1MuDTPtaLut::getPtLutThreshold(int pta_ind) const {
283 
284  if ( pta_ind >= 0 && pta_ind < MAX_PTASSMETH/2 ) {
285  return pta_threshold[pta_ind];
286  }
287  else {
288  cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
289  return 0;
290  }
291 
292 }
293 
294 
295 //
296 // set precision for look-up tables
297 //
299 
300  nbit_phi = 12;
301 
302 }
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
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
void setPrecision()
set precision for look-up tables
void close()
close file
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L1MuDTPtaLut()
constructor
Definition: L1MuDTPtaLut.cc:52
#define end
Definition: vmac.h:37
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