CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1MuDTPhiLut.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuDTPhiLut
4 //
5 // Description: Look-up tables for phi 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 
40 
41 using namespace std;
42 
43 // --------------------------------
44 // class L1MuDTPhiLut
45 //---------------------------------
46 
47 //----------------
48 // Constructors --
49 //----------------
50 
52 
53  phi_lut.reserve(2);
54  setPrecision();
55  // if ( load() != 0 ) {
56  // cout << "Can not open files to load phi-assignment look-up tables for DTTrackFinder!" << endl;
57  // }
58 
59  // if ( L1MuDTTFConfig::Debug(6) ) print();
60 
61 }
62 
63 
64 //--------------
65 // Destructor --
66 //--------------
67 
69 
70  vector<LUT>::iterator iter;
71  for ( iter = phi_lut.begin(); iter != phi_lut.end(); iter++ ) {
72  (*iter).clear();
73  }
74 
75  phi_lut.clear();
76 
77 }
78 
79 
80 //--------------
81 // Operations --
82 //--------------
83 
84 //
85 // reset phi-assignment look-up tables
86 //
88 
89  phi_lut.clear();
90 
91 }
92 
93 
94 //
95 // load phi-assignment look-up tables
96 //
98 
99  // get directory name
100  string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
101  string phi_dir = "L1TriggerData/DTTrackFinder/Ass/";
102  string phi_str = "";
103 
104  // precision : in the look-up tables the following precision is used :
105  // address (phib) ...10 bits, phi ... 12 bits
106 
107  int sh_phi = 12 - nbit_phi;
108  int sh_phib = 10 - nbit_phib;
109 
110  // loop over all phi-assignment methods
111  for ( int idx = 0; idx < 2; idx++ ) {
112  switch ( idx ) {
113  case 0 : { phi_str = "phi12"; break; }
114  case 1 : { phi_str = "phi42"; break; }
115  }
116 
117  // assemble file name
118  edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + phi_dir + phi_str + ".lut"));
119  string phi_file = lut_f.fullPath();
120 
121  // open file
122  L1TriggerLutFile file(phi_file);
123  if ( file.open() != 0 ) return -1;
124  // if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
125  // << file.getName() << endl;
126 
127  LUT tmplut;
128 
129  int number = -1;
130  int adr_old = -512 >> sh_phib;
131  int sum_phi = 0;
132 
133  // read values
134  while ( file.good() ) {
135 
136  int adr = (file.readInteger()) >> sh_phib;
137  int phi = file.readInteger();
138 
139  number++;
140 
141  if ( adr != adr_old ) {
142  tmplut.insert(make_pair( adr_old, ((sum_phi/number) >> sh_phi) ));
143 
144  adr_old = adr;
145  number = 0;
146  sum_phi = 0;
147  }
148 
149  sum_phi += phi;
150 
151  if ( !file.good() ) file.close();
152 
153  }
154 
155  file.close();
156  phi_lut.push_back(tmplut);
157  }
158  return 0;
159 
160 }
161 
162 
163 //
164 // print phi-assignment look-up tables
165 //
166 void L1MuDTPhiLut::print() const {
167 
168  cout << endl;
169  cout << "L1 barrel Track Finder Phi-Assignment look-up tables :" << endl;
170  cout << "======================================================" << endl;
171  cout << endl;
172  cout << "Precision : " << endl;
173  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
174  cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
175 
176  // loop over all phi-assignment methods
177  for ( int idx = 0; idx < 2; idx++ ) {
178 
179  cout << endl;
180  if ( idx == 0 ) cout << "Phi-Assignment Method : " << "PHI12" << endl;
181  if ( idx == 1 ) cout << "Phi-Assignment Method : " << "PHI42" << endl;
182  cout << "=============================" << endl;
183  cout << endl;
184 
185  cout << " address";
186  for ( int i = 0; i < nbit_phib; i++ ) cout << ' ';
187  cout << " value" << endl;
188  for ( int i = 0; i < nbit_phi + nbit_phib; i++ ) cout << '-';
189  cout << "----------------------" << endl;
190 
191  LUT::const_iterator iter = phi_lut[idx].begin();
192  while ( iter != phi_lut[idx].end() ) {
193  int address = (*iter).first;
194  int value = (*iter).second;
195 
196  DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
197  DTTFBitArray<12> b_value(static_cast<unsigned>(abs(value)));
198 
199  if ( address < 0 ) b_address.twoComplement();
200  if ( value < 0 ) b_value.twoComplement();
201 
202  cout.setf(ios::right,ios::adjustfield);
203  cout << " " << setbase(10) << setw(5) << address << " (";
204  for ( int i = nbit_phib-1; i >= 0; i-- ) cout << b_address[i];
205  cout << ") " << setw(5) << value << " (";
206  for ( int i = nbit_phi-1; i >= 0; i-- ) cout << b_value[i];
207  cout << ") " << endl;
208 
209  iter++;
210  }
211 
212  }
213 
214  cout << endl;
215 
216 }
217 
218 
219 //
220 // get delta-phi value for a given address
221 //
222 int L1MuDTPhiLut::getDeltaPhi(int idx, int address) const {
223 
224  LUT::const_iterator iter = phi_lut[idx].find(address);
225  if ( iter != phi_lut[idx].end() ) {
226  return (*iter).second;
227  }
228  else {
229  cerr << "PhiLut::getDeltaPhi : can not find address " << address << endl;
230  return 0;
231  }
232 
233 }
234 
235 
236 //
237 // set precision for look-up tables
238 //
240 
241  nbit_phi = 12;
242  nbit_phib = 10;
243 
244 }
245 
246 
247 //
248 // get precision for look-up tables
249 //
250 pair<unsigned short, unsigned short> L1MuDTPhiLut::getPrecision() const {
251 
252  return pair<unsigned short, unsigned short>(nbit_phi,nbit_phib);
253 
254 }
int i
Definition: DBlmapReader.cc:9
char * address
Definition: mlp_lapack.h:14
DTTFBitArray< N > twoComplement() const
Definition: DTTFBitArray.h:500
L1MuDTPhiLut()
constructor
Definition: L1MuDTPhiLut.cc:51
bool good()
return status of file stream
#define abs(x)
Definition: mlp_lapack.h:159
std::map< short, short, std::less< short > > LUT
Definition: L1MuDTPhiLut.h:72
virtual ~L1MuDTPhiLut()
destructor
Definition: L1MuDTPhiLut.cc:68
int getDeltaPhi(int idx, int address) const
get delta-phi for a given address (bend-angle)
void close()
close file
#define end
Definition: vmac.h:38
void print() const
print phi-assignment look-up tables
int load()
load phi-assignment look-up tables
Definition: L1MuDTPhiLut.cc:97
int readInteger()
read one integer from file
void setPrecision()
set precision for look-up tables
tuple cout
Definition: gather_cfg.py:121
std::pair< unsigned short, unsigned short > getPrecision() const
get precision for look-up tables
std::string fullPath() const
Definition: FileInPath.cc:171
int open()
open file
void reset()
reset phi-assignment look-up tables
Definition: L1MuDTPhiLut.cc:87
Definition: DDAxes.h:10