Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4Track class implementation << 27 // 26 // 28 // Author: Katsuya Amako, KEK - 1996 << 27 // $Id: G4Track.cc,v 1.35 2010-09-21 00:33:05 kurasige Exp $ 29 // Revisions: Hisaya Kurashige, 1998-2011 << 28 // GEANT4 tag $Name: not supported by cvs2svn $ 30 // ------------------------------------------- << 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 // Use G4VelocityTable 17 AUg. 2011 H.Kurashige 31 42 32 #include "G4Track.hh" 43 #include "G4Track.hh" 33 #include "G4PhysicalConstants.hh" << 44 #include "G4ParticleTable.hh" 34 #include "G4VAuxiliaryTrackInformation.hh" << 45 #include "G4VelocityTable.hh" 35 46 36 #include <iostream> 47 #include <iostream> 37 #include <iomanip> 48 #include <iomanip> 38 49 39 // ------------------------------------------- << 50 G4Allocator<G4Track> aTrackAllocator; 40 G4Allocator<G4Track>*& aTrackAllocator() << 41 { << 42 G4ThreadLocalStatic G4Allocator<G4Track>* _i << 43 return _instance; << 44 } << 45 51 46 // ------------------------------------------- << 52 G4VelocityTable* G4Track::velTable=0; >> 53 >> 54 /////////////////////////////////////////////////////////// 47 G4Track::G4Track(G4DynamicParticle* apValueDyn 55 G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle, 48 G4double aValueTime, 56 G4double aValueTime, 49 const G4ThreeVector& aValuePo 57 const G4ThreeVector& aValuePosition) 50 : fPosition(aValuePosition) << 58 /////////////////////////////////////////////////////////// 51 , fGlobalTime(aValueTime) << 59 : fCurrentStepNumber(0), fPosition(aValuePosition), 52 , fVelocity(c_light) << 60 fGlobalTime(aValueTime), fLocalTime(0.), 53 { << 61 fTrackLength(0.), 54 fpDynamicParticle = (apValueDynamicParticle) << 62 fParentID(0), fTrackID(0), 55 ? apValueDynamicParticle : << 63 fVelocity(c_light), >> 64 fpDynamicParticle(apValueDynamicParticle), >> 65 fTrackStatus(fAlive), >> 66 fBelowThreshold(false), fGoodForTracking(false), >> 67 fStepLength(0.0), fWeight(1.0), >> 68 fpStep(0), >> 69 fVtxKineticEnergy(0.0), >> 70 fpLVAtVertex(0), fpCreatorProcess(0), >> 71 fpUserInformation(0), >> 72 prev_mat(0), groupvel(0), >> 73 prev_velocity(0.0), prev_momentum(0.0), >> 74 is_OpticalPhoton(false) >> 75 { >> 76 static G4bool isFirstTime = true; >> 77 static G4ParticleDefinition* fOpticalPhoton =0; >> 78 if ( isFirstTime ) { >> 79 isFirstTime = false; >> 80 // set fOpticalPhoton >> 81 fOpticalPhoton = G4ParticleTable::GetParticleTable()->FindParticle("opticalphoton"); >> 82 } 56 // check if the particle type is Optical Pho 83 // check if the particle type is Optical Photon 57 is_OpticalPhoton = << 84 is_OpticalPhoton = (fpDynamicParticle->GetDefinition() == fOpticalPhoton); 58 (fpDynamicParticle->GetDefinition()->GetPD << 85 >> 86 if (velTable ==0 ) velTable = G4VelocityTable::GetVelocityTable(); >> 87 >> 88 fVelocity = CalculateVelocity(); >> 89 59 } 90 } 60 91 61 // ------------------------------------------- << 92 ////////////////// 62 G4Track::G4Track() 93 G4Track::G4Track() 63 : fVelocity(c_light) << 94 ////////////////// 64 , fpDynamicParticle(new G4DynamicParticle()) << 95 : fCurrentStepNumber(0), 65 {} << 96 fGlobalTime(0), fLocalTime(0.), 66 << 97 fTrackLength(0.), 67 // ------------------------------------------- << 98 fParentID(0), fTrackID(0), 68 G4Track::G4Track(const G4Track& right,G4bool c << 99 fVelocity(c_light), 69 : fVelocity(c_light) << 100 fpDynamicParticle(0), >> 101 fTrackStatus(fAlive), >> 102 fBelowThreshold(false), fGoodForTracking(false), >> 103 fStepLength(0.0), fWeight(1.0), >> 104 fpStep(0), >> 105 fVtxKineticEnergy(0.0), >> 106 fpLVAtVertex(0), fpCreatorProcess(0), >> 107 fpUserInformation(0), >> 108 prev_mat(0), groupvel(0), >> 109 prev_velocity(0.0), prev_momentum(0.0), >> 110 is_OpticalPhoton(false) >> 111 { >> 112 } >> 113 ////////////////// >> 114 G4Track::G4Track(const G4Track& right) >> 115 ////////////////// >> 116 : fCurrentStepNumber(0), >> 117 fGlobalTime(0), fLocalTime(0.), >> 118 fTrackLength(0.), >> 119 fParentID(0), fTrackID(0), >> 120 fVelocity(c_light), >> 121 fpDynamicParticle(0), >> 122 fTrackStatus(fAlive), >> 123 fBelowThreshold(false), fGoodForTracking(false), >> 124 fStepLength(0.0), fWeight(1.0), >> 125 fpStep(0), >> 126 fVtxKineticEnergy(0.0), >> 127 fpLVAtVertex(0), fpCreatorProcess(0), >> 128 fpUserInformation(0), >> 129 prev_mat(0), groupvel(0), >> 130 prev_velocity(0.0), prev_momentum(0.0), >> 131 is_OpticalPhoton(false) 70 { 132 { 71 fCopyTouchables = copyTouchables; << 72 *this = right; 133 *this = right; 73 fCopyTouchables = true; << 74 } 134 } 75 135 76 // ------------------------------------------- << 136 /////////////////// 77 G4Track::~G4Track() 137 G4Track::~G4Track() >> 138 /////////////////// 78 { 139 { 79 delete fpDynamicParticle; << 140 delete fpDynamicParticle; 80 delete fpUserInformation; << 141 delete fpUserInformation; 81 ClearAuxiliaryTrackInformation(); << 142 } 82 } << 83 << 84 // ------------------------------------------- << 85 G4Track& G4Track::operator=(const G4Track& rig << 86 { << 87 if(this != &right) << 88 { << 89 fPosition = right.fPosition; << 90 fGlobalTime = right.fGlobalTime; << 91 fLocalTime = right.fLocalTime; << 92 fTrackLength = right.fTrackLength; << 93 fWeight = right.fWeight; << 94 fStepLength = right.fStepLength; << 95 << 96 // additional fields required for geometri << 97 if(fCopyTouchables) { << 98 fpTouchable = right.fpTouchable; << 99 fpNextTouchable = right.fpNextTouchable; << 100 fpOriginTouchable = right.fpOriginToucha << 101 } << 102 143 103 // Track ID (and Parent ID) is not copied << 144 ////////////////// 104 fTrackID = 0; << 145 G4Track & G4Track::operator=(const G4Track &right) 105 fParentID = 0; << 146 ////////////////// 106 << 147 { 107 // CurrentStepNumber is set to be 0 << 148 if (this != &right) { 108 fCurrentStepNumber = 0; << 149 fPosition = right.fPosition; 109 << 150 fGlobalTime = right.fGlobalTime; 110 // Creator model ID << 151 fLocalTime = right.fLocalTime; 111 fCreatorModelID = right.fCreatorModelID; << 152 fTrackLength = right.fTrackLength; 112 << 153 fWeight = right.fWeight; 113 // Parent resonance << 154 fStepLength = right.fStepLength; 114 fParentResonanceDef = right.fParentResonan << 155 115 fParentResonanceID = right.fParentResonan << 156 // Track ID (and Parent ID) is not copied and set to zero for new track >> 157 fTrackID = 0; >> 158 fParentID =0; >> 159 >> 160 // CurrentStepNumber is set to be 0 >> 161 fCurrentStepNumber = 0; >> 162 >> 163 // velocity information >> 164 fVelocity = right.fVelocity; >> 165 >> 166 // dynamic particle information >> 167 fpDynamicParticle = new G4DynamicParticle(*(right.fpDynamicParticle)); >> 168 >> 169 // track status and flags for tracking >> 170 fTrackStatus = right.fTrackStatus; >> 171 fBelowThreshold = right.fBelowThreshold; >> 172 fGoodForTracking = right.fGoodForTracking; 116 173 117 // velocity information << 174 // Step information (Step Length, Step Number, pointer to the Step,) 118 fVelocity = right.fVelocity; << 175 // are not copied >> 176 fpStep=0; >> 177 >> 178 // vertex information >> 179 fVtxPosition = right.fVtxPosition; >> 180 fpLVAtVertex = right.fpLVAtVertex; >> 181 fVtxKineticEnergy = right.fVtxKineticEnergy; >> 182 fVtxMomentumDirection = right.fVtxMomentumDirection; >> 183 >> 184 // CreatorProcess and UserInformation are not copied >> 185 fpCreatorProcess = 0; >> 186 fpUserInformation = 0; >> 187 >> 188 prev_mat = right.prev_mat; >> 189 groupvel = right.groupvel; >> 190 prev_velocity = right.prev_velocity; >> 191 prev_momentum = right.prev_momentum; 119 192 120 // dynamic particle information << 193 is_OpticalPhoton = right.is_OpticalPhoton; 121 delete fpDynamicParticle; << 122 fpDynamicParticle = new G4DynamicParticle( << 123 << 124 // track status and flags for tracking << 125 fTrackStatus = right.fTrackStatus; << 126 fBelowThreshold = right.fBelowThreshold; << 127 fGoodForTracking = right.fGoodForTracking; << 128 << 129 // Step information (Step Length, Step Num << 130 // are not copied << 131 fpStep = nullptr; << 132 << 133 // vertex information << 134 fVtxPosition = right.fVtxPosition << 135 fpLVAtVertex = right.fpLVAtVertex << 136 fVtxKineticEnergy = right.fVtxKineticE << 137 fVtxMomentumDirection = right.fVtxMomentum << 138 << 139 // CreatorProcess and UserInformation are << 140 fpCreatorProcess = nullptr; << 141 delete fpUserInformation; << 142 fpUserInformation = nullptr; << 143 << 144 prev_mat = right.prev_mat; << 145 groupvel = right.groupvel; << 146 prev_velocity = right.prev_velocity; << 147 prev_momentum = right.prev_momentum; << 148 << 149 is_OpticalPhoton = right.is_OpticalPhoton; << 150 useGivenVelocity = right.useGivenVelocity; << 151 << 152 ClearAuxiliaryTrackInformation(); << 153 } 194 } 154 return *this; 195 return *this; 155 } 196 } 156 197 157 // ------------------------------------------- << 198 /////////////////// 158 void G4Track::CopyTrackInfo(const G4Track& rig << 199 void G4Track::CopyTrackInfo(const G4Track& right) >> 200 ////////////////// 159 { 201 { 160 fCopyTouchables = copyTouchables; << 161 *this = right; 202 *this = right; 162 fCopyTouchables = true; << 163 } 203 } 164 204 165 // ------------------------------------------- << 205 /////////////////// >> 206 G4double G4Track::CalculateVelocity() const >> 207 /////////////////// >> 208 { >> 209 >> 210 G4double velocity = c_light ; >> 211 >> 212 G4double mass = fpDynamicParticle->GetMass(); >> 213 >> 214 // special case for photons >> 215 if ( is_OpticalPhoton ) return CalculateVelocityForOpticalPhoton(); >> 216 >> 217 // particles other than optical photon >> 218 if (mass<DBL_MIN) { >> 219 // Zero Mass >> 220 velocity = c_light; >> 221 } else { >> 222 G4double T = (fpDynamicParticle->GetKineticEnergy())/mass; >> 223 if (T > GetMaxTOfVelocityTable()) { >> 224 velocity = c_light; >> 225 } else if (T<DBL_MIN) { >> 226 velocity =0.; >> 227 } else if (T<GetMinTOfVelocityTable()) { >> 228 velocity = c_light*std::sqrt(T*(T+2.))/(T+1.0); >> 229 } else { >> 230 velocity = velTable->Value(T); >> 231 } >> 232 >> 233 } >> 234 return velocity ; >> 235 } >> 236 >> 237 /////////////////// 166 G4double G4Track::CalculateVelocityForOpticalP 238 G4double G4Track::CalculateVelocityForOpticalPhoton() const 167 { << 239 /////////////////// 168 G4double velocity = c_light; << 240 { >> 241 >> 242 G4double velocity = c_light ; >> 243 169 244 170 G4Material* mat = nullptr; << 245 G4Material* mat=0; 171 G4bool update_groupvel = false; 246 G4bool update_groupvel = false; 172 if(fpStep != nullptr) << 247 if ( fpStep !=0 ){ 173 { << 248 mat= this->GetMaterial(); // Fix for repeated volumes 174 mat = this->GetMaterial(); // Fix for r << 249 }else{ 175 } << 250 if (fpTouchable!=0){ 176 else << 251 mat=fpTouchable->GetVolume()->GetLogicalVolume()->GetMaterial(); 177 { << 178 if(fpTouchable) << 179 { << 180 mat = fpTouchable->GetVolume()->GetLogic << 181 } 252 } 182 } 253 } 183 // check if previous step is in the same vol 254 // check if previous step is in the same volume 184 // and get new GROUPVELOCITY table if neces << 255 // and get new GROUPVELOCITY table if necessary 185 if((mat != nullptr) && ((mat != prev_mat) || << 256 if ((mat != 0) && ((mat != prev_mat)||(groupvel==0))) { 186 { << 257 groupvel = 0; 187 groupvel = nullptr; << 258 if(mat->GetMaterialPropertiesTable() != 0) 188 if(mat->GetMaterialPropertiesTable() != nu << 259 groupvel = mat->GetMaterialPropertiesTable()->GetProperty("GROUPVEL"); 189 groupvel = mat->GetMaterialPropertiesTab << 190 update_groupvel = true; 260 update_groupvel = true; 191 } 261 } 192 prev_mat = mat; 262 prev_mat = mat; 193 << 263 194 if(groupvel != nullptr) << 264 if (groupvel != 0 ) { 195 { << 196 // light velocity = c/(rindex+d(rindex)/d( 265 // light velocity = c/(rindex+d(rindex)/d(log(E_phot))) 197 // values stored in GROUPVEL material prop 266 // values stored in GROUPVEL material properties vector 198 velocity = prev_velocity; << 267 velocity = prev_velocity; 199 << 268 200 // check if momentum is same as in the pre 269 // check if momentum is same as in the previous step 201 // and calculate group velocity if necess << 270 // and calculate group velocity if necessary 202 G4double current_momentum = fpDynamicParti 271 G4double current_momentum = fpDynamicParticle->GetTotalMomentum(); 203 if(update_groupvel || (current_momentum != << 272 if( update_groupvel || (current_momentum != prev_momentum) ) { 204 { << 273 velocity = 205 velocity = groupvel->Value(current_ << 274 groupvel->Value(current_momentum); 206 prev_velocity = velocity; 275 prev_velocity = velocity; 207 prev_momentum = current_momentum; 276 prev_momentum = current_momentum; 208 } 277 } 209 } << 278 } 210 << 279 211 return velocity; << 280 return velocity ; 212 } 281 } 213 282 214 // ------------------------------------------- << 283 /////////////////// 215 void G4Track::SetAuxiliaryTrackInformation(G4i << 284 void G4Track::SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin) 216 G4VAuxiliaryTrackInformation* in << 285 /////////////////// 217 { 286 { 218 if(fpAuxiliaryTrackInformationMap == nullptr << 287 G4VelocityTable::SetVelocityTableProperties(t_max, t_min, nbin); 219 { << 288 velTable = G4VelocityTable::GetVelocityTable(); 220 fpAuxiliaryTrackInformationMap = << 221 new std::map<G4int, G4VAuxiliaryTrackInf << 222 } << 223 if(G4PhysicsModelCatalog::GetModelIndex(id) << 224 { << 225 G4ExceptionDescription ED; << 226 ED << "Process/model ID <" << id << "> is << 227 G4Exception("G4VAuxiliaryTrackInformation: << 228 "TRACK0982", FatalException, E << 229 } << 230 (*fpAuxiliaryTrackInformationMap)[id] = info << 231 } 289 } 232 290 233 // ------------------------------------------- << 291 /////////////////// 234 G4VAuxiliaryTrackInformation* << 292 G4double G4Track::GetMaxTOfVelocityTable() 235 G4Track::GetAuxiliaryTrackInformation(G4int id << 293 /////////////////// 236 { << 294 { return G4VelocityTable::GetMaxTOfVelocityTable();} 237 if(fpAuxiliaryTrackInformationMap == nullptr << 238 return nullptr; << 239 << 240 auto itr = fpAuxiliaryTrackInformationMap->f << 241 if(itr == fpAuxiliaryTrackInformationMap->ce << 242 return nullptr; << 243 return (*itr).second; << 244 } << 245 295 246 // ------------------------------------------- << 296 /////////////////// 247 void G4Track::RemoveAuxiliaryTrackInformation( << 297 G4double G4Track::GetMinTOfVelocityTable() 248 { << 298 /////////////////// 249 if(fpAuxiliaryTrackInformationMap != nullptr << 299 { return G4VelocityTable::GetMinTOfVelocityTable();} 250 fpAuxiliaryTrackInformationMap->find(id) << 251 { << 252 fpAuxiliaryTrackInformationMap->erase(id); << 253 } << 254 } << 255 300 256 // ------------------------------------------- << 301 /////////////////// 257 void G4Track::RemoveAuxiliaryTrackInformation( << 302 G4int G4Track::GetNbinOfVelocityTable() 258 { << 303 /////////////////// 259 if(fpAuxiliaryTrackInformationMap != nullptr << 304 { return G4VelocityTable::GetNbinOfVelocityTable();} 260 { << 261 G4int id = G4PhysicsModelCatalog::GetModel << 262 RemoveAuxiliaryTrackInformation(id); << 263 } << 264 } << 265 305 266 // ------------------------------------------- << 267 void G4Track::ClearAuxiliaryTrackInformation() << 268 { << 269 if(fpAuxiliaryTrackInformationMap == nullptr << 270 return; << 271 for(const auto& itr : *fpAuxiliaryTrackInfor << 272 { << 273 delete itr.second; << 274 } << 275 delete fpAuxiliaryTrackInformationMap; << 276 fpAuxiliaryTrackInformationMap = nullptr; << 277 } << 278 306