[826] | 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.30 2007/10/02 00:46:21 kurasige Exp $ |
---|
[850] | 28 | // GEANT4 tag $Name: HEAD $ |
---|
[826] | 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 | |
---|
| 41 | #include "G4Track.hh" |
---|
| 42 | |
---|
| 43 | G4Allocator<G4Track> aTrackAllocator; |
---|
| 44 | |
---|
| 45 | /////////////////////////////////////////////////////////// |
---|
| 46 | G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle, |
---|
| 47 | G4double aValueTime, |
---|
| 48 | const G4ThreeVector& aValuePosition) |
---|
| 49 | /////////////////////////////////////////////////////////// |
---|
| 50 | : fCurrentStepNumber(0), fPosition(aValuePosition), |
---|
| 51 | fGlobalTime(aValueTime), fLocalTime(0.), |
---|
| 52 | fTrackLength(0.), |
---|
| 53 | fParentID(0), fTrackID(0), |
---|
| 54 | fpDynamicParticle(apValueDynamicParticle), |
---|
| 55 | fTrackStatus(fAlive), |
---|
| 56 | fBelowThreshold(false), fGoodForTracking(false), |
---|
| 57 | fStepLength(0.0), fWeight(1.0), |
---|
| 58 | fpStep(0), |
---|
| 59 | fVtxKineticEnergy(0.0), |
---|
| 60 | fpLVAtVertex(0), fpCreatorProcess(0), |
---|
| 61 | fpUserInformation(0) |
---|
| 62 | { |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | ////////////////// |
---|
| 66 | G4Track::G4Track() |
---|
| 67 | ////////////////// |
---|
| 68 | : fCurrentStepNumber(0), |
---|
| 69 | fGlobalTime(0), fLocalTime(0.), |
---|
| 70 | fTrackLength(0.), |
---|
| 71 | fParentID(0), fTrackID(0), |
---|
| 72 | fpDynamicParticle(0), |
---|
| 73 | fTrackStatus(fAlive), |
---|
| 74 | fBelowThreshold(false), fGoodForTracking(false), |
---|
| 75 | fStepLength(0.0), fWeight(1.0), |
---|
| 76 | fpStep(0), |
---|
| 77 | fVtxKineticEnergy(0.0), |
---|
| 78 | fpLVAtVertex(0), fpCreatorProcess(0), |
---|
| 79 | fpUserInformation(0) |
---|
| 80 | { |
---|
| 81 | } |
---|
| 82 | ////////////////// |
---|
| 83 | G4Track::G4Track(const G4Track& right) |
---|
| 84 | ////////////////// |
---|
| 85 | { |
---|
| 86 | *this = right; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | /////////////////// |
---|
| 90 | G4Track::~G4Track() |
---|
| 91 | /////////////////// |
---|
| 92 | { |
---|
| 93 | delete fpDynamicParticle; |
---|
| 94 | delete fpUserInformation; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | ////////////////// |
---|
| 98 | G4Track & G4Track::operator=(const G4Track &right) |
---|
| 99 | ////////////////// |
---|
| 100 | { |
---|
| 101 | if (this != &right) { |
---|
| 102 | fPosition = right.fPosition; |
---|
| 103 | fGlobalTime = right.fGlobalTime; |
---|
| 104 | fLocalTime = right.fLocalTime; |
---|
| 105 | fTrackLength = right.fTrackLength; |
---|
| 106 | fWeight = right.fWeight; |
---|
| 107 | fStepLength = right.fStepLength; |
---|
| 108 | |
---|
| 109 | // Track ID (and Parent ID) is not copied and set to zero for new track |
---|
| 110 | fTrackID = 0; |
---|
| 111 | fParentID =0; |
---|
| 112 | |
---|
| 113 | // CurrentStepNumber is set to be 0 |
---|
| 114 | fCurrentStepNumber = 0; |
---|
| 115 | |
---|
| 116 | // dynamic particle information |
---|
| 117 | fpDynamicParticle = new G4DynamicParticle(*(right.fpDynamicParticle)); |
---|
| 118 | |
---|
| 119 | // track status and flags for tracking |
---|
| 120 | fTrackStatus = right.fTrackStatus; |
---|
| 121 | fBelowThreshold = right.fBelowThreshold; |
---|
| 122 | fGoodForTracking = right.fGoodForTracking; |
---|
| 123 | |
---|
| 124 | // Step information (Step Length, Step Number, pointer to the Step,) |
---|
| 125 | // are not copied |
---|
| 126 | fpStep=0; |
---|
| 127 | |
---|
| 128 | // vertex information |
---|
| 129 | fVtxPosition = right.fVtxPosition; |
---|
| 130 | fpLVAtVertex = right.fpLVAtVertex; |
---|
| 131 | fVtxKineticEnergy = right.fVtxKineticEnergy; |
---|
| 132 | fVtxMomentumDirection = right.fVtxMomentumDirection; |
---|
| 133 | |
---|
| 134 | // CreatorProcess and UserInformation are not copied |
---|
| 135 | fpCreatorProcess = 0; |
---|
| 136 | fpUserInformation = 0; |
---|
| 137 | } |
---|
| 138 | return *this; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | /////////////////// |
---|
| 142 | void G4Track::CopyTrackInfo(const G4Track& right) |
---|
| 143 | ////////////////// |
---|
| 144 | { |
---|
| 145 | *this = right; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | #include "G4ParticleTable.hh" |
---|
| 149 | /////////////////// |
---|
| 150 | G4double G4Track::GetVelocity() const |
---|
| 151 | /////////////////// |
---|
| 152 | { |
---|
| 153 | static G4bool isFirstTime = true; |
---|
| 154 | static G4ParticleDefinition* fOpticalPhoton =0; |
---|
| 155 | |
---|
| 156 | static G4Material* prev_mat =0; |
---|
| 157 | static G4MaterialPropertyVector* groupvel =0; |
---|
| 158 | static G4double prev_velocity =0; |
---|
| 159 | static G4double prev_momentum =0; |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | if ( isFirstTime ) { |
---|
| 163 | isFirstTime = false; |
---|
| 164 | // set fOpticalPhoton |
---|
| 165 | fOpticalPhoton = G4ParticleTable::GetParticleTable()->FindParticle("opticalphoton"); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | G4double velocity ; |
---|
| 169 | |
---|
| 170 | G4double mass = fpDynamicParticle->GetMass(); |
---|
| 171 | |
---|
| 172 | // mass less particle |
---|
| 173 | if( mass == 0. ){ |
---|
| 174 | velocity = c_light ; |
---|
| 175 | |
---|
| 176 | // special case for photons |
---|
| 177 | if ( (fOpticalPhoton !=0) && |
---|
| 178 | (fpDynamicParticle->GetDefinition()==fOpticalPhoton) ){ |
---|
| 179 | |
---|
| 180 | G4Material* mat=0; |
---|
| 181 | G4bool update_groupvel = false; |
---|
| 182 | if ( this->GetStep() ){ |
---|
| 183 | mat= this->GetMaterial(); // Fix for repeated volumes |
---|
| 184 | }else{ |
---|
| 185 | if (fpTouchable!=0){ |
---|
| 186 | mat=fpTouchable->GetVolume()->GetLogicalVolume()->GetMaterial(); |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | // check if previous step is in the same volume |
---|
| 190 | // and get new GROUPVELOVITY table if necessary |
---|
| 191 | if ((mat != prev_mat)||(groupvel==0)) { |
---|
| 192 | groupvel = 0; |
---|
| 193 | if(mat->GetMaterialPropertiesTable() != 0) |
---|
| 194 | groupvel = mat->GetMaterialPropertiesTable()->GetProperty("GROUPVEL"); |
---|
| 195 | update_groupvel = true; |
---|
| 196 | } |
---|
| 197 | prev_mat = mat; |
---|
| 198 | |
---|
| 199 | if (groupvel != 0 ) { |
---|
| 200 | // light velocity = c/(rindex+d(rindex)/d(log(E_phot))) |
---|
| 201 | // values stored in GROUPVEL material properties vector |
---|
| 202 | velocity = prev_velocity; |
---|
| 203 | |
---|
| 204 | // check if momentum is same as in the previous step |
---|
| 205 | // and calculate group velocity if necessary |
---|
| 206 | if( update_groupvel || (fpDynamicParticle->GetTotalMomentum() != prev_momentum) ) { |
---|
| 207 | velocity = |
---|
| 208 | groupvel->GetProperty(fpDynamicParticle->GetTotalMomentum()); |
---|
| 209 | prev_velocity = velocity; |
---|
| 210 | prev_momentum = fpDynamicParticle->GetTotalMomentum(); |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | } else { |
---|
| 216 | G4double T = fpDynamicParticle->GetKineticEnergy(); |
---|
| 217 | velocity = c_light*std::sqrt(T*(T+2.*mass))/(T+mass); |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | return velocity ; |
---|
| 221 | } |
---|