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 // 26 // >> 27 // $Id: G4Transportation.cc,v 1.72.2.3 2008/11/21 18:35:15 japost Exp $ >> 28 // GEANT4 tag $Name: geant4-09-02 $ 27 // 29 // 28 // ------------------------------------------- 30 // ------------------------------------------------------------ 29 // GEANT 4 include file implementation 31 // GEANT 4 include file implementation 30 // 32 // 31 // ------------------------------------------- 33 // ------------------------------------------------------------ 32 // 34 // 33 // This class is a process responsible for the 35 // This class is a process responsible for the transportation of 34 // a particle, ie the geometrical propagation 36 // a particle, ie the geometrical propagation that encounters the 35 // geometrical sub-volumes of the detectors. 37 // geometrical sub-volumes of the detectors. 36 // 38 // 37 // It is also tasked with the key role of prop 39 // It is also tasked with the key role of proposing the "isotropic safety", 38 // which will be used to update the post-ste 40 // which will be used to update the post-step point's safety. 39 // 41 // 40 // =========================================== 42 // ======================================================================= >> 43 // Modified: >> 44 // 20 Nov 2008, J.Apostolakis: Push safety to helper - after ComputeSafety >> 45 // 9 Nov 2007, J.Apostolakis: Flag for short steps, push safety to helper >> 46 // 19 Jan 2006, P.MoraDeFreitas: Fix for suspended tracks (StartTracking) >> 47 // 11 Aug 2004, M.Asai: Add G4VSensitiveDetector* for updating stepPoint. >> 48 // 21 June 2003, J.Apostolakis: Calling field manager with >> 49 // track, to enable it to configure its accuracy >> 50 // 13 May 2003, J.Apostolakis: Zero field areas now taken into >> 51 // account correclty in all cases (thanks to W Pokorski). >> 52 // 29 June 2001, J.Apostolakis, D.Cote-Ahern, P.Gumplinger: >> 53 // correction for spin tracking >> 54 // 20 Febr 2001, J.Apostolakis: update for new FieldTrack >> 55 // 22 Sept 2000, V.Grichine: update of Kinetic Energy 41 // Created: 19 March 1997, J. Apostolakis 56 // Created: 19 March 1997, J. Apostolakis 42 // =========================================== 57 // ======================================================================= 43 58 44 #include "G4Transportation.hh" 59 #include "G4Transportation.hh" 45 #include "G4TransportationProcessType.hh" << 46 #include "G4TransportationLogger.hh" << 47 << 48 #include "G4PhysicalConstants.hh" << 49 #include "G4SystemOfUnits.hh" << 50 #include "G4ProductionCutsTable.hh" 60 #include "G4ProductionCutsTable.hh" 51 #include "G4ParticleTable.hh" 61 #include "G4ParticleTable.hh" 52 << 62 #include "G4ChordFinder.hh" 53 #include "G4ChargeState.hh" << 63 #include "G4SafetyHelper.hh" 54 #include "G4EquationOfMotion.hh" << 55 << 56 #include "G4FieldManagerStore.hh" 64 #include "G4FieldManagerStore.hh" 57 << 58 #include "G4Navigator.hh" << 59 #include "G4PropagatorInField.hh" << 60 #include "G4TransportationManager.hh" << 61 << 62 #include "G4TransportationParameters.hh" << 63 << 64 class G4VSensitiveDetector; 65 class G4VSensitiveDetector; 65 66 66 G4bool G4Transportation::fUseMagneticMoment=fa << 67 G4bool G4Transportation::fUseGravity= false; << 68 G4bool G4Transportation::fSilenceLooperWarning << 69 << 70 ////////////////////////////////////////////// 67 ////////////////////////////////////////////////////////////////////////// 71 // 68 // 72 // Constructor 69 // Constructor 73 70 74 G4Transportation::G4Transportation( G4int verb << 71 G4Transportation::G4Transportation( G4int verboseLevel ) 75 : G4VProcess( aName, fTransportation ), << 72 : G4VProcess( G4String("Transportation"), fTransportation ), 76 fFieldExertedForce( false ), << 73 fParticleIsLooping( false ), 77 fPreviousSftOrigin( 0.,0.,0. ), << 74 fPreviousSftOrigin (0.,0.,0.), 78 fPreviousSafety( 0.0 ), << 75 fPreviousSafety ( 0.0 ), 79 fEndPointDistance( -1.0 ), << 76 fThreshold_Warning_Energy( 100 * MeV ), 80 fShortStepOptimisation( false ) // Old def << 77 fThreshold_Important_Energy( 250 * MeV ), >> 78 fThresholdTrials( 10 ), >> 79 fUnimportant_Energy( 1 * MeV ), >> 80 fNoLooperTrials(0), >> 81 fSumEnergyKilled( 0.0 ), fMaxEnergyKilled( 0.0 ), >> 82 fShortStepOptimisation(false), // Old default: true (=fast short steps) >> 83 fVerboseLevel( verboseLevel ) 81 { 84 { 82 SetProcessSubType(static_cast<G4int>(TRANSPO << 83 pParticleChange= &fParticleChange; // Requ << 84 SetVerboseLevel(verbosity); << 85 << 86 G4TransportationManager* transportMgr ; 85 G4TransportationManager* transportMgr ; 87 86 88 transportMgr = G4TransportationManager::GetT 87 transportMgr = G4TransportationManager::GetTransportationManager() ; 89 88 90 fLinearNavigator = transportMgr->GetNavigato 89 fLinearNavigator = transportMgr->GetNavigatorForTracking() ; 91 90 >> 91 // fGlobalFieldMgr = transportMgr->GetFieldManager() ; >> 92 92 fFieldPropagator = transportMgr->GetPropagat 93 fFieldPropagator = transportMgr->GetPropagatorInField() ; 93 94 94 fpSafetyHelper = transportMgr->GetSafetyHe 95 fpSafetyHelper = transportMgr->GetSafetyHelper(); // New 95 96 96 fpLogger = new G4TransportationLogger("G4Tra << 97 // Cannot determine whether a field exists here, >> 98 // because it would only work if the field manager has informed >> 99 // about the detector's field before this transportation process >> 100 // is constructed. >> 101 // Instead later the method DoesGlobalFieldExist() is called 97 102 98 if( G4TransportationParameters::Exists() ) << 103 static G4TouchableHandle nullTouchableHandle; // Points to (G4VTouchable*) 0 99 { << 104 fCurrentTouchableHandle = nullTouchableHandle; 100 auto trParams= G4TransportationParameters: << 101 << 102 SetThresholdWarningEnergy( trParams->GetW << 103 SetThresholdImportantEnergy( trParams->Get << 104 SetThresholdTrials( trParams->GetNumberOfT << 105 G4Transportation::fSilenceLooperWarnings= << 106 } << 107 else { << 108 SetHighLooperThresholds(); << 109 // Use the old defaults: Warning = 100 Me << 110 } << 111 << 112 PushThresholdsToLogger(); << 113 // Should be done by Set methods in SetHighL << 114 << 115 static G4ThreadLocal G4TouchableHandle* pNul << 116 if ( !pNullTouchableHandle) << 117 { << 118 pNullTouchableHandle = new G4TouchableHand << 119 } << 120 fCurrentTouchableHandle = *pNullTouchableHan << 121 // Points to (G4VTouchable*) 0 << 122 105 123 << 106 fEndGlobalTimeComputed = false; 124 #ifdef G4VERBOSE << 107 fCandidateEndGlobalTime = 0; 125 if( verboseLevel > 0) << 126 { << 127 G4cout << " G4Transportation constructor> << 128 if ( fShortStepOptimisation ) { G4cout < << 129 else { G4cout < << 130 } << 131 #endif << 132 } 108 } 133 109 134 ////////////////////////////////////////////// 110 ////////////////////////////////////////////////////////////////////////// 135 111 136 G4Transportation::~G4Transportation() 112 G4Transportation::~G4Transportation() 137 { 113 { 138 if( fSumEnergyKilled > 0.0 ) << 114 if( (fVerboseLevel > 0) && (fSumEnergyKilled > 0.0 ) ){ 139 { << 115 G4cout << " G4Transportation: Statistics for looping particles " << G4endl; 140 PrintStatistics( G4cout ); << 116 G4cout << " Sum of energy of loopers killed: " << fSumEnergyKilled << G4endl; 141 } << 117 G4cout << " Max energy of loopers killed: " << fMaxEnergyKilled << G4endl; 142 delete fpLogger; << 118 } 143 } << 144 << 145 ////////////////////////////////////////////// << 146 << 147 void << 148 G4Transportation::PrintStatistics( std::ostrea << 149 { << 150 outStr << " G4Transportation: Statistics fo << 151 if( fSumEnergyKilled > 0.0 || fNumLoopersKi << 152 { << 153 outStr << " Sum of energy of looping t << 154 << fSumEnergyKilled / CLHEP::MeV << 155 << " from " << fNumLoopersKilled << 156 << " Sum of energy of non-elect << 157 << fSumEnergyKilled_NonElectron / << 158 << " from " << fNumLoopersKilled << 159 << G4endl; << 160 outStr << " Max energy of *any type* << 161 << " its PDG was " << fMaxEner << 162 if( fMaxEnergyKilled_NonElectron > 0.0 ) << 163 { << 164 outStr << " Max energy of non-elect << 165 << fMaxEnergyKilled_NonElectro << 166 << " its PDG was " << fMaxE << 167 } << 168 if( fMaxEnergySaved > 0.0 ) << 169 { << 170 outStr << " Max energy of loopers ' << 171 outStr << " Sum of energy of looper << 172 << fSumEnergySaved << G4endl; << 173 outStr << " Sum of energy of unstab << 174 << fSumEnergyUnstableSaved << << 175 } << 176 } << 177 else << 178 { << 179 outStr << " No looping tracks found or k << 180 } << 181 } 119 } 182 120 183 ////////////////////////////////////////////// 121 ////////////////////////////////////////////////////////////////////////// 184 // 122 // 185 // Responsibilities: 123 // Responsibilities: 186 // Find whether the geometry limits the Ste 124 // Find whether the geometry limits the Step, and to what length 187 // Calculate the new value of the safety an 125 // Calculate the new value of the safety and return it. 188 // Store the final time, position and momen 126 // Store the final time, position and momentum. 189 127 190 G4double G4Transportation::AlongStepGetPhysica << 128 G4double G4Transportation:: 191 const G4Track& track, << 129 AlongStepGetPhysicalInteractionLength( const G4Track& track, 192 G4double, // previousStepSize << 130 G4double, // previousStepSize 193 G4double currentMinimumStep, G4double& curre << 131 G4double currentMinimumStep, 194 G4GPILSelection* selection) << 132 G4double& currentSafety, >> 133 G4GPILSelection* selection ) 195 { 134 { 196 // Initial actions moved to StartTrack() << 135 G4double geometryStepLength, newSafety ; >> 136 fParticleIsLooping = false ; >> 137 >> 138 // Initial actions moved to StartTrack() 197 // -------------------------------------- 139 // -------------------------------------- 198 // Note: in case another process changes tou 140 // Note: in case another process changes touchable handle 199 // it will be necessary to add here (for << 141 // it will be necessary to add here (for all steps) 200 // fCurrentTouchableHandle = aTrack->GetTouc 142 // fCurrentTouchableHandle = aTrack->GetTouchableHandle(); 201 143 202 // GPILSelection is set to defaule value of 144 // GPILSelection is set to defaule value of CandidateForSelection 203 // It is a return value 145 // It is a return value 204 // 146 // 205 *selection = CandidateForSelection; << 147 *selection = CandidateForSelection ; 206 148 207 // Get initial Energy/Momentum of the track 149 // Get initial Energy/Momentum of the track 208 // 150 // 209 const G4ThreeVector startPosition = track << 151 const G4DynamicParticle* pParticle = track.GetDynamicParticle() ; 210 const G4ThreeVector startMomentumDir = track << 152 const G4ParticleDefinition* pParticleDef = pParticle->GetDefinition() ; >> 153 G4ThreeVector startMomentumDir = pParticle->GetMomentumDirection() ; >> 154 G4ThreeVector startPosition = track.GetPosition() ; >> 155 >> 156 // G4double theTime = track.GetGlobalTime() ; 211 157 212 // The Step Point safety can be limited by o << 158 // The Step Point safety can be limited by other geometries and/or the 213 // assumptions of any process - it's not alw 159 // assumptions of any process - it's not always the geometrical safety. 214 // We calculate the starting point's isotrop 160 // We calculate the starting point's isotropic safety here. >> 161 // >> 162 G4ThreeVector OriginShift = startPosition - fPreviousSftOrigin ; >> 163 G4double MagSqShift = OriginShift.mag2() ; >> 164 if( MagSqShift >= sqr(fPreviousSafety) ) 215 { 165 { 216 const G4double MagSqShift = (startPosition << 166 currentSafety = 0.0 ; 217 << 167 } 218 if(MagSqShift >= sqr(fPreviousSafety)) << 168 else 219 currentSafety = 0.0; << 169 { 220 else << 170 currentSafety = fPreviousSafety - std::sqrt(MagSqShift) ; 221 currentSafety = fPreviousSafety - std::s << 222 } 171 } 223 172 224 // Is the particle charged or has it a magne << 173 // Is the particle charged ? 225 // 174 // 226 const G4DynamicParticle* pParticle = track.G << 175 G4double particleCharge = pParticle->GetCharge() ; 227 << 228 const G4double particleMass = pParticle->G << 229 const G4double particleCharge = pParticle->G << 230 const G4double kineticEnergy = pParticle->Ge << 231 176 232 const G4double magneticMoment = pParticle << 177 fGeometryLimitedStep = false ; 233 const G4ThreeVector particleSpin = pParticle << 178 // fEndGlobalTimeComputed = false ; 234 179 235 // There is no need to locate the current vo 180 // There is no need to locate the current volume. It is Done elsewhere: 236 // On track construction << 181 // On track construction 237 // By the tracking, after all AlongStepDoI 182 // By the tracking, after all AlongStepDoIts, in "Relocation" 238 183 239 // Check if the particle has a force, EM or << 184 // Check whether the particle have an (EM) field force exerting upon it 240 // 185 // >> 186 G4FieldManager* fieldMgr=0; >> 187 G4bool fieldExertsForce = false ; >> 188 if( (particleCharge != 0.0) ) >> 189 { >> 190 fieldMgr= fFieldPropagator->FindAndSetFieldManager( track.GetVolume() ); >> 191 if (fieldMgr != 0) { >> 192 // Message the field Manager, to configure it for this track >> 193 fieldMgr->ConfigureForTrack( &track ); >> 194 // Moved here, in order to allow a transition >> 195 // from a zero-field status (with fieldMgr->(field)0 >> 196 // to a finite field status >> 197 >> 198 // If the field manager has no field, there is no field ! >> 199 fieldExertsForce = (fieldMgr->GetDetectorField() != 0); >> 200 } >> 201 } >> 202 >> 203 // G4cout << " G4Transport: field exerts force= " << fieldExertsForce >> 204 // << " fieldMgr= " << fieldMgr << G4endl; >> 205 >> 206 // Choose the calculation of the transportation: Field or not >> 207 // >> 208 if( !fieldExertsForce ) >> 209 { >> 210 G4double linearStepLength ; >> 211 if( fShortStepOptimisation && (currentMinimumStep <= currentSafety) ) >> 212 { >> 213 // The Step is guaranteed to be taken >> 214 // >> 215 geometryStepLength = currentMinimumStep ; >> 216 fGeometryLimitedStep = false ; >> 217 } >> 218 else >> 219 { >> 220 // Find whether the straight path intersects a volume >> 221 // >> 222 linearStepLength = fLinearNavigator->ComputeStep( startPosition, >> 223 startMomentumDir, >> 224 currentMinimumStep, >> 225 newSafety) ; >> 226 // Remember last safety origin & value. >> 227 // >> 228 fPreviousSftOrigin = startPosition ; >> 229 fPreviousSafety = newSafety ; >> 230 // fpSafetyHelper->SetCurrentSafety( newSafety, startPosition); >> 231 >> 232 // The safety at the initial point has been re-calculated: >> 233 // >> 234 currentSafety = newSafety ; >> 235 >> 236 fGeometryLimitedStep= (linearStepLength <= currentMinimumStep); >> 237 if( fGeometryLimitedStep ) >> 238 { >> 239 // The geometry limits the Step size (an intersection was found.) >> 240 geometryStepLength = linearStepLength ; >> 241 } >> 242 else >> 243 { >> 244 // The full Step is taken. >> 245 geometryStepLength = currentMinimumStep ; >> 246 } >> 247 } >> 248 endpointDistance = geometryStepLength ; 241 249 242 G4bool eligibleEM = << 250 // Calculate final position 243 (particleCharge != 0.0) || ((magneticMomen << 251 // 244 G4bool eligibleGrav = (particleMass != 0.0) << 252 fTransportEndPosition = startPosition+geometryStepLength*startMomentumDir ; 245 << 246 fFieldExertedForce = false; << 247 << 248 if(eligibleEM || eligibleGrav) << 249 { << 250 if(G4FieldManager* fieldMgr = << 251 fFieldPropagator->FindAndSetFieldMana << 252 { << 253 // User can configure the field Manager << 254 fieldMgr->ConfigureForTrack(&track); << 255 // Called here to allow a transition fro << 256 // to finite field (non-zero pointer). << 257 << 258 // If the field manager has no field ptr << 259 // by definition ( = there is no field << 260 if(const G4Field* ptrField = fieldMgr->G << 261 fFieldExertedForce = << 262 eligibleEM || (eligibleGrav && ptrFi << 263 } << 264 } << 265 << 266 G4double geometryStepLength = currentMinimum << 267 << 268 if(currentMinimumStep == 0.0) << 269 { << 270 fEndPointDistance = 0.0; << 271 fGeometryLimitedStep = false; // Old cod << 272 // Changed to avoid problems when setting << 273 fMomentumChanged = false; << 274 fParticleIsLooping = false; << 275 fEndGlobalTimeComputed = false; << 276 fTransportEndPosition = startPosition << 277 fTransportEndMomentumDir = startMomentum << 278 fTransportEndKineticEnergy = kineticEnergy << 279 fTransportEndSpin = particleSpin; << 280 } << 281 else if(!fFieldExertedForce) << 282 { << 283 fGeometryLimitedStep = false; << 284 if(geometryStepLength > currentSafety || ! << 285 { << 286 const G4double linearStepLength = fLinea << 287 startPosition, startMomentumDir, curre << 288 << 289 if(linearStepLength <= currentMinimumSte << 290 { << 291 geometryStepLength = linearStepLength; << 292 fGeometryLimitedStep = true; << 293 } << 294 // Remember last safety origin & value. << 295 // << 296 fPreviousSftOrigin = startPosition; << 297 fPreviousSafety = currentSafety; << 298 fpSafetyHelper->SetCurrentSafety(current << 299 } << 300 << 301 fEndPointDistance = geometryStepLength; << 302 << 303 fMomentumChanged = false; << 304 fParticleIsLooping = false; << 305 fEndGlobalTimeComputed = false; << 306 fTransportEndPosition = << 307 startPosition + geometryStepLength * sta << 308 fTransportEndMomentumDir = startMomentum << 309 fTransportEndKineticEnergy = kineticEnergy << 310 fTransportEndSpin = particleSpin; << 311 } << 312 else // A field exerts force << 313 { << 314 const auto pParticleDef = pParticle->Ge << 315 const auto particlePDGSpin = pParticleDef- << 316 const auto particlePDGMagM = pParticleDef- << 317 << 318 auto equationOfMotion = fFieldPropagator-> << 319 << 320 // The charge can change (dynamic), theref << 321 // << 322 equationOfMotion->SetChargeMomentumMass( << 323 G4ChargeState(particleCharge, magneticMo << 324 pParticle->GetTotalMomentum(), particleM << 325 << 326 G4FieldTrack aFieldTrack(startPosition, << 327 track.GetGlobalTi << 328 startMomentumDir, << 329 particleCharge, p << 330 0.0, // Length a << 331 particlePDGSpin); << 332 << 333 // Do the Transport in the field (non rect << 334 // << 335 const G4double lengthAlongCurve = fFieldPr << 336 aFieldTrack, currentMinimumStep, current << 337 kineticEnergy < fThreshold_Important_Ene << 338 << 339 if(lengthAlongCurve < geometryStepLength) << 340 geometryStepLength = lengthAlongCurve; << 341 << 342 // Remember last safety origin & value. << 343 // << 344 fPreviousSftOrigin = startPosition; << 345 fPreviousSafety = currentSafety; << 346 fpSafetyHelper->SetCurrentSafety(currentSa << 347 << 348 fGeometryLimitedStep = fFieldPropagator->I << 349 // << 350 // It is possible that step was reduced in << 351 // previous zero steps. To cope with case << 352 // in full, we must rely on PiF to obtain << 353 253 354 G4bool changesEnergy = << 254 // Momentum direction, energy and polarisation are unchanged by transport 355 fFieldPropagator->GetCurrentFieldManager << 255 // >> 256 fTransportEndMomentumDir = startMomentumDir ; >> 257 fTransportEndKineticEnergy = track.GetKineticEnergy() ; >> 258 fTransportEndSpin = track.GetPolarization(); >> 259 fParticleIsLooping = false ; >> 260 fMomentumChanged = false ; >> 261 fEndGlobalTimeComputed = false ; >> 262 } >> 263 else // A field exerts force >> 264 { >> 265 G4double momentumMagnitude = pParticle->GetTotalMomentum() ; >> 266 G4ThreeVector EndUnitMomentum ; >> 267 G4double lengthAlongCurve ; >> 268 G4double restMass = pParticleDef->GetPDGMass() ; >> 269 >> 270 fFieldPropagator->SetChargeMomentumMass( particleCharge, // in e+ units >> 271 momentumMagnitude, // in Mev/c >> 272 restMass ) ; 356 273 357 fMomentumChanged = true; << 274 G4ThreeVector spin = track.GetPolarization() ; 358 fParticleIsLooping = fFieldPropagator->IsP << 275 G4FieldTrack aFieldTrack = G4FieldTrack( startPosition, >> 276 track.GetMomentumDirection(), >> 277 0.0, >> 278 track.GetKineticEnergy(), >> 279 restMass, >> 280 track.GetVelocity(), >> 281 track.GetGlobalTime(), // Lab. >> 282 track.GetProperTime(), // Part. >> 283 &spin ) ; >> 284 if( currentMinimumStep > 0 ) >> 285 { >> 286 // Do the Transport in the field (non recti-linear) >> 287 // >> 288 lengthAlongCurve = fFieldPropagator->ComputeStep( aFieldTrack, >> 289 currentMinimumStep, >> 290 currentSafety, >> 291 track.GetVolume() ) ; >> 292 fGeometryLimitedStep= lengthAlongCurve < currentMinimumStep; >> 293 if( fGeometryLimitedStep ) { >> 294 geometryStepLength = lengthAlongCurve ; >> 295 } else { >> 296 geometryStepLength = currentMinimumStep ; >> 297 } >> 298 } >> 299 else >> 300 { >> 301 geometryStepLength = lengthAlongCurve= 0.0 ; >> 302 fGeometryLimitedStep = false ; >> 303 } 359 304 360 fEndGlobalTimeComputed = changesEnergy; << 305 // Remember last safety origin & value. 361 fTransportEndPosition = aFieldTrack.Get << 306 // 362 fTransportEndMomentumDir = aFieldTrack.Get << 307 fPreviousSftOrigin = startPosition ; >> 308 fPreviousSafety = currentSafety ; >> 309 // fpSafetyHelper->SetCurrentSafety( newSafety, startPosition); >> 310 >> 311 // Get the End-Position and End-Momentum (Dir-ection) >> 312 // >> 313 fTransportEndPosition = aFieldTrack.GetPosition() ; 363 314 364 // G4cout << " G4Transport: End of step pM << 315 // Momentum: Magnitude and direction can be changed too now ... >> 316 // >> 317 fMomentumChanged = true ; >> 318 fTransportEndMomentumDir = aFieldTrack.GetMomentumDir() ; 365 319 366 fEndPointDistance = (fTransportEndPositio << 320 fTransportEndKineticEnergy = aFieldTrack.GetKineticEnergy() ; 367 321 368 // Ignore change in energy for fields that << 322 if( fFieldPropagator->GetCurrentFieldManager()->DoesFieldChangeEnergy() ) 369 // This hides the integration error, but g << 323 { 370 fTransportEndKineticEnergy = << 324 // If the field can change energy, then the time must be integrated 371 changesEnergy ? aFieldTrack.GetKineticEn << 325 // - so this should have been updated 372 fTransportEndSpin = aFieldTrack.GetSpin(); << 326 // >> 327 fCandidateEndGlobalTime = aFieldTrack.GetLabTimeOfFlight(); >> 328 fEndGlobalTimeComputed = true; 373 329 374 if(fEndGlobalTimeComputed) << 330 // was ( fCandidateEndGlobalTime != track.GetGlobalTime() ); 375 { << 331 // a cleaner way is to have FieldTrack knowing whether time is updated. 376 // If the field can change energy, then << 332 } 377 // - so this should have been updated << 333 else 378 // << 334 { 379 fCandidateEndGlobalTime = aFieldTrack.Ge << 335 // The energy should be unchanged by field transport, >> 336 // - so the time changed will be calculated elsewhere >> 337 // >> 338 fEndGlobalTimeComputed = false; 380 339 381 // was ( fCandidateEndGlobalTime != trac << 340 // Check that the integration preserved the energy 382 // a cleaner way is to have FieldTrack k << 341 // - and if not correct this! 383 } << 342 G4double startEnergy= track.GetKineticEnergy(); 384 #if defined(G4VERBOSE) || defined(G4DEBUG_TRAN << 343 G4double endEnergy= fTransportEndKineticEnergy; 385 else << 344 386 { << 345 static G4int no_inexact_steps=0, no_large_ediff; 387 // The energy should be unchanged by fie << 346 G4double absEdiff = std::fabs(startEnergy- endEnergy); 388 // - so the time changed will be calc << 347 if( absEdiff > perMillion * endEnergy ) 389 // << 348 { 390 // Check that the integration preserved << 349 no_inexact_steps++; 391 // - and if not correct this! << 350 // Possible statistics keeping here ... 392 G4double startEnergy = kineticEnergy; << 351 } 393 G4double endEnergy = fTransportEndKine << 352 if( fVerboseLevel > 1 ) 394 << 395 static G4ThreadLocal G4int no_large_edif << 396 if(verboseLevel > 1) << 397 { << 398 if(std::fabs(startEnergy - endEnergy) << 399 { 353 { 400 static G4ThreadLocal G4int no_warnin << 354 if( std::fabs(startEnergy- endEnergy) > perThousand * endEnergy ) 401 moduloFac << 402 no_large_ediff++; << 403 if((no_large_ediff % warnModulo) == << 404 { 355 { 405 no_warnings++; << 356 static G4int no_warnings= 0, warnModulo=1, moduloFactor= 10; 406 std::ostringstream message; << 357 no_large_ediff ++; 407 message << "Energy change in Step << 358 if( (no_large_ediff% warnModulo) == 0 ) 408 << G4endl << " Relativ << 409 << std::setw(15) << (endEn << 410 << G4endl << " Startin << 411 << startEnergy / MeV << " << 412 << " Ending E= " << << 413 << " MeV " << G4endl << 414 << "Energy has been correc << 415 << " field propagation par << 416 if((verboseLevel > 2) || (no_warni << 417 (no_large_ediff == warnModulo * << 418 { << 419 message << "These include Epsilo << 420 << G4endl << 421 << "which determine frac << 422 "integrated quantitie << 423 << G4endl << 424 << "Note also the influe << 425 "integration steps." << 426 << G4endl; << 427 } << 428 message << "Bad 'endpoint'. Energy << 429 << G4endl << "Has occurred << 430 << " times."; << 431 G4Exception("G4Transportation::Alo << 432 JustWarning, message); << 433 if(no_large_ediff == warnModulo * << 434 { 359 { 435 warnModulo *= moduloFactor; << 360 no_warnings++; >> 361 G4cout << "WARNING - G4Transportation::AlongStepGetPIL() " >> 362 << " Energy change in Step is above 1^-3 relative value. " << G4endl >> 363 << " Relative change in 'tracking' step = " >> 364 << std::setw(15) << (endEnergy-startEnergy)/startEnergy << G4endl >> 365 << " Starting E= " << std::setw(12) << startEnergy / MeV << " MeV " << G4endl >> 366 << " Ending E= " << std::setw(12) << endEnergy / MeV << " MeV " << G4endl; >> 367 G4cout << " Energy has been corrected -- however, review" >> 368 << " field propagation parameters for accuracy." << G4endl; >> 369 if( (fVerboseLevel > 2 ) || (no_warnings<4) || (no_large_ediff == warnModulo * moduloFactor) ){ >> 370 G4cout << " These include EpsilonStepMax(/Min) in G4FieldManager " >> 371 << " which determine fractional error per step for integrated quantities. " << G4endl >> 372 << " Note also the influence of the permitted number of integration steps." >> 373 << G4endl; >> 374 } >> 375 G4cerr << "ERROR - G4Transportation::AlongStepGetPIL()" << G4endl >> 376 << " Bad 'endpoint'. Energy change detected" >> 377 << " and corrected. " >> 378 << " Has occurred already " >> 379 << no_large_ediff << " times." << G4endl; >> 380 if( no_large_ediff == warnModulo * moduloFactor ) >> 381 { >> 382 warnModulo *= moduloFactor; >> 383 } 436 } 384 } 437 } 385 } 438 } << 386 } // end of if (fVerboseLevel) 439 } // end of if (verboseLevel) << 387 440 } << 388 // Correct the energy for fields that conserve it 441 #endif << 389 // This - hides the integration error >> 390 // - but gives a better physical answer >> 391 fTransportEndKineticEnergy= track.GetKineticEnergy(); >> 392 } >> 393 >> 394 fTransportEndSpin = aFieldTrack.GetSpin(); >> 395 fParticleIsLooping = fFieldPropagator->IsParticleLooping() ; >> 396 endpointDistance = (fTransportEndPosition - startPosition).mag() ; >> 397 } >> 398 >> 399 // If we are asked to go a step length of 0, and we are on a boundary >> 400 // then a boundary will also limit the step -> we must flag this. >> 401 // >> 402 if( currentMinimumStep == 0.0 ) >> 403 { >> 404 if( currentSafety == 0.0 ) fGeometryLimitedStep = true ; 442 } 405 } 443 406 444 // Update the safety starting from the end-p 407 // Update the safety starting from the end-point, 445 // if it will become negative at the end-poi 408 // if it will become negative at the end-point. 446 // 409 // 447 if(currentSafety < fEndPointDistance) << 410 if( currentSafety < endpointDistance ) 448 { 411 { 449 if(particleCharge != 0.0) << 412 // if( particleCharge == 0.0 ) 450 { << 413 // G4cout << " Avoiding call to ComputeSafety : charge = 0.0 " << G4endl; 451 G4double endSafety = << 414 452 fLinearNavigator->ComputeSafety(fTrans << 415 if( particleCharge != 0.0 ) { 453 currentSafety = endSafety; << 454 fPreviousSftOrigin = fTransportEndPositi << 455 fPreviousSafety = currentSafety; << 456 fpSafetyHelper->SetCurrentSafety(current << 457 << 458 // Because the Stepping Manager assumes << 459 // add the StepLength << 460 // << 461 currentSafety += fEndPointDistance; << 462 << 463 #ifdef G4DEBUG_TRANSPORT << 464 G4cout.precision(12); << 465 G4cout << "***G4Transportation::AlongSte << 466 G4cout << " Called Navigator->ComputeSa << 467 << " and it returned safety= << 468 G4cout << " Adding endpoint distance << 469 << " to obtain pseudo-safety= << 470 } << 471 else << 472 { << 473 G4cout << "***G4Transportation::AlongSte << 474 G4cout << " Avoiding call to ComputeSaf << 475 G4cout << " charge = " << particl << 476 G4cout << " mag moment = " << magneti << 477 #endif << 478 } << 479 } << 480 416 481 fFirstStepInVolume = fNewTrack || fLastStepI << 417 G4double endSafety = 482 fLastStepInVolume = false; << 418 fLinearNavigator->ComputeSafety( fTransportEndPosition) ; 483 fNewTrack = false; << 419 currentSafety = endSafety ; >> 420 fPreviousSftOrigin = fTransportEndPosition ; >> 421 fPreviousSafety = currentSafety ; >> 422 fpSafetyHelper->SetCurrentSafety( currentSafety, fTransportEndPosition); >> 423 >> 424 // Because the Stepping Manager assumes it is from the start point, >> 425 // add the StepLength >> 426 // >> 427 currentSafety += endpointDistance ; >> 428 >> 429 #ifdef G4DEBUG_TRANSPORT >> 430 G4cout.precision(12) ; >> 431 G4cout << "***G4Transportation::AlongStepGPIL ** " << G4endl ; >> 432 G4cout << " Called Navigator->ComputeSafety at " << fTransportEndPosition >> 433 << " and it returned safety= " << endSafety << G4endl ; >> 434 G4cout << " Adding endpoint distance " << endpointDistance >> 435 << " to obtain pseudo-safety= " << currentSafety << G4endl ; >> 436 #endif >> 437 } >> 438 } 484 439 485 fParticleChange.ProposeFirstStepInVolume(fFi << 440 fParticleChange.ProposeTrueStepLength(geometryStepLength) ; 486 fParticleChange.ProposeTrueStepLength(geomet << 487 441 488 return geometryStepLength; << 442 return geometryStepLength ; 489 } 443 } 490 444 491 ////////////////////////////////////////////// 445 ////////////////////////////////////////////////////////////////////////// 492 // 446 // 493 // Initialize ParticleChange (by setting al 447 // Initialize ParticleChange (by setting all its members equal 494 // to correspond 448 // to corresponding members in G4Track) 495 449 496 G4VParticleChange* G4Transportation::AlongStep 450 G4VParticleChange* G4Transportation::AlongStepDoIt( const G4Track& track, 497 451 const G4Step& stepData ) 498 { 452 { 499 #if defined(G4VERBOSE) || defined(G4DEBUG_TRAN << 453 static G4int noCalls=0; 500 static G4ThreadLocal G4long noCallsASDI=0; << 454 static const G4ParticleDefinition* fOpticalPhoton = 501 noCallsASDI++; << 455 G4ParticleTable::GetParticleTable()->FindParticle("opticalphoton"); 502 #else << 503 #define noCallsASDI 0 << 504 #endif << 505 456 506 if(fGeometryLimitedStep) << 457 noCalls++; 507 { << 508 stepData.GetPostStepPoint()->SetStepStatus << 509 } << 510 458 511 fParticleChange.Initialize(track) ; 459 fParticleChange.Initialize(track) ; 512 460 513 // Code for specific process 461 // Code for specific process 514 // 462 // 515 fParticleChange.ProposePosition(fTransportEn 463 fParticleChange.ProposePosition(fTransportEndPosition) ; 516 fParticleChange.ProposeMomentumDirection(fTr 464 fParticleChange.ProposeMomentumDirection(fTransportEndMomentumDir) ; 517 fParticleChange.ProposeEnergy(fTransportEndK 465 fParticleChange.ProposeEnergy(fTransportEndKineticEnergy) ; 518 fParticleChange.SetMomentumChanged(fMomentum 466 fParticleChange.SetMomentumChanged(fMomentumChanged) ; 519 467 520 fParticleChange.ProposePolarization(fTranspo 468 fParticleChange.ProposePolarization(fTransportEndSpin); 521 << 469 522 G4double deltaTime = 0.0 ; 470 G4double deltaTime = 0.0 ; 523 471 524 // Calculate Lab Time of Flight (ONLY if fi 472 // Calculate Lab Time of Flight (ONLY if field Equations used it!) 525 // G4double endTime = fCandidateEndGlobalT << 473 // G4double endTime = fCandidateEndGlobalTime; 526 // G4double delta_time = endTime - startTime << 474 // G4double delta_time = endTime - startTime; 527 475 528 G4double startTime = track.GetGlobalTime() ; 476 G4double startTime = track.GetGlobalTime() ; 529 477 530 if (!fEndGlobalTimeComputed) 478 if (!fEndGlobalTimeComputed) 531 { 479 { 532 // The time was not integrated .. make th 480 // The time was not integrated .. make the best estimate possible 533 // 481 // 534 G4double initialVelocity = stepData.GetPr << 482 G4double finalVelocity = track.GetVelocity() ; 535 G4double stepLength = track.GetStepL << 483 G4double initialVelocity = stepData.GetPreStepPoint()->GetVelocity() ; >> 484 G4double stepLength = track.GetStepLength() ; 536 485 537 deltaTime= 0.0; // in case initialVeloci 486 deltaTime= 0.0; // in case initialVelocity = 0 538 if ( initialVelocity > 0.0 ) { deltaTime << 487 const G4DynamicParticle* fpDynamicParticle = track.GetDynamicParticle(); 539 << 488 if (fpDynamicParticle->GetDefinition()== fOpticalPhoton) >> 489 { >> 490 // A photon is in the medium of the final point >> 491 // during the step, so it has the final velocity. >> 492 deltaTime = stepLength/finalVelocity ; >> 493 } >> 494 else if (finalVelocity > 0.0) >> 495 { >> 496 G4double meanInverseVelocity ; >> 497 // deltaTime = stepLength/finalVelocity ; >> 498 meanInverseVelocity = 0.5 >> 499 * ( 1.0 / initialVelocity + 1.0 / finalVelocity ) ; >> 500 deltaTime = stepLength * meanInverseVelocity ; >> 501 } >> 502 else if( initialVelocity > 0.0 ) >> 503 { >> 504 deltaTime = stepLength/initialVelocity ; >> 505 } 540 fCandidateEndGlobalTime = startTime + d 506 fCandidateEndGlobalTime = startTime + deltaTime ; 541 fParticleChange.ProposeLocalTime( track. << 542 } 507 } 543 else 508 else 544 { 509 { 545 deltaTime = fCandidateEndGlobalTime - sta 510 deltaTime = fCandidateEndGlobalTime - startTime ; 546 fParticleChange.ProposeGlobalTime( fCandi << 547 } 511 } 548 512 >> 513 fParticleChange.ProposeGlobalTime( fCandidateEndGlobalTime ) ; 549 514 550 // Now Correct by Lorentz factor to get delt << 515 // Now Correct by Lorentz factor to get "proper" deltaTime 551 516 552 G4double restMass = track.GetDynamicP 517 G4double restMass = track.GetDynamicParticle()->GetMass() ; 553 G4double deltaProperTime = deltaTime*( restM 518 G4double deltaProperTime = deltaTime*( restMass/track.GetTotalEnergy() ) ; 554 519 555 fParticleChange.ProposeProperTime(track.GetP 520 fParticleChange.ProposeProperTime(track.GetProperTime() + deltaProperTime) ; 556 //fParticleChange.ProposeTrueStepLength( tra << 521 //fParticleChange. ProposeTrueStepLength( track.GetStepLength() ) ; 557 522 558 // If the particle is caught looping or is s 523 // If the particle is caught looping or is stuck (in very difficult 559 // boundaries) in a magnetic field (doing ma << 524 // boundaries) in a magnetic field (doing many steps) >> 525 // THEN this kills it ... 560 // 526 // 561 if ( fParticleIsLooping ) 527 if ( fParticleIsLooping ) 562 { 528 { 563 G4double endEnergy= fTransportEndKinetic 529 G4double endEnergy= fTransportEndKineticEnergy; 564 fNoLooperTrials ++; << 565 auto particleType= track.GetDynamicParti << 566 << 567 G4bool stable = particleType->GetPDGStab << 568 G4bool candidateForEnd = (endEnergy < fT << 569 || (fNoLooperTrial << 570 G4bool unstableAndKillable = !stable && << 571 G4bool unstableForEnd = (endEnergy < fTh << 572 && (fNoLooperTri << 573 if( (candidateForEnd && stable) || (unst << 574 { << 575 // Kill the looping particle << 576 // << 577 fParticleChange.ProposeTrackStatus( fS << 578 G4int particlePDG= particleType->GetPD << 579 const G4int electronPDG= 11; // G4Elec << 580 << 581 // Simple statistics << 582 fSumEnergyKilled += endEnergy; << 583 fSumEnerSqKilled += endEnergy * endEne << 584 fNumLoopersKilled++; << 585 << 586 if( endEnergy > fMaxEnergyKilled ) { << 587 fMaxEnergyKilled = endEnergy; << 588 fMaxEnergyKilledPDG = particlePDG; << 589 } << 590 if( particleType->GetPDGEncoding() != << 591 { << 592 fSumEnergyKilled_NonElectron += end << 593 fSumEnerSqKilled_NonElectron += end << 594 fNumLoopersKilled_NonElectron++; << 595 << 596 if( endEnergy > fMaxEnergyKilled_No << 597 { << 598 fMaxEnergyKilled_NonElectron = e << 599 fMaxEnergyKilled_NonElecPDG = p << 600 } << 601 } << 602 530 603 if( endEnergy > fThreshold_Warning_Ene << 531 if( (endEnergy < fThreshold_Important_Energy) 604 { << 532 || (fNoLooperTrials >= fThresholdTrials ) ){ 605 fpLogger->ReportLoopingTrack( track, << 533 // Kill the looping particle 606 noCall << 534 // 607 } << 535 fParticleChange.ProposeTrackStatus( fStopAndKill ) ; 608 fNoLooperTrials=0; << 536 >> 537 // 'Bare' statistics >> 538 fSumEnergyKilled += endEnergy; >> 539 if( endEnergy > fMaxEnergyKilled) { fMaxEnergyKilled= endEnergy; } >> 540 >> 541 #ifdef G4VERBOSE >> 542 if( (fVerboseLevel > 1) || >> 543 ( endEnergy > fThreshold_Warning_Energy ) ) { >> 544 G4cout << " G4Transportation is killing track that is looping or stuck " >> 545 << G4endl >> 546 << " This track has " << track.GetKineticEnergy() / MeV >> 547 << " MeV energy." << G4endl; >> 548 G4cout << " Number of trials = " << fNoLooperTrials >> 549 << " No of calls to AlongStepDoIt = " << noCalls >> 550 << G4endl; >> 551 } >> 552 #endif >> 553 fNoLooperTrials=0; 609 } 554 } 610 else << 555 else{ 611 { << 556 fNoLooperTrials ++; 612 fMaxEnergySaved = std::max( endEnergy, << 613 if( fNoLooperTrials == 1 ) { << 614 fSumEnergySaved += endEnergy; << 615 if ( !stable ) << 616 fSumEnergyUnstableSaved += endEne << 617 } << 618 #ifdef G4VERBOSE 557 #ifdef G4VERBOSE 619 if( verboseLevel > 2 && ! fSilenceLoop << 558 if( (fVerboseLevel > 2) ){ 620 { << 559 G4cout << " G4Transportation::AlongStepDoIt(): Particle looping - " 621 G4cout << " " << __func__ << 560 << " Number of trials = " << fNoLooperTrials 622 << " Particle is looping but << 561 << " No of calls to = " << noCalls 623 << " Number of trials = " < << 562 << G4endl; 624 << " No of calls to = " << << 563 } 625 } << 626 #endif 564 #endif 627 } 565 } 628 } << 566 }else{ 629 else << 630 { << 631 fNoLooperTrials=0; 567 fNoLooperTrials=0; 632 } 568 } 633 569 634 // Another (sometimes better way) is to use 570 // Another (sometimes better way) is to use a user-limit maximum Step size 635 // to alleviate this problem .. 571 // to alleviate this problem .. 636 572 637 // Introduce smooth curved trajectories to p 573 // Introduce smooth curved trajectories to particle-change 638 // 574 // 639 fParticleChange.SetPointerToVectorOfAuxiliar 575 fParticleChange.SetPointerToVectorOfAuxiliaryPoints 640 (fFieldPropagator->GimmeTrajectoryVectorAn 576 (fFieldPropagator->GimmeTrajectoryVectorAndForgetIt() ); 641 577 642 return &fParticleChange ; 578 return &fParticleChange ; 643 } 579 } 644 580 645 ////////////////////////////////////////////// 581 ////////////////////////////////////////////////////////////////////////// 646 // 582 // 647 // This ensures that the PostStep action is a 583 // This ensures that the PostStep action is always called, 648 // so that it can do the relocation if it is 584 // so that it can do the relocation if it is needed. 649 // 585 // 650 586 651 G4double G4Transportation:: 587 G4double G4Transportation:: 652 PostStepGetPhysicalInteractionLength( const G4 588 PostStepGetPhysicalInteractionLength( const G4Track&, 653 G4 589 G4double, // previousStepSize 654 G4 590 G4ForceCondition* pForceCond ) 655 { << 591 { 656 fFieldExertedForce = false; // Not known << 657 *pForceCond = Forced ; 592 *pForceCond = Forced ; 658 return DBL_MAX ; // was kInfinity ; but con 593 return DBL_MAX ; // was kInfinity ; but convention now is DBL_MAX 659 } 594 } 660 595 661 ////////////////////////////////////////////// 596 ///////////////////////////////////////////////////////////////////////////// 662 << 663 void G4Transportation::SetTouchableInformation << 664 { << 665 const G4VPhysicalVolume* pNewVol = touchable << 666 const G4Material* pNewMaterial = 0 ; << 667 G4VSensitiveDetector* pNewSensitiveDetector << 668 << 669 if( pNewVol != 0 ) << 670 { << 671 pNewMaterial= pNewVol->GetLogicalVolume()- << 672 pNewSensitiveDetector= pNewVol->GetLogical << 673 } << 674 << 675 fParticleChange.SetMaterialInTouchable( (G4M << 676 fParticleChange.SetSensitiveDetectorInToucha << 677 // temporarily until Get/Set Material of Par << 678 // and StepPoint can be made const. << 679 << 680 const G4MaterialCutsCouple* pNewMaterialCuts << 681 if( pNewVol != 0 ) << 682 { << 683 pNewMaterialCutsCouple=pNewVol->GetLogical << 684 } << 685 << 686 if ( pNewVol!=0 && pNewMaterialCutsCouple!=0 << 687 && pNewMaterialCutsCouple->GetMaterial()!= << 688 { << 689 // for parametrized volume << 690 // << 691 pNewMaterialCutsCouple = << 692 G4ProductionCutsTable::GetProductionCuts << 693 ->GetMaterialCuts << 694 pNewMaterialCut << 695 } << 696 fParticleChange.SetMaterialCutsCoupleInTouch << 697 << 698 // Set the touchable in ParticleChange << 699 // this must always be done because the part << 700 // uses this value to overwrite the current << 701 // << 702 fParticleChange.SetTouchableHandle(touchable << 703 } << 704 << 705 ////////////////////////////////////////////// << 706 // 597 // 707 598 708 G4VParticleChange* G4Transportation::PostStepD 599 G4VParticleChange* G4Transportation::PostStepDoIt( const G4Track& track, 709 600 const G4Step& ) 710 { 601 { 711 G4TouchableHandle retCurrentTouchable ; / << 602 G4TouchableHandle retCurrentTouchable ; // The one to return 712 G4bool isLastStep= false; << 713 603 714 // Initialize ParticleChange (by setting al 604 // Initialize ParticleChange (by setting all its members equal 715 // to correspond 605 // to corresponding members in G4Track) 716 // fParticleChange.Initialize(track) ; // T 606 // fParticleChange.Initialize(track) ; // To initialise TouchableChange 717 607 718 fParticleChange.ProposeTrackStatus(track.Get 608 fParticleChange.ProposeTrackStatus(track.GetTrackStatus()) ; 719 609 720 // If the Step was determined by the volume 610 // If the Step was determined by the volume boundary, 721 // logically relocate the particle 611 // logically relocate the particle 722 << 612 723 if(fGeometryLimitedStep) 613 if(fGeometryLimitedStep) 724 { 614 { 725 // fCurrentTouchable will now become the p 615 // fCurrentTouchable will now become the previous touchable, 726 // and what was the previous will be freed 616 // and what was the previous will be freed. 727 // (Needed because the preStepPoint can po 617 // (Needed because the preStepPoint can point to the previous touchable) 728 618 729 fLinearNavigator->SetGeometricallyLimitedS 619 fLinearNavigator->SetGeometricallyLimitedStep() ; 730 fLinearNavigator-> 620 fLinearNavigator-> 731 LocateGlobalPointAndUpdateTouchableHandle( 621 LocateGlobalPointAndUpdateTouchableHandle( track.GetPosition(), 732 622 track.GetMomentumDirection(), 733 623 fCurrentTouchableHandle, 734 624 true ) ; 735 // Check whether the particle is out of th 625 // Check whether the particle is out of the world volume 736 // If so it has exited and must be killed. 626 // If so it has exited and must be killed. 737 // 627 // 738 if( fCurrentTouchableHandle->GetVolume() = 628 if( fCurrentTouchableHandle->GetVolume() == 0 ) 739 { 629 { 740 fParticleChange.ProposeTrackStatus( fSt 630 fParticleChange.ProposeTrackStatus( fStopAndKill ) ; 741 } 631 } 742 retCurrentTouchable = fCurrentTouchableHan 632 retCurrentTouchable = fCurrentTouchableHandle ; 743 fParticleChange.SetTouchableHandle( fCurre 633 fParticleChange.SetTouchableHandle( fCurrentTouchableHandle ) ; 744 << 745 // Update the Step flag which identifies t << 746 if( !fFieldExertedForce ) << 747 isLastStep = fLinearNavigator->ExitedM << 748 || fLinearNavigator->Entered << 749 else << 750 isLastStep = fFieldPropagator->IsLastSt << 751 } 634 } 752 else // fGeometryLimitedStep 635 else // fGeometryLimitedStep is false 753 { 636 { 754 // This serves only to move the Navigator' 637 // This serves only to move the Navigator's location 755 // 638 // 756 fLinearNavigator->LocateGlobalPointWithinV 639 fLinearNavigator->LocateGlobalPointWithinVolume( track.GetPosition() ) ; 757 640 758 // The value of the track's current Toucha 641 // The value of the track's current Touchable is retained. 759 // (and it must be correct because we must 642 // (and it must be correct because we must use it below to 760 // overwrite the (unset) one in particle c 643 // overwrite the (unset) one in particle change) 761 // It must be fCurrentTouchable too ?? 644 // It must be fCurrentTouchable too ?? 762 // 645 // 763 fParticleChange.SetTouchableHandle( track. 646 fParticleChange.SetTouchableHandle( track.GetTouchableHandle() ) ; 764 retCurrentTouchable = track.GetTouchableHa 647 retCurrentTouchable = track.GetTouchableHandle() ; 765 << 766 isLastStep= false; << 767 } // endif ( fGeometryLimitedStep ) 648 } // endif ( fGeometryLimitedStep ) 768 fLastStepInVolume= isLastStep; << 769 << 770 fParticleChange.ProposeFirstStepInVolume(fFi << 771 fParticleChange.ProposeLastStepInVolume(isLa << 772 649 773 SetTouchableInformation(retCurrentTouchable) << 650 const G4VPhysicalVolume* pNewVol = retCurrentTouchable->GetVolume() ; >> 651 const G4Material* pNewMaterial = 0 ; >> 652 const G4VSensitiveDetector* pNewSensitiveDetector = 0 ; >> 653 >> 654 if( pNewVol != 0 ) >> 655 { >> 656 pNewMaterial= pNewVol->GetLogicalVolume()->GetMaterial(); >> 657 pNewSensitiveDetector= pNewVol->GetLogicalVolume()->GetSensitiveDetector(); >> 658 } >> 659 >> 660 // ( <const_cast> pNewMaterial ) ; >> 661 // ( <const_cast> pNewSensitiveDetector) ; >> 662 >> 663 fParticleChange.SetMaterialInTouchable( (G4Material *) pNewMaterial ) ; >> 664 fParticleChange.SetSensitiveDetectorInTouchable( (G4VSensitiveDetector *) pNewSensitiveDetector ) ; >> 665 >> 666 const G4MaterialCutsCouple* pNewMaterialCutsCouple = 0; >> 667 if( pNewVol != 0 ) >> 668 { >> 669 pNewMaterialCutsCouple=pNewVol->GetLogicalVolume()->GetMaterialCutsCouple(); >> 670 } >> 671 >> 672 if( pNewVol!=0 && pNewMaterialCutsCouple!=0 && pNewMaterialCutsCouple->GetMaterial()!=pNewMaterial ) >> 673 { >> 674 // for parametrized volume >> 675 // >> 676 pNewMaterialCutsCouple = >> 677 G4ProductionCutsTable::GetProductionCutsTable() >> 678 ->GetMaterialCutsCouple(pNewMaterial, >> 679 pNewMaterialCutsCouple->GetProductionCuts()); >> 680 } >> 681 fParticleChange.SetMaterialCutsCoupleInTouchable( pNewMaterialCutsCouple ); >> 682 >> 683 // temporarily until Get/Set Material of ParticleChange, >> 684 // and StepPoint can be made const. >> 685 // Set the touchable in ParticleChange >> 686 // this must always be done because the particle change always >> 687 // uses this value to overwrite the current touchable pointer. >> 688 // >> 689 fParticleChange.SetTouchableHandle(retCurrentTouchable) ; 774 690 775 return &fParticleChange ; 691 return &fParticleChange ; 776 } 692 } 777 693 778 ////////////////////////////////////////////// << 694 // New method takes over the responsibility to reset the state of G4Transportation 779 // New method takes over the responsibility to << 695 // object at the start of a new track or the resumption of a suspended track. 780 // G4Transportation object at the start of a n << 781 // of a suspended track. << 782 // << 783 696 784 void 697 void 785 G4Transportation::StartTracking(G4Track* aTrac 698 G4Transportation::StartTracking(G4Track* aTrack) 786 { 699 { 787 G4VProcess::StartTracking(aTrack); 700 G4VProcess::StartTracking(aTrack); 788 fNewTrack= true; << 789 fFirstStepInVolume= true; << 790 fLastStepInVolume= false; << 791 << 792 // The actions here are those that were take << 793 // when track.GetCurrentStepNumber()==1 << 794 701 795 // Whether field exists should be determined << 702 // The actions here are those that were taken in AlongStepGPIL 796 G4FieldManagerStore* fieldMgrStore= G4FieldM << 703 // when track.GetCurrentStepNumber()==1 797 fAnyFieldExists = fieldMgrStore->size() > 0; << 704 798 << 799 // reset safety value and center 705 // reset safety value and center 800 // 706 // 801 fPreviousSafety = 0.0 ; 707 fPreviousSafety = 0.0 ; 802 fPreviousSftOrigin = G4ThreeVector(0.,0.,0.) 708 fPreviousSftOrigin = G4ThreeVector(0.,0.,0.) ; 803 709 804 // reset looping counter -- for motion in fi 710 // reset looping counter -- for motion in field 805 fNoLooperTrials= 0; 711 fNoLooperTrials= 0; 806 // Must clear this state .. else it depends 712 // Must clear this state .. else it depends on last track's value 807 // --> a better solution would set this fro 713 // --> a better solution would set this from state of suspended track TODO ? 808 // Was if( aTrack->GetCurrentStepNumber()==1 714 // Was if( aTrack->GetCurrentStepNumber()==1 ) { .. } 809 715 810 // ChordFinder reset internal state 716 // ChordFinder reset internal state 811 // 717 // 812 if( fFieldPropagator && fAnyFieldExists ) << 718 if( DoesGlobalFieldExist() ) { 813 { << 814 fFieldPropagator->ClearPropagatorState(); 719 fFieldPropagator->ClearPropagatorState(); 815 // Resets all state of field propagator << 720 // Resets all state of field propagator class (ONLY) 816 // values (in case of overlaps and to w << 721 // including safety values (in case of overlaps and to wipe for first track). >> 722 >> 723 // G4ChordFinder* chordF= fFieldPropagator->GetChordFinder(); >> 724 // if( chordF ) chordF->ResetStepEstimate(); 817 } 725 } 818 726 819 // Make sure to clear the chord finders of a << 727 // Make sure to clear the chord finders of all fields (ie managers) 820 // << 728 static G4FieldManagerStore* fieldMgrStore= G4FieldManagerStore::GetInstance(); 821 fieldMgrStore->ClearAllChordFindersState(); 729 fieldMgrStore->ClearAllChordFindersState(); 822 730 823 // Update the current touchable handle (fro 731 // Update the current touchable handle (from the track's) 824 // 732 // 825 fCurrentTouchableHandle = aTrack->GetTouchab 733 fCurrentTouchableHandle = aTrack->GetTouchableHandle(); 826 << 827 // Inform field propagator of new track << 828 // << 829 fFieldPropagator->PrepareNewTrack(); << 830 } << 831 << 832 ////////////////////////////////////////////// << 833 // << 834 << 835 G4bool G4Transportation::EnableMagneticMoment( << 836 { << 837 G4bool lastValue= fUseMagneticMoment; << 838 fUseMagneticMoment= useMoment; << 839 return lastValue; << 840 } << 841 << 842 ////////////////////////////////////////////// << 843 // << 844 << 845 G4bool G4Transportation::EnableGravity(G4bool << 846 { << 847 G4bool lastValue= fUseGravity; << 848 fUseGravity= useGravity; << 849 return lastValue; << 850 } << 851 << 852 ////////////////////////////////////////////// << 853 // << 854 // Supress (or not) warnings about 'looping' << 855 << 856 void G4Transportation::SetSilenceLooperWarning << 857 { << 858 fSilenceLooperWarnings= val; // Flag to *Su << 859 } << 860 << 861 ////////////////////////////////////////////// << 862 // << 863 G4bool G4Transportation::GetSilenceLooperWarni << 864 { << 865 return fSilenceLooperWarnings; << 866 } << 867 << 868 << 869 ////////////////////////////////////////////// << 870 // << 871 void G4Transportation::SetHighLooperThresholds << 872 { << 873 // Restores the old high values -- potential << 874 // HEP experiments. << 875 // Caution: All tracks with E < 100 MeV tha << 876 SetThresholdWarningEnergy( 100.0 * CLHEP: << 877 SetThresholdImportantEnergy( 250.0 * CLHEP: << 878 << 879 G4int maxTrials = 10; << 880 SetThresholdTrials( maxTrials ); << 881 << 882 PushThresholdsToLogger(); // Again, to be s << 883 if( verboseLevel ) ReportLooperThresholds() << 884 } << 885 << 886 ////////////////////////////////////////////// << 887 void G4Transportation::SetLowLooperThresholds( << 888 { << 889 // These values were the default in Geant4 1 << 890 SetThresholdWarningEnergy( 1.0 * CLHEP:: << 891 SetThresholdImportantEnergy( 1.0 * CLHEP:: << 892 << 893 G4int maxTrials = 30; // A new value - was << 894 SetThresholdTrials( maxTrials ); << 895 << 896 PushThresholdsToLogger(); // Again, to be s << 897 if( verboseLevel ) ReportLooperThresholds() << 898 } 734 } 899 735 900 ////////////////////////////////////////////// << 901 // << 902 void << 903 G4Transportation::ReportMissingLogger( const c << 904 { << 905 const char* message= "Logger object missing << 906 G4String classAndMethod= G4String("G4Transp << 907 G4Exception(classAndMethod, "Missing Logger << 908 } << 909 << 910 << 911 ////////////////////////////////////////////// << 912 // << 913 void << 914 G4Transportation::ReportLooperThresholds() << 915 { << 916 PushThresholdsToLogger(); // To be absolut << 917 fpLogger->ReportLooperThresholds("G4Transpo << 918 } << 919 << 920 ////////////////////////////////////////////// << 921 // << 922 void G4Transportation::ProcessDescription(std: << 923 << 924 // StreamInfo(std::ostream& out, const G4Parti << 925 << 926 { << 927 G4String indent = " "; // : ""); << 928 G4long oldPrec= outStr.precision(6); << 929 // outStr << std::setprecision(6); << 930 outStr << G4endl << indent << GetProcessName << 931 << 932 outStr << " Parameters for looping particl << 933 << " warning-E = " << fThreshold_ << 934 << " important E = " << fThreshol << 935 << " thresholdTrials " << fThresh << 936 outStr.precision(oldPrec); << 937 } << 938 736