CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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(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 parameter has been
22  // inserted in hardware strings with the shift included, 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 
35  //std::cout<< "Lut::Lut -> m_d " << m_d << " m_ST " << m_ST << " m_wheel " << 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 2004)
43  int nStat = station;
44  int nBoard = board;
45  int nTraco = traco;
46  float tracoPos[50];
47 
48  if( nStat ==1 ){
49 
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 
105  return;
106 }
107 
108 
109 int Lut::get_k( int addr ) {
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 ) {
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  }
132  else if(addr<=1023) //LUT inner
133  {
134  i=addr-512;
135  b=m_d-SL_DIFF;
136  }
137  else //LUT correlati
138  {
139  i=addr-1024;
140  b=m_d;
141  }
142  a = m_Xcn - (m_pitch_d_ST * (float)i * (float)m_wheel);
143  x = a/b;
144 
145  x = atanf(x);
146  x = x * POSRESOL;
147 
148  return (int)x;
149 }
150 
151 char exaDigit( int i ) {
152  if ( i < 10 ) return ( i + '0' );
153  else return ( ( i - 10 ) + 'A' );
154 }
155 
156 std::string lutFmt( int i ) {
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 
176 
177 /* this for dumping luts in minicrate input format - for MB1 -- Testbeam 2004
178 
179 int main( int argn, char** argv ) {
180 
181 // while ( 1 ) {
182 // int k;
183 // cin >> k;
184 // cout << lutFmt( k ) << endl;
185 // }
186 
187 // cout << argn << endl;
188  if ( argn != 3 ) return 1;
189 // cout << *argv[1] << endl;
190 // cout << *argv[2] << endl;
191  if ( *argv[1] < '0' ) return 2;
192  if ( *argv[1] > '9' ) return 2;
193  if ( *argv[2] < '0' ) return 3;
194  if ( *argv[2] > '9' ) return 3;
195  int board = *argv[1] - '0';
196  int traco = *argv[2] - '0';
197  Lut lut( board, traco );
198  int i;
199  for ( i = 1; i <= 1536; i++ ) {
200  cout << i << " " << lut.get( i ) << endl;
201  }
202 
203  char* stri = "l1_ ";
204  char* name = new char[10];
205  char* s = stri;
206  char* d = name;
207  while ( *d++ = *s++ );
208  int board;
209  int traco;
210  char winNewLine;
211  winNewLine = 13;
212  ofstream full( "l1_full" );
213  for ( board = 0; board < 4; board++ ) {
214  for ( traco = 0; traco < 4; traco++ ) {
215  if ( ( board == 3 ) && ( traco != 0 ) ) continue;
216  name[3] = '0' + board;
217  name[4] = '0' + traco;
218  cout << board << " " << traco << " " << name << endl;
219  ofstream file( name );
220  Lut lut( board, traco );
221  cout << "loop" << endl;
222  int i;
223  int nfirst;
224  int nwrite;
225  nfirst = 0;
226  nwrite = 0;
227  for ( i = 0; i <= 1535; i++ ) {
228 // if ( i < 512 )
229 // if ( ( i > 512 ) && ( i < 1024 ) )
230  int y = lut.get_x( i );
231  int z = y;
232  if ( z < 0 ) z += 65536;
233  cout << board << " " << traco << " "
234  << i << " " << y << endl;
235  if ( nwrite == 0 ) {
236  file << "4D " << board << " " << traco << " 0 "
237  << lutFmt( nfirst );
238  full << "4D " << board << " " << traco << " 0 "
239  << lutFmt( nfirst );
240 // << nfirst << " ";
241  }
242 // file << lut.get( i ) << " ";
243  file << " " << lutFmt( z );
244  full << " " << lutFmt( z );
245  nwrite++;
246  if ( nwrite == 64 ) {
247  file << winNewLine << endl;
248  full << winNewLine << endl;
249  nfirst += nwrite;
250  nwrite = 0;
251  }
252  }
253  nfirst = 0;
254  nwrite = 0;
255  for ( i = 0; i <= 1023; i++ ) {
256 // if ( i < 512 )
257 // if ( ( i > 512 ) && ( i < 1024 ) )
258  int y = lut.get_k( i );
259  int z = y;
260  if ( z < 0 ) z += 65536;
261  cout << board << " " << traco << " "
262  << i << " " << y << endl;
263  if ( nwrite == 0 ) {
264  file << "4D " << board << " " << traco << " 1 "
265  << lutFmt( nfirst );
266  full << "4D " << board << " " << traco << " 1 "
267  << lutFmt( nfirst );
268 // << nfirst << " ";
269  }
270 // file << lut.get( i ) << " ";
271  file << " " << lutFmt( z );
272  full << " " << lutFmt( z );
273  nwrite++;
274  if ( nwrite == 64 ) {
275  file << winNewLine << endl;
276  full << winNewLine << endl;
277  nfirst += nwrite;
278  nwrite = 0;
279  }
280  }
281  file << "4E " << board << " " << traco << winNewLine << endl;
282  full << "4E " << board << " " << traco << winNewLine << endl;
283  }
284  }
285 
286  return 0;
287 
288 }
289 
290 
291 *** and for MB3 -- Testbeam 2004
292 
293 int main( int argn, char** argv ) {
294 
295 // while ( 1 ) {
296 // int k;
297 // cin >> k;
298 // cout << lutFmt( k ) << endl;
299 // }
300 
301 // cout << argn << endl;
302  if ( argn != 3 ) return 1;
303 // cout << *argv[1] << endl;
304 // cout << *argv[2] << endl;
305  if ( *argv[1] < '0' ) return 2;
306  if ( *argv[1] > '9' ) return 2;
307  if ( *argv[2] < '0' ) return 3;
308  if ( *argv[2] > '9' ) return 3;
309  int board = *argv[1] - '0';
310  int traco = *argv[2] - '0';
311  Lut lut( board, traco );
312  int i;
313  for ( i = 1; i <= 1536; i++ ) {
314  cout << i << " " << lut.get( i ) << endl;
315  }
316 
317  char* stri = "l3_ ";
318  char* name = new char[10];
319  char* s = stri;
320  char* d = name;
321  while ( *d++ = *s++ );
322  int board;
323  int traco;
324  char winNewLine;
325  winNewLine = 13;
326  ofstream full( "l3_full" );
327  for ( board = 0; board < 5; board++ ) {
328  for ( traco = 0; traco < 4; traco++ ) {
329  name[3] = '0' + board;
330  name[4] = '0' + traco;
331  cout << board << " " << traco << " " << name << endl;
332  ofstream file( name );
333  Lut lut( board, traco );
334  cout << "loop" << endl;
335  int i;
336  int nfirst;
337  int nwrite;
338  nfirst = 0;
339  nwrite = 0;
340  for ( i = 0; i <= 1535; i++ ) {
341 // if ( i < 512 )
342 // if ( ( i > 512 ) && ( i < 1024 ) )
343  int y = lut.get_x( i );
344  int z = y;
345  if ( z < 0 ) z += 65536;
346  cout << board << " " << traco << " "
347  << i << " " << y << endl;
348  if ( nwrite == 0 ) {
349  file << "4D " << board << " " << traco << " 0 "
350  << lutFmt( nfirst );
351  full << "4D " << board << " " << traco << " 0 "
352  << lutFmt( nfirst );
353 // << nfirst << " ";
354  }
355 // file << lut.get( i ) << " ";
356  file << " " << lutFmt( z );
357  full << " " << lutFmt( z );
358  nwrite++;
359  if ( nwrite == 64 ) {
360  file << winNewLine << endl;
361  full << winNewLine << endl;
362  nfirst += nwrite;
363  nwrite = 0;
364  }
365  }
366  nfirst = 0;
367  nwrite = 0;
368  for ( i = 0; i <= 1023; i++ ) {
369 // if ( i < 512 )
370 // if ( ( i > 512 ) && ( i < 1024 ) )
371  int y = lut.get_k( i );
372  int z = y;
373  if ( z < 0 ) z += 65536;
374  cout << board << " " << traco << " "
375  << i << " " << y << endl;
376  if ( nwrite == 0 ) {
377  file << "4D " << board << " " << traco << " 1 "
378  << lutFmt( nfirst );
379  full << "4D " << board << " " << traco << " 1 "
380  << lutFmt( nfirst );
381 // << nfirst << " ";
382  }
383 // file << lut.get( i ) << " ";
384  file << " " << lutFmt( z );
385  full << " " << lutFmt( z );
386  nwrite++;
387  if ( nwrite == 64 ) {
388  file << winNewLine << endl;
389  full << winNewLine << endl;
390  nfirst += nwrite;
391  nwrite = 0;
392  }
393  }
394  file << "4E " << board << " " << traco << winNewLine << endl;
395  full << "4E " << board << " " << traco << winNewLine << endl;
396  }
397  }
398 
399  return 0;
400 
401 }
402 
403 */
404 
405 
406 
407 void DSPtoIEEE32(short DSPmantissa, short DSPexp, float *f)
408 {
409  DSPexp -= 15;
410  *f = DSPmantissa * (float)pow( 2.0, DSPexp );
411 
412  return;
413 }
414 
415 
416 void IEEE32toDSP(float f, short *DSPmantissa, short *DSPexp)
417 {
418  //long *pl, lm;
419  uint32_t *pl = 0;
420  uint32_t lm;
421 
422  //101104 SV convert float to int in safe way
423  union { float f; uint32_t i; } u;
424  u.f = f;
425  *pl = u.i;
426 
427  bool sign=false;
428  if( f==0.0 )
429  {
430  *DSPexp = 0;
431  *DSPmantissa = 0;
432  }
433  else
434  {
435  //pl = reinterpret_cast<uint32_t*> (&f);
436  //pl = (long*) (&f);
437  if((*pl & 0x80000000)!=0)
438  sign=true;
439  lm =( 0x800000 | (*pl & 0x7FFFFF)); // [1][23bit mantissa]
440  lm >>= 9; //reduce to 15bits
441  lm &= 0x7FFF;
442  *DSPexp = ((*pl>>23)&0xFF)-126;
443  *DSPmantissa = (short)lm;
444  if(sign)
445  *DSPmantissa = - *DSPmantissa; // convert negative value in 2.s
446  // complement
447  }
448  return;
449 }
450 
451 
int i
Definition: DBlmapReader.cc:9
void IEEE32toDSP(float f, short *DSPmantissa, short *DSPexp)
Definition: Lut.cc:416
#define ANGRESOL
Definition: Lut.h:27
int m_ST
Definition: Lut.h:54
DTConfigLUTs * _conf_luts
Definition: Lut.h:60
int Wheel() const
wheel sign (-1 or +1)
Definition: DTConfigLUTs.h:65
float m_Xcn
Definition: Lut.h:53
~Lut()
Definition: Lut.cc:39
char exaDigit(int i)
Definition: Lut.cc:151
float m_pitch_d_ST
Definition: Lut.h:58
int get_x(int addr)
Definition: Lut.cc:123
#define CELL_PITCH
Definition: Lut.h:30
std::string lutFmt(int i)
Definition: Lut.cc:156
#define SL_D
Definition: Lut.h:29
double f[11][100]
tuple conf
Definition: dbtoconf.py:185
float m_d
Definition: Lut.h:52
#define POSRESOL
Definition: Lut.h:28
void DSPtoIEEE32(short DSPmantissa, short DSPexp, float *f)
Definition: Lut.cc:407
int get_k(int addr)
Definition: Lut.cc:109
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:41
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:55
x
Definition: VDTMath.h:216
#define SL_DIFF
Definition: Lut.h:31
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:36