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