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