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