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
20 #include "StoreGate/StoreGateSvc.h"
21 
22 
23 
24 
25 
26 void TRT_HitCollectionCnv_p2::transToPers(const TRTUncompressedHitCollection* transCont, TRT_HitCollection_p2* persCont, MsgStream& /*log*/)
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 
61  lastBarcode = it->particleLink().barcode();
62  persCont->m_barcode.push_back(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 = endThis;
172  ++hitCount;
173  }
174  }
175  }
176 }
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:396
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:85
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:130
TRT_HitCollection_p2::m_hit1_startZ
std::vector< float > m_hit1_startZ
Definition: TRT_HitCollection_p2.h:26
MagicNumbers.h
HepMC::BarcodeBased::is_truth_suppressed_pileup
bool is_truth_suppressed_pileup(const T &p)
Method to establish if a particle (or barcode) corresponds to truth-suppressed pile-up.
Definition: MagicNumbers.h:197
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:123
EBC_PU_SUPPRESSED
@ EBC_PU_SUPPRESSED
Definition: MagicNumbers.h:30
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:26
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