CMS 3D CMS Logo

Lut.cc
Go to the documentation of this file.
1 //
2 // 110208 SV TRACO hardware bug included
3 //
4 //
5 //-----------------------
6 // This Class's Header --
7 //-----------------------
9 
10 //----------------
11 // Constructors --
12 //----------------
13 
14 Lut::Lut(const DTConfigLUTs *conf, int ntc, float SL_shift) : _conf_luts(conf) {
15 
16  // set parameters from configuration
17  m_d = _conf_luts->D();
18  m_ST = _conf_luts->BTIC();
20 
21  // 110208 SV TRACO hardware bug included: Xcn must be corrected because Xcn
22  // parameter has been inserted in hardware strings with the shift included,
23  // because TRACO doesn't apply shift in positive cases
24  float Xcn_corr = _conf_luts->Xcn();
25  if (SL_shift > 0) {
26  if (Xcn_corr > 0)
27  Xcn_corr = Xcn_corr - SL_shift;
28  if (Xcn_corr < 0)
29  Xcn_corr = Xcn_corr + SL_shift;
30  }
31 
32  m_Xcn = Xcn_corr - (CELL_PITCH * 4.0 * (float)(ntc - 1) * (float)m_wheel);
34 
35  // std::cout<< "Lut::Lut -> m_d " << m_d << " m_ST " << m_ST << " m_wheel "
36  // << m_wheel << " m_Xcn " << m_Xcn << " ntc " << ntc << std::endl;
37  return;
38 }
39 
41 
42 void Lut::setForTestBeam(int station, int board, int traco) {
43  // set parameters from fixed values for MB1 nd MB3 (used in Testbeams 2003
44  // 2004)
45  int nStat = station;
46  int nBoard = board;
47  int nTraco = traco;
48  float tracoPos[50];
49 
50  if (nStat == 1) {
51 
52  tracoPos[0] = -120.19;
53  tracoPos[1] = -103.39;
54  tracoPos[2] = -86.59;
55  tracoPos[3] = -69.80;
56  tracoPos[10] = -52.99;
57  tracoPos[11] = -36.19;
58  tracoPos[12] = -19.39;
59  tracoPos[13] = -2.59;
60  tracoPos[20] = 14.20;
61  tracoPos[21] = 31.00;
62  tracoPos[22] = 47.80;
63  tracoPos[23] = 64.60;
64  tracoPos[30] = 81.40;
65 
66  m_d = 431.175;
67  m_ST = 31;
68  float m_Xc = tracoPos[(nBoard * 10) + nTraco];
69  float m_Xn = +39.0;
70  m_Xcn = m_Xn - m_Xc;
71  // m_stsize = m_CELL_PITCH / m_ST;
72  // m_distp2 = 0.5 + ( 2.0 * m_CELL_H * m_ST / m_CELL_PITCH );
73  }
74 
75  if (nStat == 3) {
76  tracoPos[0] = -165.45;
77  tracoPos[1] = -148.65;
78  tracoPos[2] = -131.85;
79  tracoPos[3] = -115.05;
80  tracoPos[10] = -98.25;
81  tracoPos[11] = -81.45;
82  tracoPos[12] = -64.65;
83  tracoPos[13] = -47.85;
84  tracoPos[20] = -31.05;
85  tracoPos[21] = -14.25;
86  tracoPos[22] = 2.54;
87  tracoPos[23] = 19.34;
88  tracoPos[30] = 36.14;
89  tracoPos[31] = 52.94;
90  tracoPos[32] = 69.74;
91  tracoPos[33] = 86.54;
92  tracoPos[40] = 103.34;
93  tracoPos[41] = 120.14;
94  tracoPos[42] = 136.94;
95  tracoPos[43] = 153.74;
96 
97  m_d = 512.47;
98  m_ST = 31;
99  float m_Xc = tracoPos[(nBoard * 10) + nTraco];
100  float m_Xn = -21.0;
101  m_Xcn = m_Xn - m_Xc;
102  // m_stsize = m_CELL_PITCH / m_ST;
103  // m_distp2 = 0.5 + ( 2.0 * m_CELL_H * m_ST / m_CELL_PITCH );
104  }
105 
106  return;
107 }
108 
109 int Lut::get_k(int addr) const {
110  // FIX attenzione controlla addr - 511 o -512???
111  int i;
112  float x;
113  i = addr - 512;
114  x = (float)i * CELL_PITCH / (SL_D * m_ST);
115  x = atanf(x);
116  x = x * ANGRESOL;
117  if (m_wheel < 0)
118  x = -x;
119 
120  return (int)x;
121 }
122 
123 int Lut::get_x(int addr) const {
124  int i;
125  float a, b, x;
126 
127  if (addr <= 511) // LUT outer
128  {
129  i = addr;
130  b = m_d + SL_DIFF;
131  } else if (addr <= 1023) // LUT inner
132  {
133  i = addr - 512;
134  b = m_d - SL_DIFF;
135  } else // LUT correlati
136  {
137  i = addr - 1024;
138  b = m_d;
139  }
140  a = m_Xcn - (m_pitch_d_ST * (float)i * (float)m_wheel);
141  x = a / b;
142 
143  x = atanf(x);
144  x = x * POSRESOL;
145 
146  return (int)x;
147 }
148 
149 char exaDigit(int i) {
150  if (i < 10)
151  return (i + '0');
152  else
153  return ((i - 10) + 'A');
154 }
155 
157  char *buf = new char[6];
158  buf[2] = ' ';
159  buf[5] = '\0';
160  int j4 = i % 16;
161  i /= 16;
162  int j3 = i % 16;
163  i /= 16;
164  int j2 = i % 16;
165  i /= 16;
166  int j1 = i % 16;
167  buf[0] = exaDigit(j1);
168  buf[1] = exaDigit(j2);
169  buf[3] = exaDigit(j3);
170  buf[4] = exaDigit(j4);
171  std::string s(buf);
172  return s;
173 }
174 
175 /* this for dumping luts in minicrate input format - for MB1 -- Testbeam 2004
176 
177 int main( int argn, char** argv ) {
178 
179 // while ( 1 ) {
180 // int k;
181 // cin >> k;
182 // cout << lutFmt( k ) << endl;
183 // }
184 
185 // cout << argn << endl;
186  if ( argn != 3 ) return 1;
187 // cout << *argv[1] << endl;
188 // cout << *argv[2] << endl;
189  if ( *argv[1] < '0' ) return 2;
190  if ( *argv[1] > '9' ) return 2;
191  if ( *argv[2] < '0' ) return 3;
192  if ( *argv[2] > '9' ) return 3;
193  int board = *argv[1] - '0';
194  int traco = *argv[2] - '0';
195  Lut lut( board, traco );
196  int i;
197  for ( i = 1; i <= 1536; i++ ) {
198  cout << i << " " << lut.get( i ) << endl;
199  }
200 
201  char* stri = "l1_ ";
202  char* name = new char[10];
203  char* s = stri;
204  char* d = name;
205  while ( *d++ = *s++ );
206  int board;
207  int traco;
208  char winNewLine;
209  winNewLine = 13;
210  ofstream full( "l1_full" );
211  for ( board = 0; board < 4; board++ ) {
212  for ( traco = 0; traco < 4; traco++ ) {
213  if ( ( board == 3 ) && ( traco != 0 ) ) continue;
214  name[3] = '0' + board;
215  name[4] = '0' + traco;
216  cout << board << " " << traco << " " << name << endl;
217  ofstream file( name );
218  Lut lut( board, traco );
219  cout << "loop" << endl;
220  int i;
221  int nfirst;
222  int nwrite;
223  nfirst = 0;
224  nwrite = 0;
225  for ( i = 0; i <= 1535; i++ ) {
226 // if ( i < 512 )
227 // if ( ( i > 512 ) && ( i < 1024 ) )
228  int y = lut.get_x( i );
229  int z = y;
230  if ( z < 0 ) z += 65536;
231  cout << board << " " << traco << " "
232  << i << " " << y << endl;
233  if ( nwrite == 0 ) {
234  file << "4D " << board << " " << traco << " 0 "
235  << lutFmt( nfirst );
236  full << "4D " << board << " " << traco << " 0 "
237  << lutFmt( nfirst );
238 // << nfirst << " ";
239  }
240 // file << lut.get( i ) << " ";
241  file << " " << lutFmt( z );
242  full << " " << lutFmt( z );
243  nwrite++;
244  if ( nwrite == 64 ) {
245  file << winNewLine << endl;
246  full << winNewLine << endl;
247  nfirst += nwrite;
248  nwrite = 0;
249  }
250  }
251  nfirst = 0;
252  nwrite = 0;
253  for ( i = 0; i <= 1023; i++ ) {
254 // if ( i < 512 )
255 // if ( ( i > 512 ) && ( i < 1024 ) )
256  int y = lut.get_k( i );
257  int z = y;
258  if ( z < 0 ) z += 65536;
259  cout << board << " " << traco << " "
260  << i << " " << y << endl;
261  if ( nwrite == 0 ) {
262  file << "4D " << board << " " << traco << " 1 "
263  << lutFmt( nfirst );
264  full << "4D " << board << " " << traco << " 1 "
265  << lutFmt( nfirst );
266 // << nfirst << " ";
267  }
268 // file << lut.get( i ) << " ";
269  file << " " << lutFmt( z );
270  full << " " << lutFmt( z );
271  nwrite++;
272  if ( nwrite == 64 ) {
273  file << winNewLine << endl;
274  full << winNewLine << endl;
275  nfirst += nwrite;
276  nwrite = 0;
277  }
278  }
279  file << "4E " << board << " " << traco << winNewLine << endl;
280  full << "4E " << board << " " << traco << winNewLine << endl;
281  }
282  }
283 
284  return 0;
285 
286 }
287 
288 
289 *** and for MB3 -- Testbeam 2004
290 
291 int main( int argn, char** argv ) {
292 
293 // while ( 1 ) {
294 // int k;
295 // cin >> k;
296 // cout << lutFmt( k ) << endl;
297 // }
298 
299 // cout << argn << endl;
300  if ( argn != 3 ) return 1;
301 // cout << *argv[1] << endl;
302 // cout << *argv[2] << endl;
303  if ( *argv[1] < '0' ) return 2;
304  if ( *argv[1] > '9' ) return 2;
305  if ( *argv[2] < '0' ) return 3;
306  if ( *argv[2] > '9' ) return 3;
307  int board = *argv[1] - '0';
308  int traco = *argv[2] - '0';
309  Lut lut( board, traco );
310  int i;
311  for ( i = 1; i <= 1536; i++ ) {
312  cout << i << " " << lut.get( i ) << endl;
313  }
314 
315  char* stri = "l3_ ";
316  char* name = new char[10];
317  char* s = stri;
318  char* d = name;
319  while ( *d++ = *s++ );
320  int board;
321  int traco;
322  char winNewLine;
323  winNewLine = 13;
324  ofstream full( "l3_full" );
325  for ( board = 0; board < 5; board++ ) {
326  for ( traco = 0; traco < 4; traco++ ) {
327  name[3] = '0' + board;
328  name[4] = '0' + traco;
329  cout << board << " " << traco << " " << name << endl;
330  ofstream file( name );
331  Lut lut( board, traco );
332  cout << "loop" << endl;
333  int i;
334  int nfirst;
335  int nwrite;
336  nfirst = 0;
337  nwrite = 0;
338  for ( i = 0; i <= 1535; i++ ) {
339 // if ( i < 512 )
340 // if ( ( i > 512 ) && ( i < 1024 ) )
341  int y = lut.get_x( i );
342  int z = y;
343  if ( z < 0 ) z += 65536;
344  cout << board << " " << traco << " "
345  << i << " " << y << endl;
346  if ( nwrite == 0 ) {
347  file << "4D " << board << " " << traco << " 0 "
348  << lutFmt( nfirst );
349  full << "4D " << board << " " << traco << " 0 "
350  << lutFmt( nfirst );
351 // << nfirst << " ";
352  }
353 // file << lut.get( i ) << " ";
354  file << " " << lutFmt( z );
355  full << " " << lutFmt( z );
356  nwrite++;
357  if ( nwrite == 64 ) {
358  file << winNewLine << endl;
359  full << winNewLine << endl;
360  nfirst += nwrite;
361  nwrite = 0;
362  }
363  }
364  nfirst = 0;
365  nwrite = 0;
366  for ( i = 0; i <= 1023; i++ ) {
367 // if ( i < 512 )
368 // if ( ( i > 512 ) && ( i < 1024 ) )
369  int y = lut.get_k( i );
370  int z = y;
371  if ( z < 0 ) z += 65536;
372  cout << board << " " << traco << " "
373  << i << " " << y << endl;
374  if ( nwrite == 0 ) {
375  file << "4D " << board << " " << traco << " 1 "
376  << lutFmt( nfirst );
377  full << "4D " << board << " " << traco << " 1 "
378  << lutFmt( nfirst );
379 // << nfirst << " ";
380  }
381 // file << lut.get( i ) << " ";
382  file << " " << lutFmt( z );
383  full << " " << lutFmt( z );
384  nwrite++;
385  if ( nwrite == 64 ) {
386  file << winNewLine << endl;
387  full << winNewLine << endl;
388  nfirst += nwrite;
389  nwrite = 0;
390  }
391  }
392  file << "4E " << board << " " << traco << winNewLine << endl;
393  full << "4E " << board << " " << traco << winNewLine << endl;
394  }
395  }
396 
397  return 0;
398 
399 }
400 
401 */
402 
403 void DSPtoIEEE32(short DSPmantissa, short DSPexp, float *f) {
404  DSPexp -= 15;
405  *f = DSPmantissa * (float)pow(2.0, DSPexp);
406 
407  return;
408 }
409 
410 void IEEE32toDSP(float f, short *DSPmantissa, short *DSPexp) {
411  // long *pl, lm;
412  uint32_t pl;
413  uint32_t lm;
414 
415  // 101104 SV convert float to int in safe way
416  union {
417  float f;
418  uint32_t i;
419  } u;
420  u.f = f;
421  pl = u.i;
422 
423  bool sign = false;
424  if (f == 0.0) {
425  *DSPexp = 0;
426  *DSPmantissa = 0;
427  } else {
428  // pl = reinterpret_cast<uint32_t*> (&f);
429  // pl = (long*) (&f);
430  if ((pl & 0x80000000) != 0)
431  sign = true;
432  lm = (0x800000 | (pl & 0x7FFFFF)); // [1][23bit mantissa]
433  lm >>= 9; // reduce to 15bits
434  lm &= 0x7FFF;
435  *DSPexp = ((pl >> 23) & 0xFF) - 126;
436  *DSPmantissa = (short)lm;
437  if (sign)
438  *DSPmantissa = -*DSPmantissa; // convert negative value in 2.s
439  // complement
440  }
441  return;
442 }
#define ANGRESOL
Definition: Lut.h:25
void IEEE32toDSP(float f, short *DSPmantissa, short *DSPexp)
int m_ST
Definition: Lut.h:52
int get_k(int addr) const
Definition: Lut.cc:109
int Wheel() const
wheel sign (-1 or +1)
Definition: DTConfigLUTs.h:65
float m_Xcn
Definition: Lut.h:51
int get_x(int addr) const
Definition: Lut.cc:123
~Lut()
Definition: Lut.cc:40
char exaDigit(int i)
Definition: Lut.cc:149
float m_pitch_d_ST
Definition: Lut.h:56
#define CELL_PITCH
Definition: Lut.h:28
std::string lutFmt(int i)
Definition: Lut.cc:156
#define SL_D
Definition: Lut.h:27
double f[11][100]
void DSPtoIEEE32(short DSPmantissa, short DSPexp, float *f)
float m_d
Definition: Lut.h:50
#define POSRESOL
Definition: Lut.h:26
double b
Definition: hdecay.h:120
int BTIC() const
BTIC parameter.
Definition: DTConfigLUTs.h:56
void setForTestBeam(int station, int board, int traco)
Definition: Lut.cc:42
double a
Definition: hdecay.h:121
float Xcn() const
Xcn: distance vertex to normal, unit cm.
Definition: DTConfigLUTs.h:62
int m_wheel
Definition: Lut.h:53
const DTConfigLUTs * _conf_luts
Definition: Lut.h:58
#define SL_DIFF
Definition: Lut.h:29
float D() const
d: distance vertex to normal, unit cm.
Definition: DTConfigLUTs.h:59
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
Lut()
Definition: Lut.h:34