CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/L1Trigger/DTTraco/src/Lut.cc

Go to the documentation of this file.
00001 //-----------------------
00002 // This Class's Header --
00003 //-----------------------
00004 #include "L1Trigger/DTTraco/interface/Lut.h"
00005 
00006 //----------------
00007 // Constructors --
00008 //----------------
00009 
00010 Lut::Lut(DTConfigLUTs* conf, int ntc): _conf_luts(conf) {
00011 
00012   // set parameters from configuration
00013   m_d           = _conf_luts->D(); 
00014   m_ST          = _conf_luts->BTIC();
00015   m_wheel       = _conf_luts->Wheel();
00016   m_Xcn         = _conf_luts->Xcn() - (CELL_PITCH * 4.0 * (float)(ntc-1) * (float) m_wheel);
00017 
00018   m_pitch_d_ST  = CELL_PITCH / m_ST;
00019 
00020   std::cout<< "Lut::Lut  ->  m_d " << m_d << " m_ST " << m_ST << " m_wheel " << m_wheel << " m_Xcn " << m_Xcn << " ntc " << ntc << std::endl;
00021 
00022   return;
00023 }
00024  
00025 Lut::~Lut() {}
00026 
00027 void Lut::setForTestBeam( int station, int board, int traco ) {
00028  // set parameters from fixed values for MB1 nd MB3 (used in Testbeams 2003 2004) 
00029   int nStat = station;
00030   int nBoard = board;
00031   int nTraco = traco;
00032   float tracoPos[50];
00033 
00034   if( nStat ==1 ){
00035 
00036     tracoPos[ 0] = -120.19;
00037     tracoPos[ 1] = -103.39;
00038     tracoPos[ 2] =  -86.59;
00039     tracoPos[ 3] =  -69.80;
00040     tracoPos[10] =  -52.99;
00041     tracoPos[11] =  -36.19;
00042     tracoPos[12] =  -19.39;
00043     tracoPos[13] =   -2.59;
00044     tracoPos[20] =   14.20;
00045     tracoPos[21] =   31.00;
00046     tracoPos[22] =   47.80;
00047     tracoPos[23] =   64.60;
00048     tracoPos[30] =   81.40;
00049 
00050     m_d  = 431.175;
00051     m_ST = 31;
00052     float m_Xc = tracoPos[ ( nBoard * 10 ) + nTraco ];
00053     float m_Xn = +39.0;
00054     m_Xcn =  m_Xn - m_Xc; 
00055     //m_stsize = m_CELL_PITCH / m_ST;
00056     //m_distp2 = 0.5 + ( 2.0 * m_CELL_H * m_ST / m_CELL_PITCH );
00057   }
00058 
00059   if( nStat ==3){
00060     tracoPos[ 0] = -165.45;
00061     tracoPos[ 1] = -148.65;
00062     tracoPos[ 2] = -131.85;
00063     tracoPos[ 3] = -115.05;
00064     tracoPos[10] =  -98.25;
00065     tracoPos[11] =  -81.45;
00066     tracoPos[12] =  -64.65;
00067     tracoPos[13] =  -47.85;
00068     tracoPos[20] =  -31.05;
00069     tracoPos[21] =  -14.25;
00070     tracoPos[22] =    2.54;
00071     tracoPos[23] =   19.34;
00072     tracoPos[30] =   36.14;
00073     tracoPos[31] =   52.94;
00074     tracoPos[32] =   69.74;
00075     tracoPos[33] =   86.54;
00076     tracoPos[40] =  103.34;
00077     tracoPos[41] =  120.14;
00078     tracoPos[42] =  136.94;
00079     tracoPos[43] =  153.74;
00080 
00081     m_d  = 512.47;
00082     m_ST = 31;
00083     float m_Xc = tracoPos[ ( nBoard * 10 ) + nTraco ];
00084     float m_Xn = -21.0;
00085     m_Xcn =  m_Xn - m_Xc; 
00086     //m_stsize = m_CELL_PITCH / m_ST;
00087     //m_distp2 = 0.5 + ( 2.0 * m_CELL_H * m_ST / m_CELL_PITCH );
00088   
00089   }
00090 
00091   return;
00092 }
00093 
00094 
00095 int Lut::get_k( int addr ) {
00096 //FIX attenzione controlla addr - 511 o -512???
00097   int i;
00098   float x;
00099   i = addr - 512;
00100   x = (float)i * CELL_PITCH / ( SL_D * m_ST );
00101   x = atanf(x);
00102   x = x * ANGRESOL;
00103   if(m_wheel<0)
00104     x = -x;
00105 
00106   return (int)x;
00107 }
00108 
00109 int Lut::get_x( int addr ) {
00110   int i;
00111   float a,b,x;
00112 
00113   if(addr<=511) //LUT outer
00114   {
00115         i=addr;
00116         b=m_d+SL_DIFF;
00117   }
00118   else if(addr<=1023) //LUT inner
00119   {
00120         i=addr-512;
00121         b=m_d-SL_DIFF;          
00122   }
00123   else  //LUT correlati
00124   {
00125         i=addr-1024;
00126         b=m_d;
00127   }
00128   a = m_Xcn - (m_pitch_d_ST * (float)i * (float)m_wheel);
00129   x = a/b;
00130 
00131   x = atanf(x);
00132   x = x * POSRESOL;
00133 
00134   return (int)x;
00135 }
00136 
00137 char exaDigit( int i ) {
00138   if ( i < 10 ) return (   i        + '0' );
00139   else          return ( ( i - 10 ) + 'A' );
00140 }
00141 
00142 std::string lutFmt( int i ) {
00143   char* buf = new char[6];
00144   buf[2] = ' ';
00145   buf[5] = '\0';
00146   int j4 = i % 16;
00147   i /= 16;
00148   int j3 = i % 16;
00149   i /= 16;
00150   int j2 = i % 16;
00151   i /= 16;
00152   int j1 = i % 16;
00153   buf[0] = exaDigit( j1 );
00154   buf[1] = exaDigit( j2 );
00155   buf[3] = exaDigit( j3 );
00156   buf[4] = exaDigit( j4 );
00157   std::string s( buf );
00158   return s;
00159 }
00160 
00161 
00162 
00163 /*  this for dumping luts in minicrate input format - for MB1  -- Testbeam 2004
00164 
00165 int main( int argn, char** argv ) {
00166 
00167 //  while ( 1 ) {
00168 //    int k;
00169 //    cin >> k;
00170 //    cout << lutFmt( k ) << endl;
00171 //  }
00172 
00173 //  cout << argn << endl;
00174   if ( argn != 3 ) return 1;
00175 //  cout << *argv[1] << endl;
00176 //  cout << *argv[2] << endl;
00177   if ( *argv[1] < '0' ) return 2;
00178   if ( *argv[1] > '9' ) return 2;
00179   if ( *argv[2] < '0' ) return 3;
00180   if ( *argv[2] > '9' ) return 3;
00181   int board = *argv[1] - '0';
00182   int traco = *argv[2] - '0';
00183   Lut lut( board, traco );
00184   int i;
00185   for ( i = 1; i <= 1536; i++ ) {
00186     cout << i << " " << lut.get( i ) << endl;
00187   }
00188 
00189   char* stri = "l1_  ";
00190   char* name = new char[10];
00191   char* s = stri;
00192   char* d = name;
00193   while ( *d++ = *s++ );
00194   int board;
00195   int traco;
00196   char winNewLine;
00197   winNewLine = 13;
00198   ofstream full( "l1_full" );
00199   for ( board = 0; board < 4; board++ ) {
00200     for ( traco = 0; traco < 4; traco++ ) {
00201       if ( ( board == 3 ) && ( traco != 0 ) ) continue;
00202       name[3] = '0' + board;
00203       name[4] = '0' + traco;
00204       cout << board << " " << traco << " " << name << endl;
00205       ofstream file( name );
00206       Lut lut( board, traco );
00207       cout << "loop" << endl;
00208       int i;
00209       int nfirst;
00210       int nwrite;
00211       nfirst = 0;
00212       nwrite = 0;
00213       for ( i = 0; i <= 1535; i++ ) {
00214 //        if ( i < 512 )
00215 //        if ( ( i > 512 ) && ( i < 1024 ) )
00216         int y = lut.get_x( i );
00217         int z = y;
00218         if ( z < 0 ) z += 65536;
00219         cout << board << " " << traco << " "
00220              << i << " " << y << endl;
00221         if ( nwrite == 0 ) {
00222           file << "4D " << board << " " << traco << " 0 "
00223                << lutFmt( nfirst );
00224           full << "4D " << board << " " << traco << " 0 "
00225                << lutFmt( nfirst );
00226 //               << nfirst << " ";
00227         }
00228 //        file   << lut.get( i ) << " ";
00229         file   << " " << lutFmt( z );
00230         full   << " " << lutFmt( z );
00231         nwrite++;
00232         if ( nwrite == 64 ) {
00233           file << winNewLine << endl;
00234           full << winNewLine << endl;
00235           nfirst += nwrite;
00236           nwrite = 0;
00237         }
00238       }
00239       nfirst = 0;
00240       nwrite = 0;
00241       for ( i = 0; i <= 1023; i++ ) {
00242 //        if ( i < 512 )
00243 //        if ( ( i > 512 ) && ( i < 1024 ) )
00244         int y = lut.get_k( i );
00245         int z = y;
00246         if ( z < 0 ) z += 65536;
00247         cout << board << " " << traco << " "
00248              << i << " " << y << endl;
00249         if ( nwrite == 0 ) {
00250           file << "4D " << board << " " << traco << " 1 "
00251                << lutFmt( nfirst );
00252           full << "4D " << board << " " << traco << " 1 "
00253                << lutFmt( nfirst );
00254 //               << nfirst << " ";
00255         }
00256 //        file   << lut.get( i ) << " ";
00257         file   << " " << lutFmt( z );
00258         full   << " " << lutFmt( z );
00259         nwrite++;
00260         if ( nwrite == 64 ) {
00261           file << winNewLine << endl;
00262           full << winNewLine << endl;
00263           nfirst += nwrite;
00264           nwrite = 0;
00265         }
00266       }
00267       file << "4E " << board << " " << traco << winNewLine << endl;
00268       full << "4E " << board << " " << traco << winNewLine << endl;
00269     }
00270   }
00271 
00272   return 0;
00273 
00274 }
00275 
00276 
00277 *** and for MB3  -- Testbeam 2004
00278 
00279 int main( int argn, char** argv ) {
00280 
00281 //  while ( 1 ) {
00282 //    int k;
00283 //    cin >> k;
00284 //    cout << lutFmt( k ) << endl;
00285 //  }
00286 
00287 //  cout << argn << endl;
00288   if ( argn != 3 ) return 1;
00289 //  cout << *argv[1] << endl;
00290 //  cout << *argv[2] << endl;
00291   if ( *argv[1] < '0' ) return 2;
00292   if ( *argv[1] > '9' ) return 2;
00293   if ( *argv[2] < '0' ) return 3;
00294   if ( *argv[2] > '9' ) return 3;
00295   int board = *argv[1] - '0';
00296   int traco = *argv[2] - '0';
00297   Lut lut( board, traco );
00298   int i;
00299   for ( i = 1; i <= 1536; i++ ) {
00300     cout << i << " " << lut.get( i ) << endl;
00301   }
00302 
00303   char* stri = "l3_  ";
00304   char* name = new char[10];
00305   char* s = stri;
00306   char* d = name;
00307   while ( *d++ = *s++ );
00308   int board;
00309   int traco;
00310   char winNewLine;
00311   winNewLine = 13;
00312   ofstream full( "l3_full" );
00313   for ( board = 0; board < 5; board++ ) {
00314     for ( traco = 0; traco < 4; traco++ ) {
00315       name[3] = '0' + board;
00316       name[4] = '0' + traco;
00317       cout << board << " " << traco << " " << name << endl;
00318       ofstream file( name );
00319       Lut lut( board, traco );
00320       cout << "loop" << endl;
00321       int i;
00322       int nfirst;
00323       int nwrite;
00324       nfirst = 0;
00325       nwrite = 0;
00326       for ( i = 0; i <= 1535; i++ ) {
00327 //        if ( i < 512 )
00328 //        if ( ( i > 512 ) && ( i < 1024 ) )
00329         int y = lut.get_x( i );
00330         int z = y;
00331         if ( z < 0 ) z += 65536;
00332         cout << board << " " << traco << " "
00333              << i << " " << y << endl;
00334         if ( nwrite == 0 ) {
00335           file << "4D " << board << " " << traco << " 0 "
00336                << lutFmt( nfirst );
00337           full << "4D " << board << " " << traco << " 0 "
00338                << lutFmt( nfirst );
00339 //               << nfirst << " ";
00340         }
00341 //        file   << lut.get( i ) << " ";
00342         file   << " " << lutFmt( z );
00343         full   << " " << lutFmt( z );
00344         nwrite++;
00345         if ( nwrite == 64 ) {
00346           file << winNewLine << endl;
00347           full << winNewLine << endl;
00348           nfirst += nwrite;
00349           nwrite = 0;
00350         }
00351       }
00352       nfirst = 0;
00353       nwrite = 0;
00354       for ( i = 0; i <= 1023; i++ ) {
00355 //        if ( i < 512 )
00356 //        if ( ( i > 512 ) && ( i < 1024 ) )
00357         int y = lut.get_k( i );
00358         int z = y;
00359         if ( z < 0 ) z += 65536;
00360         cout << board << " " << traco << " "
00361              << i << " " << y << endl;
00362         if ( nwrite == 0 ) {
00363           file << "4D " << board << " " << traco << " 1 "
00364                << lutFmt( nfirst );
00365           full << "4D " << board << " " << traco << " 1 "
00366                << lutFmt( nfirst );
00367 //               << nfirst << " ";
00368         }
00369 //        file   << lut.get( i ) << " ";
00370         file   << " " << lutFmt( z );
00371         full   << " " << lutFmt( z );
00372         nwrite++;
00373         if ( nwrite == 64 ) {
00374           file << winNewLine << endl;
00375           full << winNewLine << endl;
00376           nfirst += nwrite;
00377           nwrite = 0;
00378         }
00379       }
00380       file << "4E " << board << " " << traco << winNewLine << endl;
00381       full << "4E " << board << " " << traco << winNewLine << endl;
00382     }
00383   }
00384 
00385   return 0;
00386 
00387 }
00388 
00389 */
00390 
00391 
00392 
00393 void DSPtoIEEE32(short DSPmantissa, short DSPexp, float *f)
00394 {
00395   DSPexp -= 15;
00396   *f = DSPmantissa * (float)pow( 2.0, DSPexp );
00397   
00398   return;
00399 }
00400 
00401 
00402 void IEEE32toDSP(float f, short *DSPmantissa, short *DSPexp)
00403 {
00404   //long *pl, lm;
00405   uint32_t *pl = 0;
00406   uint32_t lm;
00407 
00408   //101104 SV convert float to int in safe way
00409   union { float f; uint32_t i; } u;
00410   u.f = f;
00411   *pl = u.i;
00412 
00413   bool sign=false;
00414   if( f==0.0 )
00415   {
00416     *DSPexp = 0;
00417     *DSPmantissa = 0;
00418   }
00419   else
00420   {
00421     //pl = reinterpret_cast<uint32_t*> (&f);
00422     //pl = (long*) (&f);
00423     if((*pl & 0x80000000)!=0)
00424       sign=true;
00425     lm =( 0x800000 | (*pl & 0x7FFFFF)); // [1][23bit mantissa]
00426     lm >>= 9; //reduce to 15bits
00427     lm &= 0x7FFF;
00428     *DSPexp = ((*pl>>23)&0xFF)-126;
00429     *DSPmantissa = (short)lm;
00430     if(sign)
00431       *DSPmantissa = - *DSPmantissa; // convert negative value in 2.s
00432     // complement
00433   }
00434   return;
00435 }
00436 
00437