G4Track.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 //
00030 //---------------------------------------------------------------
00031 //
00032 //  G4Track.cc
00033 //
00034 //---------------------------------------------------------------
00035 //   Add copy constructor            Hisaya Feb. 07 01
00036 //   Fix GetVelocity                 Hisaya Feb. 17 01
00037 //   Modification for G4TouchableHandle             22 Oct. 2001  R.Chytracek//
00038 //   Fix GetVelocity (bug report #741)   Horton-Smith Apr 14 2005
00039 //   Remove massless check in  GetVelocity   02 Apr. 09 H.Kurashige
00040 //   Use G4VelocityTable                     17 AUg. 2011 H.Kurashige
00041 
00042 #include "G4Track.hh"
00043 #include "G4PhysicalConstants.hh"
00044 #include "G4ParticleTable.hh"
00045 #include "G4VelocityTable.hh"
00046 
00047 #include <iostream>
00048 #include <iomanip>
00049 
00050 G4Allocator<G4Track> aTrackAllocator;
00051 
00052 G4VelocityTable*  G4Track::velTable=0;
00053 
00055 G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle,
00056                  G4double aValueTime,
00057                  const G4ThreeVector& aValuePosition)
00059   : fCurrentStepNumber(0),    fPosition(aValuePosition),
00060     fGlobalTime(aValueTime),  fLocalTime(0.),
00061     fTrackLength(0.),
00062     fParentID(0),             fTrackID(0),
00063     fVelocity(c_light),
00064     fpDynamicParticle(apValueDynamicParticle),
00065     fTrackStatus(fAlive),
00066     fBelowThreshold(false),   fGoodForTracking(false),
00067     fStepLength(0.0),         fWeight(1.0),
00068     fpStep(0),
00069     fVtxKineticEnergy(0.0),
00070     fpLVAtVertex(0),          fpCreatorProcess(0),
00071     fpUserInformation(0),
00072     prev_mat(0),  groupvel(0),
00073     prev_velocity(0.0), prev_momentum(0.0),
00074     is_OpticalPhoton(false),
00075     useGivenVelocity(false)
00076 {    
00077   static G4bool isFirstTime = true;
00078   static G4ParticleDefinition* fOpticalPhoton =0;
00079   if ( isFirstTime ) {
00080     isFirstTime = false;
00081     // set  fOpticalPhoton
00082     fOpticalPhoton = G4ParticleTable::GetParticleTable()->FindParticle("opticalphoton");
00083   }
00084   // check if the particle type is Optical Photon
00085   is_OpticalPhoton = (fpDynamicParticle->GetDefinition() == fOpticalPhoton);
00086 
00087   if (velTable ==0 ) velTable = G4VelocityTable::GetVelocityTable();
00088 
00089   fVelocity = CalculateVelocity();
00090 
00091 }
00092 
00094 G4Track::G4Track()
00096   : fCurrentStepNumber(0),    
00097     fGlobalTime(0),           fLocalTime(0.),
00098     fTrackLength(0.),
00099     fParentID(0),             fTrackID(0),
00100     fVelocity(c_light),
00101     fpDynamicParticle(0),
00102     fTrackStatus(fAlive),
00103     fBelowThreshold(false),   fGoodForTracking(false),
00104     fStepLength(0.0),         fWeight(1.0),
00105     fpStep(0),
00106     fVtxKineticEnergy(0.0),
00107     fpLVAtVertex(0),          fpCreatorProcess(0),
00108     fpUserInformation(0),
00109     prev_mat(0),  groupvel(0),
00110     prev_velocity(0.0), prev_momentum(0.0),
00111     is_OpticalPhoton(false),
00112     useGivenVelocity(false)
00113 {
00114 }
00116 G4Track::G4Track(const G4Track& right)
00118   : fCurrentStepNumber(0),    
00119     fGlobalTime(0),           fLocalTime(0.),
00120     fTrackLength(0.),
00121     fParentID(0),             fTrackID(0),
00122     fVelocity(c_light),
00123     fpDynamicParticle(0),
00124     fTrackStatus(fAlive),
00125     fBelowThreshold(false),   fGoodForTracking(false),
00126     fStepLength(0.0),         fWeight(1.0),
00127     fpStep(0),
00128     fVtxKineticEnergy(0.0),
00129     fpLVAtVertex(0),          fpCreatorProcess(0),
00130     fpUserInformation(0),
00131     prev_mat(0),  groupvel(0),
00132     prev_velocity(0.0), prev_momentum(0.0),
00133     is_OpticalPhoton(false),
00134     useGivenVelocity(false)
00135 {
00136   *this = right;
00137 }
00138 
00140 G4Track::~G4Track()
00142 {
00143    delete fpDynamicParticle;
00144    delete fpUserInformation;
00145 }
00146 
00148 G4Track & G4Track::operator=(const G4Track &right)
00150 {
00151   if (this != &right) {
00152    fPosition = right.fPosition;
00153    fGlobalTime = right.fGlobalTime;
00154    fLocalTime = right.fLocalTime;
00155    fTrackLength = right.fTrackLength;
00156    fWeight = right.fWeight;
00157    fStepLength = right.fStepLength;
00158 
00159    // Track ID (and Parent ID) is not copied and set to zero for new track
00160    fTrackID = 0;
00161    fParentID =0;
00162 
00163    // CurrentStepNumber is set to be 0
00164    fCurrentStepNumber = 0;
00165 
00166    // velocity information 
00167    fVelocity = right.fVelocity;
00168 
00169    // dynamic particle information 
00170    fpDynamicParticle = new G4DynamicParticle(*(right.fpDynamicParticle));
00171  
00172    // track status and flags for tracking  
00173    fTrackStatus = right.fTrackStatus;
00174    fBelowThreshold = right.fBelowThreshold;
00175    fGoodForTracking = right.fGoodForTracking;
00176    
00177    // Step information (Step Length, Step Number, pointer to the Step,) 
00178    // are not copied
00179    fpStep=0;
00180 
00181    // vertex information
00182    fVtxPosition = right.fVtxPosition;
00183    fpLVAtVertex = right.fpLVAtVertex;
00184    fVtxKineticEnergy = right.fVtxKineticEnergy;
00185    fVtxMomentumDirection = right.fVtxMomentumDirection;
00186 
00187    // CreatorProcess and UserInformation are not copied 
00188    fpCreatorProcess = 0;
00189    fpUserInformation = 0;
00190 
00191    prev_mat = right.prev_mat;
00192    groupvel = right.groupvel;
00193    prev_velocity = right.prev_velocity;
00194    prev_momentum = right.prev_momentum;
00195 
00196    is_OpticalPhoton = right.is_OpticalPhoton;
00197    useGivenVelocity = right.useGivenVelocity; 
00198   }
00199   return *this;
00200 }
00201 
00203 void G4Track::CopyTrackInfo(const G4Track& right)
00205 {
00206   *this = right;
00207 }
00208 
00210 G4double G4Track::CalculateVelocity() const
00212 { 
00213   if (useGivenVelocity) return fVelocity;    
00214 
00215   G4double velocity = c_light ;
00216   
00217   G4double mass = fpDynamicParticle->GetMass();
00218 
00219   // special case for photons
00220   if ( is_OpticalPhoton ) return CalculateVelocityForOpticalPhoton();
00221 
00222   // particles other than optical photon
00223   if (mass<DBL_MIN) {
00224     // Zero Mass
00225     velocity = c_light;
00226   } else {
00227     G4double T = (fpDynamicParticle->GetKineticEnergy())/mass;
00228     if (T > GetMaxTOfVelocityTable()) {
00229       velocity = c_light;
00230     } else if (T<DBL_MIN) {
00231       velocity =0.;
00232     } else if (T<GetMinTOfVelocityTable()) {
00233       velocity = c_light*std::sqrt(T*(T+2.))/(T+1.0);
00234     } else {    
00235       velocity = velTable->Value(T);
00236     }
00237     
00238   }                                                                             
00239   return velocity ;
00240 }
00241 
00243 G4double G4Track::CalculateVelocityForOpticalPhoton() const
00245 { 
00246     
00247   G4double velocity = c_light ;
00248   
00249 
00250   G4Material* mat=0; 
00251   G4bool update_groupvel = false;
00252   if ( fpStep !=0  ){
00253     mat= this->GetMaterial();         //   Fix for repeated volumes
00254   }else{
00255     if (fpTouchable!=0){ 
00256       mat=fpTouchable->GetVolume()->GetLogicalVolume()->GetMaterial();
00257     }
00258   }
00259   // check if previous step is in the same volume
00260     //  and get new GROUPVELOCITY table if necessary 
00261   if ((mat != 0) && ((mat != prev_mat)||(groupvel==0))) {
00262     groupvel = 0;
00263     if(mat->GetMaterialPropertiesTable() != 0)
00264       groupvel = mat->GetMaterialPropertiesTable()->GetProperty("GROUPVEL");
00265     update_groupvel = true;
00266   }
00267   prev_mat = mat;
00268   
00269   if  (groupvel != 0 ) {
00270     // light velocity = c/(rindex+d(rindex)/d(log(E_phot)))
00271     // values stored in GROUPVEL material properties vector
00272     velocity =  prev_velocity;
00273     
00274     // check if momentum is same as in the previous step
00275     //  and calculate group velocity if necessary 
00276     G4double current_momentum = fpDynamicParticle->GetTotalMomentum();
00277     if( update_groupvel || (current_momentum != prev_momentum) ) {
00278       velocity =
00279         groupvel->Value(current_momentum);
00280       prev_velocity = velocity;
00281       prev_momentum = current_momentum;
00282     }
00283   }   
00284   
00285   return velocity ;
00286 }
00287 
00289 void G4Track::SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin)
00291 {
00292   G4VelocityTable::SetVelocityTableProperties(t_max, t_min, nbin);
00293   velTable = G4VelocityTable::GetVelocityTable();
00294 }
00295 
00297 G4double G4Track::GetMaxTOfVelocityTable()
00299 { return G4VelocityTable::GetMaxTOfVelocityTable();}
00300 
00302 G4double G4Track::GetMinTOfVelocityTable() 
00303 
00304 { return G4VelocityTable::GetMinTOfVelocityTable();}
00305 
00307 G4int    G4Track::GetNbinOfVelocityTable() 
00308 
00309 { return G4VelocityTable::GetNbinOfVelocityTable();}
00310 

Generated on Mon May 27 17:50:00 2013 for Geant4 by  doxygen 1.4.7