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