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  assert(number);
143  tmplut.insert(make_pair( adr_old, ((sum_phi/number) >> sh_phi) ));
144 
145  adr_old = adr;
146  number = 0;
147  sum_phi = 0;
148  }
149 
150  sum_phi += phi;
151 
152  if ( !file.good() ) file.close();
153 
154  }
155 
156  file.close();
157  phi_lut.push_back(tmplut);
158  }
159  return 0;
160 
161 }
162 
163 
164 //
165 // print phi-assignment look-up tables
166 //
167 void L1MuDTPhiLut::print() const {
168 
169  cout << endl;
170  cout << "L1 barrel Track Finder Phi-Assignment look-up tables :" << endl;
171  cout << "======================================================" << endl;
172  cout << endl;
173  cout << "Precision : " << endl;
174  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
175  cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
176 
177  // loop over all phi-assignment methods
178  for ( int idx = 0; idx < 2; idx++ ) {
179 
180  cout << endl;
181  if ( idx == 0 ) cout << "Phi-Assignment Method : " << "PHI12" << endl;
182  if ( idx == 1 ) cout << "Phi-Assignment Method : " << "PHI42" << endl;
183  cout << "=============================" << endl;
184  cout << endl;
185 
186  cout << " address";
187  for ( int i = 0; i < nbit_phib; i++ ) cout << ' ';
188  cout << " value" << endl;
189  for ( int i = 0; i < nbit_phi + nbit_phib; i++ ) cout << '-';
190  cout << "----------------------" << endl;
191 
192  LUT::const_iterator iter = phi_lut[idx].begin();
193  while ( iter != phi_lut[idx].end() ) {
194  int address = (*iter).first;
195  int value = (*iter).second;
196 
197  DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
198  DTTFBitArray<12> b_value(static_cast<unsigned>(abs(value)));
199 
200  if ( address < 0 ) b_address.twoComplement();
201  if ( value < 0 ) b_value.twoComplement();
202 
203  cout.setf(ios::right,ios::adjustfield);
204  cout << " " << setbase(10) << setw(5) << address << " (";
205  for ( int i = nbit_phib-1; i >= 0; i-- ) cout << b_address[i];
206  cout << ") " << setw(5) << value << " (";
207  for ( int i = nbit_phi-1; i >= 0; i-- ) cout << b_value[i];
208  cout << ") " << endl;
209 
210  iter++;
211  }
212 
213  }
214 
215  cout << endl;
216 
217 }
218 
219 
220 //
221 // get delta-phi value for a given address
222 //
223 int L1MuDTPhiLut::getDeltaPhi(int idx, int address) const {
224 
225  LUT::const_iterator iter = phi_lut[idx].find(address);
226  if ( iter != phi_lut[idx].end() ) {
227  return (*iter).second;
228  }
229  else {
230  cerr << "PhiLut::getDeltaPhi : can not find address " << address << endl;
231  return 0;
232  }
233 
234 }
235 
236 
237 //
238 // set precision for look-up tables
239 //
241 
242  nbit_phi = 12;
243  nbit_phib = 10;
244 
245 }
246 
247 
248 //
249 // get precision for look-up tables
250 //
251 pair<unsigned short, unsigned short> L1MuDTPhiLut::getPrecision() const {
252 
253  return pair<unsigned short, unsigned short>(nbit_phi,nbit_phib);
254 
255 }
int i
Definition: DBlmapReader.cc:9
DTTFBitArray< N > twoComplement() const
Definition: DTTFBitArray.h:500
assert(m_qm.get())
L1MuDTPhiLut()
constructor
Definition: L1MuDTPhiLut.cc:51
bool good()
return status of file stream
std::map< short, short, std::less< short > > LUT
Definition: L1MuDTPhiLut.h:74
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
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define end
Definition: vmac.h:37
void print() const
print phi-assignment look-up tables
int load()
load phi-assignment look-up tables
Definition: L1MuDTPhiLut.cc:97
Geom::Phi< T > phi() const
int readInteger()
read one integer from file
void setPrecision()
set precision for look-up tables
tuple cout
Definition: gather_cfg.py:145
std::pair< unsigned short, unsigned short > getPrecision() const
get precision for look-up tables
std::string fullPath() const
Definition: FileInPath.cc:184
int open()
open file
void reset()
reset phi-assignment look-up tables
Definition: L1MuDTPhiLut.cc:87