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 // G4ParticleChangeForTransport class implemen << 27 // 26 // 28 // Author: Hisaya Kurashige, 10 May 1998 << 27 // $Id: G4ParticleChangeForTransport.cc 68795 2013-04-05 13:24:46Z gcosmo $ 29 // ------------------------------------------- << 28 // >> 29 // >> 30 // -------------------------------------------------------------- >> 31 // GEANT 4 class implementation file >> 32 // >> 33 // >> 34 // >> 35 // ------------------------------------------------------------ >> 36 // Implemented for the new scheme 10 May. 1998 H.Kurahige >> 37 // Correct tratment of fpNextTouchable 12 May. 1998 H.Kurashige >> 38 // Change to the next volume only if energy>0 19 Jan. 2004 V.Ivanchenko >> 39 // -------------------------------------------------------------- 30 40 31 #include "G4ParticleChangeForTransport.hh" 41 #include "G4ParticleChangeForTransport.hh" 32 #include "G4TouchableHandle.hh" 42 #include "G4TouchableHandle.hh" 33 #include "G4Track.hh" 43 #include "G4Track.hh" 34 #include "G4Step.hh" 44 #include "G4Step.hh" 35 #include "G4TrackFastVector.hh" 45 #include "G4TrackFastVector.hh" 36 #include "G4DynamicParticle.hh" 46 #include "G4DynamicParticle.hh" 37 47 38 // ------------------------------------------- << 48 G4ParticleChangeForTransport::G4ParticleChangeForTransport() 39 G4ParticleChangeForTransport::G4ParticleChange << 49 : G4ParticleChange(), isMomentumChanged(false), theMaterialChange(0), >> 50 theMaterialCutsCoupleChange(0), theSensitiveDetectorChange(0), >> 51 fpVectorOfAuxiliaryPointsPointer(0) >> 52 { >> 53 if (verboseLevel>2) { >> 54 G4cout << "G4ParticleChangeForTransport::G4ParticleChangeForTransport() " >> 55 << G4endl; >> 56 } >> 57 } >> 58 >> 59 G4ParticleChangeForTransport::~G4ParticleChangeForTransport() >> 60 { >> 61 if (verboseLevel>2) { >> 62 G4cout << "G4ParticleChangeForTransport::~G4ParticleChangeForTransport() " >> 63 << G4endl; >> 64 } >> 65 } >> 66 >> 67 G4ParticleChangeForTransport:: >> 68 G4ParticleChangeForTransport(const G4ParticleChangeForTransport &r) >> 69 : G4ParticleChange(r), >> 70 fpVectorOfAuxiliaryPointsPointer(0) >> 71 { >> 72 if (verboseLevel>0) { >> 73 G4cout << "G4ParticleChangeForTransport:: copy constructor is called " >> 74 << G4endl; >> 75 } >> 76 theTouchableHandle = r.theTouchableHandle; >> 77 isMomentumChanged = r.isMomentumChanged; >> 78 theMaterialChange = r.theMaterialChange; >> 79 theMaterialCutsCoupleChange = r.theMaterialCutsCoupleChange; >> 80 theSensitiveDetectorChange = r.theSensitiveDetectorChange; >> 81 } >> 82 >> 83 // assignemnt operator >> 84 G4ParticleChangeForTransport & >> 85 G4ParticleChangeForTransport::operator=(const G4ParticleChangeForTransport &r) 40 { 86 { 41 // Disable flag that is enabled in G4VPartic << 87 if (verboseLevel>1) { 42 debugFlag = false; << 88 G4cout << "G4ParticleChangeForTransport:: assignment operator is called " >> 89 << G4endl; >> 90 } >> 91 if (this != &r) >> 92 { >> 93 theListOfSecondaries = r.theListOfSecondaries; >> 94 theSizeOftheListOfSecondaries = r.theSizeOftheListOfSecondaries; >> 95 theNumberOfSecondaries = r.theNumberOfSecondaries; >> 96 theStatusChange = r.theStatusChange; >> 97 theTouchableHandle = r.theTouchableHandle; >> 98 theMaterialChange = r.theMaterialChange; >> 99 theMaterialCutsCoupleChange = r.theMaterialCutsCoupleChange; >> 100 theSensitiveDetectorChange = r.theSensitiveDetectorChange; >> 101 theMomentumDirectionChange = r.theMomentumDirectionChange; >> 102 thePolarizationChange = r.thePolarizationChange; >> 103 thePositionChange = r.thePositionChange; >> 104 theTimeChange = r.theTimeChange; >> 105 theEnergyChange = r.theEnergyChange; >> 106 theVelocityChange = r.theVelocityChange; >> 107 theTrueStepLength = r.theTrueStepLength; >> 108 theLocalEnergyDeposit = r.theLocalEnergyDeposit; >> 109 theSteppingControlFlag = r.theSteppingControlFlag; >> 110 } >> 111 return *this; 43 } 112 } 44 113 45 // ------------------------------------------- << 114 //---------------------------------------------------------------- >> 115 // methods for updating G4Step >> 116 // >> 117 46 G4Step* G4ParticleChangeForTransport::UpdateSt 118 G4Step* G4ParticleChangeForTransport::UpdateStepForAtRest(G4Step* pStep) 47 { 119 { 48 // Update the G4Step specific attributes << 120 // Nothing happens for AtRestDoIt >> 121 if (verboseLevel>0) { >> 122 G4cout << "G4ParticleChangeForTransport::UpdateStepForAtRest() is called" >> 123 << G4endl; >> 124 G4cout << " Nothing happens for this method " << G4endl; >> 125 } >> 126 // Update the G4Step specific attributes 49 return UpdateStepInfo(pStep); 127 return UpdateStepInfo(pStep); 50 } 128 } 51 129 52 // ------------------------------------------- << 130 53 G4Step* G4ParticleChangeForTransport::UpdateSt 131 G4Step* G4ParticleChangeForTransport::UpdateStepForAlongStep(G4Step* pStep) 54 { 132 { 55 // Smooth curved tajectory representation: l 133 // Smooth curved tajectory representation: let the Step know about 56 // the auxiliary trajectory points (jacek 30 134 // the auxiliary trajectory points (jacek 30/10/2002) 57 pStep->SetPointerToVectorOfAuxiliaryPoints(f 135 pStep->SetPointerToVectorOfAuxiliaryPoints(fpVectorOfAuxiliaryPointsPointer); 58 136 59 // Most of the code assumes that transportat << 137 // copy of G4ParticleChange::UpdateStepForAlongStep 60 // so the pre- and post-step point are still << 138 // i.e. no effect for touchable >> 139 >> 140 // A physics process always calculates the final state of the >> 141 // particle relative to the initial state at the beginning >> 142 // of the Step, i.e., based on information of G4Track (or >> 143 // equivalently the PreStepPoint). >> 144 // So, the differences (delta) between these two states have to be >> 145 // calculated and be accumulated in PostStepPoint. >> 146 >> 147 // Take note that the return type of GetMomentumChange is a >> 148 // pointer to G4ThreeVector. Also it is a normalized >> 149 // momentum vector. >> 150 61 G4StepPoint* pPreStepPoint = pStep->GetPreS 151 G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint(); 62 G4StepPoint* pPostStepPoint = pStep->GetPost 152 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint(); >> 153 G4Track* aTrack = pStep->GetTrack(); >> 154 G4double mass = aTrack->GetDynamicParticle()->GetMass(); >> 155 >> 156 // uodate kinetic energy >> 157 // now assume that no energy change in transportation >> 158 // However it is not true in electric fields >> 159 // Case for changing energy will be implemented in future >> 160 63 161 64 // update momentum direction and energy 162 // update momentum direction and energy 65 if(isMomentumChanged) << 163 if (isMomentumChanged) { 66 { << 164 G4double energy; 67 pPostStepPoint->SetMomentumDirection(theMo << 165 energy= pPostStepPoint->GetKineticEnergy() 68 pPostStepPoint->SetKineticEnergy(theEnergy << 166 + (theEnergyChange - pPreStepPoint->GetKineticEnergy()); >> 167 >> 168 // calculate new momentum >> 169 G4ThreeVector pMomentum = pPostStepPoint->GetMomentum() >> 170 + ( CalcMomentum(theEnergyChange, theMomentumDirectionChange, mass) >> 171 - pPreStepPoint->GetMomentum()); >> 172 G4double tMomentum = pMomentum.mag(); >> 173 G4ThreeVector direction(1.0,0.0,0.0); >> 174 if( tMomentum > 0. ){ >> 175 G4double inv_Momentum= 1.0 / tMomentum; >> 176 direction= pMomentum * inv_Momentum; >> 177 } >> 178 pPostStepPoint->SetMomentumDirection(direction); >> 179 pPostStepPoint->SetKineticEnergy( energy ); 69 } 180 } 70 if(isVelocityChanged) << 181 if (isVelocityChanged) pPostStepPoint->SetVelocity(theVelocityChange); 71 pPostStepPoint->SetVelocity(theVelocityCha << 182 >> 183 // stop case should not occur >> 184 //pPostStepPoint->SetMomentumDirection(G4ThreeVector(1., 0., 0.)); >> 185 72 186 73 // update polarization 187 // update polarization 74 pPostStepPoint->SetPolarization(thePolarizat << 188 pPostStepPoint->AddPolarization( thePolarizationChange >> 189 - pPreStepPoint->GetPolarization()); 75 190 76 // update position and time 191 // update position and time 77 pPostStepPoint->SetPosition(thePositionChang << 192 pPostStepPoint->AddPosition( thePositionChange 78 pPostStepPoint->AddGlobalTime(theTimeChange << 193 - pPreStepPoint->GetPosition() ); 79 pPostStepPoint->AddLocalTime(theTimeChange - << 194 pPostStepPoint->AddGlobalTime( theTimeChange 80 pPostStepPoint->SetProperTime(theProperTimeC << 195 - pPreStepPoint->GetLocalTime()); >> 196 pPostStepPoint->AddLocalTime( theTimeChange >> 197 - pPreStepPoint->GetLocalTime()); >> 198 pPostStepPoint->AddProperTime( theProperTimeChange >> 199 - pPreStepPoint->GetProperTime()); 81 200 82 #ifdef G4VERBOSE 201 #ifdef G4VERBOSE 83 if(debugFlag) { CheckIt(*theCurrentTrack); } << 202 if (debugFlag) CheckIt(*aTrack); 84 #endif 203 #endif 85 204 86 // Update the G4Step specific attributes << 205 // Update the G4Step specific attributes 87 pStep->SetStepLength( theTrueStepLength ); << 206 //pStep->SetStepLength( theTrueStepLength ); 88 pStep->SetControlFlag(theSteppingControlFlag << 207 // pStep->AddTotalEnergyDeposit( theLocalEnergyDeposit ); 89 << 208 pStep->SetControlFlag( theSteppingControlFlag ); 90 return pStep; 209 return pStep; >> 210 // return UpdateStepInfo(pStep); 91 } 211 } 92 212 93 // ------------------------------------------- << 94 G4Step* G4ParticleChangeForTransport::UpdateSt 213 G4Step* G4ParticleChangeForTransport::UpdateStepForPostStep(G4Step* pStep) 95 { 214 { 96 // A physics process always calculates the f 215 // A physics process always calculates the final state of the particle 97 216 98 // Change volume only if some kinetic energy 217 // Change volume only if some kinetic energy remains 99 G4StepPoint* pPostStepPoint = pStep->GetPost 218 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint(); 100 if(pPostStepPoint->GetKineticEnergy() > 0.0) << 219 if(pPostStepPoint->GetKineticEnergy() > 0.0) { 101 { << 220 102 // update next touchable 221 // update next touchable 103 // (touchable can be changed only at PostS 222 // (touchable can be changed only at PostStepDoIt) 104 pPostStepPoint->SetTouchableHandle(theTouc << 223 pPostStepPoint->SetTouchableHandle( theTouchableHandle ); 105 224 106 pPostStepPoint->SetMaterial(theMaterialCha << 225 pPostStepPoint->SetMaterial( theMaterialChange ); 107 pPostStepPoint->SetMaterialCutsCouple(theM << 226 pPostStepPoint->SetMaterialCutsCouple( theMaterialCutsCoupleChange ); 108 pPostStepPoint->SetSensitiveDetector(theSe << 227 pPostStepPoint->SetSensitiveDetector( theSensitiveDetectorChange ); 109 } << 110 if(this->GetFirstStepInVolume()) << 111 { << 112 pStep->SetFirstStepFlag(); << 113 } << 114 else << 115 { << 116 pStep->ClearFirstStepFlag(); << 117 } 228 } 118 if(this->GetLastStepInVolume()) << 229 if( this->GetLastStepInVolume() ){ 119 { << 120 pStep->SetLastStepFlag(); 230 pStep->SetLastStepFlag(); 121 } << 231 }else{ 122 else << 232 pStep->ClearLastStepFlag(); 123 { << 124 pStep->ClearLastStepFlag(); << 125 } 233 } 126 // It used to call base class's method 234 // It used to call base class's method 127 // - but this would copy uninitialised dat 235 // - but this would copy uninitialised data members 128 // return G4ParticleChange::UpdateStepForPos 236 // return G4ParticleChange::UpdateStepForPostStep(pStep); 129 237 130 // Copying what the base class does would in 238 // Copying what the base class does would instead 131 // - also not useful 239 // - also not useful 132 // return G4VParticleChange::UpdateStepInfo( 240 // return G4VParticleChange::UpdateStepInfo(pStep); 133 241 134 return pStep; 242 return pStep; 135 } 243 } 136 244 137 // ------------------------------------------- << 245 >> 246 //---------------------------------------------------------------- >> 247 // methods for printing messages >> 248 // >> 249 138 void G4ParticleChangeForTransport::DumpInfo() 250 void G4ParticleChangeForTransport::DumpInfo() const 139 { 251 { 140 // use base-class DumpInfo << 252 // use base-class DumpInfo 141 G4ParticleChange::DumpInfo(); 253 G4ParticleChange::DumpInfo(); 142 G4cout << " Touchable (pointer) : " < << 254 143 << theTouchableHandle() << G4endl; << 255 G4int oldprc = G4cout.precision(3); >> 256 G4cout << " Touchable (pointer) : " >> 257 << std::setw(20) << theTouchableHandle() << G4endl; >> 258 G4cout.precision(oldprc); 144 } 259 } >> 260 145 261