Ignore:
Timestamp:
Nov 5, 2010, 3:45:55 PM (14 years ago)
Author:
garnier
Message:

update ti head

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/track/src/G4Track.cc

    r1337 r1340  
    2525//
    2626//
    27 // $Id: G4Track.cc,v 1.32 2009/04/08 08:07:24 kurasige Exp $
    28 // GEANT4 tag $Name: geant4-09-04-beta-01 $
     27// $Id: G4Track.cc,v 1.35 2010/09/21 00:33:05 kurasige Exp $
     28// GEANT4 tag $Name: track-V09-03-09 $
    2929//
    3030//
     
    4141
    4242#include "G4Track.hh"
     43#include "G4ParticleTable.hh"
    4344
    4445G4Allocator<G4Track> aTrackAllocator;
     46
     47G4PhysicsLogVector* G4Track::velTable = 0;
     48
     49const G4double G4Track::maxT = 100.0;
     50const G4double G4Track::minT = 0.0001;
    4551
    4652///////////////////////////////////////////////////////////
     
    6066    fVtxKineticEnergy(0.0),
    6167    fpLVAtVertex(0),          fpCreatorProcess(0),
    62     fpUserInformation(0)
     68    fpUserInformation(0),
     69    prev_mat(0),  groupvel(0),
     70    prev_velocity(0.0), prev_momentum(0.0),
     71    is_OpticalPhoton(false)
    6372{   
     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();
    6484}
    6585
     
    7898    fVtxKineticEnergy(0.0),
    7999    fpLVAtVertex(0),          fpCreatorProcess(0),
    80     fpUserInformation(0)
     100    fpUserInformation(0),
     101    prev_mat(0),  groupvel(0),
     102    prev_velocity(0.0), prev_momentum(0.0),
     103    is_OpticalPhoton(false)
    81104{
    82105}
     
    84107G4Track::G4Track(const G4Track& right)
    85108//////////////////
     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)
    86124{
    87125  *this = right;
     
    136174   fpCreatorProcess = 0;
    137175   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
    138184  }
    139185  return *this;
     
    147193}
    148194
    149 #include "G4ParticleTable.hh"
    150195///////////////////
    151196G4double G4Track::GetVelocity() const
    152197///////////////////
    153198{
    154   static G4bool isFirstTime = true;
    155   static G4ParticleDefinition* fOpticalPhoton =0;
    156  
    157   static G4Material*               prev_mat =0;
    158   static G4MaterialPropertyVector* groupvel =0;
    159   static G4double                  prev_velocity =0;
    160   static G4double                  prev_momentum =0;
    161  
    162 
    163   if ( isFirstTime ) {
    164     isFirstTime = false;
    165     // set  fOpticalPhoton
    166     fOpticalPhoton = G4ParticleTable::GetParticleTable()->FindParticle("opticalphoton");
    167   }
    168 
    169   G4double velocity ;
     199   
     200  G4double velocity = c_light ;
    170201 
    171202  G4double mass = fpDynamicParticle->GetMass();
    172203
    173   velocity = c_light ;
    174 
    175204  // special case for photons
    176   if (  (fOpticalPhoton !=0)  &&
    177         (fpDynamicParticle->GetDefinition()==fOpticalPhoton) ){
     205  if ( is_OpticalPhoton ) {
    178206
    179207    G4Material* mat=0;
     
    187215    }
    188216    // check if previous step is in the same volume
    189     //  and get new GROUPVELOVITY table if necessary
    190     if ((mat != prev_mat)||(groupvel==0)) {
     217    //  and get new GROUPVELOCITY table if necessary
     218    if ((mat != 0) && ((mat != prev_mat)||(groupvel==0))) {
    191219        groupvel = 0;
    192220        if(mat->GetMaterialPropertiesTable() != 0)
     
    203231        // check if momentum is same as in the previous step
    204232        //  and calculate group velocity if necessary
    205         if( update_groupvel || (fpDynamicParticle->GetTotalMomentum() != prev_momentum) ) {
     233        G4double current_momentum = fpDynamicParticle->GetTotalMomentum();
     234        if( update_groupvel || (current_momentum != prev_momentum) ) {
    206235          velocity =
    207             groupvel->GetProperty(fpDynamicParticle->GetTotalMomentum());
    208            prev_velocity = velocity;
    209           prev_momentum = fpDynamicParticle->GetTotalMomentum();
     236            groupvel->GetProperty(current_momentum);
     237          prev_velocity = velocity;
     238          prev_momentum = current_momentum;
    210239        }
    211240    }
    212241
    213242  } else {
     243    // particles other than optical photon
    214244    if (mass<DBL_MIN) {
     245      // Zero Mass
    215246      velocity = c_light;
    216247    } else {
    217       G4double T = fpDynamicParticle->GetKineticEnergy();
    218       velocity = c_light*std::sqrt(T*(T+2.*mass))/(T+mass);
    219     }
     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     
    220260  }
    221261                                                                               
    222262  return velocity ;
    223263}
     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 TracChangeset for help on using the changeset viewer.