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