Geant4 10.7.0
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"
36
37#include <iostream>
38#include <iomanip>
39
40// --------------------------------------------------------------------
42{
43 G4ThreadLocalStatic G4Allocator<G4Track>* _instance = nullptr;
44 return _instance;
45}
46
47// --------------------------------------------------------------------
48G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle,
49 G4double aValueTime,
50 const G4ThreeVector& aValuePosition)
51 : fPosition(aValuePosition)
52 , fGlobalTime(aValueTime)
53 , fVelocity(c_light)
54{
55 fpDynamicParticle = (apValueDynamicParticle)
56 ? apValueDynamicParticle : new G4DynamicParticle();
57 // check if the particle type is Optical Photon
58 is_OpticalPhoton =
59 (fpDynamicParticle->GetDefinition()->GetPDGEncoding() == -22);
60}
61
62// --------------------------------------------------------------------
64 : fVelocity(c_light)
65 , fpDynamicParticle(new G4DynamicParticle())
66{}
67
68// --------------------------------------------------------------------
70 : fVelocity(c_light)
71{
72 *this = right;
73}
74
75// --------------------------------------------------------------------
77{
78 delete fpDynamicParticle;
79 delete fpUserInformation;
80 ClearAuxiliaryTrackInformation();
81}
82
83// --------------------------------------------------------------------
85{
86 if(this != &right)
87 {
88 fPosition = right.fPosition;
89 fGlobalTime = right.fGlobalTime;
90 fLocalTime = right.fLocalTime;
91 fTrackLength = right.fTrackLength;
92 fWeight = right.fWeight;
93 fStepLength = right.fStepLength;
94
95 // Track ID (and Parent ID) is not copied and set to zero for new track
96 fTrackID = 0;
97 fParentID = 0;
98
99 // CurrentStepNumber is set to be 0
100 fCurrentStepNumber = 0;
101
102 // velocity information
103 fVelocity = right.fVelocity;
104
105 // dynamic particle information
106 delete fpDynamicParticle;
107 fpDynamicParticle = new G4DynamicParticle(*(right.fpDynamicParticle));
108
109 // track status and flags for tracking
110 fTrackStatus = right.fTrackStatus;
111 fBelowThreshold = right.fBelowThreshold;
112 fGoodForTracking = right.fGoodForTracking;
113
114 // Step information (Step Length, Step Number, pointer to the Step,)
115 // are not copied
116 fpStep = nullptr;
117
118 // vertex information
119 fVtxPosition = right.fVtxPosition;
120 fpLVAtVertex = right.fpLVAtVertex;
121 fVtxKineticEnergy = right.fVtxKineticEnergy;
122 fVtxMomentumDirection = right.fVtxMomentumDirection;
123
124 // CreatorProcess and UserInformation are not copied
125 fpCreatorProcess = nullptr;
126 delete fpUserInformation;
127 fpUserInformation = nullptr;
128
129 prev_mat = right.prev_mat;
130 groupvel = right.groupvel;
131 prev_velocity = right.prev_velocity;
132 prev_momentum = right.prev_momentum;
133
134 is_OpticalPhoton = right.is_OpticalPhoton;
135 useGivenVelocity = right.useGivenVelocity;
136
137 ClearAuxiliaryTrackInformation();
138 }
139 return *this;
140}
141
142// --------------------------------------------------------------------
144{
145 *this = right;
146}
147
148// --------------------------------------------------------------------
150{
151 G4double velocity = c_light;
152
153 G4Material* mat = nullptr;
154 G4bool update_groupvel = false;
155 if(fpStep != nullptr)
156 {
157 mat = this->GetMaterial(); // Fix for repeated volumes
158 }
159 else
160 {
161 if(fpTouchable != 0)
162 {
163 mat = fpTouchable->GetVolume()->GetLogicalVolume()->GetMaterial();
164 }
165 }
166 // check if previous step is in the same volume
167 // and get new GROUPVELOCITY table if necessary
168 if((mat != nullptr) && ((mat != prev_mat) || (groupvel == nullptr)))
169 {
170 groupvel = nullptr;
171 if(mat->GetMaterialPropertiesTable() != nullptr)
172 groupvel = mat->GetMaterialPropertiesTable()->GetProperty("GROUPVEL");
173 update_groupvel = true;
174 }
175 prev_mat = mat;
176
177 if(groupvel != nullptr)
178 {
179 // light velocity = c/(rindex+d(rindex)/d(log(E_phot)))
180 // values stored in GROUPVEL material properties vector
181 velocity = prev_velocity;
182
183 // check if momentum is same as in the previous step
184 // and calculate group velocity if necessary
185 G4double current_momentum = fpDynamicParticle->GetTotalMomentum();
186 if(update_groupvel || (current_momentum != prev_momentum))
187 {
188 velocity = groupvel->Value(current_momentum);
189 prev_velocity = velocity;
190 prev_momentum = current_momentum;
191 }
192 }
193
194 return velocity;
195}
196
197// --------------------------------------------------------------------
200{
201 if(fpAuxiliaryTrackInformationMap == nullptr)
202 {
203 fpAuxiliaryTrackInformationMap =
204 new std::map<G4int, G4VAuxiliaryTrackInformation*>;
205 }
206 if(idx < 0 || idx >= G4PhysicsModelCatalog::Entries())
207 {
209 ED << "Process/model index <" << idx << "> is invalid.";
210 G4Exception("G4VAuxiliaryTrackInformation::G4VAuxiliaryTrackInformation()",
211 "TRACK0982", FatalException, ED);
212 }
213 (*fpAuxiliaryTrackInformationMap)[idx] = info;
214}
215
216// --------------------------------------------------------------------
219{
220 if(fpAuxiliaryTrackInformationMap == nullptr)
221 return nullptr;
222 auto itr = fpAuxiliaryTrackInformationMap->find(idx);
223 if(itr == fpAuxiliaryTrackInformationMap->cend())
224 return nullptr;
225 else
226 return (*itr).second;
227}
228
229// --------------------------------------------------------------------
231{
232 if(fpAuxiliaryTrackInformationMap != nullptr
233 && idx >= 0 && idx < G4PhysicsModelCatalog::Entries())
234 {
235 fpAuxiliaryTrackInformationMap->erase(idx);
236 }
237}
238
239// --------------------------------------------------------------------
241{
242 if(fpAuxiliaryTrackInformationMap != nullptr)
243 {
246 }
247}
248
249// --------------------------------------------------------------------
250void G4Track::ClearAuxiliaryTrackInformation()
251{
252 if(fpAuxiliaryTrackInformationMap == nullptr)
253 return;
254 for(auto itr = fpAuxiliaryTrackInformationMap->cbegin();
255 itr != fpAuxiliaryTrackInformationMap->cend(); ++itr)
256 {
257 delete(*itr).second;
258 }
259 delete fpAuxiliaryTrackInformationMap;
260 fpAuxiliaryTrackInformationMap = nullptr;
261}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
G4Allocator< G4Track > *& aTrackAllocator()
Definition: G4Track.cc:41
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, G4bool warning=false)
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
Definition: G4Material.hh:254
static G4int GetIndex(const G4String &)
G4double Value(G4double theEnergy, std::size_t &lastidx) const
void SetAuxiliaryTrackInformation(G4int idx, G4VAuxiliaryTrackInformation *info) const
Definition: G4Track.cc:198
G4double CalculateVelocityForOpticalPhoton() const
Definition: G4Track.cc:149
void CopyTrackInfo(const G4Track &)
Definition: G4Track.cc:143
G4Material * GetMaterial() const
G4Track()
Definition: G4Track.cc:63
void RemoveAuxiliaryTrackInformation(G4int idx)
Definition: G4Track.cc:230
G4VAuxiliaryTrackInformation * GetAuxiliaryTrackInformation(G4int idx) const
Definition: G4Track.cc:218
G4Track & operator=(const G4Track &)
Definition: G4Track.cc:84
~G4Track()
Definition: G4Track.cc:76
G4LogicalVolume * GetLogicalVolume() const
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:41
#define G4ThreadLocalStatic
Definition: tls.hh:76