Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
27 // $Id: G4Track.cc 77080 2013-11-21 10:33:55Z gcosmo $
28 //
29 //
30 //---------------------------------------------------------------
31 //
32 // G4Track.cc
33 //
34 //---------------------------------------------------------------
35 // Add copy constructor Hisaya Feb. 07 01
36 // Fix GetVelocity Hisaya Feb. 17 01
37 // Modification for G4TouchableHandle 22 Oct. 2001 R.Chytracek//
38 // Fix GetVelocity (bug report #741) Horton-Smith Apr 14 2005
39 // Remove massless check in GetVelocity 02 Apr. 09 H.Kurashige
40 // Use G4VelocityTable 17 AUg. 2011 H.Kurashige
41 
42 #include "G4Track.hh"
43 #include "G4PhysicalConstants.hh"
44 #include "G4ParticleTable.hh"
45 #include "G4VelocityTable.hh"
46 
47 #include <iostream>
48 #include <iomanip>
49 
51 
52 G4ThreadLocal G4VelocityTable* G4Track::velTable=0;
53 
54 ///////////////////////////////////////////////////////////
55 G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle,
56  G4double aValueTime,
57  const G4ThreeVector& aValuePosition)
58 ///////////////////////////////////////////////////////////
59  : fCurrentStepNumber(0), fPosition(aValuePosition),
60  fGlobalTime(aValueTime), fLocalTime(0.),
61  fTrackLength(0.),
62  fParentID(0), fTrackID(0),
63  fVelocity(c_light),
64  fpDynamicParticle(apValueDynamicParticle),
65  fTrackStatus(fAlive),
66  fBelowThreshold(false), fGoodForTracking(false),
67  fStepLength(0.0), fWeight(1.0),
68  fpStep(0),
69  fVtxKineticEnergy(0.0),
70  fpLVAtVertex(0), fpCreatorProcess(0),
71  fCreatorModelIndex(-1),
72  fpUserInformation(0),
73  prev_mat(0), groupvel(0),
74  prev_velocity(0.0), prev_momentum(0.0),
75  is_OpticalPhoton(false),
76  useGivenVelocity(false)
77 {
78  static G4ThreadLocal G4bool isFirstTime = true;
79  static G4ThreadLocal G4ParticleDefinition* fOpticalPhoton =0;
80  if ( isFirstTime ) {
81  isFirstTime = false;
82  // set fOpticalPhoton
83  fOpticalPhoton = G4ParticleTable::GetParticleTable()->FindParticle("opticalphoton");
84  }
85  // check if the particle type is Optical Photon
86  is_OpticalPhoton = (fpDynamicParticle->GetDefinition() == fOpticalPhoton);
87 
88  if (velTable ==0 ) velTable = G4VelocityTable::GetVelocityTable();
89 
90  fVelocity = CalculateVelocity();
91 
92 }
93 
94 //////////////////
96 //////////////////
97  : fCurrentStepNumber(0),
98  fGlobalTime(0), fLocalTime(0.),
99  fTrackLength(0.),
100  fParentID(0), fTrackID(0),
101  fVelocity(c_light),
102  fpDynamicParticle(0),
103  fTrackStatus(fAlive),
104  fBelowThreshold(false), fGoodForTracking(false),
105  fStepLength(0.0), fWeight(1.0),
106  fpStep(0),
107  fVtxKineticEnergy(0.0),
108  fpLVAtVertex(0), fpCreatorProcess(0),
109  fCreatorModelIndex(-1),
110  fpUserInformation(0),
111  prev_mat(0), groupvel(0),
112  prev_velocity(0.0), prev_momentum(0.0),
113  is_OpticalPhoton(false),
114  useGivenVelocity(false)
115 {
116 }
117 
118 //////////////////
120 //////////////////
121  : fCurrentStepNumber(0),
122  fGlobalTime(0), fLocalTime(0.),
123  fTrackLength(0.),
124  fParentID(0), fTrackID(0),
125  fVelocity(c_light),
126  fpDynamicParticle(0),
127  fTrackStatus(fAlive),
128  fBelowThreshold(false), fGoodForTracking(false),
129  fStepLength(0.0), fWeight(1.0),
130  fpStep(0),
131  fVtxKineticEnergy(0.0),
132  fpLVAtVertex(0), fpCreatorProcess(0),
133  fCreatorModelIndex(-1),
134  fpUserInformation(0),
135  prev_mat(0), groupvel(0),
136  prev_velocity(0.0), prev_momentum(0.0),
137  is_OpticalPhoton(false),
138  useGivenVelocity(false)
139 {
140  *this = right;
141 }
142 
143 ///////////////////
145 ///////////////////
146 {
147  delete fpDynamicParticle;
148  delete fpUserInformation;
149 }
150 
151 //////////////////
152 G4Track & G4Track::operator=(const G4Track &right)
153 //////////////////
154 {
155  if (this != &right) {
156  fPosition = right.fPosition;
157  fGlobalTime = right.fGlobalTime;
158  fLocalTime = right.fLocalTime;
159  fTrackLength = right.fTrackLength;
160  fWeight = right.fWeight;
161  fStepLength = right.fStepLength;
162 
163  // Track ID (and Parent ID) is not copied and set to zero for new track
164  fTrackID = 0;
165  fParentID =0;
166 
167  // CurrentStepNumber is set to be 0
168  fCurrentStepNumber = 0;
169 
170  // velocity information
171  fVelocity = right.fVelocity;
172 
173  // dynamic particle information
174  fpDynamicParticle = new G4DynamicParticle(*(right.fpDynamicParticle));
175 
176  // track status and flags for tracking
177  fTrackStatus = right.fTrackStatus;
178  fBelowThreshold = right.fBelowThreshold;
179  fGoodForTracking = right.fGoodForTracking;
180 
181  // Step information (Step Length, Step Number, pointer to the Step,)
182  // are not copied
183  fpStep=0;
184 
185  // vertex information
186  fVtxPosition = right.fVtxPosition;
187  fpLVAtVertex = right.fpLVAtVertex;
188  fVtxKineticEnergy = right.fVtxKineticEnergy;
189  fVtxMomentumDirection = right.fVtxMomentumDirection;
190 
191  // CreatorProcess and UserInformation are not copied
192  fpCreatorProcess = 0;
193  fpUserInformation = 0;
194 
195  prev_mat = right.prev_mat;
196  groupvel = right.groupvel;
197  prev_velocity = right.prev_velocity;
198  prev_momentum = right.prev_momentum;
199 
200  is_OpticalPhoton = right.is_OpticalPhoton;
201  useGivenVelocity = right.useGivenVelocity;
202  }
203  return *this;
204 }
205 
206 ///////////////////
207 void G4Track::CopyTrackInfo(const G4Track& right)
208 //////////////////
209 {
210  *this = right;
211 }
212 
213 ///////////////////
215 ///////////////////
216 {
217  if (useGivenVelocity) return fVelocity;
218 
219  G4double velocity = c_light ;
220 
221  G4double mass = fpDynamicParticle->GetMass();
222 
223  // special case for photons
224  if ( is_OpticalPhoton ) return CalculateVelocityForOpticalPhoton();
225 
226  // particles other than optical photon
227  if (mass<DBL_MIN) {
228  // Zero Mass
229  velocity = c_light;
230  } else {
231  G4double T = (fpDynamicParticle->GetKineticEnergy())/mass;
232  if (T > GetMaxTOfVelocityTable()) {
233  velocity = c_light;
234  } else if (T<DBL_MIN) {
235  velocity =0.;
236  } else if (T<GetMinTOfVelocityTable()) {
237  velocity = c_light*std::sqrt(T*(T+2.))/(T+1.0);
238  } else {
239  velocity = velTable->Value(T);
240  }
241 
242  }
243  return velocity ;
244 }
245 
246 ///////////////////
248 ///////////////////
249 {
250 
251  G4double velocity = c_light ;
252 
253 
254  G4Material* mat=0;
255  G4bool update_groupvel = false;
256  if ( fpStep !=0 ){
257  mat= this->GetMaterial(); // Fix for repeated volumes
258  }else{
259  if (fpTouchable!=0){
260  mat=fpTouchable->GetVolume()->GetLogicalVolume()->GetMaterial();
261  }
262  }
263  // check if previous step is in the same volume
264  // and get new GROUPVELOCITY table if necessary
265  if ((mat != 0) && ((mat != prev_mat)||(groupvel==0))) {
266  groupvel = 0;
267  if(mat->GetMaterialPropertiesTable() != 0)
268  groupvel = mat->GetMaterialPropertiesTable()->GetProperty("GROUPVEL");
269  update_groupvel = true;
270  }
271  prev_mat = mat;
272 
273  if (groupvel != 0 ) {
274  // light velocity = c/(rindex+d(rindex)/d(log(E_phot)))
275  // values stored in GROUPVEL material properties vector
276  velocity = prev_velocity;
277 
278  // check if momentum is same as in the previous step
279  // and calculate group velocity if necessary
280  G4double current_momentum = fpDynamicParticle->GetTotalMomentum();
281  if( update_groupvel || (current_momentum != prev_momentum) ) {
282  velocity =
283  groupvel->Value(current_momentum);
284  prev_velocity = velocity;
285  prev_momentum = current_momentum;
286  }
287  }
288 
289  return velocity ;
290 }
291 
292 ///////////////////
294 ///////////////////
295 {
298 }
299 
300 ///////////////////
302 ///////////////////
304 
305 ///////////////////
307 ///////////////////
309 
310 ///////////////////
312 ///////////////////
static G4VelocityTable * GetVelocityTable()
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4MaterialPropertyVector * GetProperty(const char *key)
G4ThreadLocal G4Allocator< G4Track > * aTrackAllocator
Definition: G4Track.cc:50
G4double GetKineticEnergy() const
static G4double GetMinTOfVelocityTable()
G4Material * GetMaterial() const
G4ParticleDefinition * GetDefinition() const
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
G4double GetTotalMomentum() const
G4double CalculateVelocityForOpticalPhoton() const
Definition: G4Track.cc:247
G4double GetMass() const
bool G4bool
Definition: G4Types.hh:79
static G4int GetNbinOfVelocityTable()
G4double Value(G4double theEnergy, size_t &lastidx) const
G4double CalculateVelocity() const
Definition: G4Track.cc:214
static void SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin)
G4Material * GetMaterial() const
static G4int GetNbinOfVelocityTable()
Definition: G4Track.cc:311
G4LogicalVolume * GetLogicalVolume() const
static G4ParticleTable * GetParticleTable()
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:44
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
Definition: G4Material.hh:250
static G4double GetMinTOfVelocityTable()
Definition: G4Track.cc:306
#define DBL_MIN
Definition: templates.hh:75
static void SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin)
Definition: G4Track.cc:293
static G4double GetMaxTOfVelocityTable()
Definition: G4Track.cc:301
double G4double
Definition: G4Types.hh:76
static G4double GetMaxTOfVelocityTable()
G4double Value(G4double theEnergy)
G4Track()
Definition: G4Track.cc:95
float c_light
Definition: hepunit.py:257
void CopyTrackInfo(const G4Track &)
Definition: G4Track.cc:207
~G4Track()
Definition: G4Track.cc:144