00001 00002 00003 //----------------------- 00004 // This Class's Header -- 00005 //----------------------- 00006 #include "L1Trigger/DTTraco/interface/Lut.h" 00007 00008 //---------------- 00009 // Constructors -- 00010 //---------------- 00011 00012 00013 Lut::Lut( int station, int board, int traco ): nStat( station ), nBoard( board ), nTraco( traco ) { 00014 00015 switch( nStat ){ 00016 case 1: 00017 tracoPos = new float[50]; 00018 tracoPos[ 0] = -120.19; 00019 tracoPos[ 1] = -103.39; 00020 tracoPos[ 2] = -86.59; 00021 tracoPos[ 3] = -69.80; 00022 tracoPos[10] = -52.99; 00023 tracoPos[11] = -36.19; 00024 tracoPos[12] = -19.39; 00025 tracoPos[13] = -2.59; 00026 tracoPos[20] = 14.20; 00027 tracoPos[21] = 31.00; 00028 tracoPos[22] = 47.80; 00029 tracoPos[23] = 64.60; 00030 tracoPos[30] = 81.40; 00031 00032 SL_DIFF = 11.8; 00033 CELL_H = 1.3; 00034 CELL_PITCH = 4.2; 00035 ANGRESOL = 512; 00036 POSRESOL = 4096; 00037 00038 m_d = 431.175; 00039 m_ST = 31.0; 00040 m_Xc = tracoPos[ ( nBoard * 10 ) + nTraco ]; 00041 m_Xn = +39.0; 00042 m_shift = 18.0; 00043 m_stsize = CELL_PITCH / m_ST; 00044 m_distp2 = 0.5 + ( 2.0 * CELL_H * m_ST / CELL_PITCH ); 00045 00046 break; 00047 00048 case 3: 00049 tracoPos = new float[50]; 00050 tracoPos[ 0] = -165.45; 00051 tracoPos[ 1] = -148.65; 00052 tracoPos[ 2] = -131.85; 00053 tracoPos[ 3] = -115.05; 00054 tracoPos[10] = -98.25; 00055 tracoPos[11] = -81.45; 00056 tracoPos[12] = -64.65; 00057 tracoPos[13] = -47.85; 00058 tracoPos[20] = -31.05; 00059 tracoPos[21] = -14.25; 00060 tracoPos[22] = 2.54; 00061 tracoPos[23] = 19.34; 00062 tracoPos[30] = 36.14; 00063 tracoPos[31] = 52.94; 00064 tracoPos[32] = 69.74; 00065 tracoPos[33] = 86.54; 00066 tracoPos[40] = 103.34; 00067 tracoPos[41] = 120.14; 00068 tracoPos[42] = 136.94; 00069 tracoPos[43] = 153.74; 00070 00071 SL_DIFF = 11.8; 00072 CELL_H = 1.3; 00073 CELL_PITCH = 4.2; 00074 ANGRESOL = 512; 00075 POSRESOL = 4096; 00076 00077 m_d = 512.47; 00078 m_ST = 31.0; 00079 m_Xc = tracoPos[ ( nBoard * 10 ) + nTraco ]; 00080 m_Xn = -21.0; 00081 m_shift = 18.0; 00082 m_stsize = CELL_PITCH / m_ST; 00083 m_distp2 = 0.5 + ( 2.0 * CELL_H * m_ST / CELL_PITCH ); 00084 00085 break; 00086 00087 }//end switch 00088 } 00089 00090 Lut::~Lut() { 00091 } 00092 00093 int Lut::get_k( int addr ) { 00094 int i; 00095 float x; 00096 i = addr - 511; 00097 x = 2.0 * i / ( m_shift * m_distp2 ); 00098 x = atanf(x); 00099 x = x * ANGRESOL; 00100 return x; 00101 } 00102 00103 int Lut::get_x( int addr ) { 00104 int i; 00105 float d,x,Xl; 00106 if ( addr <= 511 ) { 00107 i = addr; 00108 d = m_d + SL_DIFF; 00109 } 00110 else 00111 if ( addr <= 1023 ) { 00112 i = addr - 512; 00113 d = m_d - SL_DIFF; 00114 } 00115 else 00116 { 00117 i = addr - 1024; 00118 d = m_d; 00119 } 00120 00121 Xl = m_Xc + m_stsize * i; 00122 x = ( m_Xn - Xl ) / d; 00123 x = atanf(x); 00124 x = x * POSRESOL; 00125 return x; 00126 } 00127 00128 char exaDigit( int i ) { 00129 if ( i < 10 ) return ( i + '0' ); 00130 else return ( ( i - 10 ) + 'A' ); 00131 } 00132 00133 std::string lutFmt( int i ) { 00134 char* buf = new char[6]; 00135 buf[2] = ' '; 00136 buf[5] = '\0'; 00137 int j4 = i % 16; 00138 i /= 16; 00139 int j3 = i % 16; 00140 i /= 16; 00141 int j2 = i % 16; 00142 i /= 16; 00143 int j1 = i % 16; 00144 buf[0] = exaDigit( j1 ); 00145 buf[1] = exaDigit( j2 ); 00146 buf[3] = exaDigit( j3 ); 00147 buf[4] = exaDigit( j4 ); 00148 std::string s( buf ); 00149 return s; 00150 } 00151 00152 00153 /* this for dumping luts in minicrate input format - for MB1 -- Testbeam 2004 00154 00155 int main( int argn, char** argv ) { 00156 00157 // while ( 1 ) { 00158 // int k; 00159 // cin >> k; 00160 // cout << lutFmt( k ) << endl; 00161 // } 00162 00163 // cout << argn << endl; 00164 if ( argn != 3 ) return 1; 00165 // cout << *argv[1] << endl; 00166 // cout << *argv[2] << endl; 00167 if ( *argv[1] < '0' ) return 2; 00168 if ( *argv[1] > '9' ) return 2; 00169 if ( *argv[2] < '0' ) return 3; 00170 if ( *argv[2] > '9' ) return 3; 00171 int board = *argv[1] - '0'; 00172 int traco = *argv[2] - '0'; 00173 Lut lut( board, traco ); 00174 int i; 00175 for ( i = 1; i <= 1536; i++ ) { 00176 cout << i << " " << lut.get( i ) << endl; 00177 } 00178 00179 char* stri = "l1_ "; 00180 char* name = new char[10]; 00181 char* s = stri; 00182 char* d = name; 00183 while ( *d++ = *s++ ); 00184 int board; 00185 int traco; 00186 char winNewLine; 00187 winNewLine = 13; 00188 ofstream full( "l1_full" ); 00189 for ( board = 0; board < 4; board++ ) { 00190 for ( traco = 0; traco < 4; traco++ ) { 00191 if ( ( board == 3 ) && ( traco != 0 ) ) continue; 00192 name[3] = '0' + board; 00193 name[4] = '0' + traco; 00194 cout << board << " " << traco << " " << name << endl; 00195 ofstream file( name ); 00196 Lut lut( board, traco ); 00197 cout << "loop" << endl; 00198 int i; 00199 int nfirst; 00200 int nwrite; 00201 nfirst = 0; 00202 nwrite = 0; 00203 for ( i = 0; i <= 1535; i++ ) { 00204 // if ( i < 512 ) 00205 // if ( ( i > 512 ) && ( i < 1024 ) ) 00206 int y = lut.get_x( i ); 00207 int z = y; 00208 if ( z < 0 ) z += 65536; 00209 cout << board << " " << traco << " " 00210 << i << " " << y << endl; 00211 if ( nwrite == 0 ) { 00212 file << "4D " << board << " " << traco << " 0 " 00213 << lutFmt( nfirst ); 00214 full << "4D " << board << " " << traco << " 0 " 00215 << lutFmt( nfirst ); 00216 // << nfirst << " "; 00217 } 00218 // file << lut.get( i ) << " "; 00219 file << " " << lutFmt( z ); 00220 full << " " << lutFmt( z ); 00221 nwrite++; 00222 if ( nwrite == 64 ) { 00223 file << winNewLine << endl; 00224 full << winNewLine << endl; 00225 nfirst += nwrite; 00226 nwrite = 0; 00227 } 00228 } 00229 nfirst = 0; 00230 nwrite = 0; 00231 for ( i = 0; i <= 1023; i++ ) { 00232 // if ( i < 512 ) 00233 // if ( ( i > 512 ) && ( i < 1024 ) ) 00234 int y = lut.get_k( i ); 00235 int z = y; 00236 if ( z < 0 ) z += 65536; 00237 cout << board << " " << traco << " " 00238 << i << " " << y << endl; 00239 if ( nwrite == 0 ) { 00240 file << "4D " << board << " " << traco << " 1 " 00241 << lutFmt( nfirst ); 00242 full << "4D " << board << " " << traco << " 1 " 00243 << lutFmt( nfirst ); 00244 // << nfirst << " "; 00245 } 00246 // file << lut.get( i ) << " "; 00247 file << " " << lutFmt( z ); 00248 full << " " << lutFmt( z ); 00249 nwrite++; 00250 if ( nwrite == 64 ) { 00251 file << winNewLine << endl; 00252 full << winNewLine << endl; 00253 nfirst += nwrite; 00254 nwrite = 0; 00255 } 00256 } 00257 file << "4E " << board << " " << traco << winNewLine << endl; 00258 full << "4E " << board << " " << traco << winNewLine << endl; 00259 } 00260 } 00261 00262 return 0; 00263 00264 } 00265 00266 00267 *** and for MB3 -- Testbeam 2004 00268 00269 int main( int argn, char** argv ) { 00270 00271 // while ( 1 ) { 00272 // int k; 00273 // cin >> k; 00274 // cout << lutFmt( k ) << endl; 00275 // } 00276 00277 // cout << argn << endl; 00278 if ( argn != 3 ) return 1; 00279 // cout << *argv[1] << endl; 00280 // cout << *argv[2] << endl; 00281 if ( *argv[1] < '0' ) return 2; 00282 if ( *argv[1] > '9' ) return 2; 00283 if ( *argv[2] < '0' ) return 3; 00284 if ( *argv[2] > '9' ) return 3; 00285 int board = *argv[1] - '0'; 00286 int traco = *argv[2] - '0'; 00287 Lut lut( board, traco ); 00288 int i; 00289 for ( i = 1; i <= 1536; i++ ) { 00290 cout << i << " " << lut.get( i ) << endl; 00291 } 00292 00293 char* stri = "l3_ "; 00294 char* name = new char[10]; 00295 char* s = stri; 00296 char* d = name; 00297 while ( *d++ = *s++ ); 00298 int board; 00299 int traco; 00300 char winNewLine; 00301 winNewLine = 13; 00302 ofstream full( "l3_full" ); 00303 for ( board = 0; board < 5; board++ ) { 00304 for ( traco = 0; traco < 4; traco++ ) { 00305 name[3] = '0' + board; 00306 name[4] = '0' + traco; 00307 cout << board << " " << traco << " " << name << endl; 00308 ofstream file( name ); 00309 Lut lut( board, traco ); 00310 cout << "loop" << endl; 00311 int i; 00312 int nfirst; 00313 int nwrite; 00314 nfirst = 0; 00315 nwrite = 0; 00316 for ( i = 0; i <= 1535; i++ ) { 00317 // if ( i < 512 ) 00318 // if ( ( i > 512 ) && ( i < 1024 ) ) 00319 int y = lut.get_x( i ); 00320 int z = y; 00321 if ( z < 0 ) z += 65536; 00322 cout << board << " " << traco << " " 00323 << i << " " << y << endl; 00324 if ( nwrite == 0 ) { 00325 file << "4D " << board << " " << traco << " 0 " 00326 << lutFmt( nfirst ); 00327 full << "4D " << board << " " << traco << " 0 " 00328 << lutFmt( nfirst ); 00329 // << nfirst << " "; 00330 } 00331 // file << lut.get( i ) << " "; 00332 file << " " << lutFmt( z ); 00333 full << " " << lutFmt( z ); 00334 nwrite++; 00335 if ( nwrite == 64 ) { 00336 file << winNewLine << endl; 00337 full << winNewLine << endl; 00338 nfirst += nwrite; 00339 nwrite = 0; 00340 } 00341 } 00342 nfirst = 0; 00343 nwrite = 0; 00344 for ( i = 0; i <= 1023; i++ ) { 00345 // if ( i < 512 ) 00346 // if ( ( i > 512 ) && ( i < 1024 ) ) 00347 int y = lut.get_k( i ); 00348 int z = y; 00349 if ( z < 0 ) z += 65536; 00350 cout << board << " " << traco << " " 00351 << i << " " << y << endl; 00352 if ( nwrite == 0 ) { 00353 file << "4D " << board << " " << traco << " 1 " 00354 << lutFmt( nfirst ); 00355 full << "4D " << board << " " << traco << " 1 " 00356 << lutFmt( nfirst ); 00357 // << nfirst << " "; 00358 } 00359 // file << lut.get( i ) << " "; 00360 file << " " << lutFmt( z ); 00361 full << " " << lutFmt( z ); 00362 nwrite++; 00363 if ( nwrite == 64 ) { 00364 file << winNewLine << endl; 00365 full << winNewLine << endl; 00366 nfirst += nwrite; 00367 nwrite = 0; 00368 } 00369 } 00370 file << "4E " << board << " " << traco << winNewLine << endl; 00371 full << "4E " << board << " " << traco << winNewLine << endl; 00372 } 00373 } 00374 00375 return 0; 00376 00377 } 00378 00379 */ 00380 00381