5 #ifndef JETEVENTTPCNV_SIGNALSTATESTORE_H
6 #define JETEVENTTPCNV_SIGNALSTATESTORE_H
71 char round(
double d)
const {
return (
char)floor(
d+0.5);}
105 double mantissa[4] = {0};
116 << momRaw.
m_px <<
" | "
117 << momRaw.
m_py <<
" | "
118 << momRaw.
m_pz <<
" | "
121 << momCal.
m_px <<
" | "
122 << momCal.
m_py <<
" | "
123 << momCal.
m_pz <<
" | "
126 bool forceNoCompression=
false;
129 if ( momRaw.
m_m == 0 || momCal.
m_m == 0 )
130 forceNoCompression=
true;
131 if ( momRaw.
m_px == 0 && momRaw.
m_py == 0 )
132 forceNoCompression=
true;
133 if ( momCal.
m_px == 0 && momCal.
m_py == 0 )
134 forceNoCompression=
true;
136 if ( forceNoCompression )
138 msg <<
MSG::DEBUG <<
"M or PT of calibrated or raw signal state of jet zero !"
139 <<
" Switching off compression for this jet !!!" <<
endmsg;
146 double angleC = atan2( momCal.
m_py, momCal.
m_px );
147 double angleR = atan2( momRaw.
m_py, momRaw.
m_px );
148 double p_traC = sqrt( momCal.
m_px * momCal.
m_px + momCal.
m_py * momCal.
m_py );
149 double p_traR = sqrt( momRaw.
m_px * momRaw.
m_px + momRaw.
m_py * momRaw.
m_py );
150 mantissa[0] = frexp( momCal.
m_m / momRaw.
m_m - 1, &exponent[0] );
151 mantissa[1] = frexp( angleC - angleR, &exponent[1] );
152 mantissa[2] = frexp( momCal.
eta() - momRaw.
eta(), &exponent[2] );
153 mantissa[3] = frexp( p_traC / p_traR - 1, &exponent[3] );
155 delta0 = momCal.
m_m / momRaw.
m_m - 1;
156 delta1 = angleC - angleR;
157 delta2 = momCal.
eta() - momRaw.
eta();
158 delta3 = p_traC / p_traR - 1;
161 unsigned long tmp0(0);
162 unsigned long tmp1(0);
163 unsigned long tmp2(0);
164 unsigned long tmp3(0);
167 unsigned short vec0(0);
168 unsigned short vec1(0);
169 unsigned short vec2(0);
176 if ( exponent[0] > 0x7 ) exponent[0] = 0x7;
177 if ( exponent[0] < 0x0 )
179 factor = -exponent[0];
182 tmp0 =
int( fabs(mantissa[0]) * 0x10 ) >> factor;
183 tmp0 |= ( exponent[0] & 0x7 ) << 5;
184 if ( mantissa[0] < 0 ) tmp0 |= 0x10;
188 if ( exponent[1] > 0x7 ) exponent[1] = 0x7;
189 if ( exponent[1] < 0x0 )
191 factor = -exponent[1];
194 tmp1 =
int( fabs(mantissa[1]) * 0x10 ) >> factor;
195 tmp1 |= ( exponent[1] & 0x7 ) << 5;
196 if ( mantissa[1] < 0 ) tmp1 |= 0x10;
200 if ( exponent[2] > 0x7 ) exponent[2] = 0x7;
201 if ( exponent[2] < 0x0 )
203 factor = -exponent[2];
206 tmp2 =
int( fabs(mantissa[2]) * 0x10 ) >> factor;
207 tmp2 |= ( exponent[2] & 0x7 ) << 5;
208 if ( mantissa[2] < 0 )
tmp2 |= 0x10;
212 if ( exponent[3] > 0x7 ) exponent[3] = 0x7;
213 if ( exponent[3] < 0x0 )
215 factor = -exponent[3];
218 tmp3 =
int( fabs(mantissa[3]) * 0x10 ) >> factor;
219 tmp3 |= ( exponent[3] & 0x7 ) << 5;
220 if ( mantissa[3] < 0 ) tmp3 |= 0x10;
233 if ( exponent[0] > 0xF ) exponent[0] = 0xF;
234 if ( exponent[0] < 0x0 )
236 factor = -exponent[0];
239 tmp0 =
int( fabs(mantissa[0]) * 0x80 ) >> factor;
240 if ( mantissa[0] < 0 ) tmp0 |= 0x80;
244 if ( exponent[1] > 0xF ) exponent[1] = 0xF;
245 if ( exponent[1] < 0x0 )
247 factor = -exponent[1];
250 tmp1 =
int( fabs(mantissa[1]) * 0x80 ) >> factor;
251 if ( mantissa[1] < 0 ) tmp1 |= 0x80;
255 if ( exponent[2] > 0xF ) exponent[2] = 0xF;
256 if ( exponent[2] < 0x0 )
258 factor = -exponent[2];
261 tmp2 =
int( fabs(mantissa[2]) * 0x80 ) >> factor;
262 if ( mantissa[2] < 0 )
tmp2 |= 0x80;
266 if ( exponent[3] > 0xF ) exponent[3] = 0xF;
267 if ( exponent[3] < 0x0 )
269 factor = -exponent[3];
272 tmp3 =
int( fabs(mantissa[3]) * 0x80 ) >> factor;
273 if ( mantissa[3] < 0 ) tmp3 |= 0x80;
275 vec0 = ( tmp0 & 0xFF );
276 vec0 += ( tmp1 & 0xFF ) << 8;
277 vec1 = (
tmp2 & 0xFF );
278 vec1 += ( tmp3 & 0xFF ) << 8;
280 vec2 |= exponent[1] << 4;
281 vec2 |= exponent[2] << 8;
282 vec2 |= exponent[3] << 12;
291 if ( exponent[0] > 31 ) exponent[0] = 31;
292 if ( exponent[0] < 0 )
294 factor = -exponent[0];
297 tmp0 =
int( fabs(mantissa[0]) * 0x400 ) >> factor;
298 tmp0 |= exponent[0] << 11;
299 if ( mantissa[0] < 0 ) tmp0 |= 0x400;
303 if ( exponent[1] > 31 ) exponent[1] = 31;
304 if ( exponent[1] < 0 )
306 factor = -exponent[1];
309 tmp1 =
int( fabs(mantissa[1]) * 0x400 ) >> factor;
310 tmp1 |= exponent[1] << 11;
311 if ( mantissa[1] < 0 ) tmp1 |= 0x400;
315 if ( exponent[2] > 31 ) exponent[2] = 31;
316 if ( exponent[2] < 0 )
318 factor = -exponent[2];
321 tmp2 =
int( fabs(mantissa[2]) * 0x400 ) >> factor;
322 tmp2 |= exponent[2] << 11;
323 if ( mantissa[2] < 0 )
tmp2 |= 0x400;
327 if ( exponent[3] > 31 ) exponent[3] = 31;
328 if ( exponent[3] < 0 )
330 factor = -exponent[3];
333 tmp3 =
int( fabs(mantissa[3]) * 0x400 ) >> factor;
334 tmp3 |= exponent[3] << 11;
335 if ( mantissa[3] < 0 ) tmp3 |= 0x400;
349 m.f = momRaw.
m_px; ps.push_back(
m.s[0]); ps.push_back(
m.s[1]);
350 m.f = momRaw.
m_py; ps.push_back(
m.s[0]); ps.push_back(
m.s[1]);
351 m.f = momRaw.
m_pz; ps.push_back(
m.s[0]); ps.push_back(
m.s[1]);
352 m.f = momRaw.
m_m; ps.push_back(
m.s[0]); ps.push_back(
m.s[1]);
362 for ( JetConverterTypes::signalState_pers_t::const_iterator
it=ps.begin();
it != ps.end(); ++
it )
363 msg << std::hex << *
it <<
" ";
383 << mantissa[0] <<
" *2^ " << exponent[0]-
d0 <<
endmsg;
385 << mantissa[1] <<
" *2^ " << exponent[1]-
d1 <<
endmsg;
387 << mantissa[2] <<
" *2^ " << exponent[2]-
d1 <<
endmsg;
389 << mantissa[3] <<
" *2^ " << exponent[3]-
d1 <<
endmsg;
396 MsgStream&
msg )
const
399 int exponent[4] = {0};
400 double mantissa[4] = {0};
406 exponent[0] = ( ( ps[0] >> 5 ) & 0x7 ) - 2;
407 exponent[1] = ( ( ps[0] >> 13 ) & 0x7 ) - 5;
408 exponent[2] = ( ( ps[1] >> 5 ) & 0x7 ) - 5;
409 exponent[3] = ( ( ps[1] >> 13 ) & 0x7 ) - 5;
411 mantissa[0] =
double( ps[0] & 0x1F ) / 0x10;
412 mantissa[1] =
double( ( ps[0] >> 8 ) & 0x1F ) / 0x10;
413 mantissa[2] =
double( ps[1] & 0x1F ) / 0x10;
414 mantissa[3] =
double( ( ps[1] >> 8 ) & 0x1F ) / 0x10;
415 if ( ps[0] & 0x10 ) mantissa[0] = -mantissa[0];
416 if ( ps[0] & 0x1000 ) mantissa[1] = -mantissa[1];
417 if ( ps[1] & 0x10 ) mantissa[2] = -mantissa[2];
418 if ( ps[1] & 0x1000 ) mantissa[3] = -mantissa[3];
422 exponent[0] = ( ps[2] & 0xF ) - 3;
423 exponent[1] = ( ( ps[2] >> 4 ) & 0xF ) - 6;
424 exponent[2] = ( ( ps[2] >> 8 ) & 0xF ) - 6;
425 exponent[3] = ( ( ps[2] >> 12 ) & 0xF ) - 6;
427 mantissa[0] =
double( ps[0] & 0x7F ) / 0x80;
428 mantissa[1] =
double( ( ps[0] >> 8 ) & 0x7F ) / 0x80;
429 mantissa[2] =
double( ps[1] & 0x7F ) / 0x80;
430 mantissa[3] =
double( ( ps[1] >> 8 ) & 0x7F ) / 0x80;
431 if ( ps[0] & 0x80 ) mantissa[0] = -mantissa[0];
432 if ( ps[0] & 0x8000 ) mantissa[1] = -mantissa[1];
433 if ( ps[1] & 0x80 ) mantissa[2] = -mantissa[2];
434 if ( ps[1] & 0x8000 ) mantissa[3] = -mantissa[3];
438 exponent[0] = ( ( ps[0] >> 11 ) & 0x1F ) - 5;
439 exponent[1] = ( ( ps[1] >> 11 ) & 0x1F ) - 7;
440 exponent[2] = ( ( ps[2] >> 11 ) & 0x1F ) - 7;
441 exponent[3] = ( ( ps[3] >> 11 ) & 0x1F ) - 7;
443 mantissa[0] =
double( ps[0] & 0x3FF ) / 0x400;
444 mantissa[1] =
double( ps[1] & 0x3FF ) / 0x400;
445 mantissa[2] =
double( ps[2] & 0x3FF ) / 0x400;
446 mantissa[3] =
double( ps[3] & 0x3FF ) / 0x400;
447 if ( ps[0] & 0x400 ) mantissa[0] = -mantissa[0];
448 if ( ps[1] & 0x400 ) mantissa[1] = -mantissa[1];
449 if ( ps[2] & 0x400 ) mantissa[2] = -mantissa[2];
450 if ( ps[3] & 0x400 ) mantissa[3] = -mantissa[3];
460 m.s[0] = ps[0];
m.s[1] = ps[1]; momRaw.
m_px =
m.f;
461 m.s[0] = ps[2];
m.s[1] = ps[3]; momRaw.
m_py =
m.f;
462 m.s[0] = ps[4];
m.s[1] = ps[5]; momRaw.
m_pz =
m.f;
463 m.s[0] = ps[6];
m.s[1] = ps[7]; momRaw.
m_m =
m.f;
473 double delta0 = ldexp( mantissa[0], exponent[0] );
474 double delta1 = ldexp( mantissa[1], exponent[1] );
475 double delta2 = ldexp( mantissa[2], exponent[2] );
476 double delta3 = ldexp( mantissa[3], exponent[3] );
480 if( ( delta0==-1) || (delta3==-1)){
481 msg << MSG::WARNING <<
"A jet was badly decompressed. Returning null to avoid fpe in SignalStateCnv::decompress "<<
endmsg;
485 msg <<
MSG::VERBOSE <<
" RS 0 : " << delta0 <<
" = " << mantissa[0] <<
" = " << exponent[0] <<
endmsg;
486 msg <<
MSG::VERBOSE <<
" RS 1 : " << delta1 <<
" = " << mantissa[1] <<
" = " << exponent[1] <<
endmsg;
487 msg <<
MSG::VERBOSE <<
" RS 2 : " << delta2 <<
" = " << mantissa[2] <<
" = " << exponent[2] <<
endmsg;
488 msg <<
MSG::VERBOSE <<
" RS 3 : " << delta3 <<
" = " << mantissa[3] <<
" = " << exponent[3] <<
endmsg;
490 double angleC = atan2( momCal.
m_py, momCal.
m_px );
491 double p_traC = sqrt( momCal.
m_px * momCal.
m_px + momCal.
m_py * momCal.
m_py );
493 double angleR = angleC - delta1;
494 double eta_R = momCal.
eta() - delta2;
495 double p_traR = p_traC / ( delta3 + 1 );
496 momRaw.
m_m = momCal.
m_m / ( delta0 + 1 );
497 momRaw.
m_px = p_traR *
cos(angleR);
498 momRaw.
m_py = p_traR *
sin(angleR);
499 momRaw.
m_pz = p_traR * sinh(eta_R);
502 for ( JetConverterTypes::signalState_pers_t::const_iterator
it=ps.begin();
it != ps.end(); ++
it )
503 msg << std::hex << *
it <<
" ";