13 #include "CLHEP/Geometry/Point3D.h"
14 #include "CLHEP/Units/SystemOfUnits.h"
17 #include "GaudiKernel/MsgStream.h"
48 static const double dRcut = 1.0e-7*
CLHEP::mm;
49 static const double dTcut = 1.0*
CLHEP::ns;
57 unsigned int endBC = 0;
58 unsigned int endId = 0;
59 unsigned int endHit = 0;
60 HepGeom::Point3D<double> lastEnd(0.0, 0.0, 0.0);
67 if ( trtHit->particleLink().barcode() != lastBarcode ||
idx - endBC > 65500) {
69 lastBarcode = trtHit->particleLink().barcode();
70 persCont->
m_barcode.push_back(lastBarcode);
72 persCont->
m_nBC.push_back(
idx - endBC);
77 if ( (
int)trtHit->GetParticleEncoding() != lastId ||
idx - endId > 65500) {
79 lastId = trtHit->GetParticleEncoding();
80 persCont->
m_id.push_back(lastId);
82 persCont->
m_nId.push_back(
idx - endId);
87 const HepGeom::Point3D<double> hitStart(trtHit->GetPreStepX(), trtHit->GetPreStepY(), trtHit->GetPreStepZ());
89 const double meanTime = trtHit->GetGlobalTime();
90 const double dTLast = fabs(meanTime - lastT);
91 const double dRLast = lastEnd.distance(hitStart);
96 if ( dRLast >= dRcut || dTLast >= dTcut ) {
108 const unsigned int strawId = trtHit->GetHitID();
109 persCont->
m_strawId1b.push_back( (
unsigned char)(strawId % 256) );
110 persCont->
m_strawId2b.push_back( (
unsigned short)(strawId / 256) );
111 if ( strawId>16777215 )
112 log << MSG::WARNING <<
"TRT_HitCollectionCnv: strawId > 2^24-1 cannot be persistified correctly! " <<
endmsg;
121 const double startR = sqrt( hitStart.x()*hitStart.x() + hitStart.y()*hitStart.y() );
122 unsigned short istartRflag;
135 const double startPhi = atan2( hitStart.y(), hitStart.x() );
136 persCont->
m_startPhi.push_back( (
unsigned char)( (startPhi+
M_PI)/(2.0*
M_PI)*256.0 ) );
152 istartZ = (istartZ << 1) | istartRflag;
153 persCont->
m_startZ.push_back( istartZ );
175 const HepGeom::Point3D<double> hitEnd(trtHit->GetPostStepX(), trtHit->GetPostStepY(), trtHit->GetPostStepZ());
176 const HepGeom::Point3D<double> hitLength = (hitEnd - hitStart);
195 double kinEne = trtHit->GetKineticEnergy() * 1.0e9;
196 double steplength = hitLength.distance() * 1.0e9;
197 if ( kinEne < 1.0 ) kinEne=1.0;
198 if ( steplength < 1.0 ) steplength=1.0;
199 if ( kinEne > 9.0e18 ) kinEne=9.0e18;
200 if ( steplength > 9.0e18 ) steplength=9.0e18;
201 const unsigned int kexponent = (
unsigned int)ceil(log10(kinEne)/0.30102999566398);
202 const unsigned int sexponent = (
unsigned int)ceil(log10(steplength)/0.30102999566398);
203 const unsigned int kmantissa = (
unsigned int)(kinEne/
pow(2.0,kexponent)*1024) - 512;
204 const unsigned int smantissa = (
unsigned int)(steplength/
pow(2.0,sexponent)*1024) - 512;
205 persCont->
m_kinEne.push_back( (kmantissa << 6) | kexponent );
206 persCont->
m_steplength.push_back( (smantissa << 6) | sexponent );
216 const double endR = sqrt( hitEnd.x()*hitEnd.x() + hitEnd.y()*hitEnd.y() );
217 unsigned short iendRflag;
223 persCont->
m_endR.push_back( (
unsigned char)(endR/(2.0*
CLHEP::mm)*256.0) );
231 const double endPhi = atan2( hitEnd.y(), hitEnd.x() );
232 persCont->
m_endPhi.push_back( (
unsigned char)( (endPhi+
M_PI)/(2.0*
M_PI)*256.0 ) );
240 unsigned short idZsign = (hitLength.z()>0.0) ? 1 : 0;
241 unsigned short imeanTime = ( meanTime < 75.0*
CLHEP::ns ) ? (
unsigned short)(meanTime/(75.0*
CLHEP::ns)*1024.0) : 1023;
242 if ( imeanTime == 1023 ) persCont->
m_meanTimeof.push_back( (
float)meanTime );
243 imeanTime = (imeanTime << 2) | (idZsign << 1) | iendRflag;
251 (
int)(abs(lastId)/100000) == 41 ||
252 (
int)(abs(lastId)/10000000) == 1
253 ) persCont->
m_hitEne.push_back( (
float)(trtHit->GetEnergyDeposit()) );
273 persCont->
m_nBC.push_back(
idx - endBC);
274 persCont->
m_nId.push_back(
idx - endId);
282 std::unique_ptr<TRTUncompressedHitCollection> trans(std::make_unique<TRTUncompressedHitCollection>(
"DefaultCollectionName",persObj->
m_nHits.size()));
284 return(trans.release());
295 unsigned int meanTimeofCount=0, startRCount=0, endRCount=0, hitEneCount=0;
296 unsigned int idxBC=0, idxId=0, endHit=0, endBC=0, endId=0;
306 for (
unsigned int i = 0;
i < persCont->
m_nHits.size();
i++ ) {
310 const unsigned int startHit = endHit;
318 const unsigned int strawId = i2*256+i1;
323 const unsigned int istartPhi = persCont->
m_startPhi[
i];
324 const double startPhi = -
M_PI + (istartPhi+0.5)*2.0*
M_PI/256.0;
329 const unsigned int istartZ = persCont->
m_startZ[
i] >> 1;
335 const unsigned int istartRflag = persCont->
m_startZ[
i] & 1;
341 if ( istartRflag == 1 ) {
345 const unsigned int istartR = persCont->
m_startR[startRCount++];
346 startR = (istartR+0.5)*2.0*
CLHEP::mm/256.0;
353 double startX = startR*
cos(startPhi);
354 double startY = startR*
sin(startPhi);
370 for (
unsigned int j = startHit; j < endHit; j++ ) {
372 if ( j >= endBC + persCont->
m_nBC[idxBC] ) endBC += persCont->
m_nBC[idxBC++];
373 if ( j >= endId + persCont->
m_nId[idxId] ) endId += persCont->
m_nId[idxId++];
378 const unsigned int imeanTime = persCont->
m_meanTime[j] >> 2;
379 double meanTime = (imeanTime+0.5)*75.0*
CLHEP::ns/1024.0;
380 if ( imeanTime == 1023 ) meanTime = (
double)persCont->
m_meanTimeof[meanTimeofCount++];
385 const unsigned int idZsign = (persCont->
m_meanTime[j] >> 1 ) & 1;
390 const unsigned int iendRflag = persCont->
m_meanTime[j] & 1;
395 const double hitEne = ( persCont->
m_id[idxId] == 22 ||
396 (
int)(abs(persCont->
m_id[idxId])/100000) == 41 ||
397 (
int)(abs(persCont->
m_id[idxId])/10000000) == 1
403 const unsigned int iendPhi = persCont->
m_endPhi[j];
404 double endPhi = -
M_PI + (iendPhi+0.5)*2.0*
M_PI/256.0;
410 if ( iendRflag==1 ) {
414 const unsigned int iendR = persCont->
m_endR[endRCount++];
422 double endX = endR*
cos(endPhi);
423 double endY = endR*
sin(endPhi);
435 const int kmantissa = persCont->
m_kinEne[j] >> 6;
437 const int kexponent = persCont->
m_kinEne[j] & 0x3F;
439 const double kinEne = (kmantissa+512.5)/1024 *
pow(2.0,kexponent) / 1.0e9;
440 double g4steplength = (smantissa+512.5)/1024 *
pow(2.0,sexponent) / 1.0e9;
441 if ( idZsign==0 ) g4steplength = -g4steplength;
446 double dX = endX-startX;
447 double dY = endY-startY;
449 double dXY2 = dX*dX+dY*dY;
450 double dL2 = g4steplength*g4steplength;
453 if (g4steplength<0.0) dZ=-dZ;
456 dX = dX * sqrt(dL2/dXY2);
457 dY = dY * sqrt(dL2/dXY2);
464 double endZ = startZ + dZ;
490 transCont->
Emplace( strawId, partLink, persCont->
m_id[idxId],
491 kinEne, hitEne, startX, startY, startZ,
492 endX, endY, endZ, meanTime );
498 startX = endXo; startY = endYo; startZ = endZ;