source: trunk/source/track/src/G4Track.cc @ 1340

Last change on this file since 1340 was 1340, checked in by garnier, 14 years ago

update ti head

File size: 8.6 KB
Line 
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,v 1.35 2010/09/21 00:33:05 kurasige Exp $
28// GEANT4 tag $Name: track-V09-03-09 $
29//
30//
31//---------------------------------------------------------------
32//
33//  G4Track.cc
34//
35//---------------------------------------------------------------
36//   Add copy constructor            Hisaya Feb. 07 01
37//   Fix GetVelocity                 Hisaya Feb. 17 01
38//   Modification for G4TouchableHandle             22 Oct. 2001  R.Chytracek//
39//   Fix GetVelocity (bug report #741)   Horton-Smith Apr 14 2005
40//   Remove massless check in  GetVelocity   02 Apr. 09 H.Kurashige
41
42#include "G4Track.hh"
43#include "G4ParticleTable.hh"
44
45G4Allocator<G4Track> aTrackAllocator;
46
47G4PhysicsLogVector* G4Track::velTable = 0;
48
49const G4double G4Track::maxT = 100.0;
50const G4double G4Track::minT = 0.0001;
51
52///////////////////////////////////////////////////////////
53G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle,
54                 G4double aValueTime,
55                 const G4ThreeVector& aValuePosition)
56///////////////////////////////////////////////////////////
57  : fCurrentStepNumber(0),    fPosition(aValuePosition),
58    fGlobalTime(aValueTime),  fLocalTime(0.),
59    fTrackLength(0.),
60    fParentID(0),             fTrackID(0),
61    fpDynamicParticle(apValueDynamicParticle),
62    fTrackStatus(fAlive),
63    fBelowThreshold(false),   fGoodForTracking(false),
64    fStepLength(0.0),         fWeight(1.0),
65    fpStep(0),
66    fVtxKineticEnergy(0.0),
67    fpLVAtVertex(0),          fpCreatorProcess(0),
68    fpUserInformation(0),
69    prev_mat(0),  groupvel(0),
70    prev_velocity(0.0), prev_momentum(0.0),
71    is_OpticalPhoton(false)
72{   
73  static G4bool isFirstTime = true;
74  static G4ParticleDefinition* fOpticalPhoton =0;
75  if ( isFirstTime ) {
76    isFirstTime = false;
77    // set  fOpticalPhoton
78    fOpticalPhoton = G4ParticleTable::GetParticleTable()->FindParticle("opticalphoton");
79  }
80  // check if the particle type is Optical Photon
81  is_OpticalPhoton = (fpDynamicParticle->GetDefinition() == fOpticalPhoton);
82
83  if (velTable==0) PrepareVelocityTable();
84}
85
86//////////////////
87G4Track::G4Track()
88//////////////////
89  : fCurrentStepNumber(0),   
90    fGlobalTime(0),           fLocalTime(0.),
91    fTrackLength(0.),
92    fParentID(0),             fTrackID(0),
93    fpDynamicParticle(0),
94    fTrackStatus(fAlive),
95    fBelowThreshold(false),   fGoodForTracking(false),
96    fStepLength(0.0),         fWeight(1.0),
97    fpStep(0),
98    fVtxKineticEnergy(0.0),
99    fpLVAtVertex(0),          fpCreatorProcess(0),
100    fpUserInformation(0),
101    prev_mat(0),  groupvel(0),
102    prev_velocity(0.0), prev_momentum(0.0),
103    is_OpticalPhoton(false) 
104{
105}
106//////////////////
107G4Track::G4Track(const G4Track& right)
108//////////////////
109  : fCurrentStepNumber(0),   
110    fGlobalTime(0),           fLocalTime(0.),
111    fTrackLength(0.),
112    fParentID(0),             fTrackID(0),
113    fpDynamicParticle(0),
114    fTrackStatus(fAlive),
115    fBelowThreshold(false),   fGoodForTracking(false),
116    fStepLength(0.0),         fWeight(1.0),
117    fpStep(0),
118    fVtxKineticEnergy(0.0),
119    fpLVAtVertex(0),          fpCreatorProcess(0),
120    fpUserInformation(0),
121    prev_mat(0),  groupvel(0),
122    prev_velocity(0.0), prev_momentum(0.0),
123    is_OpticalPhoton(false) 
124{
125  *this = right;
126}
127
128///////////////////
129G4Track::~G4Track()
130///////////////////
131{
132   delete fpDynamicParticle;
133   delete fpUserInformation;
134}
135
136//////////////////
137G4Track & G4Track::operator=(const G4Track &right)
138//////////////////
139{
140  if (this != &right) {
141   fPosition = right.fPosition;
142   fGlobalTime = right.fGlobalTime;
143   fLocalTime = right.fLocalTime;
144   fTrackLength = right.fTrackLength;
145   fWeight = right.fWeight;
146   fStepLength = right.fStepLength;
147
148   // Track ID (and Parent ID) is not copied and set to zero for new track
149   fTrackID = 0;
150   fParentID =0;
151
152   // CurrentStepNumber is set to be 0
153   fCurrentStepNumber = 0;
154
155   // dynamic particle information
156   fpDynamicParticle = new G4DynamicParticle(*(right.fpDynamicParticle));
157 
158   // track status and flags for tracking 
159   fTrackStatus = right.fTrackStatus;
160   fBelowThreshold = right.fBelowThreshold;
161   fGoodForTracking = right.fGoodForTracking;
162   
163   // Step information (Step Length, Step Number, pointer to the Step,)
164   // are not copied
165   fpStep=0;
166
167   // vertex information
168   fVtxPosition = right.fVtxPosition;
169   fpLVAtVertex = right.fpLVAtVertex;
170   fVtxKineticEnergy = right.fVtxKineticEnergy;
171   fVtxMomentumDirection = right.fVtxMomentumDirection;
172
173   // CreatorProcess and UserInformation are not copied
174   fpCreatorProcess = 0;
175   fpUserInformation = 0;
176
177   prev_mat = right.prev_mat;
178   groupvel = right.groupvel;
179   prev_velocity = right.prev_velocity;
180   prev_momentum = right.prev_momentum;
181
182   is_OpticalPhoton = right.is_OpticalPhoton; 
183
184  }
185  return *this;
186}
187
188///////////////////
189void G4Track::CopyTrackInfo(const G4Track& right)
190//////////////////
191{
192  *this = right;
193}
194
195///////////////////
196G4double G4Track::GetVelocity() const
197///////////////////
198{ 
199   
200  G4double velocity = c_light ;
201 
202  G4double mass = fpDynamicParticle->GetMass();
203
204  // special case for photons
205  if ( is_OpticalPhoton ) {
206
207    G4Material* mat=0; 
208    G4bool update_groupvel = false;
209    if ( this->GetStep() ){
210      mat= this->GetMaterial();         //   Fix for repeated volumes
211    }else{
212      if (fpTouchable!=0){ 
213        mat=fpTouchable->GetVolume()->GetLogicalVolume()->GetMaterial();
214      }
215    }
216    // check if previous step is in the same volume
217    //  and get new GROUPVELOCITY table if necessary
218    if ((mat != 0) && ((mat != prev_mat)||(groupvel==0))) {
219        groupvel = 0;
220        if(mat->GetMaterialPropertiesTable() != 0)
221          groupvel = mat->GetMaterialPropertiesTable()->GetProperty("GROUPVEL");
222        update_groupvel = true;
223    }
224    prev_mat = mat;
225     
226    if  (groupvel != 0 ) {
227        // light velocity = c/(rindex+d(rindex)/d(log(E_phot)))
228        // values stored in GROUPVEL material properties vector
229        velocity =  prev_velocity;
230         
231        // check if momentum is same as in the previous step
232        //  and calculate group velocity if necessary
233        G4double current_momentum = fpDynamicParticle->GetTotalMomentum();
234        if( update_groupvel || (current_momentum != prev_momentum) ) {
235          velocity =
236            groupvel->GetProperty(current_momentum);
237          prev_velocity = velocity;
238          prev_momentum = current_momentum;
239        }
240    }
241
242  } else {
243    // particles other than optical photon
244    if (mass<DBL_MIN) {
245      // Zero Mass
246      velocity = c_light;
247    } else {
248      G4double T = (fpDynamicParticle->GetKineticEnergy())/mass;
249      if (T > maxT) {
250        velocity = c_light;
251      } else if (T<DBL_MIN) {
252        velocity =0.;
253      } else if (T<minT) {
254        velocity = c_light*std::sqrt(T*(T+2.))/(T+1.0);
255      } else { 
256        velocity = velTable->Value(T);
257      }
258    }
259     
260  }
261                                                                               
262  return velocity ;
263}
264
265///////////////////
266void G4Track::PrepareVelocityTable()
267///////////////////
268{
269  const G4int NBIN=300;
270  velTable = new G4PhysicsLogVector(minT, maxT, NBIN);
271  for (G4int i=0; i<=NBIN; i++){
272    G4double T = velTable->Energy(i);
273    velTable->PutValue(i, c_light*std::sqrt(T*(T+2.))/(T+1.0) );
274  }
275  return;
276}
Note: See TracBrowser for help on using the repository browser.