Geant4-11
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)
55 ? apValueDynamicParticle : new G4DynamicParticle();
56 // check if the particle type is Optical Photon
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;
80}
81
82// --------------------------------------------------------------------
84{
85 if(this != &right)
86 {
87 fPosition = right.fPosition;
89 fLocalTime = right.fLocalTime;
91 fWeight = right.fWeight;
93
94 // additional fields required for geometrical splitting
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
105
106 // Creator model ID
108
109 // velocity information
110 fVelocity = right.fVelocity;
111
112 // dynamic particle information
113 delete fpDynamicParticle;
115
116 // track status and flags for tracking
120
121 // Step information (Step Length, Step Number, pointer to the Step,)
122 // are not copied
123 fpStep = nullptr;
124
125 // vertex information
130
131 // CreatorProcess and UserInformation are not copied
132 fpCreatorProcess = nullptr;
133 delete fpUserInformation;
134 fpUserInformation = nullptr;
135
136 prev_mat = right.prev_mat;
137 groupvel = right.groupvel;
140
143
145 }
146 return *this;
147}
148
149// --------------------------------------------------------------------
151{
152 *this = right;
153}
154
155// --------------------------------------------------------------------
157{
158 G4double velocity = c_light;
159
160 G4Material* mat = nullptr;
161 G4bool update_groupvel = false;
162 if(fpStep != nullptr)
163 {
164 mat = this->GetMaterial(); // Fix for repeated volumes
165 }
166 else
167 {
168 if(fpTouchable != 0)
169 {
171 }
172 }
173 // check if previous step is in the same volume
174 // and get new GROUPVELOCITY table if necessary
175 if((mat != nullptr) && ((mat != prev_mat) || (groupvel == nullptr)))
176 {
177 groupvel = nullptr;
178 if(mat->GetMaterialPropertiesTable() != nullptr)
180 update_groupvel = true;
181 }
182 prev_mat = mat;
183
184 if(groupvel != nullptr)
185 {
186 // light velocity = c/(rindex+d(rindex)/d(log(E_phot)))
187 // values stored in GROUPVEL material properties vector
188 velocity = prev_velocity;
189
190 // check if momentum is same as in the previous step
191 // and calculate group velocity if necessary
192 G4double current_momentum = fpDynamicParticle->GetTotalMomentum();
193 if(update_groupvel || (current_momentum != prev_momentum))
194 {
195 velocity = groupvel->Value(current_momentum);
196 prev_velocity = velocity;
197 prev_momentum = current_momentum;
198 }
199 }
200
201 return velocity;
202}
203
204// --------------------------------------------------------------------
207{
208 if(fpAuxiliaryTrackInformationMap == nullptr)
209 {
211 new std::map<G4int, G4VAuxiliaryTrackInformation*>;
212 }
214 {
216 ED << "Process/model ID <" << id << "> is invalid.";
217 G4Exception("G4VAuxiliaryTrackInformation::G4VAuxiliaryTrackInformation()",
218 "TRACK0982", FatalException, ED);
219 }
220 (*fpAuxiliaryTrackInformationMap)[id] = info;
221}
222
223// --------------------------------------------------------------------
226{
227 if(fpAuxiliaryTrackInformationMap == nullptr)
228 return nullptr;
229 auto itr = fpAuxiliaryTrackInformationMap->find(id);
230 if(itr == fpAuxiliaryTrackInformationMap->cend())
231 return nullptr;
232 else
233 return (*itr).second;
234}
235
236// --------------------------------------------------------------------
238{
239 if(fpAuxiliaryTrackInformationMap != nullptr &&
241 {
243 }
244}
245
246// --------------------------------------------------------------------
248{
249 if(fpAuxiliaryTrackInformationMap != nullptr)
250 {
253 }
254}
255
256// --------------------------------------------------------------------
258{
259 if(fpAuxiliaryTrackInformationMap == nullptr)
260 return;
261 for(auto itr = fpAuxiliaryTrackInformationMap->cbegin();
262 itr != fpAuxiliaryTrackInformationMap->cend(); ++itr)
263 {
264 delete(*itr).second;
265 }
268}
@ 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: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
Definition: G4Material.hh:252
static G4int GetModelIndex(const G4int modelID)
static G4int GetModelID(const G4int modelIndex)
G4double Value(const G4double energy, std::size_t &lastidx) const
G4double fLocalTime
Definition: G4Track.hh:266
G4TrackStatus fTrackStatus
Definition: G4Track.hh:279
G4double prev_velocity
Definition: G4Track.hh:307
G4double fWeight
Definition: G4Track.hh:287
G4double CalculateVelocityForOpticalPhoton() const
Definition: G4Track.cc:156
G4double fVtxKineticEnergy
Definition: G4Track.hh:296
G4int fParentID
Definition: G4Track.hh:320
G4double fStepLength
Definition: G4Track.hh:281
const G4Step * fpStep
Definition: G4Track.hh:290
void SetAuxiliaryTrackInformation(G4int id, G4VAuxiliaryTrackInformation *info) const
Definition: G4Track.cc:205
G4ThreeVector fPosition
Definition: G4Track.hh:262
G4int fCreatorModelID
Definition: G4Track.hh:317
void CopyTrackInfo(const G4Track &)
Definition: G4Track.cc:150
G4TouchableHandle fpOriginTouchable
Definition: G4Track.hh:275
void RemoveAuxiliaryTrackInformation(G4int id)
Definition: G4Track.cc:237
const G4VProcess * fpCreatorProcess
Definition: G4Track.hh:300
G4double fVelocity
Definition: G4Track.hh:271
G4ThreeVector fVtxMomentumDirection
Definition: G4Track.hh:294
G4bool useGivenVelocity
Definition: G4Track.hh:332
G4VUserTrackInformation * fpUserInformation
Definition: G4Track.hh:303
G4double prev_momentum
Definition: G4Track.hh:308
G4int fTrackID
Definition: G4Track.hh:321
G4VAuxiliaryTrackInformation * GetAuxiliaryTrackInformation(G4int id) const
Definition: G4Track.cc:225
G4Material * GetMaterial() const
const G4LogicalVolume * fpLVAtVertex
Definition: G4Track.hh:298
G4double fGlobalTime
Definition: G4Track.hh:264
G4Track()
Definition: G4Track.cc:62
G4Material * prev_mat
Definition: G4Track.hh:305
G4double fTrackLength
Definition: G4Track.hh:268
std::map< G4int, G4VAuxiliaryTrackInformation * > * fpAuxiliaryTrackInformationMap
Definition: G4Track.hh:312
G4TouchableHandle fpTouchable
Definition: G4Track.hh:273
G4int fCurrentStepNumber
Definition: G4Track.hh:314
G4bool fBelowThreshold
Definition: G4Track.hh:323
G4DynamicParticle * fpDynamicParticle
Definition: G4Track.hh:278
G4TouchableHandle fpNextTouchable
Definition: G4Track.hh:274
void ClearAuxiliaryTrackInformation()
Definition: G4Track.cc:257
G4bool is_OpticalPhoton
Definition: G4Track.hh:330
G4Track & operator=(const G4Track &)
Definition: G4Track.cc:83
G4MaterialPropertyVector * groupvel
Definition: G4Track.hh:306
G4ThreeVector fVtxPosition
Definition: G4Track.hh:292
G4bool fGoodForTracking
Definition: G4Track.hh:326
~G4Track()
Definition: G4Track.cc:75
G4LogicalVolume * GetLogicalVolume() const
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:34
const char * name(G4int ptype)
float c_light
Definition: hepunit.py:256
#define G4ThreadLocalStatic
Definition: tls.hh:76