Geant4  10.03.p03
 All Classes 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 91231 2015-06-26 10:40:45Z 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"
47 #include "G4PhysicsModelCatalog.hh"
48 
49 #include <iostream>
50 #include <iomanip>
51 
53 
54 G4ThreadLocal G4VelocityTable* G4Track::velTable=0;
55 
57 G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle,
58  G4double aValueTime,
59  const G4ThreeVector& aValuePosition)
61  : fCurrentStepNumber(0), fPosition(aValuePosition),
62  fGlobalTime(aValueTime), fLocalTime(0.),
63  fTrackLength(0.),
64  fParentID(0), fTrackID(0),
65  fVelocity(c_light),
66  fpDynamicParticle(apValueDynamicParticle),
67  fTrackStatus(fAlive),
68  fBelowThreshold(false), fGoodForTracking(false),
69  fStepLength(0.0), fWeight(1.0),
70  fpStep(0),
71  fVtxKineticEnergy(0.0),
72  fpLVAtVertex(0), fpCreatorProcess(0),
73  fCreatorModelIndex(-1),
74  fpUserInformation(0),
75  prev_mat(0), groupvel(0),
76  prev_velocity(0.0), prev_momentum(0.0),
77  is_OpticalPhoton(false),
78  useGivenVelocity(false),
79  fpAuxiliaryTrackInformationMap(0)
80 {
81  static G4ThreadLocal G4bool isFirstTime = true;
82  static G4ThreadLocal G4ParticleDefinition* fOpticalPhoton =0;
83  if ( isFirstTime ) {
84  isFirstTime = false;
85  // set fOpticalPhoton
86  fOpticalPhoton = G4ParticleTable::GetParticleTable()->FindParticle("opticalphoton");
87  }
88  // check if the particle type is Optical Photon
89  is_OpticalPhoton = (fpDynamicParticle->GetDefinition() == fOpticalPhoton);
90 
91  if (velTable ==0 ) velTable = G4VelocityTable::GetVelocityTable();
92 
93  fVelocity = CalculateVelocity();
94 
95 }
96 
100  : fCurrentStepNumber(0),
101  fGlobalTime(0), fLocalTime(0.),
102  fTrackLength(0.),
103  fParentID(0), fTrackID(0),
104  fVelocity(c_light),
105  fpDynamicParticle(0),
106  fTrackStatus(fAlive),
107  fBelowThreshold(false), fGoodForTracking(false),
108  fStepLength(0.0), fWeight(1.0),
109  fpStep(0),
110  fVtxKineticEnergy(0.0),
111  fpLVAtVertex(0), fpCreatorProcess(0),
112  fCreatorModelIndex(-1),
113  fpUserInformation(0),
114  prev_mat(0), groupvel(0),
115  prev_velocity(0.0), prev_momentum(0.0),
116  is_OpticalPhoton(false),
117  useGivenVelocity(false),
118  fpAuxiliaryTrackInformationMap(0)
119 {
120 }
121 
125  : fCurrentStepNumber(0),
126  fGlobalTime(0), fLocalTime(0.),
127  fTrackLength(0.),
128  fParentID(0), fTrackID(0),
129  fVelocity(c_light),
130  fpDynamicParticle(0),
131  fTrackStatus(fAlive),
132  fBelowThreshold(false), fGoodForTracking(false),
133  fStepLength(0.0), fWeight(1.0),
134  fpStep(0),
135  fVtxKineticEnergy(0.0),
136  fpLVAtVertex(0), fpCreatorProcess(0),
137  fCreatorModelIndex(-1),
138  fpUserInformation(0),
139  prev_mat(0), groupvel(0),
140  prev_velocity(0.0), prev_momentum(0.0),
141  is_OpticalPhoton(false),
142  useGivenVelocity(false),
143  fpAuxiliaryTrackInformationMap(0)
144 {
145  *this = right;
146 }
147 
151 {
152  delete fpDynamicParticle;
153  delete fpUserInformation;
154  ClearAuxiliaryTrackInformation();
155 }
156 
158 G4Track & G4Track::operator=(const G4Track &right)
160 {
161  if (this != &right) {
162  fPosition = right.fPosition;
163  fGlobalTime = right.fGlobalTime;
164  fLocalTime = right.fLocalTime;
165  fTrackLength = right.fTrackLength;
166  fWeight = right.fWeight;
167  fStepLength = right.fStepLength;
168 
169  // Track ID (and Parent ID) is not copied and set to zero for new track
170  fTrackID = 0;
171  fParentID =0;
172 
173  // CurrentStepNumber is set to be 0
174  fCurrentStepNumber = 0;
175 
176  // velocity information
177  fVelocity = right.fVelocity;
178 
179  // dynamic particle information
180  fpDynamicParticle = new G4DynamicParticle(*(right.fpDynamicParticle));
181 
182  // track status and flags for tracking
183  fTrackStatus = right.fTrackStatus;
184  fBelowThreshold = right.fBelowThreshold;
185  fGoodForTracking = right.fGoodForTracking;
186 
187  // Step information (Step Length, Step Number, pointer to the Step,)
188  // are not copied
189  fpStep=0;
190 
191  // vertex information
192  fVtxPosition = right.fVtxPosition;
193  fpLVAtVertex = right.fpLVAtVertex;
194  fVtxKineticEnergy = right.fVtxKineticEnergy;
195  fVtxMomentumDirection = right.fVtxMomentumDirection;
196 
197  // CreatorProcess and UserInformation are not copied
198  fpCreatorProcess = 0;
199  fpUserInformation = 0;
200 
201  prev_mat = right.prev_mat;
202  groupvel = right.groupvel;
203  prev_velocity = right.prev_velocity;
204  prev_momentum = right.prev_momentum;
205 
206  is_OpticalPhoton = right.is_OpticalPhoton;
207  useGivenVelocity = right.useGivenVelocity;
208 
209  fpAuxiliaryTrackInformationMap = 0;
210  }
211  return *this;
212 }
213 
215 void G4Track::CopyTrackInfo(const G4Track& right)
217 {
218  *this = right;
219 }
220 
224 {
225  if (useGivenVelocity) return fVelocity;
226 
227  G4double velocity = c_light ;
228 
229  G4double mass = fpDynamicParticle->GetMass();
230 
231  // special case for photons
232  if ( is_OpticalPhoton ) return CalculateVelocityForOpticalPhoton();
233 
234  // particles other than optical photon
235  if (mass<DBL_MIN) {
236  // Zero Mass
237  velocity = c_light;
238  } else {
239  G4double T = (fpDynamicParticle->GetKineticEnergy())/mass;
240  if (T > GetMaxTOfVelocityTable()) {
241  velocity = c_light;
242  } else if (T<DBL_MIN) {
243  velocity =0.;
244  } else if (T<GetMinTOfVelocityTable()) {
245  velocity = c_light*std::sqrt(T*(T+2.))/(T+1.0);
246  } else {
247  velocity = velTable->Value(T);
248  }
249 
250  }
251  return velocity ;
252 }
253 
257 {
258 
259  G4double velocity = c_light ;
260 
261 
262  G4Material* mat=0;
263  G4bool update_groupvel = false;
264  if ( fpStep !=0 ){
265  mat= this->GetMaterial(); // Fix for repeated volumes
266  }else{
267  if (fpTouchable!=0){
268  mat=fpTouchable->GetVolume()->GetLogicalVolume()->GetMaterial();
269  }
270  }
271  // check if previous step is in the same volume
272  // and get new GROUPVELOCITY table if necessary
273  if ((mat != 0) && ((mat != prev_mat)||(groupvel==0))) {
274  groupvel = 0;
275  if(mat->GetMaterialPropertiesTable() != 0)
276  groupvel = mat->GetMaterialPropertiesTable()->GetProperty("GROUPVEL");
277  update_groupvel = true;
278  }
279  prev_mat = mat;
280 
281  if (groupvel != 0 ) {
282  // light velocity = c/(rindex+d(rindex)/d(log(E_phot)))
283  // values stored in GROUPVEL material properties vector
284  velocity = prev_velocity;
285 
286  // check if momentum is same as in the previous step
287  // and calculate group velocity if necessary
288  G4double current_momentum = fpDynamicParticle->GetTotalMomentum();
289  if( update_groupvel || (current_momentum != prev_momentum) ) {
290  velocity =
291  groupvel->Value(current_momentum);
292  prev_velocity = velocity;
293  prev_momentum = current_momentum;
294  }
295  }
296 
297  return velocity ;
298 }
299 
303 {
306 }
307 
312 
317 
322 
326 {
327  if(!fpAuxiliaryTrackInformationMap)
328  { fpAuxiliaryTrackInformationMap = new std::map<G4int,G4VAuxiliaryTrackInformation*>; }
329  if(idx<0 || idx>=G4PhysicsModelCatalog::Entries())
330  {
332  ED << "Process/model index <" << idx << "> is invalid.";
333  G4Exception("G4VAuxiliaryTrackInformation::G4VAuxiliaryTrackInformation()","TRACK0982",
334  FatalException, ED);
335  }
336  (*fpAuxiliaryTrackInformationMap)[idx] = info;
337 }
338 
342 {
343  if(!fpAuxiliaryTrackInformationMap) return 0;
344  std::map<G4int,G4VAuxiliaryTrackInformation*>::iterator itr
345  = fpAuxiliaryTrackInformationMap->find(idx);
346  if(itr==fpAuxiliaryTrackInformationMap->end()) return 0;
347  else return (*itr).second;
348 }
349 
353 {
354  if(fpAuxiliaryTrackInformationMap && idx>=0 && idx<G4PhysicsModelCatalog::Entries())
355  fpAuxiliaryTrackInformationMap->erase(idx);
356 }
357 
361 {
362  if(fpAuxiliaryTrackInformationMap)
363  {
366  }
367 }
368 
370 void G4Track::ClearAuxiliaryTrackInformation()
372 {
373  if(!fpAuxiliaryTrackInformationMap) return;
374  for(std::map<G4int,G4VAuxiliaryTrackInformation*>::iterator itr=fpAuxiliaryTrackInformationMap->begin();
375  itr!=fpAuxiliaryTrackInformationMap->end(); itr++)
376  { delete (*itr).second; }
377  delete fpAuxiliaryTrackInformationMap;
378  fpAuxiliaryTrackInformationMap = 0;
379 }
380 
381 
const XML_Char XML_Encoding * info
Definition: expat.h:530
const XML_Char * name
Definition: expat.h:151
static G4VelocityTable * GetVelocityTable()
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4Material * GetMaterial() const
G4ThreadLocal G4Allocator< G4Track > * aTrackAllocator
Definition: G4Track.cc:52
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4double GetKineticEnergy() const
static G4double GetMinTOfVelocityTable()
void RemoveAuxiliaryTrackInformation(G4int idx)
Definition: G4Track.cc:351
void SetAuxiliaryTrackInformation(G4int idx, G4VAuxiliaryTrackInformation *info) const
Definition: G4Track.cc:324
G4ParticleDefinition * GetDefinition() const
#define G4ThreadLocal
Definition: tls.hh:89
const G4ThreeVector const G4double const
int G4int
Definition: G4Types.hh:78
G4double GetTotalMomentum() const
G4double CalculateVelocityForOpticalPhoton() const
Definition: G4Track.cc:255
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:222
static void SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin)
G4Material * GetMaterial() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4VAuxiliaryTrackInformation * GetAuxiliaryTrackInformation(G4int idx) const
Definition: G4Track.cc:340
static G4int GetNbinOfVelocityTable()
Definition: G4Track.cc:319
G4LogicalVolume * GetLogicalVolume() const
static G4ParticleTable * GetParticleTable()
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:44
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
Definition: G4Material.hh:252
static G4double GetMinTOfVelocityTable()
Definition: G4Track.cc:314
#define DBL_MIN
Definition: templates.hh:75
static void SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin)
Definition: G4Track.cc:301
static G4double GetMaxTOfVelocityTable()
Definition: G4Track.cc:309
double G4double
Definition: G4Types.hh:76
static G4double GetMaxTOfVelocityTable()
G4double Value(G4double theEnergy)
static G4int GetIndex(const G4String &)
G4Track()
Definition: G4Track.cc:98
G4MaterialPropertyVector * GetProperty(const char *key)
float c_light
Definition: hepunit.py:257
void CopyTrackInfo(const G4Track &)
Definition: G4Track.cc:215
~G4Track()
Definition: G4Track.cc:149