49 static const double dRcut = 1.0e-7*CLHEP::mm;
50 static const double dTcut = 1.0*CLHEP::ns;
56 double lastT = 0.0*CLHEP::ns;
58 unsigned int endBC = 0;
59 unsigned int endId = 0;
60 unsigned int endHit = 0;
61 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 using barcodeType =
decltype(persCont->
m_barcode)::value_type;
71 persCont->
m_barcode.push_back(
static_cast<barcodeType
>(lastBarcode));
73 persCont->
m_nBC.push_back(idx - endBC);
78 if ( (
int)trtHit->GetParticleEncoding() != lastId || idx - endId > 65500) {
80 lastId = trtHit->GetParticleEncoding();
81 persCont->
m_id.push_back(lastId);
83 persCont->
m_nId.push_back(idx - endId);
88 const HepGeom::Point3D<double> hitStart(trtHit->GetPreStepX(), trtHit->GetPreStepY(), trtHit->GetPreStepZ());
90 const double meanTime = trtHit->GetGlobalTime();
91 const double dTLast = fabs(meanTime - lastT);
92 const double dRLast = lastEnd.distance(hitStart);
97 if ( dRLast >= dRcut || dTLast >= dTcut ) {
109 const unsigned int strawId = trtHit->GetHitID();
110 persCont->
m_strawId1b.push_back( (
unsigned char)(strawId % 256) );
111 persCont->
m_strawId2b.push_back( (
unsigned short)(strawId / 256) );
112 if ( strawId>16777215 )
113 log << MSG::WARNING <<
"TRT_HitCollectionCnv: strawId > 2^24-1 cannot be persistified correctly! " <<
endmsg;
122 const double startR = sqrt( hitStart.x()*hitStart.x() + hitStart.y()*hitStart.y() );
123 unsigned short istartRflag;
124 if ( startR > 1.9999*CLHEP::mm ) {
129 persCont->
m_startR.push_back( (
unsigned char)(startR/(2.0*CLHEP::mm)*256.0) );
136 const double startPhi = atan2( hitStart.y(), hitStart.x() );
137 persCont->
m_startPhi.push_back( (
unsigned char)( (startPhi+
M_PI)/(2.0*
M_PI)*256.0 ) );
152 unsigned char istartZ = (
unsigned char)( (hitStart.z()+365.0*CLHEP::mm)/(730.0*CLHEP::mm)*16.0 );
153 istartZ = (istartZ << 1) | istartRflag;
154 persCont->
m_startZ.push_back( istartZ );
157 persCont->
m_nHits.push_back( idx - endHit );
176 const HepGeom::Point3D<double> hitEnd(trtHit->GetPostStepX(), trtHit->GetPostStepY(), trtHit->GetPostStepZ());
177 const HepGeom::Point3D<double> hitLength = (hitEnd - hitStart);
196 double kinEne = trtHit->GetKineticEnergy() * 1.0e9;
197 double steplength = hitLength.distance() * 1.0e9;
198 if ( kinEne < 1.0 ) kinEne=1.0;
199 if ( steplength < 1.0 ) steplength=1.0;
200 if ( kinEne > 9.0e18 ) kinEne=9.0e18;
201 if ( steplength > 9.0e18 ) steplength=9.0e18;
202 const unsigned int kexponent = (
unsigned int)ceil(log10(kinEne)/0.30102999566398);
203 const unsigned int sexponent = (
unsigned int)ceil(log10(steplength)/0.30102999566398);
204 const unsigned int kmantissa = (
unsigned int)(kinEne/pow(2.0,kexponent)*1024) - 512;
205 const unsigned int smantissa = (
unsigned int)(steplength/pow(2.0,sexponent)*1024) - 512;
206 persCont->
m_kinEne.push_back( (kmantissa << 6) | kexponent );
207 persCont->
m_steplength.push_back( (smantissa << 6) | sexponent );
217 const double endR = sqrt( hitEnd.x()*hitEnd.x() + hitEnd.y()*hitEnd.y() );
218 unsigned short iendRflag;
219 if ( endR > 1.9999*CLHEP::mm ) {
224 persCont->
m_endR.push_back( (
unsigned char)(endR/(2.0*CLHEP::mm)*256.0) );
232 const double endPhi = atan2( hitEnd.y(), hitEnd.x() );
233 persCont->
m_endPhi.push_back( (
unsigned char)( (endPhi+
M_PI)/(2.0*
M_PI)*256.0 ) );
241 unsigned short idZsign = (hitLength.z()>0.0) ? 1 : 0;
242 unsigned short imeanTime = ( meanTime < 75.0*CLHEP::ns ) ? (
unsigned short)(meanTime/(75.0*CLHEP::ns)*1024.0) : 1023;
243 if ( imeanTime == 1023 ) persCont->
m_meanTimeof.push_back( (
float)meanTime );
244 imeanTime = (imeanTime << 2) | (idZsign << 1) | iendRflag;
252 (
int)(abs(lastId)/100000) == 41 ||
253 (
int)(abs(lastId)/10000000) == 1
254 ) persCont->
m_hitEne.push_back( (
float)(trtHit->GetEnergyDeposit()) );
274 persCont->
m_nBC.push_back(idx - endBC);
275 persCont->
m_nId.push_back(idx - endId);
276 persCont->
m_nHits.push_back( idx - endHit );
296 unsigned int meanTimeofCount=0, startRCount=0, endRCount=0, hitEneCount=0;
297 unsigned int idxBC=0, idxId=0, endHit=0, endBC=0, endId=0;
300 const EventContext& ctx = Gaudi::Hive::currentContext();
307 for (
unsigned int i = 0; i < persCont->
m_nHits.size(); i++ ) {
311 const unsigned int startHit = endHit;
312 endHit += persCont->
m_nHits[i];
319 const unsigned int strawId = i2*256+i1;
324 const unsigned int istartPhi = persCont->
m_startPhi[i];
325 const double startPhi = -
M_PI + (istartPhi+0.5)*2.0*
M_PI/256.0;
330 const unsigned int istartZ = persCont->
m_startZ[i] >> 1;
331 double startZ = -365.0*CLHEP::mm + (istartZ+0.5)*730.0*CLHEP::mm/16.0;
336 const unsigned int istartRflag = persCont->
m_startZ[i] & 1;
342 if ( istartRflag == 1 ) {
343 startR = 2.0*CLHEP::mm;
346 const unsigned int istartR = persCont->
m_startR[startRCount++];
347 startR = (istartR+0.5)*2.0*CLHEP::mm/256.0;
348 if ( startR < 0.0155*CLHEP::mm ) startR = 0.0155*CLHEP::mm;
354 double startX = startR*cos(startPhi);
355 double startY = startR*sin(startPhi);
371 for (
unsigned int j = startHit; j < endHit; j++ ) {
373 if ( j >= endBC + persCont->
m_nBC[idxBC] ) endBC += persCont->
m_nBC[idxBC++];
374 if ( j >= endId + persCont->
m_nId[idxId] ) endId += persCont->
m_nId[idxId++];
379 const unsigned int imeanTime = persCont->
m_meanTime[j] >> 2;
380 double meanTime = (imeanTime+0.5)*75.0*CLHEP::ns/1024.0;
381 if ( imeanTime == 1023 ) meanTime = (double)persCont->
m_meanTimeof[meanTimeofCount++];
386 const unsigned int idZsign = (persCont->
m_meanTime[j] >> 1 ) & 1;
391 const unsigned int iendRflag = persCont->
m_meanTime[j] & 1;
396 const double hitEne = ( persCont->
m_id[idxId] == 22 ||
397 (int)(abs(persCont->
m_id[idxId])/100000) == 41 ||
398 (int)(abs(persCont->
m_id[idxId])/10000000) == 1
399 ) ? (
double)persCont->
m_hitEne[hitEneCount++] : 0.0;
404 const unsigned int iendPhi = persCont->
m_endPhi[j];
405 double endPhi = -
M_PI + (iendPhi+0.5)*2.0*
M_PI/256.0;
411 if ( iendRflag==1 ) {
412 endR = 2.0*CLHEP::mm;
415 const unsigned int iendR = persCont->
m_endR[endRCount++];
416 endR = (iendR+0.5)*2.0*CLHEP::mm/256.0;
417 if ( endR < 0.0155*CLHEP::mm ) endR = 0.0155*CLHEP::mm;
423 double endX = endR*cos(endPhi);
424 double endY = endR*sin(endPhi);
436 const int kmantissa = persCont->
m_kinEne[j] >> 6;
438 const int kexponent = persCont->
m_kinEne[j] & 0x3F;
440 const double kinEne = (kmantissa+512.5)/1024 * pow(2.0,kexponent) / 1.0e9;
441 double g4steplength = (smantissa+512.5)/1024 * pow(2.0,sexponent) / 1.0e9;
442 if ( idZsign==0 ) g4steplength = -g4steplength;
447 double dX = endX-startX;
448 double dY = endY-startY;
450 double dXY2 = dX*dX+dY*dY;
451 double dL2 = g4steplength*g4steplength;
454 if (g4steplength<0.0) dZ=-dZ;
457 dX = dX * sqrt(dL2/dXY2);
458 dY = dY * sqrt(dL2/dXY2);
465 double endZ = startZ + dZ;
491 transCont->
Emplace( strawId, partLink, persCont->
m_id[idxId],
492 kinEne, hitEne, startX, startY, startZ,
493 endX, endY, endZ, meanTime );
499 startX = endXo; startY = endYo; startZ = endZ;
a link optimized in size for a GenParticle in a McEventCollection
static int getEventNumberAtPosition(index_type position, const IProxyDict *sg)
Return the event number of the GenEvent at the specified position in the McEventCollection.
void setTruthSuppressionType(EBC_SUPPRESSED_TRUTH truthSupp)
Return whether the truth particle has been suppressed.