CMS 3D CMS Logo

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