ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_HitCollectionCnv_p2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include <cmath>
11
12// CLHEP
13#include "CLHEP/Geometry/Point3D.h"
14
15// Gaudi
16#include "GaudiKernel/MsgStream.h"
17
18// Athena
21
22
23
24
25
27{
28 // Finds hits belonging to a "string" (in which the end point of one hit is the same as the start point of the next) and
29 // persistifies the end point of each hit plus the start point of the first hit in each string.
30 //
31 // Further compression is achieved by optimising the storage of the position vectors:- start (x,y,z) and (theta,phi) of
32 // first hit are stored as floats, (delta_theta,delta_phi) relative to the fisrst hit are stored as 2 byte numbers and
33 // used to specify the hit direction. All hit lengths are stored as 2 byte numbers.
34 //
35 // Additional savings are achieved by storing the energy loss for each hit as a 2 byte number and only storing the mean
36 // time of the first hit per string.
37 //
38 // See http://indico.cern.ch/getFile.py/access?contribId=11&resId=2&materialId=slides&confId=30893 for more info.
39
40 static const double dRcut = 1.0e-7;
41 static const double dTcut = 1.0;
42
43 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "In TRT_HitCollectionCnv_p2::transToPers()" << endmsg;
44
45 int lastBarcode = -1;
46 int lastId = -1;
47 double lastT = 0.0;
48 unsigned int idx = 0;
49 unsigned int endBC = 0;
50 unsigned int endId = 0;
51 unsigned int endHit = 0;
52 HepGeom::Point3D<double> lastEnd(0.0, 0.0, 0.0);
53
54 for (TRTUncompressedHitCollection::const_iterator it = transCont->begin(); it != transCont->end(); ++it) {
55
56
57 if ( it->particleLink().barcode() != lastBarcode ) {
58
59 // store barcode once for set of consecutive hits with same barcode
60 using barcodeType = decltype(persCont->m_barcode)::value_type;
61 lastBarcode = it->particleLink().barcode();
62 persCont->m_barcode.push_back(static_cast<barcodeType>(lastBarcode));
63
64 if (idx > 0) {
65 persCont->m_nBC.push_back(idx - endBC);
66 endBC = idx;
67 }
68 }
69
70 if ( (int)it->GetParticleEncoding() != lastId ) {
71
72 // store id once for set of consecutive hits with same id
73
74 lastId = it->GetParticleEncoding();
75 persCont->m_id.push_back(lastId);
76
77 if (idx > 0) {
78 persCont->m_nId.push_back(idx - endId);
79 endId = idx;
80 }
81 }
82
83 const HepGeom::Point3D<double> hitStart(it->GetPreStepX(), it->GetPreStepY(), it->GetPreStepZ());
84 const double t = it->GetGlobalTime();
85
86 const double dRLast = lastEnd.distance(hitStart); // dR between end of previous hit and start of current one
87 const double dTLast = fabs(t - lastT);
88
89 if (dRLast >= dRcut || dTLast >= dTcut) {
90
91 // begin new hit string
92
93 persCont->m_hit1_startX.push_back( hitStart.x() );
94 persCont->m_hit1_startY.push_back( hitStart.y() );
95 persCont->m_hit1_startZ.push_back( hitStart.z() );
96
97 if (idx > 0) {
98 persCont->m_nHits.push_back(idx - endHit);
99 endHit = idx;
100 }
101 }
102
103 persCont->m_hitId.push_back( it->GetHitID() );
104 persCont->m_kinEne.push_back( it->GetKineticEnergy() );
105 persCont->m_meanTime.push_back( t );
106
107 persCont->m_hitEne.push_back( it->GetEnergyDeposit() );
108 persCont->m_endX.push_back( it->GetPostStepX() );
109 persCont->m_endY.push_back( it->GetPostStepY() );
110 persCont->m_endZ.push_back( it->GetPostStepZ() );
111
112 lastEnd = HepGeom::Point3D<double>(it->GetPostStepX(), it->GetPostStepY(), it->GetPostStepZ());
113 lastT = t;
114 ++idx;
115 }
116
117 persCont->m_nBC.push_back(idx - endBC);
118 persCont->m_nId.push_back(idx - endId);
119 persCont->m_nHits.push_back(idx - endHit);
120}
121
122
124 std::unique_ptr<TRTUncompressedHitCollection> trans(std::make_unique<TRTUncompressedHitCollection>("DefaultCollectionName",persObj->m_nHits.size()));
125 persToTrans(persObj, trans.get(), log);
126 return(trans.release());
127}
128
129
131{
132 // if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "In TRT_HitCollectionCnv_p2::persToTrans()" << endmsg;
133
134 unsigned int hitCount = 0;
135 unsigned int idxBC = 0;
136 unsigned int idxId = 0;
137 unsigned int endHit = 0;
138 unsigned int endBC = 0;
139 unsigned int endId = 0;
140
141 for (unsigned int i = 0; i < persCont->m_nHits.size(); i++) {
142
143 if (persCont->m_nHits[i]) {
144
145 const unsigned int start = endHit;
146 endHit += persCont->m_nHits[i];
147
148 HepGeom::Point3D<double> endLast(persCont->m_hit1_startX[i], persCont->m_hit1_startY[i], persCont->m_hit1_startZ[i]);
149
150 for (unsigned int j = start; j < endHit; j++) {
151
152 if (j >= endBC + persCont->m_nBC[idxBC])
153 endBC += persCont->m_nBC[idxBC++];
154
155 if (j >= endId + persCont->m_nId[idxId])
156 endId += persCont->m_nId[idxId++];
157
158 const double eneLoss = persCont->m_hitEne[hitCount];
159
160 HepGeom::Point3D<double> endThis(persCont->m_endX[j], persCont->m_endY[j], persCont->m_endZ[j]);
161
162 HepMcParticleLink partLink(persCont->m_barcode[idxBC], 0, HepMcParticleLink::IS_POSITION, HepMcParticleLink::IS_BARCODE); // FIXME barcode-based
164 if ( HepMC::BarcodeBased::is_truth_suppressed_pileup(static_cast<int>(persCont->m_barcode[idxBC])) ) {
166 }
167 transCont->Emplace( persCont->m_hitId[hitCount], partLink, persCont->m_id[idxId], persCont->m_kinEne[hitCount],
168 eneLoss, endLast.x(), endLast.y(), endLast.z(), endThis.x(), endThis.y(), endThis.z(),
169 persCont->m_meanTime[hitCount] );
170
171 endLast = std::move(endThis);
172 ++hitCount;
173 }
174 }
175 }
176}
@ EBC_PU_SUPPRESSED
AtlasHitsVector< TRTUncompressedHit > TRTUncompressedHitCollection
const_iterator begin() const
void Emplace(Args &&... args)
const_iterator end() const
virtual TRTUncompressedHitCollection * createTransient(const TRT_HitCollection_p2 *persObj, MsgStream &log)
virtual void transToPers(const TRTUncompressedHitCollection *transCont, TRT_HitCollection_p2 *persCont, MsgStream &log)
virtual void persToTrans(const TRT_HitCollection_p2 *persCont, TRTUncompressedHitCollection *transCont, MsgStream &log)
std::vector< float > m_endY
std::vector< float > m_meanTime
std::vector< unsigned short > m_nBC
std::vector< float > m_endX
std::vector< float > m_kinEne
std::vector< long > m_id
std::vector< float > m_endZ
std::vector< float > m_hit1_startZ
std::vector< unsigned long > m_barcode
std::vector< float > m_hitEne
std::vector< unsigned long > m_hitId
std::vector< unsigned short > m_nId
std::vector< float > m_hit1_startX
std::vector< unsigned short > m_nHits
std::vector< float > m_hit1_startY
bool is_truth_suppressed_pileup(const T &p)
Method to establish if a particle (or barcode) corresponds to truth-suppressed pile-up.