|
||||
File indexing completed on 2024-04-06 12:19:44
0001 // 0002 // 110208 SV TRACO hardware bug included 0003 // 0004 // 0005 //----------------------- 0006 // This Class's Header -- 0007 //----------------------- 0008 #include "L1Trigger/DTTraco/interface/Lut.h" 0009 0010 //---------------- 0011 // Constructors -- 0012 //---------------- 0013 0014 Lut::Lut(const DTConfigLUTs *conf, int ntc, float SL_shift) : _conf_luts(conf) { 0015 // set parameters from configuration 0016 m_d = _conf_luts->D(); 0017 m_ST = _conf_luts->BTIC(); 0018 m_wheel = _conf_luts->Wheel(); 0019 0020 // 110208 SV TRACO hardware bug included: Xcn must be corrected because Xcn 0021 // parameter has been inserted in hardware strings with the shift included, 0022 // because TRACO doesn't apply shift in positive cases 0023 float Xcn_corr = _conf_luts->Xcn(); 0024 if (SL_shift > 0) { 0025 if (Xcn_corr > 0) 0026 Xcn_corr = Xcn_corr - SL_shift; 0027 if (Xcn_corr < 0) 0028 Xcn_corr = Xcn_corr + SL_shift; 0029 } 0030 0031 m_Xcn = Xcn_corr - (CELL_PITCH * 4.0 * (float)(ntc - 1) * (float)m_wheel); 0032 m_pitch_d_ST = CELL_PITCH / m_ST; 0033 0034 // std::cout<< "Lut::Lut -> m_d " << m_d << " m_ST " << m_ST << " m_wheel " 0035 // << m_wheel << " m_Xcn " << m_Xcn << " ntc " << ntc << std::endl; 0036 return; 0037 } 0038 0039 Lut::~Lut() {} 0040 0041 void Lut::setForTestBeam(int station, int board, int traco) { 0042 // set parameters from fixed values for MB1 nd MB3 (used in Testbeams 2003 0043 // 2004) 0044 int nStat = station; 0045 int nBoard = board; 0046 int nTraco = traco; 0047 float tracoPos[50]; 0048 0049 if (nStat == 1) { 0050 tracoPos[0] = -120.19; 0051 tracoPos[1] = -103.39; 0052 tracoPos[2] = -86.59; 0053 tracoPos[3] = -69.80; 0054 tracoPos[10] = -52.99; 0055 tracoPos[11] = -36.19; 0056 tracoPos[12] = -19.39; 0057 tracoPos[13] = -2.59; 0058 tracoPos[20] = 14.20; 0059 tracoPos[21] = 31.00; 0060 tracoPos[22] = 47.80; 0061 tracoPos[23] = 64.60; 0062 tracoPos[30] = 81.40; 0063 0064 m_d = 431.175; 0065 m_ST = 31; 0066 float m_Xc = tracoPos[(nBoard * 10) + nTraco]; 0067 float m_Xn = +39.0; 0068 m_Xcn = m_Xn - m_Xc; 0069 // m_stsize = m_CELL_PITCH / m_ST; 0070 // m_distp2 = 0.5 + ( 2.0 * m_CELL_H * m_ST / m_CELL_PITCH ); 0071 } 0072 0073 if (nStat == 3) { 0074 tracoPos[0] = -165.45; 0075 tracoPos[1] = -148.65; 0076 tracoPos[2] = -131.85; 0077 tracoPos[3] = -115.05; 0078 tracoPos[10] = -98.25; 0079 tracoPos[11] = -81.45; 0080 tracoPos[12] = -64.65; 0081 tracoPos[13] = -47.85; 0082 tracoPos[20] = -31.05; 0083 tracoPos[21] = -14.25; 0084 tracoPos[22] = 2.54; 0085 tracoPos[23] = 19.34; 0086 tracoPos[30] = 36.14; 0087 tracoPos[31] = 52.94; 0088 tracoPos[32] = 69.74; 0089 tracoPos[33] = 86.54; 0090 tracoPos[40] = 103.34; 0091 tracoPos[41] = 120.14; 0092 tracoPos[42] = 136.94; 0093 tracoPos[43] = 153.74; 0094 0095 m_d = 512.47; 0096 m_ST = 31; 0097 float m_Xc = tracoPos[(nBoard * 10) + nTraco]; 0098 float m_Xn = -21.0; 0099 m_Xcn = m_Xn - m_Xc; 0100 // m_stsize = m_CELL_PITCH / m_ST; 0101 // m_distp2 = 0.5 + ( 2.0 * m_CELL_H * m_ST / m_CELL_PITCH ); 0102 } 0103 0104 return; 0105 } 0106 0107 int Lut::get_k(int addr) const { 0108 // FIX attenzione controlla addr - 511 o -512??? 0109 int i; 0110 float x; 0111 i = addr - 512; 0112 x = (float)i * CELL_PITCH / (SL_D * m_ST); 0113 x = atanf(x); 0114 x = x * ANGRESOL; 0115 if (m_wheel < 0) 0116 x = -x; 0117 0118 return (int)x; 0119 } 0120 0121 int Lut::get_x(int addr) const { 0122 int i; 0123 float a, b, x; 0124 0125 if (addr <= 511) // LUT outer 0126 { 0127 i = addr; 0128 b = m_d + SL_DIFF; 0129 } else if (addr <= 1023) // LUT inner 0130 { 0131 i = addr - 512; 0132 b = m_d - SL_DIFF; 0133 } else // LUT correlati 0134 { 0135 i = addr - 1024; 0136 b = m_d; 0137 } 0138 a = m_Xcn - (m_pitch_d_ST * (float)i * (float)m_wheel); 0139 x = a / b; 0140 0141 x = atanf(x); 0142 x = x * POSRESOL; 0143 0144 return (int)x; 0145 } 0146 0147 char exaDigit(int i) { 0148 if (i < 10) 0149 return (i + '0'); 0150 else 0151 return ((i - 10) + 'A'); 0152 } 0153 0154 std::string lutFmt(int i) { 0155 char *buf = new char[6]; 0156 buf[2] = ' '; 0157 buf[5] = '\0'; 0158 int j4 = i % 16; 0159 i /= 16; 0160 int j3 = i % 16; 0161 i /= 16; 0162 int j2 = i % 16; 0163 i /= 16; 0164 int j1 = i % 16; 0165 buf[0] = exaDigit(j1); 0166 buf[1] = exaDigit(j2); 0167 buf[3] = exaDigit(j3); 0168 buf[4] = exaDigit(j4); 0169 std::string s(buf); 0170 return s; 0171 } 0172 0173 /* this for dumping luts in minicrate input format - for MB1 -- Testbeam 2004 0174 0175 int main( int argn, char** argv ) { 0176 0177 // while ( 1 ) { 0178 // int k; 0179 // cin >> k; 0180 // cout << lutFmt( k ) << endl; 0181 // } 0182 0183 // cout << argn << endl; 0184 if ( argn != 3 ) return 1; 0185 // cout << *argv[1] << endl; 0186 // cout << *argv[2] << endl; 0187 if ( *argv[1] < '0' ) return 2; 0188 if ( *argv[1] > '9' ) return 2; 0189 if ( *argv[2] < '0' ) return 3; 0190 if ( *argv[2] > '9' ) return 3; 0191 int board = *argv[1] - '0'; 0192 int traco = *argv[2] - '0'; 0193 Lut lut( board, traco ); 0194 int i; 0195 for ( i = 1; i <= 1536; i++ ) { 0196 cout << i << " " << lut.get( i ) << endl; 0197 } 0198 0199 char* stri = "l1_ "; 0200 char* name = new char[10]; 0201 char* s = stri; 0202 char* d = name; 0203 while ( *d++ = *s++ ); 0204 int board; 0205 int traco; 0206 char winNewLine; 0207 winNewLine = 13; 0208 ofstream full( "l1_full" ); 0209 for ( board = 0; board < 4; board++ ) { 0210 for ( traco = 0; traco < 4; traco++ ) { 0211 if ( ( board == 3 ) && ( traco != 0 ) ) continue; 0212 name[3] = '0' + board; 0213 name[4] = '0' + traco; 0214 cout << board << " " << traco << " " << name << endl; 0215 ofstream file( name ); 0216 Lut lut( board, traco ); 0217 cout << "loop" << endl; 0218 int i; 0219 int nfirst; 0220 int nwrite; 0221 nfirst = 0; 0222 nwrite = 0; 0223 for ( i = 0; i <= 1535; i++ ) { 0224 // if ( i < 512 ) 0225 // if ( ( i > 512 ) && ( i < 1024 ) ) 0226 int y = lut.get_x( i ); 0227 int z = y; 0228 if ( z < 0 ) z += 65536; 0229 cout << board << " " << traco << " " 0230 << i << " " << y << endl; 0231 if ( nwrite == 0 ) { 0232 file << "4D " << board << " " << traco << " 0 " 0233 << lutFmt( nfirst ); 0234 full << "4D " << board << " " << traco << " 0 " 0235 << lutFmt( nfirst ); 0236 // << nfirst << " "; 0237 } 0238 // file << lut.get( i ) << " "; 0239 file << " " << lutFmt( z ); 0240 full << " " << lutFmt( z ); 0241 nwrite++; 0242 if ( nwrite == 64 ) { 0243 file << winNewLine << endl; 0244 full << winNewLine << endl; 0245 nfirst += nwrite; 0246 nwrite = 0; 0247 } 0248 } 0249 nfirst = 0; 0250 nwrite = 0; 0251 for ( i = 0; i <= 1023; i++ ) { 0252 // if ( i < 512 ) 0253 // if ( ( i > 512 ) && ( i < 1024 ) ) 0254 int y = lut.get_k( i ); 0255 int z = y; 0256 if ( z < 0 ) z += 65536; 0257 cout << board << " " << traco << " " 0258 << i << " " << y << endl; 0259 if ( nwrite == 0 ) { 0260 file << "4D " << board << " " << traco << " 1 " 0261 << lutFmt( nfirst ); 0262 full << "4D " << board << " " << traco << " 1 " 0263 << lutFmt( nfirst ); 0264 // << nfirst << " "; 0265 } 0266 // file << lut.get( i ) << " "; 0267 file << " " << lutFmt( z ); 0268 full << " " << lutFmt( z ); 0269 nwrite++; 0270 if ( nwrite == 64 ) { 0271 file << winNewLine << endl; 0272 full << winNewLine << endl; 0273 nfirst += nwrite; 0274 nwrite = 0; 0275 } 0276 } 0277 file << "4E " << board << " " << traco << winNewLine << endl; 0278 full << "4E " << board << " " << traco << winNewLine << endl; 0279 } 0280 } 0281 0282 return 0; 0283 0284 } 0285 0286 0287 *** and for MB3 -- Testbeam 2004 0288 0289 int main( int argn, char** argv ) { 0290 0291 // while ( 1 ) { 0292 // int k; 0293 // cin >> k; 0294 // cout << lutFmt( k ) << endl; 0295 // } 0296 0297 // cout << argn << endl; 0298 if ( argn != 3 ) return 1; 0299 // cout << *argv[1] << endl; 0300 // cout << *argv[2] << endl; 0301 if ( *argv[1] < '0' ) return 2; 0302 if ( *argv[1] > '9' ) return 2; 0303 if ( *argv[2] < '0' ) return 3; 0304 if ( *argv[2] > '9' ) return 3; 0305 int board = *argv[1] - '0'; 0306 int traco = *argv[2] - '0'; 0307 Lut lut( board, traco ); 0308 int i; 0309 for ( i = 1; i <= 1536; i++ ) { 0310 cout << i << " " << lut.get( i ) << endl; 0311 } 0312 0313 char* stri = "l3_ "; 0314 char* name = new char[10]; 0315 char* s = stri; 0316 char* d = name; 0317 while ( *d++ = *s++ ); 0318 int board; 0319 int traco; 0320 char winNewLine; 0321 winNewLine = 13; 0322 ofstream full( "l3_full" ); 0323 for ( board = 0; board < 5; board++ ) { 0324 for ( traco = 0; traco < 4; traco++ ) { 0325 name[3] = '0' + board; 0326 name[4] = '0' + traco; 0327 cout << board << " " << traco << " " << name << endl; 0328 ofstream file( name ); 0329 Lut lut( board, traco ); 0330 cout << "loop" << endl; 0331 int i; 0332 int nfirst; 0333 int nwrite; 0334 nfirst = 0; 0335 nwrite = 0; 0336 for ( i = 0; i <= 1535; i++ ) { 0337 // if ( i < 512 ) 0338 // if ( ( i > 512 ) && ( i < 1024 ) ) 0339 int y = lut.get_x( i ); 0340 int z = y; 0341 if ( z < 0 ) z += 65536; 0342 cout << board << " " << traco << " " 0343 << i << " " << y << endl; 0344 if ( nwrite == 0 ) { 0345 file << "4D " << board << " " << traco << " 0 " 0346 << lutFmt( nfirst ); 0347 full << "4D " << board << " " << traco << " 0 " 0348 << lutFmt( nfirst ); 0349 // << nfirst << " "; 0350 } 0351 // file << lut.get( i ) << " "; 0352 file << " " << lutFmt( z ); 0353 full << " " << lutFmt( z ); 0354 nwrite++; 0355 if ( nwrite == 64 ) { 0356 file << winNewLine << endl; 0357 full << winNewLine << endl; 0358 nfirst += nwrite; 0359 nwrite = 0; 0360 } 0361 } 0362 nfirst = 0; 0363 nwrite = 0; 0364 for ( i = 0; i <= 1023; i++ ) { 0365 // if ( i < 512 ) 0366 // if ( ( i > 512 ) && ( i < 1024 ) ) 0367 int y = lut.get_k( i ); 0368 int z = y; 0369 if ( z < 0 ) z += 65536; 0370 cout << board << " " << traco << " " 0371 << i << " " << y << endl; 0372 if ( nwrite == 0 ) { 0373 file << "4D " << board << " " << traco << " 1 " 0374 << lutFmt( nfirst ); 0375 full << "4D " << board << " " << traco << " 1 " 0376 << lutFmt( nfirst ); 0377 // << nfirst << " "; 0378 } 0379 // file << lut.get( i ) << " "; 0380 file << " " << lutFmt( z ); 0381 full << " " << lutFmt( z ); 0382 nwrite++; 0383 if ( nwrite == 64 ) { 0384 file << winNewLine << endl; 0385 full << winNewLine << endl; 0386 nfirst += nwrite; 0387 nwrite = 0; 0388 } 0389 } 0390 file << "4E " << board << " " << traco << winNewLine << endl; 0391 full << "4E " << board << " " << traco << winNewLine << endl; 0392 } 0393 } 0394 0395 return 0; 0396 0397 } 0398 0399 */ 0400 0401 void DSPtoIEEE32(short DSPmantissa, short DSPexp, float *f) { 0402 DSPexp -= 15; 0403 *f = DSPmantissa * (float)pow(2.0, DSPexp); 0404 0405 return; 0406 } 0407 0408 void IEEE32toDSP(float f, short *DSPmantissa, short *DSPexp) { 0409 // long *pl, lm; 0410 uint32_t pl; 0411 uint32_t lm; 0412 0413 // 101104 SV convert float to int in safe way 0414 union { 0415 float f; 0416 uint32_t i; 0417 } u; 0418 u.f = f; 0419 pl = u.i; 0420 0421 bool sign = false; 0422 if (f == 0.0) { 0423 *DSPexp = 0; 0424 *DSPmantissa = 0; 0425 } else { 0426 // pl = reinterpret_cast<uint32_t*> (&f); 0427 // pl = (long*) (&f); 0428 if ((pl & 0x80000000) != 0) 0429 sign = true; 0430 lm = (0x800000 | (pl & 0x7FFFFF)); // [1][23bit mantissa] 0431 lm >>= 9; // reduce to 15bits 0432 lm &= 0x7FFF; 0433 *DSPexp = ((pl >> 23) & 0xFF) - 126; 0434 *DSPmantissa = (short)lm; 0435 if (sign) 0436 *DSPmantissa = -*DSPmantissa; // convert negative value in 2.s 0437 // complement 0438 } 0439 return; 0440 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.2.1 LXR engine. The LXR team |