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 // class G4PropagatorInField Implementation << 26 // >> 27 // 27 // 28 // 28 // This class implements an algorithm to trac 29 // This class implements an algorithm to track a particle in a 29 // non-uniform magnetic field. It utilises an 30 // non-uniform magnetic field. It utilises an ODE solver (with 30 // the Runge - Kutta method) to evolve the pa 31 // the Runge - Kutta method) to evolve the particle, and drives it 31 // until the particle has traveled a set dist 32 // until the particle has traveled a set distance or it enters a new 32 // volume. 33 // volume. 33 // 34 // 34 // 14.10.96 John Apostolakis, design and imple << 35 // 14.10.96 John Apostolakis, design and implementation 35 // 17.03.97 John Apostolakis, renaming new set << 36 // 17.03.97 John Apostolakis, renaming new set functions being added >> 37 // >> 38 // $Id$ >> 39 // GEANT4 tag $ Name: $ 36 // ------------------------------------------- 40 // --------------------------------------------------------------------------- 37 41 38 #include <iomanip> 42 #include <iomanip> 39 43 40 #include "G4PropagatorInField.hh" 44 #include "G4PropagatorInField.hh" 41 #include "G4ios.hh" 45 #include "G4ios.hh" 42 #include "G4SystemOfUnits.hh" 46 #include "G4SystemOfUnits.hh" 43 #include "G4ThreeVector.hh" 47 #include "G4ThreeVector.hh" 44 #include "G4Material.hh" << 45 #include "G4VPhysicalVolume.hh" 48 #include "G4VPhysicalVolume.hh" 46 #include "G4Navigator.hh" 49 #include "G4Navigator.hh" 47 #include "G4GeometryTolerance.hh" 50 #include "G4GeometryTolerance.hh" 48 #include "G4VCurvedTrajectoryFilter.hh" 51 #include "G4VCurvedTrajectoryFilter.hh" 49 #include "G4ChordFinder.hh" 52 #include "G4ChordFinder.hh" 50 #include "G4MultiLevelLocator.hh" 53 #include "G4MultiLevelLocator.hh" 51 54 52 << 55 /////////////////////////////////////////////////////////////////////////// 53 // ------------------------------------------- << 54 // Constructors and destructor << 55 // 56 // 56 G4PropagatorInField::G4PropagatorInField( G4Na << 57 // Constructors and destructor 57 G4Fi << 58 58 G4VI << 59 G4PropagatorInField::G4PropagatorInField( G4Navigator *theNavigator, 59 : fDetectorFieldMgr(detectorFieldMgr), << 60 G4FieldManager *detectorFieldMgr, >> 61 G4VIntersectionLocator *vLocator ) >> 62 : >> 63 fMax_loop_count(1000), >> 64 fUseSafetyForOptimisation(true), // (false) is less sensitive to incorrect safety >> 65 fZeroStepThreshold( 0.0 ), // length of what is recognised as 'zero' step >> 66 fDetectorFieldMgr(detectorFieldMgr), >> 67 fpTrajectoryFilter( 0 ), 60 fNavigator(theNavigator), 68 fNavigator(theNavigator), 61 fCurrentFieldMgr(detectorFieldMgr), 69 fCurrentFieldMgr(detectorFieldMgr), >> 70 fSetFieldMgr(false), >> 71 fCharge(0.0), fInitialMomentumModulus(0.0), fMass(0.0), 62 End_PointAndTangent(G4ThreeVector(0.,0.,0. 72 End_PointAndTangent(G4ThreeVector(0.,0.,0.), 63 G4ThreeVector(0.,0.,0. << 73 G4ThreeVector(0.,0.,0.),0.0,0.0,0.0,0.0,0.0), 64 { << 74 fParticleIsLooping(false), 65 fEpsilonStep = (fDetectorFieldMgr != nullptr << 75 fNoZeroStep(0), 66 ? fDetectorFieldMgr->GetMaximum << 76 fVerboseLevel(0) 67 << 77 { >> 78 if(fDetectorFieldMgr) { fEpsilonStep = fDetectorFieldMgr->GetMaximumEpsilonStep();} >> 79 else { fEpsilonStep= 1.0e-5; } >> 80 fActionThreshold_NoZeroSteps = 2; >> 81 fSevereActionThreshold_NoZeroSteps = 10; >> 82 fAbandonThreshold_NoZeroSteps = 50; >> 83 fFull_CurveLen_of_LastAttempt = -1; >> 84 fLast_ProposedStepLength = -1; >> 85 fLargestAcceptableStep = 1000.0 * meter; 68 86 69 fPreviousSftOrigin = G4ThreeVector(0.,0.,0.) << 87 fPreviousSftOrigin= G4ThreeVector(0.,0.,0.); >> 88 fPreviousSafety= 0.0; 70 kCarTolerance = G4GeometryTolerance::GetInst 89 kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); 71 fZeroStepThreshold = std::max( 1.0e5 * kCarT << 90 fZeroStepThreshold= std::max( 1.0e5 * kCarTolerance, 1.0e-1 * micrometer ); 72 91 73 fLargestAcceptableStep = 100.0 * meter; // << 74 fMaxStepSizeMultiplier= 0.1 ; // 0.1 in << 75 fMinBigDistance= 100. * CLHEP::mm; << 76 #ifdef G4DEBUG_FIELD 92 #ifdef G4DEBUG_FIELD 77 G4cout << " PiF: Zero Step Threshold set to 93 G4cout << " PiF: Zero Step Threshold set to " 78 << fZeroStepThreshold / millimeter 94 << fZeroStepThreshold / millimeter 79 << " mm." << G4endl; << 95 << " mm." << G4endl; 80 G4cout << " PiF: Value of kCarTolerance = 96 G4cout << " PiF: Value of kCarTolerance = " 81 << kCarTolerance / millimeter 97 << kCarTolerance / millimeter 82 << " mm. " << G4endl; << 98 << " mm. " << G4endl; 83 fVerboseLevel = 2; << 84 fVerbTracePiF = true; << 85 #endif 99 #endif 86 100 87 // Defining Intersection Locator and his par << 101 // Definding Intersection Locator and his parameters 88 if ( vLocator == nullptr ) << 102 if(vLocator==0){ 89 { << 103 fIntersectionLocator= new G4MultiLevelLocator(theNavigator); 90 fIntersectionLocator = new G4MultiLevelLoc << 104 fAllocatedLocator=true; 91 fAllocatedLocator = true; << 105 }else{ >> 106 fIntersectionLocator=vLocator; >> 107 fAllocatedLocator=false; 92 } 108 } 93 else << 109 RefreshIntersectionLocator(); // Copy all relevant parameters 94 { << 95 fIntersectionLocator = vLocator; << 96 fAllocatedLocator = false; << 97 } << 98 RefreshIntersectionLocator(); // Copy all << 99 } 110 } 100 111 101 // ------------------------------------------- << 102 // << 103 G4PropagatorInField::~G4PropagatorInField() 112 G4PropagatorInField::~G4PropagatorInField() 104 { 113 { 105 if(fAllocatedLocator) { delete fIntersecti << 114 if(fAllocatedLocator)delete fIntersectionLocator; 106 } 115 } 107 116 108 // ------------------------------------------- << 109 // Update the IntersectionLocator with current 117 // Update the IntersectionLocator with current parameters 110 // << 118 void 111 void G4PropagatorInField::RefreshIntersectionL << 119 G4PropagatorInField::RefreshIntersectionLocator() 112 { 120 { 113 fIntersectionLocator->SetEpsilonStepFor(fEps 121 fIntersectionLocator->SetEpsilonStepFor(fEpsilonStep); 114 fIntersectionLocator->SetDeltaIntersectionFo 122 fIntersectionLocator->SetDeltaIntersectionFor(fCurrentFieldMgr->GetDeltaIntersection()); 115 fIntersectionLocator->SetChordFinderFor(GetC 123 fIntersectionLocator->SetChordFinderFor(GetChordFinder()); 116 fIntersectionLocator->SetSafetyParametersFor 124 fIntersectionLocator->SetSafetyParametersFor( fUseSafetyForOptimisation); 117 } 125 } 118 << 126 /////////////////////////////////////////////////////////////////////////// 119 // ------------------------------------------- << 120 // Compute the next geometric Step << 121 // 127 // 122 G4double G4PropagatorInField::ComputeStep( << 128 // Compute the next geometric Step >> 129 >> 130 G4double >> 131 G4PropagatorInField::ComputeStep( 123 G4FieldTrack& pFieldTrack 132 G4FieldTrack& pFieldTrack, 124 G4double CurrentProp 133 G4double CurrentProposedStepLength, 125 G4double& currentSafe 134 G4double& currentSafety, // IN/OUT 126 G4VPhysicalVolume* pPhysVol, << 135 G4VPhysicalVolume* pPhysVol) 127 G4bool canRelaxDel << 128 { 136 { 129 GetChordFinder()->OnComputeStep(&pFieldTrack << 130 const G4double deltaChord = GetChordFinder() << 131 << 132 // If CurrentProposedStepLength is too small 137 // If CurrentProposedStepLength is too small for finding Chords 133 // then return with no action (for now - TOD 138 // then return with no action (for now - TODO: some action) 134 // 139 // 135 const char* methodName = "G4PropagatorInFiel << 140 if(CurrentProposedStepLength<kCarTolerance) 136 if (CurrentProposedStepLength<kCarTolerance) << 137 { 141 { 138 return kInfinity; 142 return kInfinity; 139 } 143 } 140 144 141 // Introducing smooth trajectory display (ja 145 // Introducing smooth trajectory display (jacek 01/11/2002) 142 // 146 // 143 if (fpTrajectoryFilter != nullptr) << 147 if (fpTrajectoryFilter) 144 { 148 { 145 fpTrajectoryFilter->CreateNewTrajectorySeg 149 fpTrajectoryFilter->CreateNewTrajectorySegment(); 146 } 150 } 147 151 148 fFirstStepInVolume = fNewTrack ? true : fLas << 149 fLastStepInVolume = false; << 150 fNewTrack = false; << 151 << 152 if( fVerboseLevel > 2 ) << 153 { << 154 G4cout << methodName << " called" << G4end << 155 G4cout << " Starting FT: " << pFieldTrac << 156 G4cout << " Requested length = " << Curr << 157 G4cout << " PhysVol = "; << 158 if( pPhysVol != nullptr ) << 159 { << 160 G4cout << pPhysVol->GetName() << G4endl << 161 } << 162 else << 163 { << 164 G4cout << " N/A "; << 165 } << 166 G4cout << G4endl; << 167 } << 168 << 169 // Parameters for adaptive Runge-Kutta integ 152 // Parameters for adaptive Runge-Kutta integration 170 153 171 G4double h_TrialStepSize; // 1st Step << 154 G4double h_TrialStepSize; // 1st Step Size 172 G4double TruePathLength = CurrentProposedSte << 155 G4double TruePathLength = CurrentProposedStepLength; 173 G4double StepTaken = 0.0; << 156 G4double StepTaken = 0.0; 174 G4double s_length_taken, epsilon; << 157 G4double s_length_taken, epsilon ; 175 G4bool intersects; << 158 G4bool intersects; 176 G4bool first_substep = true; << 159 G4bool first_substep = true; 177 160 178 G4double NewSafety; << 161 G4double NewSafety; 179 fParticleIsLooping = false; 162 fParticleIsLooping = false; 180 163 181 // If not yet done, 164 // If not yet done, 182 // Set the field manager to the local one 165 // Set the field manager to the local one if the volume has one, 183 // or to the global one 166 // or to the global one if not 184 // 167 // 185 if( !fSetFieldMgr ) << 168 if( !fSetFieldMgr ) fCurrentFieldMgr= FindAndSetFieldManager( pPhysVol ); 186 { << 169 // For the next call, the field manager must again be set 187 fCurrentFieldMgr = FindAndSetFieldManager( << 170 fSetFieldMgr= false; 188 } << 171 189 fSetFieldMgr = false; // For next call, the << 172 GetChordFinder()->SetChargeMomentumMass(fCharge,fInitialMomentumModulus,fMass); >> 173 >> 174 // Values for Intersection Locator has to be updated on each call for the >> 175 // case that CurrentFieldManager has changed from the one of previous step >> 176 RefreshIntersectionLocator(); 190 177 191 G4FieldTrack CurrentState(pFieldTrack); << 178 G4FieldTrack CurrentState(pFieldTrack); 192 G4FieldTrack OriginalState = CurrentState; << 179 G4FieldTrack OriginalState = CurrentState; 193 180 194 // If the Step length is "infinite", then an 181 // If the Step length is "infinite", then an approximate-maximum Step 195 // length (used to calculate the relative ac << 182 // length (used to calculate the relative accuracy) must be guessed. 196 // 183 // 197 if( CurrentProposedStepLength >= fLargestAcc 184 if( CurrentProposedStepLength >= fLargestAcceptableStep ) 198 { 185 { 199 G4ThreeVector StartPointA, VelocityUnit; 186 G4ThreeVector StartPointA, VelocityUnit; 200 StartPointA = pFieldTrack.GetPosition(); 187 StartPointA = pFieldTrack.GetPosition(); 201 VelocityUnit = pFieldTrack.GetMomentumDir( 188 VelocityUnit = pFieldTrack.GetMomentumDir(); 202 189 203 G4double trialProposedStep = fMaxStepSizeM << 190 G4double trialProposedStep = 1.e2 * ( 10.0 * cm + 204 fNavigator->GetWorldVolume()->GetLogical 191 fNavigator->GetWorldVolume()->GetLogicalVolume()-> 205 GetSolid()->DistanceToOut(St 192 GetSolid()->DistanceToOut(StartPointA, VelocityUnit) ); 206 CurrentProposedStepLength = std::min( tria << 193 CurrentProposedStepLength= std::min( trialProposedStep, 207 fLar << 194 fLargestAcceptableStep ); 208 } 195 } 209 epsilon = fCurrentFieldMgr->GetDeltaOneStep( 196 epsilon = fCurrentFieldMgr->GetDeltaOneStep() / CurrentProposedStepLength; >> 197 // G4double raw_epsilon= epsilon; 210 G4double epsilonMin= fCurrentFieldMgr->GetMi 198 G4double epsilonMin= fCurrentFieldMgr->GetMinimumEpsilonStep(); 211 G4double epsilonMax= fCurrentFieldMgr->GetMa << 199 G4double epsilonMax= fCurrentFieldMgr->GetMaximumEpsilonStep();; 212 if( epsilon < epsilonMin ) { epsilon = epsi << 200 if( epsilon < epsilonMin ) epsilon = epsilonMin; 213 if( epsilon > epsilonMax ) { epsilon = epsi << 201 if( epsilon > epsilonMax ) epsilon = epsilonMax; 214 SetEpsilonStep( epsilon ); 202 SetEpsilonStep( epsilon ); 215 203 216 // Values for Intersection Locator has to be << 204 // G4cout << "G4PiF: Epsilon of current step - raw= " << raw_epsilon 217 // case that CurrentFieldManager has changed << 205 // << " final= " << epsilon << G4endl; 218 // << 219 RefreshIntersectionLocator(); << 220 206 221 // Shorten the proposed step in case of earl << 207 // Shorten the proposed step in case of earlier problems (zero steps) 222 // 208 // 223 if( fNoZeroStep > fActionThreshold_NoZeroSte 209 if( fNoZeroStep > fActionThreshold_NoZeroSteps ) 224 { 210 { 225 G4double stepTrial; 211 G4double stepTrial; 226 212 227 stepTrial = fFull_CurveLen_of_LastAttempt; << 213 stepTrial= fFull_CurveLen_of_LastAttempt; 228 if( (stepTrial <= 0.0) && (fLast_ProposedS << 214 if( (stepTrial <= 0.0) && (fLast_ProposedStepLength > 0.0) ) 229 { << 215 stepTrial= fLast_ProposedStepLength; 230 stepTrial = fLast_ProposedStepLength; << 231 } << 232 216 233 G4double decreaseFactor = 0.9; // Unused d 217 G4double decreaseFactor = 0.9; // Unused default 234 if( (fNoZeroStep < fSevereActionThreshol 218 if( (fNoZeroStep < fSevereActionThreshold_NoZeroSteps) 235 && (stepTrial > 100.0*fZeroStepThreshol 219 && (stepTrial > 100.0*fZeroStepThreshold) ) 236 { 220 { 237 // Attempt quick convergence 221 // Attempt quick convergence 238 // 222 // 239 decreaseFactor= 0.25; 223 decreaseFactor= 0.25; 240 } 224 } 241 else 225 else 242 { 226 { 243 // We are in significant difficulties, p 227 // We are in significant difficulties, probably at a boundary that 244 // is either geometrically sharp or betw 228 // is either geometrically sharp or between very different materials. 245 // Careful decreases to cope with tolera << 229 // Careful decreases to cope with tolerance are required. 246 // 230 // 247 if( stepTrial > 100.0*fZeroStepThreshold << 231 if( stepTrial > 100.0*fZeroStepThreshold ) 248 decreaseFactor = 0.35; // Try decr 232 decreaseFactor = 0.35; // Try decreasing slower 249 } else if( stepTrial > 30.0*fZeroStepThr << 233 else if( stepTrial > 30.0*fZeroStepThreshold ) 250 decreaseFactor= 0.5; // Try yet 234 decreaseFactor= 0.5; // Try yet slower decrease 251 } else if( stepTrial > 10.0*fZeroStepThr << 235 else if( stepTrial > 10.0*fZeroStepThreshold ) 252 decreaseFactor= 0.75; // Try even 236 decreaseFactor= 0.75; // Try even slower decreases 253 } else { << 237 else 254 decreaseFactor= 0.9; // Try very 238 decreaseFactor= 0.9; // Try very slow decreases 255 } << 256 } 239 } 257 stepTrial *= decreaseFactor; 240 stepTrial *= decreaseFactor; 258 241 259 #ifdef G4DEBUG_FIELD 242 #ifdef G4DEBUG_FIELD 260 if( fVerboseLevel > 2 << 243 G4cout << " G4PropagatorInField::ComputeStep(): " << G4endl 261 || (fNoZeroStep >= fSevereActionThreshol << 244 << " Decreasing step - " 262 { << 245 << " decreaseFactor= " << std::setw(8) << decreaseFactor 263 G4cerr << " " << methodName << 246 << " stepTrial = " << std::setw(18) << stepTrial << " " 264 << " Decreasing step after " < << 247 << " fZeroStepThreshold = " << fZeroStepThreshold << G4endl; 265 << " - in volume " << pPhysVol; << 248 PrintStepLengthDiagnostic(CurrentProposedStepLength, decreaseFactor, 266 if( pPhysVol ) << 249 stepTrial, pFieldTrack); 267 G4cerr << " with name " << pPhysVol << 268 else << 269 G4cerr << " i.e. *unknown* volume." << 270 G4cerr << G4endl; << 271 PrintStepLengthDiagnostic(CurrentPropo << 272 stepTrial, p << 273 } << 274 #endif 250 #endif 275 if( stepTrial == 0.0 ) // Change to mak 251 if( stepTrial == 0.0 ) // Change to make it < 0.1 * kCarTolerance ?? 276 { 252 { 277 std::ostringstream message; 253 std::ostringstream message; 278 message << "Particle abandoned due to l 254 message << "Particle abandoned due to lack of progress in field." 279 << G4endl 255 << G4endl 280 << " Properties : " << pFieldT 256 << " Properties : " << pFieldTrack << G4endl 281 << " Attempting a zero step = 257 << " Attempting a zero step = " << stepTrial << G4endl 282 << " while attempting to progr 258 << " while attempting to progress after " << fNoZeroStep 283 << " trial steps. Will abandon 259 << " trial steps. Will abandon step."; 284 G4Exception(methodName, "GeomNav1002", << 260 G4Exception("G4PropagatorInField::ComputeStep()", "GeomNav1002", 285 fParticleIsLooping = true; << 261 JustWarning, message); >> 262 fParticleIsLooping= true; 286 return 0; // = stepTrial; 263 return 0; // = stepTrial; 287 } 264 } 288 if( stepTrial < CurrentProposedStepLength 265 if( stepTrial < CurrentProposedStepLength ) 289 { << 290 CurrentProposedStepLength = stepTrial; 266 CurrentProposedStepLength = stepTrial; 291 } << 292 } 267 } 293 fLast_ProposedStepLength = CurrentProposedSt 268 fLast_ProposedStepLength = CurrentProposedStepLength; 294 269 295 G4int do_loop_count = 0; 270 G4int do_loop_count = 0; 296 do // Loop checking, 07.10.2016, JA << 271 do 297 { 272 { 298 G4FieldTrack SubStepStartState = CurrentSt 273 G4FieldTrack SubStepStartState = CurrentState; 299 G4ThreeVector SubStartPoint = CurrentState 274 G4ThreeVector SubStartPoint = CurrentState.GetPosition(); 300 << 275 301 if(!first_substep) << 276 if( !first_substep) { 302 { << 303 if( fVerboseLevel > 4 ) << 304 { << 305 G4cout << " PiF: Calling Nav/Locate Gl << 306 << G4endl; << 307 } << 308 fNavigator->LocateGlobalPointWithinVolum 277 fNavigator->LocateGlobalPointWithinVolume( SubStartPoint ); 309 } 278 } 310 279 311 // How far to attempt to move the particle 280 // How far to attempt to move the particle ! 312 // 281 // 313 h_TrialStepSize = CurrentProposedStepLengt 282 h_TrialStepSize = CurrentProposedStepLength - StepTaken; 314 283 315 if (canRelaxDeltaChord && << 316 fIncreaseChordDistanceThreshold > 0 & << 317 do_loop_count > fIncreaseChordDistance << 318 do_loop_count % fIncreaseChordDistance << 319 { << 320 GetChordFinder()->SetDeltaChord( << 321 GetChordFinder()->GetDeltaChord() * << 322 ); << 323 } << 324 << 325 // Integrate as far as "chord miss" rule a 284 // Integrate as far as "chord miss" rule allows. 326 // 285 // 327 s_length_taken = GetChordFinder()->Advance 286 s_length_taken = GetChordFinder()->AdvanceChordLimited( 328 CurrentState, 287 CurrentState, // Position & velocity 329 h_TrialStepSize, 288 h_TrialStepSize, 330 fEpsilonStep, 289 fEpsilonStep, 331 fPreviousSftOrigi 290 fPreviousSftOrigin, 332 fPreviousSafety ) << 291 fPreviousSafety 333 // CurrentState is now updated with the << 292 ); >> 293 // CurrentState is now updated with the final position and velocity. 334 294 335 fFull_CurveLen_of_LastAttempt = s_length_t 295 fFull_CurveLen_of_LastAttempt = s_length_taken; 336 296 337 G4ThreeVector EndPointB = CurrentState.Get << 297 G4ThreeVector EndPointB = CurrentState.GetPosition(); 338 G4ThreeVector InterSectionPointE; << 298 G4ThreeVector InterSectionPointE; 339 G4double LinearStepLength; << 299 G4double LinearStepLength; 340 300 341 // Intersect chord AB with geometry 301 // Intersect chord AB with geometry 342 // << 343 intersects= IntersectChord( SubStartPoint, 302 intersects= IntersectChord( SubStartPoint, EndPointB, 344 NewSafety, Lin << 303 NewSafety, LinearStepLength, 345 InterSectionPo 304 InterSectionPointE ); 346 // E <- Intersection Point of chord AB a << 305 // E <- Intersection Point of chord AB and either volume A's surface 347 // or a << 306 // or a daughter volume's surface .. 348 307 349 if( first_substep ) << 308 if( first_substep ) { 350 { << 351 currentSafety = NewSafety; 309 currentSafety = NewSafety; 352 } // Updating safety in other steps is pot 310 } // Updating safety in other steps is potential future extention 353 311 354 if( intersects ) 312 if( intersects ) 355 { 313 { 356 G4FieldTrack IntersectPointVelct_G(Curr 314 G4FieldTrack IntersectPointVelct_G(CurrentState); // FT-Def-Construct 357 315 358 // Find the intersection point of AB tr 316 // Find the intersection point of AB true path with the surface 359 // of vol(A), if it exists. Start wit 317 // of vol(A), if it exists. Start with point E as first "estimate". 360 G4bool recalculatedEndPt = false; << 318 G4bool recalculatedEndPt= false; 361 319 362 G4bool found_intersection = fIntersecti << 320 G4bool found_intersection = fIntersectionLocator-> 363 EstimateIntersectionPoint( SubStepSta 321 EstimateIntersectionPoint( SubStepStartState, CurrentState, 364 InterSecti << 322 InterSectionPointE, IntersectPointVelct_G, 365 recalculat << 323 recalculatedEndPt,fPreviousSafety,fPreviousSftOrigin); 366 fPreviousS << 324 intersects = intersects && found_intersection; 367 intersects = found_intersection; << 325 if( found_intersection ) { 368 if( found_intersection ) << 369 { << 370 End_PointAndTangent= IntersectPointV 326 End_PointAndTangent= IntersectPointVelct_G; // G is our EndPoint ... 371 StepTaken = TruePathLength = Interse 327 StepTaken = TruePathLength = IntersectPointVelct_G.GetCurveLength() 372 - Origina << 328 - OriginalState.GetCurveLength(); 373 } << 329 } else { 374 else << 330 // intersects= false; // "Minor" chords do not intersect 375 { << 331 if( recalculatedEndPt ){ 376 // Either "minor" chords do not inte << 332 CurrentState= IntersectPointVelct_G; 377 // or else stopped (due to too many << 378 // << 379 if( recalculatedEndPt ) << 380 { << 381 G4double endAchieved = IntersectP << 382 G4double endExpected = CurrentSta << 383 << 384 // Detect failure - due to too ma << 385 G4bool shortEnd = endAchieved << 386 < (endExpected*(1 << 387 << 388 G4double stepAchieved = endAchiev << 389 - SubStepSt << 390 << 391 // Update remaining state - must << 392 // abandonned intersection << 393 // << 394 CurrentState = IntersectPointVelc << 395 s_length_taken = stepAchieved; << 396 if( shortEnd ) << 397 { << 398 fParticleIsLooping = true; << 399 } << 400 } 333 } 401 } 334 } 402 } 335 } 403 if( !intersects ) 336 if( !intersects ) 404 { 337 { 405 StepTaken += s_length_taken; << 338 StepTaken += s_length_taken; 406 << 339 // For smooth trajectory display (jacek 01/11/2002) 407 if (fpTrajectoryFilter != nullptr) // Fo << 340 if (fpTrajectoryFilter) { 408 { << 409 fpTrajectoryFilter->TakeIntermediatePo 341 fpTrajectoryFilter->TakeIntermediatePoint(CurrentState.GetPosition()); 410 } 342 } 411 } 343 } 412 first_substep = false; 344 first_substep = false; 413 345 414 #ifdef G4DEBUG_FIELD 346 #ifdef G4DEBUG_FIELD 415 if( fNoZeroStep > fActionThreshold_NoZeroS << 347 if( fNoZeroStep > fActionThreshold_NoZeroSteps ) { 416 { << 417 if( fNoZeroStep > fSevereActionThreshold << 418 G4cout << " Above 'Severe Action' thre << 419 else << 420 G4cout << " Above 'action' threshold - << 421 G4cout << " Number of zero steps = " << << 422 printStatus( SubStepStartState, // or O 348 printStatus( SubStepStartState, // or OriginalState, 423 CurrentState, CurrentPropos << 349 CurrentState, CurrentProposedStepLength, 424 NewSafety, do_loop_count, p << 350 NewSafety, do_loop_count, pPhysVol ); 425 } 351 } 426 if( (fVerboseLevel > 1) && (do_loop_count << 352 if( (fVerboseLevel > 1) && (do_loop_count > fMax_loop_count-10 )) { 427 { << 353 if( do_loop_count == fMax_loop_count-9 ){ 428 if( do_loop_count == fMax_loop_count-9 ) << 429 { << 430 G4cout << " G4PropagatorInField::Compu 354 G4cout << " G4PropagatorInField::ComputeStep(): " << G4endl 431 << " Difficult track - taking 355 << " Difficult track - taking many sub steps." << G4endl; 432 printStatus( SubStepStartState, SubSte << 433 NewSafety, 0, pPhysVol ); << 434 } 356 } 435 printStatus( SubStepStartState, CurrentS 357 printStatus( SubStepStartState, CurrentState, CurrentProposedStepLength, 436 NewSafety, do_loop_count, p 358 NewSafety, do_loop_count, pPhysVol ); 437 } 359 } 438 #endif 360 #endif 439 361 440 ++do_loop_count; << 362 do_loop_count++; 441 363 442 } while( (!intersects ) 364 } while( (!intersects ) 443 && (!fParticleIsLooping) << 444 && (StepTaken + kCarTolerance < Curren 365 && (StepTaken + kCarTolerance < CurrentProposedStepLength) 445 && ( do_loop_count < fMax_loop_count ) 366 && ( do_loop_count < fMax_loop_count ) ); 446 367 447 if( do_loop_count >= fMax_loop_count << 368 if( do_loop_count >= fMax_loop_count ) 448 && (StepTaken + kCarTolerance < CurrentPro << 449 { 369 { 450 fParticleIsLooping = true; 370 fParticleIsLooping = true; >> 371 >> 372 if ( fVerboseLevel > 0 ) >> 373 { >> 374 G4cout << " G4PropagateInField::ComputeStep(): " << G4endl >> 375 << " Killing looping particle " >> 376 // << " of " << energy << " energy " >> 377 << " after " << do_loop_count << " field substeps " >> 378 << " totaling " << StepTaken / mm << " mm " ; >> 379 if( pPhysVol ) >> 380 G4cout << " in volume " << pPhysVol->GetName() ; >> 381 else >> 382 G4cout << " in unknown or null volume. " ; >> 383 G4cout << G4endl; >> 384 } 451 } 385 } 452 if ( ( fParticleIsLooping ) && (fVerboseLeve << 386 453 { << 454 ReportLoopingParticle( do_loop_count, Step << 455 CurrentProposedStep << 456 CurrentState.GetMom << 457 } << 458 << 459 if( !intersects ) 387 if( !intersects ) 460 { 388 { 461 // Chord AB or "minor chords" do not inter 389 // Chord AB or "minor chords" do not intersect 462 // B is the endpoint Step of the current S 390 // B is the endpoint Step of the current Step. 463 // 391 // 464 End_PointAndTangent = CurrentState; 392 End_PointAndTangent = CurrentState; 465 TruePathLength = StepTaken; // Original << 393 TruePathLength = StepTaken; 466 << 467 // Tried the following to avoid potential << 468 // - but has issues... Suppressing this ch << 469 // TruePathLength = CurrentProposedStepLen << 470 } 394 } 471 fLastStepInVolume = intersects; << 472 395 473 // Set pFieldTrack to the return value 396 // Set pFieldTrack to the return value 474 // 397 // 475 pFieldTrack = End_PointAndTangent; 398 pFieldTrack = End_PointAndTangent; 476 399 477 #ifdef G4VERBOSE 400 #ifdef G4VERBOSE 478 // Check that "s" is correct 401 // Check that "s" is correct 479 // 402 // 480 if( std::fabs(OriginalState.GetCurveLength() 403 if( std::fabs(OriginalState.GetCurveLength() + TruePathLength 481 - End_PointAndTangent.GetCurveLength()) 404 - End_PointAndTangent.GetCurveLength()) > 3.e-4 * TruePathLength ) 482 { 405 { 483 std::ostringstream message; 406 std::ostringstream message; 484 message << "Curve length mis-match between 407 message << "Curve length mis-match between original state " 485 << "and proposed endpoint of propa 408 << "and proposed endpoint of propagation." << G4endl 486 << " The curve length of the endp 409 << " The curve length of the endpoint should be: " 487 << OriginalState.GetCurveLength() 410 << OriginalState.GetCurveLength() + TruePathLength << G4endl 488 << " and it is instead: " 411 << " and it is instead: " 489 << End_PointAndTangent.GetCurveLen 412 << End_PointAndTangent.GetCurveLength() << "." << G4endl 490 << " A difference of: " 413 << " A difference of: " 491 << OriginalState.GetCurveLength() 414 << OriginalState.GetCurveLength() + TruePathLength 492 - End_PointAndTangent.GetCurveL 415 - End_PointAndTangent.GetCurveLength() << G4endl 493 << " Original state = " << Origin 416 << " Original state = " << OriginalState << G4endl 494 << " Proposed state = " << End_Po 417 << " Proposed state = " << End_PointAndTangent; 495 G4Exception(methodName, "GeomNav0003", Fat << 418 G4Exception("G4PropagatorInField::ComputeStep()", >> 419 "GeomNav0003", FatalException, message); 496 } 420 } 497 #endif 421 #endif 498 422 499 if( TruePathLength+kCarTolerance >= CurrentP << 423 // In particular anomalous cases, we can get repeated zero steps >> 424 // In order to correct this efficiently, we identify these cases >> 425 // and only take corrective action when they occur. >> 426 // >> 427 if( ( (TruePathLength < fZeroStepThreshold) >> 428 && ( TruePathLength+kCarTolerance < CurrentProposedStepLength ) >> 429 ) >> 430 || ( TruePathLength < 0.5*kCarTolerance ) >> 431 ) 500 { 432 { 501 fNoZeroStep = 0; << 433 fNoZeroStep++; 502 } 434 } 503 else << 435 else{ 504 { << 436 fNoZeroStep = 0; 505 // In particular anomalous cases, we can << 506 // We identify these cases and take corre << 507 // << 508 if( TruePathLength < std::max( fZeroStepT << 509 { << 510 ++fNoZeroStep; << 511 } << 512 else << 513 { << 514 fNoZeroStep = 0; << 515 } << 516 } 437 } >> 438 517 if( fNoZeroStep > fAbandonThreshold_NoZeroSt 439 if( fNoZeroStep > fAbandonThreshold_NoZeroSteps ) 518 { 440 { 519 fParticleIsLooping = true; 441 fParticleIsLooping = true; 520 ReportStuckParticle( fNoZeroStep, Current << 442 std::ostringstream message; 521 fFull_CurveLen_of_La << 443 message << "Particle is stuck; it will be killed." << G4endl >> 444 << " Zero progress for " << fNoZeroStep << " attempted steps." >> 445 << G4endl >> 446 << " Proposed Step is " << CurrentProposedStepLength >> 447 << " but Step Taken is "<< fFull_CurveLen_of_LastAttempt << G4endl >> 448 << " For Particle with Charge = " << fCharge >> 449 << " Momentum = "<< fInitialMomentumModulus >> 450 << " Mass = " << fMass << G4endl; >> 451 if( pPhysVol ) >> 452 message << " in volume " << pPhysVol->GetName() ; >> 453 else >> 454 message << " in unknown or null volume. " ; >> 455 G4Exception("G4PropagatorInField::ComputeStep()", >> 456 "GeomNav1002", JustWarning, message); 522 fNoZeroStep = 0; 457 fNoZeroStep = 0; 523 } 458 } 524 459 525 GetChordFinder()->SetDeltaChord(deltaChord); << 526 return TruePathLength; 460 return TruePathLength; 527 } 461 } 528 462 529 // ------------------------------------------- << 463 /////////////////////////////////////////////////////////////////////////// 530 // Dumps status of propagator << 531 // 464 // >> 465 // Dumps status of propagator. >> 466 532 void 467 void 533 G4PropagatorInField::printStatus( const G4Fiel << 468 G4PropagatorInField::printStatus( const G4FieldTrack& StartFT, 534 const G4Fiel << 469 const G4FieldTrack& CurrentFT, 535 G4doub << 470 G4double requestStep, 536 G4doub << 471 G4double safety, 537 G4int << 472 G4int stepNo, 538 G4VPhy << 473 G4VPhysicalVolume* startVolume) 539 { 474 { 540 const G4int verboseLevel = fVerboseLevel; << 475 const G4int verboseLevel=fVerboseLevel; 541 const G4ThreeVector StartPosition = St 476 const G4ThreeVector StartPosition = StartFT.GetPosition(); 542 const G4ThreeVector StartUnitVelocity = St 477 const G4ThreeVector StartUnitVelocity = StartFT.GetMomentumDir(); 543 const G4ThreeVector CurrentPosition = Cu 478 const G4ThreeVector CurrentPosition = CurrentFT.GetPosition(); 544 const G4ThreeVector CurrentUnitVelocity = Cu 479 const G4ThreeVector CurrentUnitVelocity = CurrentFT.GetMomentumDir(); 545 480 546 G4double step_len = CurrentFT.GetCurveLength 481 G4double step_len = CurrentFT.GetCurveLength() - StartFT.GetCurveLength(); 547 482 548 G4long oldprec; // cout/cerr precision set << 483 G4int oldprec; // cout/cerr precision settings 549 484 550 if( ((stepNo == 0) && (verboseLevel <3)) || 485 if( ((stepNo == 0) && (verboseLevel <3)) || (verboseLevel >= 3) ) 551 { 486 { 552 oldprec = G4cout.precision(4); 487 oldprec = G4cout.precision(4); >> 488 G4cout << std::setw( 6) << " " >> 489 << std::setw( 25) << " Current Position and Direction" << " " >> 490 << G4endl; 553 G4cout << std::setw( 5) << "Step#" 491 G4cout << std::setw( 5) << "Step#" 554 << std::setw(10) << " s " << " " 492 << std::setw(10) << " s " << " " 555 << std::setw(10) << "X(mm)" << " " 493 << std::setw(10) << "X(mm)" << " " 556 << std::setw(10) << "Y(mm)" << " " 494 << std::setw(10) << "Y(mm)" << " " 557 << std::setw(10) << "Z(mm)" << " " 495 << std::setw(10) << "Z(mm)" << " " 558 << std::setw( 7) << " N_x " << " " 496 << std::setw( 7) << " N_x " << " " 559 << std::setw( 7) << " N_y " << " " 497 << std::setw( 7) << " N_y " << " " 560 << std::setw( 7) << " N_z " << " " 498 << std::setw( 7) << " N_z " << " " ; 561 G4cout << std::setw( 7) << " Delta|N|" << 499 G4cout << std::setw( 7) << " Delta|N|" << " " 562 << std::setw( 9) << "StepLen" << " 500 << std::setw( 9) << "StepLen" << " " 563 << std::setw(12) << "StartSafety" < 501 << std::setw(12) << "StartSafety" << " " 564 << std::setw( 9) << "PhsStep" << " 502 << std::setw( 9) << "PhsStep" << " "; 565 if( startVolume != nullptr ) << 503 if( startVolume ) 566 { G4cout << std::setw(18) << "NextVolume 504 { G4cout << std::setw(18) << "NextVolume" << " "; } 567 G4cout.precision(oldprec); 505 G4cout.precision(oldprec); 568 G4cout << G4endl; 506 G4cout << G4endl; 569 } 507 } 570 if((stepNo == 0) && (verboseLevel <=3)) 508 if((stepNo == 0) && (verboseLevel <=3)) 571 { 509 { 572 // Recurse to print the start values 510 // Recurse to print the start values 573 // 511 // 574 printStatus( StartFT, StartFT, -1.0, safet 512 printStatus( StartFT, StartFT, -1.0, safety, -1, startVolume); 575 } 513 } 576 if( verboseLevel <= 3 ) 514 if( verboseLevel <= 3 ) 577 { 515 { 578 if( stepNo >= 0) 516 if( stepNo >= 0) 579 { G4cout << std::setw( 4) << stepNo << " 517 { G4cout << std::setw( 4) << stepNo << " "; } 580 else 518 else 581 { G4cout << std::setw( 5) << "Start" ; } 519 { G4cout << std::setw( 5) << "Start" ; } 582 oldprec = G4cout.precision(8); 520 oldprec = G4cout.precision(8); 583 G4cout << std::setw(10) << CurrentFT.GetCu 521 G4cout << std::setw(10) << CurrentFT.GetCurveLength() << " "; 584 G4cout.precision(8); 522 G4cout.precision(8); 585 G4cout << std::setw(10) << CurrentPosition 523 G4cout << std::setw(10) << CurrentPosition.x() << " " 586 << std::setw(10) << CurrentPosition 524 << std::setw(10) << CurrentPosition.y() << " " 587 << std::setw(10) << CurrentPosition 525 << std::setw(10) << CurrentPosition.z() << " "; 588 G4cout.precision(4); 526 G4cout.precision(4); 589 G4cout << std::setw( 7) << CurrentUnitVelo 527 G4cout << std::setw( 7) << CurrentUnitVelocity.x() << " " 590 << std::setw( 7) << CurrentUnitVelo 528 << std::setw( 7) << CurrentUnitVelocity.y() << " " 591 << std::setw( 7) << CurrentUnitVelo 529 << std::setw( 7) << CurrentUnitVelocity.z() << " "; 592 G4cout.precision(3); 530 G4cout.precision(3); 593 G4cout << std::setw( 7) 531 G4cout << std::setw( 7) 594 << CurrentFT.GetMomentum().mag()-St 532 << CurrentFT.GetMomentum().mag()-StartFT.GetMomentum().mag() << " "; 595 G4cout << std::setw( 9) << step_len << " " 533 G4cout << std::setw( 9) << step_len << " "; 596 G4cout << std::setw(12) << safety << " "; 534 G4cout << std::setw(12) << safety << " "; 597 if( requestStep != -1.0 ) 535 if( requestStep != -1.0 ) 598 { G4cout << std::setw( 9) << requestStep 536 { G4cout << std::setw( 9) << requestStep << " "; } 599 else 537 else 600 { G4cout << std::setw( 9) << "Init/NotKn 538 { G4cout << std::setw( 9) << "Init/NotKnown" << " "; } 601 if( startVolume != nullptr) << 539 if( startVolume != 0) 602 { G4cout << std::setw(12) << startVolume 540 { G4cout << std::setw(12) << startVolume->GetName() << " "; } 603 G4cout.precision(oldprec); 541 G4cout.precision(oldprec); 604 G4cout << G4endl; 542 G4cout << G4endl; 605 } 543 } 606 else // if( verboseLevel > 3 ) 544 else // if( verboseLevel > 3 ) 607 { 545 { 608 // Multi-line output 546 // Multi-line output 609 547 610 G4cout << "Step taken was " << step_len 548 G4cout << "Step taken was " << step_len 611 << " out of PhysicalStep = " << re 549 << " out of PhysicalStep = " << requestStep << G4endl; 612 G4cout << "Final safety is: " << safety << 550 G4cout << "Final safety is: " << safety << G4endl; 613 G4cout << "Chord length = " << (CurrentPos 551 G4cout << "Chord length = " << (CurrentPosition-StartPosition).mag() 614 << G4endl; 552 << G4endl; 615 G4cout << G4endl; 553 G4cout << G4endl; 616 } 554 } 617 } 555 } 618 556 619 // ------------------------------------------- << 557 /////////////////////////////////////////////////////////////////////////// 620 // Prints Step diagnostics << 621 // 558 // >> 559 // Prints Step diagnostics >> 560 622 void 561 void 623 G4PropagatorInField::PrintStepLengthDiagnostic 562 G4PropagatorInField::PrintStepLengthDiagnostic( 624 G4double CurrentProp 563 G4double CurrentProposedStepLength, 625 G4double decreaseFac 564 G4double decreaseFactor, 626 G4double stepTrial, 565 G4double stepTrial, 627 const G4FieldTrack& ) 566 const G4FieldTrack& ) 628 { 567 { 629 G4long iprec= G4cout.precision(8); << 568 G4int iprec= G4cout.precision(8); 630 G4cout << " " << std::setw(12) << " PiF: NoZ 569 G4cout << " " << std::setw(12) << " PiF: NoZeroStep " 631 << " " << std::setw(20) << " CurrentP 570 << " " << std::setw(20) << " CurrentProposed len " 632 << " " << std::setw(18) << " Full_cur 571 << " " << std::setw(18) << " Full_curvelen_last" 633 << " " << std::setw(18) << " last pro 572 << " " << std::setw(18) << " last proposed len " 634 << " " << std::setw(18) << " decrease 573 << " " << std::setw(18) << " decrease factor " 635 << " " << std::setw(15) << " step tri 574 << " " << std::setw(15) << " step trial " 636 << G4endl; 575 << G4endl; 637 576 638 G4cout << " " << std::setw(10) << fNoZeroSte 577 G4cout << " " << std::setw(10) << fNoZeroStep << " " 639 << " " << std::setw(20) << CurrentPro 578 << " " << std::setw(20) << CurrentProposedStepLength 640 << " " << std::setw(18) << fFull_Curv 579 << " " << std::setw(18) << fFull_CurveLen_of_LastAttempt 641 << " " << std::setw(18) << fLast_Prop 580 << " " << std::setw(18) << fLast_ProposedStepLength 642 << " " << std::setw(18) << decreaseFa 581 << " " << std::setw(18) << decreaseFactor 643 << " " << std::setw(15) << stepTrial 582 << " " << std::setw(15) << stepTrial 644 << G4endl; 583 << G4endl; 645 G4cout.precision( iprec ); << 584 G4cout.precision( iprec ); >> 585 646 } 586 } 647 587 648 // Access the points which have passed through 588 // Access the points which have passed through the filter. The 649 // points are stored as ThreeVectors for the i 589 // points are stored as ThreeVectors for the initial impelmentation 650 // only (jacek 30/10/2002) 590 // only (jacek 30/10/2002) 651 // Responsibility for deleting the points lies 591 // Responsibility for deleting the points lies with 652 // SmoothTrajectoryPoint, which is the points' 592 // SmoothTrajectoryPoint, which is the points' final 653 // destination. The points pointer is set to N 593 // destination. The points pointer is set to NULL, to ensure that 654 // the points are not re-used in subsequent st 594 // the points are not re-used in subsequent steps, therefore THIS 655 // METHOD MUST BE CALLED EXACTLY ONCE PER STEP 595 // METHOD MUST BE CALLED EXACTLY ONCE PER STEP. (jacek 08/11/2002) 656 596 657 std::vector<G4ThreeVector>* 597 std::vector<G4ThreeVector>* 658 G4PropagatorInField::GimmeTrajectoryVectorAndF 598 G4PropagatorInField::GimmeTrajectoryVectorAndForgetIt() const 659 { 599 { 660 // NB, GimmeThePointsAndForgetThem really fo 600 // NB, GimmeThePointsAndForgetThem really forgets them, so it can 661 // only be called (exactly) once for each st 601 // only be called (exactly) once for each step. 662 602 663 if (fpTrajectoryFilter != nullptr) << 603 if (fpTrajectoryFilter) 664 { 604 { 665 return fpTrajectoryFilter->GimmeThePointsA 605 return fpTrajectoryFilter->GimmeThePointsAndForgetThem(); 666 } 606 } 667 return nullptr; << 607 else >> 608 { >> 609 return 0; >> 610 } 668 } 611 } 669 612 670 // ------------------------------------------- << 671 // << 672 void 613 void 673 G4PropagatorInField::SetTrajectoryFilter(G4VCu 614 G4PropagatorInField::SetTrajectoryFilter(G4VCurvedTrajectoryFilter* filter) 674 { 615 { 675 fpTrajectoryFilter = filter; 616 fpTrajectoryFilter = filter; 676 } 617 } 677 618 678 // ------------------------------------------- << 679 // << 680 void G4PropagatorInField::ClearPropagatorState 619 void G4PropagatorInField::ClearPropagatorState() 681 { 620 { 682 // Goal: Clear all memory of previous steps, 621 // Goal: Clear all memory of previous steps, cached information 683 622 684 fParticleIsLooping = false; << 623 fParticleIsLooping= false; 685 fNoZeroStep = 0; << 624 fNoZeroStep= 0; 686 625 687 fSetFieldMgr = false; // Has field-manager << 688 fEpsilonStep= 1.0e-5; // Relative accuracy << 689 << 690 End_PointAndTangent= G4FieldTrack( G4ThreeVe 626 End_PointAndTangent= G4FieldTrack( G4ThreeVector(0.,0.,0.), 691 G4ThreeVe 627 G4ThreeVector(0.,0.,0.), 692 0.0,0.0,0 628 0.0,0.0,0.0,0.0,0.0); 693 fFull_CurveLen_of_LastAttempt = -1; 629 fFull_CurveLen_of_LastAttempt = -1; 694 fLast_ProposedStepLength = -1; 630 fLast_ProposedStepLength = -1; 695 631 696 fPreviousSftOrigin= G4ThreeVector(0.,0.,0.); 632 fPreviousSftOrigin= G4ThreeVector(0.,0.,0.); 697 fPreviousSafety= 0.0; 633 fPreviousSafety= 0.0; 698 << 699 fNewTrack = true; << 700 } 634 } 701 635 702 // ------------------------------------------- << 703 // << 704 G4FieldManager* G4PropagatorInField:: 636 G4FieldManager* G4PropagatorInField:: 705 FindAndSetFieldManager( G4VPhysicalVolume* pCu << 637 FindAndSetFieldManager( G4VPhysicalVolume* pCurrentPhysicalVolume) 706 { 638 { 707 G4FieldManager* currentFieldMgr; 639 G4FieldManager* currentFieldMgr; 708 640 709 currentFieldMgr = fDetectorFieldMgr; 641 currentFieldMgr = fDetectorFieldMgr; 710 if( pCurrentPhysicalVolume != nullptr ) << 642 if( pCurrentPhysicalVolume) 711 { 643 { 712 G4FieldManager *pRegionFieldMgr = nullptr << 644 G4FieldManager *pRegionFieldMgr= 0, *localFieldMgr = 0; 713 G4LogicalVolume* pLogicalVol = pCurrentPh << 645 G4LogicalVolume* pLogicalVol= pCurrentPhysicalVolume->GetLogicalVolume(); 714 646 715 if( pLogicalVol != nullptr ) << 647 if( pLogicalVol ) { 716 { << 648 // Value for Region, if any, Overrides 717 // Value for Region, if any, overrides << 649 G4Region* pRegion= pLogicalVol->GetRegion(); 718 // << 650 if( pRegion ) { 719 G4Region* pRegion = pLogicalVol->GetR << 651 pRegionFieldMgr= pRegion->GetFieldManager(); 720 if( pRegion != nullptr ) << 652 if( pRegionFieldMgr ) 721 { << 653 currentFieldMgr= pRegionFieldMgr; 722 pRegionFieldMgr = pRegion->GetField << 654 } 723 if( pRegionFieldMgr != nullptr ) << 655 724 { << 656 // 'Local' Value from logical volume, if any, Overrides 725 currentFieldMgr= pRegionFieldMgr << 657 localFieldMgr= pLogicalVol->GetFieldManager(); 726 } << 658 if ( localFieldMgr ) 727 } << 659 currentFieldMgr = localFieldMgr; 728 << 729 // 'Local' Value from logical volume, << 730 // << 731 localFieldMgr = pLogicalVol->GetFieldM << 732 if ( localFieldMgr != nullptr ) << 733 { << 734 currentFieldMgr = localFieldMgr; << 735 } << 736 } 660 } 737 } 661 } 738 fCurrentFieldMgr = currentFieldMgr; << 662 fCurrentFieldMgr= currentFieldMgr; 739 663 740 // Flag that field manager has been set << 664 // Flag that field manager has been set. 741 // << 665 fSetFieldMgr= true; 742 fSetFieldMgr = true; << 743 666 744 return currentFieldMgr; 667 return currentFieldMgr; 745 } 668 } 746 669 747 // ------------------------------------------- << 748 // << 749 G4int G4PropagatorInField::SetVerboseLevel( G4 670 G4int G4PropagatorInField::SetVerboseLevel( G4int level ) 750 { 671 { 751 G4int oldval = fVerboseLevel; << 672 G4int oldval= fVerboseLevel; 752 fVerboseLevel = level; << 673 fVerboseLevel= level; 753 674 754 // Forward the verbose level 'reduced' to Ch 675 // Forward the verbose level 'reduced' to ChordFinder, 755 // MagIntegratorDriver ... ? 676 // MagIntegratorDriver ... ? 756 // 677 // 757 auto integrDriver = GetChordFinder()->GetInt << 678 G4MagInt_Driver* integrDriver= GetChordFinder()->GetIntegrationDriver(); 758 integrDriver->SetVerboseLevel( fVerboseLevel 679 integrDriver->SetVerboseLevel( fVerboseLevel - 2 ); 759 G4cout << "Set Driver verbosity to " << fVer 680 G4cout << "Set Driver verbosity to " << fVerboseLevel - 2 << G4endl; 760 681 761 return oldval; 682 return oldval; 762 } << 763 << 764 // ------------------------------------------- << 765 // << 766 void G4PropagatorInField::ReportLoopingParticl << 767 << 768 << 769 << 770 << 771 << 772 { << 773 std::ostringstream message; << 774 G4double fraction = StepTaken / StepRequest << 775 message << " Unfinished integration of trac << 776 << " of momentum " << momentumVec < << 777 << momentumVec.mag() << " ) " << G4 << 778 << " after " << count << " field su << 779 << " totaling " << std::setprecisio << 780 << " out of requested step " << std << 781 << StepRequested / mm << " mm "; << 782 message << " a fraction of "; << 783 G4int prec = 4; << 784 if( fraction > 0.99 ) << 785 { << 786 prec = 7; << 787 } << 788 else << 789 { << 790 if (fraction > 0.97 ) { prec = 5; } << 791 } << 792 message << std::setprecision(prec) << 793 << 100. * StepTaken / StepRequested << 794 if( pPhysVol != nullptr ) << 795 { << 796 message << " in volume " << pPhysVol->Get << 797 auto material = pPhysVol->GetLogicalVolum << 798 if( material != nullptr ) << 799 { << 800 message << " with material " << materia << 801 << " ( density = " << 802 << material->GetDensity() / ( g << 803 } << 804 } << 805 else << 806 { << 807 message << " in unknown (null) volume. " << 808 } << 809 G4Exception(methodName, "GeomNav1002", Just << 810 } << 811 << 812 // ------------------------------------------- << 813 // << 814 void G4PropagatorInField::ReportStuckParticle( << 815 << 816 << 817 << 818 { << 819 std::ostringstream message; << 820 message << "Particle is stuck; it will be k << 821 << " Zero progress for " << noZero << 822 << G4endl << 823 << " Proposed Step is " << propose << 824 << " but Step Taken is "<< lastTrie << 825 if( physVol != nullptr ) << 826 { << 827 message << " in volume " << physVol->Get << 828 } << 829 else << 830 { << 831 message << " in unknown or null volume. << 832 } << 833 G4Exception("G4PropagatorInField::ComputeSt << 834 "GeomNav1002", JustWarning, mes << 835 } << 836 << 837 // ------------------------------------------- << 838 << 839 // ------------------------------------------- << 840 // Methods to alter Parameters << 841 // ------------------------------------------- << 842 << 843 // Was a data member (of an object) -- now mov << 844 G4double G4PropagatorInField::GetLargestAccep << 845 { << 846 return fLargestAcceptableStep; << 847 } << 848 << 849 // ------------------------------------------- << 850 // << 851 void G4PropagatorInField::SetLargestAcceptable << 852 { << 853 if( fLargestAcceptableStep>0.0 ) << 854 { << 855 fLargestAcceptableStep = newBigDist; << 856 } << 857 } << 858 << 859 // ------------------------------------------- << 860 << 861 G4double G4PropagatorInField::GetMaxStepSizeMu << 862 { << 863 return fMaxStepSizeMultiplier; << 864 } << 865 << 866 // ------------------------------------------- << 867 << 868 void G4PropagatorInField::SetMaxStepSizeMu << 869 { << 870 fMaxStepSizeMultiplier=vm; << 871 } << 872 << 873 // ------------------------------------------- << 874 << 875 G4double G4PropagatorInField::GetMinBigDistanc << 876 { << 877 return fMinBigDistance; << 878 } << 879 << 880 // ------------------------------------------- << 881 << 882 void G4PropagatorInField::SetMinBigDistanc << 883 { << 884 fMinBigDistance= val; << 885 } 683 } 886 684