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