Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Track.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4Track class implementation
27//
28// Author: Katsuya Amako, KEK - 1996
29// Revisions: Hisaya Kurashige, 1998-2011
30// --------------------------------------------------------------------
31
32#include "G4Track.hh"
35
36#include <iostream>
37#include <iomanip>
38
39// --------------------------------------------------------------------
41{
42 G4ThreadLocalStatic G4Allocator<G4Track>* _instance = nullptr;
43 return _instance;
44}
45
46// --------------------------------------------------------------------
47G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle,
48 G4double aValueTime,
49 const G4ThreeVector& aValuePosition)
50 : fPosition(aValuePosition)
51 , fGlobalTime(aValueTime)
52 , fVelocity(c_light)
53{
54 fpDynamicParticle = (apValueDynamicParticle) != nullptr
55 ? apValueDynamicParticle : new G4DynamicParticle();
56 // check if the particle type is Optical Photon
57 is_OpticalPhoton =
58 (fpDynamicParticle->GetDefinition()->GetPDGEncoding() == -22);
59}
60
61// --------------------------------------------------------------------
63 : fVelocity(c_light)
64 , fpDynamicParticle(new G4DynamicParticle())
65{}
66
67// --------------------------------------------------------------------
69 : fVelocity(c_light)
70{
71 *this = right;
72}
73
74// --------------------------------------------------------------------
76{
77 delete fpDynamicParticle;
78 delete fpUserInformation;
79 ClearAuxiliaryTrackInformation();
80}
81
82// --------------------------------------------------------------------
84{
85 if(this != &right)
86 {
87 fPosition = right.fPosition;
88 fGlobalTime = right.fGlobalTime;
89 fLocalTime = right.fLocalTime;
90 fTrackLength = right.fTrackLength;
91 fWeight = right.fWeight;
92 fStepLength = right.fStepLength;
93
94 // additional fields required for geometrical splitting
95 fpTouchable = right.fpTouchable;
96 fpNextTouchable = right.fpNextTouchable;
97 fpOriginTouchable = right.fpOriginTouchable;
98
99 // Track ID (and Parent ID) is not copied and set to zero for new track
100 fTrackID = 0;
101 fParentID = 0;
102
103 // CurrentStepNumber is set to be 0
104 fCurrentStepNumber = 0;
105
106 // Creator model ID
107 fCreatorModelID = right.fCreatorModelID;
108
109 // Parent resonance
110 fParentResonanceDef = right.fParentResonanceDef;
111 fParentResonanceID = right.fParentResonanceID;
112
113 // velocity information
114 fVelocity = right.fVelocity;
115
116 // dynamic particle information
117 delete fpDynamicParticle;
118 fpDynamicParticle = new G4DynamicParticle(*(right.fpDynamicParticle));
119
120 // track status and flags for tracking
121 fTrackStatus = right.fTrackStatus;
122 fBelowThreshold = right.fBelowThreshold;
123 fGoodForTracking = right.fGoodForTracking;
124
125 // Step information (Step Length, Step Number, pointer to the Step,)
126 // are not copied
127 fpStep = nullptr;
128
129 // vertex information
130 fVtxPosition = right.fVtxPosition;
131 fpLVAtVertex = right.fpLVAtVertex;
132 fVtxKineticEnergy = right.fVtxKineticEnergy;
133 fVtxMomentumDirection = right.fVtxMomentumDirection;
134
135 // CreatorProcess and UserInformation are not copied
136 fpCreatorProcess = nullptr;
137 delete fpUserInformation;
138 fpUserInformation = nullptr;
139
140 prev_mat = right.prev_mat;
141 groupvel = right.groupvel;
142 prev_velocity = right.prev_velocity;
143 prev_momentum = right.prev_momentum;
144
145 is_OpticalPhoton = right.is_OpticalPhoton;
146 useGivenVelocity = right.useGivenVelocity;
147
148 ClearAuxiliaryTrackInformation();
149 }
150 return *this;
151}
152
153// --------------------------------------------------------------------
155{
156 *this = right;
157}
158
159// --------------------------------------------------------------------
161{
162 G4double velocity = c_light;
163
164 G4Material* mat = nullptr;
165 G4bool update_groupvel = false;
166 if(fpStep != nullptr)
167 {
168 mat = this->GetMaterial(); // Fix for repeated volumes
169 }
170 else
171 {
172 if(fpTouchable)
173 {
174 mat = fpTouchable->GetVolume()->GetLogicalVolume()->GetMaterial();
175 }
176 }
177 // check if previous step is in the same volume
178 // and get new GROUPVELOCITY table if necessary
179 if((mat != nullptr) && ((mat != prev_mat) || (groupvel == nullptr)))
180 {
181 groupvel = nullptr;
182 if(mat->GetMaterialPropertiesTable() != nullptr)
184 update_groupvel = true;
185 }
186 prev_mat = mat;
187
188 if(groupvel != nullptr)
189 {
190 // light velocity = c/(rindex+d(rindex)/d(log(E_phot)))
191 // values stored in GROUPVEL material properties vector
192 velocity = prev_velocity;
193
194 // check if momentum is same as in the previous step
195 // and calculate group velocity if necessary
196 G4double current_momentum = fpDynamicParticle->GetTotalMomentum();
197 if(update_groupvel || (current_momentum != prev_momentum))
198 {
199 velocity = groupvel->Value(current_momentum);
200 prev_velocity = velocity;
201 prev_momentum = current_momentum;
202 }
203 }
204
205 return velocity;
206}
207
208// --------------------------------------------------------------------
211{
212 if(fpAuxiliaryTrackInformationMap == nullptr)
213 {
214 fpAuxiliaryTrackInformationMap =
215 new std::map<G4int, G4VAuxiliaryTrackInformation*>;
216 }
218 {
220 ED << "Process/model ID <" << id << "> is invalid.";
221 G4Exception("G4VAuxiliaryTrackInformation::G4VAuxiliaryTrackInformation()",
222 "TRACK0982", FatalException, ED);
223 }
224 (*fpAuxiliaryTrackInformationMap)[id] = info;
225}
226
227// --------------------------------------------------------------------
230{
231 if(fpAuxiliaryTrackInformationMap == nullptr)
232 return nullptr;
233
234 auto itr = fpAuxiliaryTrackInformationMap->find(id);
235 if(itr == fpAuxiliaryTrackInformationMap->cend())
236 return nullptr;
237 return (*itr).second;
238}
239
240// --------------------------------------------------------------------
242{
243 if(fpAuxiliaryTrackInformationMap != nullptr &&
244 fpAuxiliaryTrackInformationMap->find(id) != fpAuxiliaryTrackInformationMap->cend())
245 {
246 fpAuxiliaryTrackInformationMap->erase(id);
247 }
248}
249
250// --------------------------------------------------------------------
252{
253 if(fpAuxiliaryTrackInformationMap != nullptr)
254 {
257 }
258}
259
260// --------------------------------------------------------------------
261void G4Track::ClearAuxiliaryTrackInformation()
262{
263 if(fpAuxiliaryTrackInformationMap == nullptr)
264 return;
265 for(const auto& itr : *fpAuxiliaryTrackInformationMap)
266 {
267 delete itr.second;
268 }
269 delete fpAuxiliaryTrackInformationMap;
270 fpAuxiliaryTrackInformationMap = nullptr;
271}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4Allocator< G4Track > *& aTrackAllocator()
Definition G4Track.cc:40
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4ParticleDefinition * GetDefinition() const
G4double GetTotalMomentum() const
G4Material * GetMaterial() const
G4MaterialPropertyVector * GetProperty(const char *key) const
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
static G4int GetModelIndex(const G4int modelID)
static G4int GetModelID(const G4int modelIndex)
G4double Value(const G4double energy, std::size_t &lastidx) const
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
G4double CalculateVelocityForOpticalPhoton() const
Definition G4Track.cc:160
void SetAuxiliaryTrackInformation(G4int id, G4VAuxiliaryTrackInformation *info) const
Definition G4Track.cc:209
void CopyTrackInfo(const G4Track &)
Definition G4Track.cc:154
void RemoveAuxiliaryTrackInformation(G4int id)
Definition G4Track.cc:241
G4VAuxiliaryTrackInformation * GetAuxiliaryTrackInformation(G4int id) const
Definition G4Track.cc:229
G4Material * GetMaterial() const
G4Track()
Definition G4Track.cc:62
G4Track & operator=(const G4Track &)
Definition G4Track.cc:83
~G4Track()
Definition G4Track.cc:75
G4LogicalVolume * GetLogicalVolume() const
#define G4ThreadLocalStatic
Definition tls.hh:76