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