PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/L1Trigger/DTTraco/src/Lut.cc

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