ATLAS Offline Software
TRTProcessingOfEndCapHits.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Class header
7 
8 // Package headers
9 #include "TRTSensitiveDetector.h"
10 
11 // Athena headers
12 #include "MCTruth/TrackHelper.h"
13 #include "TRT_G4Utilities/TRTParameters.hh"
14 
15 // Geant4 headers
16 #include "G4AffineTransform.hh"
17 #include "G4NavigationHistory.hh"
18 #include "G4Step.hh"
19 #include "G4StepPoint.hh"
20 #include "G4ThreeVector.hh"
21 #include "G4TouchableHandle.hh"
22 #include "G4TouchableHistory.hh"
23 #include "G4Track.hh"
24 
25 // STL headers
26 #include <cmath>
27 
28 // Called by TRTSensitiveDetector::InitializeHitProcessing
29 
31 (TRTSensitiveDetector* pSensitiveDet):
32  m_printMessages(0), //FIXME obsolete?
33  m_sectorsABC(0),
34  m_testLocalCoordinatesOfHits(0),
35  m_numberOfStrawsInPlanesAB(0),
36  m_numberOfStrawsInPlaneC(0),
37  m_numberOfWheelsAB(0),
38  m_numberOfStrawsInSectorsAB(0),
39  m_numberOfStrawsInSectorC(0),
40  m_initialStrawIDInSectorsAB(0),
41  m_initialStrawIDInSectorC(0),
42  m_numberOfStrawsInIDSectorsAB(0),
43  m_numberOfStrawsInIDSectorC(0),
44  m_pParameters(nullptr),
45  m_pSensitiveDetector(pSensitiveDet),
46  m_verboseLevel(pSensitiveDet->verboseLevel)
47 {
48  m_pParameters = TRTParameters::GetPointer();
49 
50  m_printMessages = m_pParameters->GetInteger("PrintMessages"); //FIXME Obsolete?
51 
52  if (m_verboseLevel>5) { G4cout << "##### Constructor TRTProcessingOfEndCapHits" << G4endl; }
53 
54  this->Initialize();
55 
56  m_pParameters = nullptr;
57 
58  if (m_verboseLevel>5) { G4cout << "##### Constructor TRTProcessingOfEndCapHits done" << G4endl; }
59 }
60 
61 
62 // Called by TRTSensitiveDetector::DeleteObjects
63 
65 {
66 }
67 
68 
69 // Called by TRTProcessingOfEndCapHits
70 
72 {
73  if (m_verboseLevel>5) { G4cout << "######### Method TRTProcessingOfEndCapHits::Initialize" << G4endl; }
74 
75  m_sectorsABC = m_pParameters->GetInteger("SectorsABC");
76 
78  m_pParameters->GetInteger("TestLocalCoordinatesOfHits");
79 
80  if (m_verboseLevel>5) { G4cout << "######### Method TRTProcessingOfEndCapHits::Initialize done" << G4endl; }
81 
82 }
83 
84 
85 // Called by Geant4
86 
88 {
89  G4Track* pTrack = pStep->GetTrack();
90  // get the HepMC barcode using the track helper
91  TrackHelper trHelp(pTrack);
92 
93  G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint();
94  G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
95 
96  G4TouchableHandle pTouchableHandle = pPreStepPoint->GetTouchableHandle();
97  int depth = 1;
98 
99  int strawID = pTouchableHandle->GetReplicaNumber(depth++);
100 
101  int sectorID = 0;
102 
103  if (m_sectorsABC)
104  sectorID = pTouchableHandle->GetReplicaNumber(depth++);
105 
106  int planeID = pTouchableHandle->GetReplicaNumber(depth++);
107 
108  int wheelID = pTouchableHandle->GetReplicaNumber(depth);
109 
110  G4ThreeVector globalPreStepPoint = pPreStepPoint->GetPosition();
111 
112  int endCapID;
113 
114  if (globalPreStepPoint.z() > 0.)
115  endCapID = 0;
116  else
117  endCapID = 1;
118 
119  if (m_sectorsABC)
120  {
121  if (wheelID < m_numberOfWheelsAB)
122  {
123  strawID += m_numberOfStrawsInSectorsAB * sectorID -
125  if (strawID < 0)
126  strawID += m_numberOfStrawsInPlanesAB;
127  }
128  else
129  {
131  if (strawID < 0)
132  strawID += m_numberOfStrawsInPlaneC;
133  }
134  }
135 
136  G4ThreeVector globalPostStepPoint = pPostStepPoint->GetPosition();
137 
138  const G4TouchableHistory* pTouchableHistory =
139  static_cast<const G4TouchableHistory*>(pPreStepPoint->GetTouchable());
140 
141  const G4AffineTransform& topTransform = pTouchableHistory->GetHistory()->
142  GetTopTransform();
143 
144  G4ThreeVector localPreStepPoint = topTransform.TransformPoint(globalPreStepPoint);
145  G4ThreeVector localPostStepPoint = topTransform.TransformPoint(globalPostStepPoint);
146 
147  double preStepX = localPreStepPoint.x();
148  double preStepY = localPreStepPoint.y();
149  double preStepZ = localPreStepPoint.z();
150  double postStepX = localPostStepPoint.x();
151  double postStepY = localPostStepPoint.y();
152  double postStepZ = localPostStepPoint.z();
153 
154 
156  {
157  double preStepR = std::sqrt(preStepX * preStepX + preStepY * preStepY);
158  double postStepR = std::sqrt(postStepX * postStepX + postStepY * postStepY);
159 
160  if (preStepR > 2.0000001 || postStepR > 2.0000001)
161  {
162  G4int particleEncoding = m_pSensitiveDetector->m_particleEncoding;
163  G4double kineticEnergy = m_pSensitiveDetector->m_kineticEnergy;
165 
166  std::cout << "!!!!! End-caps. Error in local coordinates of hits!" << std::endl;
167  std::cout << " endCapID=" << endCapID << " wheelID=" << wheelID
168  << " planeID=" << planeID << " strawID=" << strawID
169  << " trackID=" << trHelp.GetUniqueID() << std::endl;
170  std::cout << " particleEncoding=" << particleEncoding;
171 
172  if (kineticEnergy < 0.0001)
173  std::cout << " kineticEnergy=" << kineticEnergy * 1000000. << " eV";
174  else if (kineticEnergy < 0.1)
175  std::cout << " kineticEnergy=" << kineticEnergy * 1000. << " keV";
176  else if (kineticEnergy >= 100.)
177  std::cout << " kineticEnergy=" << kineticEnergy / 1000. << " GeV";
178  else if (kineticEnergy >= 100000.)
179  std::cout << " kineticEnergy=" << kineticEnergy / 1000000. << " TeV";
180  else
181  std::cout << " kineticEnergy=" << kineticEnergy << " MeV";
182 
183  if (energyDeposit < 0.1)
184  std::cout << " energyDeposit=" << energyDeposit * 1000. << " eV"
185  << std::endl;
186  else if (energyDeposit >= 100.)
187  std::cout << " energyDeposit=" << energyDeposit / 1000. << " MeV"
188  << std::endl;
189  else
190  std::cout << " energyDeposit=" << energyDeposit << " keV" << std::endl;
191 
192  std::cout << " preStepX=" << preStepX << " mm preStepY=" << preStepY
193  << " mm preStepR=" << preStepR << " mm" << std::endl;
194  std::cout << " postStepX=" << postStepX << " mm postStepY=" << postStepY
195  << " mm postStepR=" << postStepR << " mm" << std::endl << std::endl;
196  }
197  }
198 
199  double preStepGlobalTime = pPreStepPoint->GetGlobalTime();
200  double postStepGlobalTime = pPostStepPoint->GetGlobalTime();
201  double globalTime = (preStepGlobalTime + postStepGlobalTime) / 2.;
202 
203 
204  int numberOfStrawsInPlane;
205  int numberOfStrawsInIDSector;
206 
207  if (wheelID < m_numberOfWheelsAB) {
208  numberOfStrawsInPlane = m_numberOfStrawsInPlanesAB;
209  numberOfStrawsInIDSector = m_numberOfStrawsInIDSectorsAB;
210  } else {
211  numberOfStrawsInPlane = m_numberOfStrawsInPlaneC;
212  numberOfStrawsInIDSector = m_numberOfStrawsInIDSectorC;
213  }
214 
215  // Mapping for negative endcap is
216  // nSectors = 32
217  // nStraws = num straws in sector
218  // straw = straw number within sector
219  // sector -> (nSectors + nSectors/2 - sector - 1) % nSectors
220  // straw -> nStraws - 1 - straw
221  //
222  // Since we calculate sector number below from strawID (where
223  // strawID is straw number in plane), its equivalent to map strawID
224  // first and then calculate sector number and straw number within sector.
225 
226  // Mapping straw number in plane for negative endcap
227  if (endCapID > 0) {
228  strawID = (3*numberOfStrawsInPlane/2 - strawID - 1) % numberOfStrawsInPlane;
229  }
230 
231  // Calculate sector number and straw number within sector.
232  sectorID = strawID / numberOfStrawsInIDSector;
233  strawID %= numberOfStrawsInIDSector;
234 
235 
236  int hitID;
237  if (endCapID == 0)
238  hitID = 0x00200000;
239  else
240  hitID = 0x00300000;
241 
242  hitID += (wheelID << 15);
243  hitID += (sectorID << 10);
244  hitID += (planeID << 5);
245  hitID += strawID;
246 
247  m_pSensitiveDetector->m_hitID = hitID;
249  m_pSensitiveDetector->m_preStepX = preStepX;
250  m_pSensitiveDetector->m_preStepY = preStepY;
251  m_pSensitiveDetector->m_preStepZ = preStepZ;
252  m_pSensitiveDetector->m_postStepX = postStepX;
253  m_pSensitiveDetector->m_postStepY = postStepY;
254  m_pSensitiveDetector->m_postStepZ = postStepZ;
255  m_pSensitiveDetector->m_globalTime = globalTime;
256 
257  return true;
258 }
TRTProcessingOfEndCapHits::m_pParameters
const TRTParameters * m_pParameters
Definition: TRTProcessingOfEndCapHits.h:49
egammaParameters::depth
@ depth
pointing depth of the shower as calculated in egammaqgcld
Definition: egammaParamDefs.h:276
TRTProcessingOfEndCapHits::m_printMessages
int m_printMessages
Definition: TRTProcessingOfEndCapHits.h:31
TrackHelper.h
TRTParametersForBarrelHits::m_verboseLevel
int m_verboseLevel
Definition: TRTParametersForBarrelHits.h:28
TRTSensitiveDetector::m_energyDeposit
double m_energyDeposit
Definition: TRTSensitiveDetector.h:73
TRTProcessingOfEndCapHits::m_verboseLevel
int m_verboseLevel
Definition: TRTProcessingOfEndCapHits.h:52
TRTProcessingOfEndCapHits.h
TRTProcessingOfEndCapHits::m_initialStrawIDInSectorC
int m_initialStrawIDInSectorC
Definition: TRTProcessingOfEndCapHits.h:44
TRTProcessingOfEndCapHits::m_numberOfWheelsAB
int m_numberOfWheelsAB
Definition: TRTProcessingOfEndCapHits.h:39
TRTParametersForBarrelHits::m_printMessages
int m_printMessages
Definition: TRTParametersForBarrelHits.h:23
TRTProcessingOfEndCapHits::m_numberOfStrawsInPlanesAB
int m_numberOfStrawsInPlanesAB
Definition: TRTProcessingOfEndCapHits.h:36
TRTSensitiveDetector
Definition: TRTSensitiveDetector.h:25
TRTProcessingOfEndCapHits::m_numberOfStrawsInSectorC
int m_numberOfStrawsInSectorC
Definition: TRTProcessingOfEndCapHits.h:42
TRTProcessingOfEndCapHits::m_numberOfStrawsInSectorsAB
int m_numberOfStrawsInSectorsAB
Definition: TRTProcessingOfEndCapHits.h:41
Trk::energyDeposit
@ energyDeposit
Definition: MeasurementType.h:32
TRTSensitiveDetector::m_partLink
HepMcParticleLink m_partLink
Definition: TRTSensitiveDetector.h:70
TRTProcessingOfEndCapHits::Initialize
void Initialize()
Definition: TRTProcessingOfEndCapHits.cxx:71
TrackHelper
Definition: TrackHelper.h:14
TRTSensitiveDetector::m_postStepX
double m_postStepX
Definition: TRTSensitiveDetector.h:78
TRTProcessingOfEndCapHits::m_sectorsABC
int m_sectorsABC
Definition: TRTProcessingOfEndCapHits.h:33
TRTProcessingOfEndCapHits::TRTProcessingOfEndCapHits
TRTProcessingOfEndCapHits(TRTSensitiveDetector *)
Definition: TRTProcessingOfEndCapHits.cxx:31
TRTSensitiveDetector::m_globalTime
double m_globalTime
Definition: TRTSensitiveDetector.h:81
TRTSensitiveDetector::m_kineticEnergy
double m_kineticEnergy
Definition: TRTSensitiveDetector.h:72
TRTProcessingOfEndCapHits::m_initialStrawIDInSectorsAB
int m_initialStrawIDInSectorsAB
Definition: TRTProcessingOfEndCapHits.h:43
TRTSensitiveDetector.h
TRTSensitiveDetector::m_postStepY
double m_postStepY
Definition: TRTSensitiveDetector.h:79
TRTProcessingOfEndCapHits::~TRTProcessingOfEndCapHits
~TRTProcessingOfEndCapHits()
Definition: TRTProcessingOfEndCapHits.cxx:64
TRTSensitiveDetector::m_preStepX
double m_preStepX
Definition: TRTSensitiveDetector.h:75
TRTProcessingOfEndCapHits::m_testLocalCoordinatesOfHits
int m_testLocalCoordinatesOfHits
Definition: TRTProcessingOfEndCapHits.h:34
TRTSensitiveDetector::m_preStepY
double m_preStepY
Definition: TRTSensitiveDetector.h:76
TRTSensitiveDetector::m_postStepZ
double m_postStepZ
Definition: TRTSensitiveDetector.h:80
TRTProcessingOfEndCapHits::m_numberOfStrawsInPlaneC
int m_numberOfStrawsInPlaneC
Definition: TRTProcessingOfEndCapHits.h:37
TRTProcessingOfEndCapHits::m_numberOfStrawsInIDSectorC
int m_numberOfStrawsInIDSectorC
Definition: TRTProcessingOfEndCapHits.h:47
TRTProcessingOfEndCapHits::m_numberOfStrawsInIDSectorsAB
int m_numberOfStrawsInIDSectorsAB
Definition: TRTProcessingOfEndCapHits.h:46
TRTSensitiveDetector::m_preStepZ
double m_preStepZ
Definition: TRTSensitiveDetector.h:77
TRTProcessingOfEndCapHits::ProcessHit
bool ProcessHit(G4Step *)
Definition: TRTProcessingOfEndCapHits.cxx:87
TRTParametersForBarrelHits::m_pParameters
const TRTParameters * m_pParameters
Definition: TRTParametersForBarrelHits.h:25
TRTSensitiveDetector::m_particleEncoding
int m_particleEncoding
Definition: TRTSensitiveDetector.h:71
TrackHelper::GenerateParticleLink
HepMcParticleLink GenerateParticleLink()
Generates a creates new HepMcParticleLink object on the stack based on GetUniqueID(),...
Definition: TrackHelper.h:35
TrackHelper::GetUniqueID
int GetUniqueID() const
Definition: TrackHelper.cxx:41
TRTSensitiveDetector::m_hitID
int m_hitID
Properties of current TRTUncompressedHit, set by TRTProcessingOfBarrelHits and TRTProcessingOfEndCapH...
Definition: TRTSensitiveDetector.h:69
TRTProcessingOfEndCapHits::m_pSensitiveDetector
TRTSensitiveDetector * m_pSensitiveDetector
Definition: TRTProcessingOfEndCapHits.h:50