Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/navigation/src/G4PropagatorInField.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/navigation/src/G4PropagatorInField.cc (Version 11.3.0) and /geometry/navigation/src/G4PropagatorInField.cc (Version 8.0.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 // class G4PropagatorInField Implementation    <<  23 //
                                                   >>  24 // $Id: G4PropagatorInField.cc,v 1.22 2006/02/08 18:21:02 japost Exp $
                                                   >>  25 // GEANT4 tag $Name: geant4-08-00-patch-01 $
                                                   >>  26 // 
 27 //                                                 27 // 
 28 //  This class implements an algorithm to trac     28 //  This class implements an algorithm to track a particle in a
 29 //  non-uniform magnetic field. It utilises an     29 //  non-uniform magnetic field. It utilises an ODE solver (with
 30 //  the Runge - Kutta method) to evolve the pa     30 //  the Runge - Kutta method) to evolve the particle, and drives it
 31 //  until the particle has traveled a set dist     31 //  until the particle has traveled a set distance or it enters a new 
 32 //  volume.                                        32 //  volume.
 33 //                                                 33 //                                                                     
 34 // 14.10.96 John Apostolakis, design and imple <<  34 // 14.10.96 John Apostolakis,   design and implementation
 35 // 17.03.97 John Apostolakis, renaming new set <<  35 // 17.03.97 John Apostolakis,   renaming new set functions being added
                                                   >>  36 //
 36 // -------------------------------------------     37 // ---------------------------------------------------------------------------
 37                                                    38 
 38 #include <iomanip>                             << 
 39                                                << 
 40 #include "G4PropagatorInField.hh"                  39 #include "G4PropagatorInField.hh"
 41 #include "G4ios.hh"                                40 #include "G4ios.hh"
 42 #include "G4SystemOfUnits.hh"                  <<  41 #include <iomanip>
                                                   >>  42 
 43 #include "G4ThreeVector.hh"                        43 #include "G4ThreeVector.hh"
 44 #include "G4Material.hh"                       << 
 45 #include "G4VPhysicalVolume.hh"                    44 #include "G4VPhysicalVolume.hh"
 46 #include "G4Navigator.hh"                          45 #include "G4Navigator.hh"
 47 #include "G4GeometryTolerance.hh"              << 
 48 #include "G4VCurvedTrajectoryFilter.hh"            46 #include "G4VCurvedTrajectoryFilter.hh"
 49 #include "G4ChordFinder.hh"                        47 #include "G4ChordFinder.hh"
 50 #include "G4MultiLevelLocator.hh"              << 
 51                                                << 
 52                                                    48 
 53 // ------------------------------------------- <<  49 ///////////////////////////////////////////////////////////////////////////
 54 // Constructors and destructor                 << 
 55 //                                                 50 //
 56 G4PropagatorInField::G4PropagatorInField( G4Na <<  51 // Constructors and destructor
 57                                           G4Fi <<  52 
 58                                           G4VI <<  53 G4PropagatorInField::G4PropagatorInField( G4Navigator    *theNavigator, 
                                                   >>  54                                           G4FieldManager *detectorFieldMgr )
 59   : fDetectorFieldMgr(detectorFieldMgr),           55   : fDetectorFieldMgr(detectorFieldMgr), 
                                                   >>  56     fCurrentFieldMgr(detectorFieldMgr), 
 60     fNavigator(theNavigator),                      57     fNavigator(theNavigator),
 61     fCurrentFieldMgr(detectorFieldMgr),        << 
 62     End_PointAndTangent(G4ThreeVector(0.,0.,0.     58     End_PointAndTangent(G4ThreeVector(0.,0.,0.),
 63                         G4ThreeVector(0.,0.,0. <<  59                         G4ThreeVector(0.,0.,0.),0.0,0.0,0.0,0.0,0.0),
                                                   >>  60     fParticleIsLooping(false),
                                                   >>  61     fVerboseLevel(0),
                                                   >>  62     fMax_loop_count(1000),
                                                   >>  63     fNoZeroStep(0), 
                                                   >>  64     fCharge(0.0), fInitialMomentumModulus(0.0), fMass(0.0),
                                                   >>  65     fUseSafetyForOptimisation(true),   // (false) is less sensitive to incorrect safety
                                                   >>  66     fSetFieldMgr(false),
                                                   >>  67     fpTrajectoryFilter( 0 )
 64 {                                                  68 {
 65   fEpsilonStep = (fDetectorFieldMgr != nullptr <<  69   if(fDetectorFieldMgr) { fEpsilonStep = fDetectorFieldMgr->GetMaximumEpsilonStep();}
 66                ? fDetectorFieldMgr->GetMaximum <<  70   else                  { fEpsilonStep= 1.0e-5; } 
 67                                                <<  71   fActionThreshold_NoZeroSteps = 2; 
 68                                                <<  72   fSevereActionThreshold_NoZeroSteps = 10; 
 69   fPreviousSftOrigin = G4ThreeVector(0.,0.,0.) <<  73   fAbandonThreshold_NoZeroSteps = 50; 
 70   kCarTolerance = G4GeometryTolerance::GetInst <<  74   fFull_CurveLen_of_LastAttempt = -1; 
 71   fZeroStepThreshold = std::max( 1.0e5 * kCarT <<  75   fLast_ProposedStepLength = -1;
 72                                                <<  76   fLargestAcceptableStep = 1000.0 * meter;
 73   fLargestAcceptableStep = 100.0 * meter;  //  << 
 74   fMaxStepSizeMultiplier=   0.1 ;   // 0.1 in  << 
 75   fMinBigDistance= 100. * CLHEP::mm;           << 
 76 #ifdef G4DEBUG_FIELD                           << 
 77   G4cout << " PiF: Zero Step Threshold set to  << 
 78          << fZeroStepThreshold / millimeter    << 
 79          << " mm." << G4endl;                  << 
 80   G4cout << " PiF:   Value of kCarTolerance =  << 
 81          << kCarTolerance / millimeter         << 
 82          << " mm. " << G4endl;                 << 
 83   fVerboseLevel = 2;                           << 
 84   fVerbTracePiF = true;                        << 
 85 #endif                                         << 
 86                                                    77 
 87   // Defining Intersection Locator and his par <<  78   fPreviousSftOrigin= G4ThreeVector(0.,0.,0.);
 88   if ( vLocator == nullptr )                   <<  79   fPreviousSafety= 0.0;
 89   {                                            << 
 90     fIntersectionLocator = new G4MultiLevelLoc << 
 91     fAllocatedLocator = true;                  << 
 92   }                                            << 
 93   else                                         << 
 94   {                                            << 
 95     fIntersectionLocator = vLocator;           << 
 96     fAllocatedLocator = false;                 << 
 97   }                                            << 
 98   RefreshIntersectionLocator();  //  Copy all  << 
 99 }                                                  80 }
100                                                    81 
101 // ------------------------------------------- << 
102 //                                             << 
103 G4PropagatorInField::~G4PropagatorInField()        82 G4PropagatorInField::~G4PropagatorInField()
104 {                                                  83 {
105   if(fAllocatedLocator)  { delete  fIntersecti << 
106 }                                                  84 }
107                                                    85 
108 // ------------------------------------------- <<  86 ///////////////////////////////////////////////////////////////////////////
109 // Update the IntersectionLocator with current << 
110 //                                                 87 //
111 void G4PropagatorInField::RefreshIntersectionL << 
112 {                                              << 
113   fIntersectionLocator->SetEpsilonStepFor(fEps << 
114   fIntersectionLocator->SetDeltaIntersectionFo << 
115   fIntersectionLocator->SetChordFinderFor(GetC << 
116   fIntersectionLocator->SetSafetyParametersFor << 
117 }                                              << 
118                                                << 
119 // ------------------------------------------- << 
120 // Compute the next geometric Step                 88 // Compute the next geometric Step
121 //                                             <<  89 
122 G4double G4PropagatorInField::ComputeStep(     <<  90 G4double
                                                   >>  91 G4PropagatorInField::ComputeStep(
123                 G4FieldTrack&      pFieldTrack     92                 G4FieldTrack&      pFieldTrack,
124                 G4double           CurrentProp     93                 G4double           CurrentProposedStepLength,
125                 G4double&          currentSafe     94                 G4double&          currentSafety,                // IN/OUT
126                 G4VPhysicalVolume* pPhysVol,   <<  95                 G4VPhysicalVolume* pPhysVol)
127                 G4bool             canRelaxDel <<  96 {
128 {                                              << 
129   GetChordFinder()->OnComputeStep(&pFieldTrack << 
130   const G4double deltaChord = GetChordFinder() << 
131                                                << 
132   // If CurrentProposedStepLength is too small     97   // If CurrentProposedStepLength is too small for finding Chords
133   // then return with no action (for now - TOD <<  98   // just forget.
134   //                                           <<  99   if(CurrentProposedStepLength<kCarTolerance) return DBL_MAX;
135   const char* methodName = "G4PropagatorInFiel << 
136   if (CurrentProposedStepLength<kCarTolerance) << 
137   {                                            << 
138     return kInfinity;                          << 
139   }                                            << 
140                                                   100 
141   // Introducing smooth trajectory display (ja    101   // Introducing smooth trajectory display (jacek 01/11/2002)
142   //                                           << 102   if (fpTrajectoryFilter) {
143   if (fpTrajectoryFilter != nullptr)           << 
144   {                                            << 
145     fpTrajectoryFilter->CreateNewTrajectorySeg    103     fpTrajectoryFilter->CreateNewTrajectorySegment();
146   }                                               104   }
147                                                   105 
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    106   // Parameters for adaptive Runge-Kutta integration
170                                                   107   
171   G4double h_TrialStepSize;        // 1st Step << 108   G4double      h_TrialStepSize;        // 1st Step Size 
172   G4double TruePathLength = CurrentProposedSte << 109   G4double      TruePathLength = CurrentProposedStepLength;
173   G4double StepTaken = 0.0;                    << 110   G4double      StepTaken = 0.0; 
174   G4double s_length_taken, epsilon;            << 111   G4double      s_length_taken, epsilon ; 
175   G4bool   intersects;                         << 112   G4bool        intersects;
176   G4bool   first_substep = true;               << 113   G4bool        first_substep = true;
177                                                   114 
178   G4double NewSafety;                          << 115   G4double      NewSafety;
179   fParticleIsLooping = false;                     116   fParticleIsLooping = false;
180                                                   117 
181   // If not yet done,                             118   // If not yet done, 
182   //   Set the field manager to the local  one    119   //   Set the field manager to the local  one if the volume has one, 
183   //                      or to the global one    120   //                      or to the global one if not
184   //                                              121   //
185   if( !fSetFieldMgr )                          << 122   if( !fSetFieldMgr ) fCurrentFieldMgr= FindAndSetFieldManager( pPhysVol ); 
186   {                                            << 123   // For the next call, the field manager must again be set
187     fCurrentFieldMgr = FindAndSetFieldManager( << 124   fSetFieldMgr= false;
188   }                                            << 
189   fSetFieldMgr = false; // For next call, the  << 
190                                                   125 
191   G4FieldTrack CurrentState(pFieldTrack);      << 126   GetChordFinder()->SetChargeMomentumMass(fCharge, fInitialMomentumModulus, fMass);  
192   G4FieldTrack OriginalState = CurrentState;   << 127 
                                                   >> 128   G4FieldTrack  CurrentState(pFieldTrack);
                                                   >> 129   G4FieldTrack  OriginalState = CurrentState;
193                                                   130 
194   // If the Step length is "infinite", then an    131   // If the Step length is "infinite", then an approximate-maximum Step
195   // length (used to calculate the relative ac << 132   // length (used to calculate the relative accuracy) must be guessed.
196   //                                              133   //
197   if( CurrentProposedStepLength >= fLargestAcc    134   if( CurrentProposedStepLength >= fLargestAcceptableStep )
198   {                                               135   {
199     G4ThreeVector StartPointA, VelocityUnit;      136     G4ThreeVector StartPointA, VelocityUnit;
200     StartPointA  = pFieldTrack.GetPosition();     137     StartPointA  = pFieldTrack.GetPosition();
201     VelocityUnit = pFieldTrack.GetMomentumDir(    138     VelocityUnit = pFieldTrack.GetMomentumDir();
202                                                   139 
203     G4double trialProposedStep = fMaxStepSizeM << 140     G4double trialProposedStep = 1.e2 * ( 10.0 * cm + 
204       fNavigator->GetWorldVolume()->GetLogical    141       fNavigator->GetWorldVolume()->GetLogicalVolume()->
205                   GetSolid()->DistanceToOut(St    142                   GetSolid()->DistanceToOut(StartPointA, VelocityUnit) );
206     CurrentProposedStepLength = std::min( tria << 143     CurrentProposedStepLength= std::min( trialProposedStep,
207                                           fLar << 144                                            fLargestAcceptableStep ); 
208   }                                               145   }
209   epsilon = fCurrentFieldMgr->GetDeltaOneStep( << 146   epsilon = GetDeltaOneStep() / CurrentProposedStepLength;
                                                   >> 147   // G4double raw_epsilon= epsilon;
210   G4double epsilonMin= fCurrentFieldMgr->GetMi    148   G4double epsilonMin= fCurrentFieldMgr->GetMinimumEpsilonStep();
211   G4double epsilonMax= fCurrentFieldMgr->GetMa << 149   G4double epsilonMax= fCurrentFieldMgr->GetMaximumEpsilonStep();; 
212   if( epsilon < epsilonMin )  { epsilon = epsi << 150   if( epsilon < epsilonMin ) epsilon = epsilonMin;
213   if( epsilon > epsilonMax )  { epsilon = epsi << 151   if( epsilon > epsilonMax ) epsilon = epsilonMax;
214   SetEpsilonStep( epsilon );                      152   SetEpsilonStep( epsilon );
215                                                   153 
216   // Values for Intersection Locator has to be << 154   // G4cout << "G4PiF: Epsilon of current step - raw= " << raw_epsilon
217   // case that CurrentFieldManager has changed << 155   //        << " final= " << epsilon << G4endl;
218   //                                           << 
219   RefreshIntersectionLocator();                << 
220                                                   156 
221   // Shorten the proposed step in case of earl << 157   //  Shorten the proposed step in case of earlier problems (zero steps)
222   //                                              158   // 
223   if( fNoZeroStep > fActionThreshold_NoZeroSte    159   if( fNoZeroStep > fActionThreshold_NoZeroSteps )
224   {                                               160   {
225     G4double stepTrial;                           161     G4double stepTrial;
226                                                   162 
227     stepTrial = fFull_CurveLen_of_LastAttempt; << 163     stepTrial= fFull_CurveLen_of_LastAttempt; 
228     if( (stepTrial <= 0.0) && (fLast_ProposedS << 164     if( (stepTrial <= 0.0) && (fLast_ProposedStepLength > 0.0) ) 
229     {                                          << 165       stepTrial= fLast_ProposedStepLength; 
230       stepTrial = fLast_ProposedStepLength;    << 
231     }                                          << 
232                                                   166 
233     G4double decreaseFactor = 0.9; // Unused d    167     G4double decreaseFactor = 0.9; // Unused default
234     if(   (fNoZeroStep < fSevereActionThreshol    168     if(   (fNoZeroStep < fSevereActionThreshold_NoZeroSteps)
235        && (stepTrial > 100.0*fZeroStepThreshol << 169        && (stepTrial > 1000.0*kCarTolerance) )
236     {                                             170     {
237       // Attempt quick convergence             << 171       // Ensure quicker convergence
238       //                                          172       //
239       decreaseFactor= 0.25;                    << 173       decreaseFactor= 0.1;
240     }                                             174     } 
241     else                                          175     else
242     {                                             176     {
243       // We are in significant difficulties, p    177       // We are in significant difficulties, probably at a boundary that
244       // is either geometrically sharp or betw    178       // is either geometrically sharp or between very different materials.
245       // Careful decreases to cope with tolera << 179       // Careful decreases to cope with tolerance are required.
246       //                                          180       //
247       if( stepTrial > 100.0*fZeroStepThreshold << 181       if( stepTrial > 1000.0*kCarTolerance )
248         decreaseFactor = 0.35;     // Try decr << 182         decreaseFactor = 0.25;     // Try slow decreases
249       } else if( stepTrial > 30.0*fZeroStepThr << 183       else if( stepTrial > 100.0*kCarTolerance )
250         decreaseFactor= 0.5;       // Try yet  << 184         decreaseFactor= 0.5;       // Try slower decreases
251       } else if( stepTrial > 10.0*fZeroStepThr << 185       else if( stepTrial > 10.0*kCarTolerance )
252         decreaseFactor= 0.75;      // Try even    186         decreaseFactor= 0.75;      // Try even slower decreases
253       } else {                                 << 187       else
254         decreaseFactor= 0.9;       // Try very    188         decreaseFactor= 0.9;       // Try very slow decreases
255       }                                        << 
256      }                                            189      }
257      stepTrial *= decreaseFactor;                 190      stepTrial *= decreaseFactor;
258                                                   191 
259 #ifdef G4DEBUG_FIELD                              192 #ifdef G4DEBUG_FIELD
260      if( fVerboseLevel > 2                     << 193      PrintStepLengthDiagnostic(CurrentProposedStepLength, decreaseFactor,
261       || (fNoZeroStep >= fSevereActionThreshol << 194                                stepTrial, pFieldTrack);
262      {                                         << 
263         G4cerr << " " << methodName            << 
264                << "  Decreasing step after " < << 
265                << " - in volume " << pPhysVol; << 
266         if( pPhysVol )                         << 
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                                            195 #endif
275      if( stepTrial == 0.0 )  //  Change to mak << 196      if( stepTrial == 0.0 )
276      {                                            197      {
277        std::ostringstream message;             << 198        G4cout << " G4PropagatorInField::ComputeStep "
278        message << "Particle abandoned due to l << 199               << " Particle abandoned due to lack of progress in field."
279                << G4endl                       << 200               << G4endl
280                << "  Properties : " << pFieldT << 201               << " Properties : " << pFieldTrack << " "
281                << "  Attempting a zero step =  << 202               << G4endl;
282                << "  while attempting to progr << 203        G4cerr << " G4PropagatorInField::ComputeStep "
283                << " trial steps. Will abandon  << 204               << "  ERROR : attempting a zero step= " << stepTrial << G4endl
284        G4Exception(methodName, "GeomNav1002",  << 205               << " while attempting to progress after " << fNoZeroStep
285        fParticleIsLooping = true;              << 206               << " trial steps.  Will abandon step." << G4endl;
286        return 0;  // = stepTrial;              << 207          fParticleIsLooping= true;
                                                   >> 208          return 0;  // = stepTrial;
287      }                                            209      }
288      if( stepTrial < CurrentProposedStepLength    210      if( stepTrial < CurrentProposedStepLength )
289      {                                         << 
290        CurrentProposedStepLength = stepTrial;     211        CurrentProposedStepLength = stepTrial;
291      }                                         << 
292   }                                               212   }
293   fLast_ProposedStepLength = CurrentProposedSt    213   fLast_ProposedStepLength = CurrentProposedStepLength;
294                                                   214 
295   G4int do_loop_count = 0;                        215   G4int do_loop_count = 0; 
296   do  // Loop checking, 07.10.2016, JA         << 216   do
297   {                                               217   { 
298     G4FieldTrack SubStepStartState = CurrentSt    218     G4FieldTrack SubStepStartState = CurrentState;
299     G4ThreeVector SubStartPoint = CurrentState    219     G4ThreeVector SubStartPoint = CurrentState.GetPosition(); 
300                                                << 220 
301     if(!first_substep)                         << 221     if( !first_substep) {
302     {                                          << 
303       if( fVerboseLevel > 4 )                  << 
304       {                                        << 
305         G4cout << " PiF: Calling Nav/Locate Gl << 
306                << G4endl;                      << 
307       }                                        << 
308       fNavigator->LocateGlobalPointWithinVolum    222       fNavigator->LocateGlobalPointWithinVolume( SubStartPoint );
309     }                                             223     }
310                                                   224 
311     // How far to attempt to move the particle    225     // How far to attempt to move the particle !
312     //                                            226     //
313     h_TrialStepSize = CurrentProposedStepLengt    227     h_TrialStepSize = CurrentProposedStepLength - StepTaken;
314                                                   228 
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    229     // Integrate as far as "chord miss" rule allows.
326     //                                            230     //
327     s_length_taken = GetChordFinder()->Advance    231     s_length_taken = GetChordFinder()->AdvanceChordLimited( 
328                              CurrentState,        232                              CurrentState,    // Position & velocity
329                              h_TrialStepSize,     233                              h_TrialStepSize,
330                              fEpsilonStep,        234                              fEpsilonStep,
331                              fPreviousSftOrigi    235                              fPreviousSftOrigin,
332                              fPreviousSafety ) << 236                              fPreviousSafety
333       // CurrentState is now updated with the  << 237                              );
                                                   >> 238     //  CurrentState is now updated with the final position and velocity. 
334                                                   239 
335     fFull_CurveLen_of_LastAttempt = s_length_t    240     fFull_CurveLen_of_LastAttempt = s_length_taken;
336                                                   241 
337     G4ThreeVector EndPointB = CurrentState.Get << 242     G4ThreeVector  EndPointB = CurrentState.GetPosition(); 
338     G4ThreeVector InterSectionPointE;          << 243     G4ThreeVector  InterSectionPointE;
339     G4double      LinearStepLength;            << 244     G4double       LinearStepLength;
340                                                   245  
341     // Intersect chord AB with geometry           246     // Intersect chord AB with geometry
342     //                                         << 
343     intersects= IntersectChord( SubStartPoint,    247     intersects= IntersectChord( SubStartPoint, EndPointB, 
344                                 NewSafety, Lin << 248         NewSafety,     LinearStepLength, 
345                                 InterSectionPo << 249         InterSectionPointE );
346       // E <- Intersection Point of chord AB a << 250     // E <- Intersection Point of chord AB and either volume A's surface 
347       //                                  or a << 251     //                                  or a daughter volume's surface ..
348                                                   252 
349     if( first_substep )                        << 253     if( first_substep ) { 
350     {                                          << 
351        currentSafety = NewSafety;                 254        currentSafety = NewSafety;
352     } // Updating safety in other steps is pot    255     } // Updating safety in other steps is potential future extention
353                                                   256 
354     if( intersects )                              257     if( intersects )
355     {                                             258     {
356        G4FieldTrack IntersectPointVelct_G(Curr    259        G4FieldTrack IntersectPointVelct_G(CurrentState);  // FT-Def-Construct
357                                                   260 
358        // Find the intersection point of AB tr    261        // Find the intersection point of AB true path with the surface
359        //   of vol(A), if it exists. Start wit    262        //   of vol(A), if it exists. Start with point E as first "estimate".
360        G4bool recalculatedEndPt = false;       << 263        G4bool recalculatedEndPt= false;
361                                                << 264        G4bool found_intersection = 
362        G4bool found_intersection = fIntersecti << 265          LocateIntersectionPoint( SubStepStartState, CurrentState, 
363          EstimateIntersectionPoint( SubStepSta << 266                                   InterSectionPointE, IntersectPointVelct_G,
364                                     InterSecti << 267           recalculatedEndPt);
365                                     recalculat << 268        intersects = intersects && found_intersection;
366                                     fPreviousS << 269        if( found_intersection ) {        
367        intersects = found_intersection;        << 
368        if( found_intersection )                << 
369        {                                       << 
370           End_PointAndTangent= IntersectPointV    270           End_PointAndTangent= IntersectPointVelct_G;  // G is our EndPoint ...
371           StepTaken = TruePathLength = Interse    271           StepTaken = TruePathLength = IntersectPointVelct_G.GetCurveLength()
372                                      - Origina << 272                                       - OriginalState.GetCurveLength();
373        }                                       << 273        } else {
374        else                                    << 274     // intersects= false;          // "Minor" chords do not intersect
375        {                                       << 275     if( recalculatedEndPt ){
376           // Either "minor" chords do not inte << 276        CurrentState= IntersectPointVelct_G; 
377           // or else stopped (due to too many  << 277     }
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           }                                    << 
401        }                                          278        }
402     }                                             279     }
403     if( !intersects )                             280     if( !intersects )
404     {                                             281     {
405       StepTaken += s_length_taken;             << 282       StepTaken += s_length_taken; 
406                                                << 283       // For smooth trajectory display (jacek 01/11/2002)
407       if (fpTrajectoryFilter != nullptr) // Fo << 284       if (fpTrajectoryFilter) {
408       {                                        << 
409         fpTrajectoryFilter->TakeIntermediatePo    285         fpTrajectoryFilter->TakeIntermediatePoint(CurrentState.GetPosition());
410       }                                           286       }
411     }                                             287     }
412     first_substep = false;                        288     first_substep = false;
413                                                   289 
414 #ifdef G4DEBUG_FIELD                              290 #ifdef G4DEBUG_FIELD
415     if( fNoZeroStep > fActionThreshold_NoZeroS << 291     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    292       printStatus( SubStepStartState,  // or OriginalState,
423                    CurrentState, CurrentPropos << 293                    CurrentState,  CurrentProposedStepLength, 
424                    NewSafety, do_loop_count, p << 294                    NewSafety,     do_loop_count,  pPhysVol );
425     }                                             295     }
426     if( (fVerboseLevel > 1) && (do_loop_count  << 296 #endif
427     {                                          << 297 #ifdef G4VERBOSE
428       if( do_loop_count == fMax_loop_count-9 ) << 298     if( (fVerboseLevel > 1) && (do_loop_count > fMax_loop_count-10 )) {
429       {                                        << 299       if( do_loop_count == fMax_loop_count-9 ){
430         G4cout << " G4PropagatorInField::Compu << 300   G4cout << "G4PropagatorInField::ComputeStep "
431                << "  Difficult track - taking  << 301          << " Difficult track - taking many sub steps." << G4endl;
432         printStatus( SubStepStartState, SubSte << 
433                      NewSafety, 0, pPhysVol ); << 
434       }                                           302       }
435       printStatus( SubStepStartState, CurrentS    303       printStatus( SubStepStartState, CurrentState, CurrentProposedStepLength, 
436                    NewSafety, do_loop_count, p << 304        NewSafety, do_loop_count, pPhysVol );
437     }                                             305     }
438 #endif                                            306 #endif
439                                                   307 
440     ++do_loop_count;                           << 308     do_loop_count++;
441                                                   309 
442   } while( (!intersects )                         310   } while( (!intersects )
443         && (!fParticleIsLooping)               << 
444         && (StepTaken + kCarTolerance < Curren    311         && (StepTaken + kCarTolerance < CurrentProposedStepLength)  
445         && ( do_loop_count < fMax_loop_count )    312         && ( do_loop_count < fMax_loop_count ) );
446                                                   313 
447   if(  do_loop_count >= fMax_loop_count        << 314   if( do_loop_count >= fMax_loop_count  )
448     && (StepTaken + kCarTolerance < CurrentPro << 
449   {                                               315   {
450     fParticleIsLooping = true;                    316     fParticleIsLooping = true;
                                                   >> 317 
                                                   >> 318     if ( fVerboseLevel > 0 ){
                                                   >> 319        G4cout << "G4PropagateInField: Killing looping particle " 
                                                   >> 320               // << " of " << energy  << " energy "
                                                   >> 321               << " after " << do_loop_count << " field substeps "
                                                   >> 322               << " totaling " << StepTaken / mm << " mm " ;
                                                   >> 323        if( pPhysVol )
                                                   >> 324           G4cout << " in the volume " << pPhysVol->GetName() ; 
                                                   >> 325        else
                                                   >> 326          G4cout << " in unknown or null volume. " ; 
                                                   >> 327        G4cout << G4endl;
                                                   >> 328     }
451   }                                               329   }
452   if ( ( fParticleIsLooping ) && (fVerboseLeve << 330 
453   {                                            << 
454     ReportLoopingParticle( do_loop_count, Step << 
455                            CurrentProposedStep << 
456                            CurrentState.GetMom << 
457   }                                            << 
458                                                << 
459   if( !intersects )                               331   if( !intersects )
460   {                                               332   {
461     // Chord AB or "minor chords" do not inter    333     // Chord AB or "minor chords" do not intersect
462     // B is the endpoint Step of the current S    334     // B is the endpoint Step of the current Step.
463     //                                            335     //
464     End_PointAndTangent = CurrentState;           336     End_PointAndTangent = CurrentState; 
465     TruePathLength = StepTaken;   //  Original << 337     TruePathLength = StepTaken;
466                                                << 
467     // Tried the following to avoid potential  << 
468     // - but has issues... Suppressing this ch << 
469     // TruePathLength = CurrentProposedStepLen << 
470   }                                               338   }
471   fLastStepInVolume = intersects;              << 
472                                                   339   
473   // Set pFieldTrack to the return value          340   // Set pFieldTrack to the return value
474   //                                              341   //
475   pFieldTrack = End_PointAndTangent;              342   pFieldTrack = End_PointAndTangent;
476                                                   343 
477 #ifdef G4VERBOSE                                  344 #ifdef G4VERBOSE
478   // Check that "s" is correct                    345   // Check that "s" is correct
479   //                                              346   //
480   if( std::fabs(OriginalState.GetCurveLength()    347   if( std::fabs(OriginalState.GetCurveLength() + TruePathLength 
481       - End_PointAndTangent.GetCurveLength())     348       - End_PointAndTangent.GetCurveLength()) > 3.e-4 * TruePathLength )
482   {                                               349   {
483     std::ostringstream message;                << 350     G4cerr << " ERROR - G4PropagatorInField::ComputeStep():" << G4endl
484     message << "Curve length mis-match between << 351            << " Curve length mis-match, is advancement wrong ? " << G4endl;
485             << "and proposed endpoint of propa << 352     G4cerr << " The curve length of the endpoint should be: " 
486             << "  The curve length of the endp << 353            << OriginalState.GetCurveLength() + TruePathLength << G4endl
487             << OriginalState.GetCurveLength()  << 354            << " and it is instead: "
488             << "  and it is instead: "         << 355            << End_PointAndTangent.GetCurveLength() << "." << G4endl
489             << End_PointAndTangent.GetCurveLen << 356            << " A difference of: "
490             << "  A difference of: "           << 357            << OriginalState.GetCurveLength() + TruePathLength 
491             << OriginalState.GetCurveLength()  << 358               - End_PointAndTangent.GetCurveLength() << G4endl;
492                - End_PointAndTangent.GetCurveL << 359     G4cerr << " Original state= " << OriginalState   << G4endl
493             << "  Original state = " << Origin << 360      << " Proposed state= " << End_PointAndTangent << G4endl;
494             << "  Proposed state = " << End_Po << 361     G4Exception("G4PropagatorInField::ComputeStep()", "IncorrectProposedEndPoint",
495     G4Exception(methodName, "GeomNav0003", Fat << 362     FatalException, 
                                                   >> 363     "Curve length mis-match between original state and proposed endpoint of propagation.");
496   }                                               364   }
497 #endif                                            365 #endif
498                                                   366 
499   if( TruePathLength+kCarTolerance >= CurrentP << 367 #ifdef G4DEBUG_FIELD
500   {                                            << 368   // static G4std::vector<G4int>  ZeroStepNumberHist(fAbandonThreshold+1);
501      fNoZeroStep = 0;                          << 369   if( fNoZeroStep ){
502   }                                            << 370      // ZeroStepNumberHist[fNoZeroStep]++; 
503   else                                         << 371      if( fNoZeroStep > fActionThreshold_NoZeroSteps ){
504   {                                            << 372         G4cout << " PiF: Step returning=" << StepTaken << G4endl;
505      // In particular anomalous cases, we can  << 373         G4cout << " ------------------------------------------------------- "
506      // We identify these cases and take corre << 374                << G4endl;
507      //                                        << 
508      if( TruePathLength < std::max( fZeroStepT << 
509      {                                         << 
510         ++fNoZeroStep;                         << 
511      }                                         << 
512      else                                      << 
513      {                                         << 
514         fNoZeroStep = 0;                       << 
515      }                                            375      }
516   }                                               376   }
517   if( fNoZeroStep > fAbandonThreshold_NoZeroSt << 377 #endif
518   {                                            << 378 
                                                   >> 379   // In particular anomalous cases, we can get repeated zero steps
                                                   >> 380   // In order to correct this efficiently, we identify these cases
                                                   >> 381   // and only take corrective action when they occur.
                                                   >> 382   // 
                                                   >> 383   if( TruePathLength < 0.5*kCarTolerance ) 
                                                   >> 384     fNoZeroStep++;
                                                   >> 385   else
                                                   >> 386     fNoZeroStep = 0;
                                                   >> 387 
                                                   >> 388   if( fNoZeroStep > fAbandonThreshold_NoZeroSteps ) { 
519      fParticleIsLooping = true;                   389      fParticleIsLooping = true;
520      ReportStuckParticle( fNoZeroStep, Current << 390      G4cout << " WARNING - G4PropagatorInField::ComputeStep():" << G4endl
521                           fFull_CurveLen_of_La << 391             << " Zero progress for "  << fNoZeroStep << " attempted steps." 
                                                   >> 392             << G4endl;
                                                   >> 393 #ifdef G4VERBOSE
                                                   >> 394      if ( fVerboseLevel > 2 )
                                                   >> 395        G4cout << " Particle that is stuck will be killed." << G4endl;
                                                   >> 396 #endif
522      fNoZeroStep = 0;                             397      fNoZeroStep = 0; 
523   }                                               398   }
524                                                << 399 
525   GetChordFinder()->SetDeltaChord(deltaChord); << 400 #ifdef G4VERBOSE
                                                   >> 401   if ( fVerboseLevel > 3 ){
                                                   >> 402      G4cout << "G4PropagatorInField returns " << TruePathLength << G4endl;
                                                   >> 403   }
                                                   >> 404 #endif
                                                   >> 405 
526   return TruePathLength;                          406   return TruePathLength;
527 }                                                 407 }
528                                                   408 
529 // ------------------------------------------- << 409 // --------------------------------------------------------------------------
530 // Dumps status of propagator                  << 410 // G4bool 
                                                   >> 411 // G4PropagatorInField::LocateIntersectionPoint( 
                                                   >> 412 //   const G4FieldTrack&       CurveStartPointVelocity,   //  A
                                                   >> 413 //   const G4FieldTrack&       CurveEndPointVelocity,     //  B
                                                   >> 414 //   const G4ThreeVector&      TrialPoint,                //  E
                                                   >> 415 //         G4FieldTrack&       IntersectedOrRecalculated  // Output
                                                   >> 416 //         G4bool&             recalculated)              // Out
                                                   >> 417 // --------------------------------------------------------------------------
                                                   >> 418 //
                                                   >> 419 // Function that returns the intersection of the true path with the surface
                                                   >> 420 // of the current volume (either the external one or the inner one with one
                                                   >> 421 // of the daughters 
                                                   >> 422 //
                                                   >> 423 //     A = Initial point
                                                   >> 424 //     B = another point 
                                                   >> 425 //
                                                   >> 426 // Both A and B are assumed to be on the true path.
                                                   >> 427 //
                                                   >> 428 //     E is the first point of intersection of the chord AB with 
                                                   >> 429 //     a volume other than A  (on the surface of A or of a daughter)
                                                   >> 430 //
                                                   >> 431 // Convention of Use :
                                                   >> 432 //     i) If it returns "true", then IntersectionPointVelocity is set
                                                   >> 433 //       to the approximate intersection point.
                                                   >> 434 //    ii) If it returns "false", no intersection was found.
                                                   >> 435 //          The validity of IntersectedOrRecalculated depends on 'recalculated'
                                                   >> 436 //        a) if latter is false, then IntersectedOrRecalculated is invalid. 
                                                   >> 437 //        b) if latter is true,  then IntersectedOrRecalculated is
                                                   >> 438 //             the new endpoint, due to a re-integration.
                                                   >> 439 // --------------------------------------------------------------------------
                                                   >> 440 
                                                   >> 441 G4bool 
                                                   >> 442 G4PropagatorInField::LocateIntersectionPoint( 
                                                   >> 443   const   G4FieldTrack&       CurveStartPointVelocity,   //  A
                                                   >> 444   const   G4FieldTrack&       CurveEndPointVelocity,     //  B
                                                   >> 445   const   G4ThreeVector&      TrialPoint,                //  E
                                                   >> 446           G4FieldTrack&       IntersectedOrRecalculatedFT,    // Out: point found
                                                   >> 447           G4bool&             recalculatedEndPoint)      // Out: 
                                                   >> 448 {
                                                   >> 449   // Find Intersection Point ( A, B, E )  of true path AB - start at E.
                                                   >> 450 
                                                   >> 451   G4bool found_approximate_intersection = false;
                                                   >> 452   G4bool there_is_no_intersection       = false;
                                                   >> 453 
                                                   >> 454   G4FieldTrack  CurrentA_PointVelocity = CurveStartPointVelocity; 
                                                   >> 455   G4FieldTrack  CurrentB_PointVelocity = CurveEndPointVelocity;
                                                   >> 456   G4ThreeVector CurrentE_Point = TrialPoint;
                                                   >> 457 
                                                   >> 458   G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity); // FT-Def-Construct
                                                   >> 459   G4double    NewSafety= -0.0;   
                                                   >> 460   G4bool final_section= true;  // Shows whether current section is last (ie B=full end)
                                                   >> 461 
                                                   >> 462   recalculatedEndPoint= false; 
                                                   >> 463 
                                                   >> 464   G4bool restoredFullEndpoint= false;
                                                   >> 465 
                                                   >> 466   G4int       substep_no = 0;
                                                   >> 467 
                                                   >> 468   // Limits for substep number
                                                   >> 469   const G4int max_substeps=   10000;  // Test 120  (old value 100 )
                                                   >> 470   const G4int warn_substeps=   1000;  //      100  
                                                   >> 471   // Statistics for substeps 
                                                   >> 472   static G4int max_no_seen= -1; 
                                                   >> 473   static G4int trigger_substepno_print= warn_substeps - 20 ;  
                                                   >> 474 
                                                   >> 475   do{                // REPEAT
                                                   >> 476 
                                                   >> 477     G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();  
                                                   >> 478     G4ThreeVector Point_B = CurrentB_PointVelocity.GetPosition();  
                                                   >> 479 
                                                   >> 480     // F = a point on true AB path close to point E  (the closest if possible)
                                                   >> 481     //
                                                   >> 482     ApproxIntersecPointV =
                                                   >> 483       GetChordFinder()->ApproxCurvePointV( CurrentA_PointVelocity, 
                                                   >> 484                                            CurrentB_PointVelocity, 
                                                   >> 485                                            CurrentE_Point,
                                                   >> 486                                            fEpsilonStep );
                                                   >> 487     //  The above method is the key & most intuitive part ...
                                                   >> 488 
                                                   >> 489 #ifdef G4DEBUG_FIELD
                                                   >> 490     if( ApproxIntersecPointV.GetCurveLength() > 
                                                   >> 491         CurrentB_PointVelocity.GetCurveLength() * (1.0 + kAngTolerance) ) {
                                                   >> 492       G4cerr << "Error - Intermediate F point is more advanced than endpoint B." 
                                                   >> 493        << G4endl;
                                                   >> 494       G4Exception("G4PropagatorInField::LocateIntersectionPoint()", 
                                                   >> 495       "IntermediatePointConfusion",
                                                   >> 496       FatalException, "Intermediate F point is past end B point" ); 
                                                   >> 497     }
                                                   >> 498 #endif
                                                   >> 499 
                                                   >> 500     G4ThreeVector CurrentF_Point= ApproxIntersecPointV.GetPosition();
                                                   >> 501 
                                                   >> 502     // First check whether EF is small - then F is a good approx. point 
                                                   >> 503     // Calculate the length and direction of the chord AF
                                                   >> 504     //
                                                   >> 505     G4ThreeVector  ChordEF_Vector = CurrentF_Point - CurrentE_Point;
                                                   >> 506 
                                                   >> 507     if ( ChordEF_Vector.mag2() <= sqr(GetDeltaIntersection()) )
                                                   >> 508     {
                                                   >> 509       found_approximate_intersection = true;
                                                   >> 510 
                                                   >> 511       // Create the "point" return value
                                                   >> 512       //
                                                   >> 513       IntersectedOrRecalculatedFT = ApproxIntersecPointV;
                                                   >> 514       IntersectedOrRecalculatedFT.SetPosition( CurrentE_Point );
                                                   >> 515 
                                                   >> 516       // Note: in order to return a point on the boundary, 
                                                   >> 517       //       we must return E. But it is F on the curve.
                                                   >> 518       //       So we must "cheat": we are using the position at point E
                                                   >> 519       //       and the velocity at point F !!!
                                                   >> 520       //
                                                   >> 521       // This must limit the length we can allow for displacement!
                                                   >> 522 
                                                   >> 523     }
                                                   >> 524     else  // E is NOT close enough to the curve (ie point F)
                                                   >> 525     {
                                                   >> 526       // Check whether any volumes are encountered by the chord AF
                                                   >> 527       // ---------------------------------------------------------
                                                   >> 528       // First relocate to restore any Voxel etc information in the Navigator
                                                   >> 529       //   before calling ComputeStep 
                                                   >> 530       fNavigator->LocateGlobalPointWithinVolume( Point_A );
                                                   >> 531 
                                                   >> 532       G4ThreeVector PointG;   // Candidate intersection point
                                                   >> 533       G4double stepLengthAF; 
                                                   >> 534       G4bool Intersects_AF = IntersectChord( Point_A,   CurrentF_Point,
                                                   >> 535                                              NewSafety, stepLengthAF,
                                                   >> 536                                              PointG
                                                   >> 537                                              );
                                                   >> 538       if( Intersects_AF )
                                                   >> 539       {
                                                   >> 540         // G is our new Candidate for the intersection point.
                                                   >> 541         // It replaces  "E" and we will repeat the test to see if
                                                   >> 542         // it is a good enough approximate point for us.
                                                   >> 543         //       B    <- F
                                                   >> 544         //       E    <- G
                                                   >> 545         CurrentB_PointVelocity = ApproxIntersecPointV;
                                                   >> 546         CurrentE_Point = PointG;  
                                                   >> 547 
                                                   >> 548         // By moving point B, must take care if current AF has no intersection
                                                   >> 549   //  to try current FB!!
                                                   >> 550   final_section= false; 
                                                   >> 551 
                                                   >> 552 #ifdef G4VERBOSE
                                                   >> 553   if( fVerboseLevel > 3 ){
                                                   >> 554     G4cout << "G4PiF::LI> Investigating intermediate point"
                                                   >> 555      << " at s=" << ApproxIntersecPointV.GetCurveLength()
                                                   >> 556      << " on way to full s=" << CurveEndPointVelocity.GetCurveLength()
                                                   >> 557      << G4endl;
                                                   >> 558   }
                                                   >> 559 #endif
                                                   >> 560       }
                                                   >> 561       else  // not Intersects_AF
                                                   >> 562       {  
                                                   >> 563          // In this case:
                                                   >> 564          // There is NO intersection of AF with a volume boundary.
                                                   >> 565          // We must continue the search in the segment FB!
                                                   >> 566          fNavigator->LocateGlobalPointWithinVolume( CurrentF_Point );
                                                   >> 567 
                                                   >> 568          G4double stepLengthFB;
                                                   >> 569          G4ThreeVector PointH;
                                                   >> 570          // Check whether any volumes are encountered by the chord FB
                                                   >> 571          // ---------------------------------------------------------
                                                   >> 572          G4bool Intersects_FB = 
                                                   >> 573            IntersectChord( CurrentF_Point, Point_B, 
                                                   >> 574                            NewSafety,      stepLengthFB,  PointH );
                                                   >> 575          if( Intersects_FB )
                                                   >> 576          { 
                                                   >> 577            // There is an intersection of FB with a volume boundary
                                                   >> 578            // H <- First Intersection of Chord FB 
                                                   >> 579 
                                                   >> 580            // H is our new Candidate for the intersection point.
                                                   >> 581            // It replaces  "E" and we will repeat the test to see if
                                                   >> 582            // it is a good enough approximate point for us.
                                                   >> 583 
                                                   >> 584            // Note that F must be in volume volA  (the same as A)
                                                   >> 585            // (otherwise AF would meet a volume boundary!)
                                                   >> 586            //   A    <- F 
                                                   >> 587            //   E    <- H
                                                   >> 588            CurrentA_PointVelocity = ApproxIntersecPointV;
                                                   >> 589            CurrentE_Point = PointH;
                                                   >> 590          }
                                                   >> 591          else  // not Intersects_FB
                                                   >> 592          {
                                                   >> 593            // There is NO intersection of FB with a volume boundary
                                                   >> 594      if( final_section  ){
                                                   >> 595        // If B is the original endpoint, this means that whatever volume(s)
                                                   >> 596        // intersected the original chord, none touch the smaller chords 
                                                   >> 597        // we have used.
                                                   >> 598        // The value of IntersectedOrRecalculatedFT returned is likely not valid 
                                                   >> 599        //
                                                   >> 600        there_is_no_intersection = true;
                                                   >> 601      }else{
                                                   >> 602        // We must restore the original endpoint
                                                   >> 603        CurrentA_PointVelocity= CurrentB_PointVelocity;  // We have got to B
                                                   >> 604        CurrentB_PointVelocity= CurveEndPointVelocity;
                                                   >> 605        restoredFullEndpoint = true;
                                                   >> 606      }
                                                   >> 607 
                                                   >> 608          } // Endif (Intersects_FB)
                                                   >> 609        } // Endif (Intersects_AF)
                                                   >> 610 
                                                   >> 611        // Ensure that the new endpoints are not further apart in space
                                                   >> 612        // than on the curve due to different errors in the integration
                                                   >> 613        //
                                                   >> 614        G4double linDistSq, curveDist; 
                                                   >> 615        linDistSq = ( CurrentB_PointVelocity.GetPosition() 
                                                   >> 616                    - CurrentA_PointVelocity.GetPosition() ).mag2(); 
                                                   >> 617        curveDist = CurrentB_PointVelocity.GetCurveLength()
                                                   >> 618                    - CurrentA_PointVelocity.GetCurveLength();
                                                   >> 619        if( curveDist*(curveDist+2*perMillion ) < linDistSq )
                                                   >> 620        {
                                                   >> 621           // Re-integrate to obtain a new B
                                                   >> 622           //
                                                   >> 623           G4FieldTrack newEndPointFT=
                                                   >> 624                   ReEstimateEndpoint( CurrentA_PointVelocity,
                                                   >> 625                                       CurrentB_PointVelocity,
                                                   >> 626                                       linDistSq,    // to avoid recalculation
                                                   >> 627                                       curveDist );
                                                   >> 628     G4FieldTrack oldPointVelB = CurrentB_PointVelocity; 
                                                   >> 629     CurrentB_PointVelocity = newEndPointFT;
                                                   >> 630 
                                                   >> 631     if( final_section ){
                                                   >> 632        recalculatedEndPoint= true;
                                                   >> 633        IntersectedOrRecalculatedFT= newEndPointFT;  // So that we can return it, 
                                                   >> 634                                              //  if it is the endpoint!
                                                   >> 635     }
                                                   >> 636        }
                                                   >> 637        if( curveDist < 0.0 )
                                                   >> 638        {
                                                   >> 639          G4cerr << "G4PropagatorInField::LocateIntersectionPoint():" << G4endl
                                                   >> 640                 << "Error in advancing propagation." << G4endl;
                                                   >> 641    fVerboseLevel= 5; // Print out a maximum of information
                                                   >> 642          printStatus( CurrentA_PointVelocity,  CurrentB_PointVelocity,
                                                   >> 643                       -1.0, NewSafety,  substep_no, 0);
                                                   >> 644    G4cerr << " Point A (start) is " << CurrentA_PointVelocity << G4endl;
                                                   >> 645    G4cerr << " Point B (end)   is " << CurrentB_PointVelocity << G4endl;
                                                   >> 646    G4cerr << " curveDist is " << curveDist << G4endl;
                                                   >> 647          G4cerr << G4endl
                                                   >> 648                 << "The final curve point is not further along"
                                                   >> 649                 << " than the original!" << G4endl;
                                                   >> 650          G4Exception("G4PropagatorInField::LocateIntersectionPoint()", "FatalError",
                                                   >> 651                      FatalException, "Error in advancing propagation.");
                                                   >> 652        }
                                                   >> 653 
                                                   >> 654        if(restoredFullEndpoint) {
                                                   >> 655    final_section= restoredFullEndpoint;    
                                                   >> 656    restoredFullEndpoint=false;
                                                   >> 657        }
                                                   >> 658 
                                                   >> 659      } // EndIf ( E is close enough to the curve, ie point F. )
                                                   >> 660        // tests ChordAF_Vector.mag() <= maximum_lateral_displacement 
                                                   >> 661 
                                                   >> 662 #ifdef G4DEBUG_LOCATE_INTERSECTION  
                                                   >> 663 // #ifdef G4VERBOSE
                                                   >> 664     if( substep_no >= trigger_substepno_print ) {
                                                   >> 665        G4cout << "Difficulty in converging in G4PropagatorInField::LocateIntersectionPoint:"
                                                   >> 666         << " Substep no = " << substep_no << G4endl;
                                                   >> 667        if( substep_no == trigger_substepno_print ){
                                                   >> 668    printStatus( CurveStartPointVelocity,  CurveEndPointVelocity,
                                                   >> 669         -1.0, NewSafety,  0,          0);
                                                   >> 670        }
                                                   >> 671        G4cout << " State of point A: "; 
                                                   >> 672        printStatus( CurrentA_PointVelocity,  CurrentA_PointVelocity,
                                                   >> 673         -1.0, NewSafety,  substep_no-1, 0);
                                                   >> 674        G4cout << " State of point B: "; 
                                                   >> 675        printStatus( CurrentA_PointVelocity,  CurrentB_PointVelocity,
                                                   >> 676         -1.0, NewSafety,  substep_no, 0);
                                                   >> 677     }
                                                   >> 678 #endif
                                                   >> 679 
                                                   >> 680     substep_no++; 
                                                   >> 681 
                                                   >> 682   } while (  ( ! found_approximate_intersection )
                                                   >> 683        && ( ! there_is_no_intersection )     
                                                   >> 684        && ( substep_no <= max_substeps) ); // UNTIL found or failed
                                                   >> 685 
                                                   >> 686   if( substep_no > max_no_seen ) {
                                                   >> 687     max_no_seen = substep_no; 
                                                   >> 688     if( max_no_seen > warn_substeps ) {
                                                   >> 689       trigger_substepno_print= max_no_seen - 20;   // Want to see that last 20 steps 
                                                   >> 690     } 
                                                   >> 691   }
                                                   >> 692 
                                                   >> 693   if(  ( substep_no >= max_substeps) && !there_is_no_intersection && !found_approximate_intersection ) {
                                                   >> 694 
                                                   >> 695     G4cerr << "Problem in G4PropagatorInField::LocateIntersectionPoint:"
                                                   >> 696      << " Convergence is requiring too many substeps: " << substep_no;
                                                   >> 697     G4cerr << " Abandoning effort to intersect. " << G4endl;
                                                   >> 698     G4cerr << " Information on start & current step follows in cout: " << G4endl;
                                                   >> 699     G4cout << "Problem in G4PropagatorInField::LocateIntersectionPoint:"
                                                   >> 700      << " Convergence is requiring too many substeps: " << substep_no << G4endl;
                                                   >> 701     G4cout << "   found intersection= " << found_approximate_intersection
                                                   >> 702      << "   intersection exists = " <<  ! there_is_no_intersection << G4endl;
                                                   >> 703 
                                                   >> 704     G4cout << G4endl;
                                                   >> 705     G4cout << " Start and Endpoint of Requested Step " << G4endl;
                                                   >> 706     printStatus( CurveStartPointVelocity,  CurveEndPointVelocity,
                                                   >> 707      -1.0, NewSafety,  0,          0);
                                                   >> 708 
                                                   >> 709     G4cout << G4endl;
                                                   >> 710     G4cout << " 'Bracketing' starting and endpoint of current Sub-Step " << G4endl;
                                                   >> 711     printStatus( CurrentA_PointVelocity,  CurrentA_PointVelocity,
                                                   >> 712      -1.0, NewSafety,  substep_no-1, 0);
                                                   >> 713     printStatus( CurrentA_PointVelocity,  CurrentB_PointVelocity,
                                                   >> 714      -1.0, NewSafety,  substep_no, 0);
                                                   >> 715 
                                                   >> 716     G4cout << G4endl;
                                                   >> 717  
                                                   >> 718 // #ifdef G4DEBUG_LOCATE_INTERSECTION  
                                                   >> 719 // #ifdef G4VERBOSE
                                                   >> 720 // #endif
                                                   >> 721 
                                                   >> 722     // G4Exception("G4PropagatorInField::LocateIntersectionPoint()", "UnableToLocateIntersection",
                                                   >> 723     //    FatalException, "Too many substeps while trying to locate intersection.");
                                                   >> 724 
                                                   >> 725 #ifdef FUTURE_CORRECTION
                                                   >> 726     // Attempt to correct the results of the method // FIX - TODO
                                                   >> 727     if ( ! found_approximate_intersection ){ 
                                                   >> 728       recalculatedEndPoint= true;
                                                   >> 729       // Return the further valid intersection point -- potentially A ??  JA/19 Jan 2006
                                                   >> 730       IntersectedOrRecalculatedFT = CurrentA_PointVelocity;
                                                   >> 731 
                                                   >> 732       G4cout << "G4PropagatorInField::LocateIntersectionPoint:"
                                                   >> 733        << " did not convergence after " << substep_no << " substeps." << G4endl;
                                                   >> 734       G4cout << " The endpoint was adjused to pointA resulting from the last substep: " 
                                                   >> 735        << CurrentA_PointVelocity
                                                   >> 736        << G4endl;
                                                   >> 737     }
                                                   >> 738 #endif
                                                   >> 739 
                                                   >> 740     G4cout.precision( 10 ); 
                                                   >> 741     G4double done_len=     CurrentA_PointVelocity.GetCurveLength(); 
                                                   >> 742     G4double full_len= CurveEndPointVelocity.GetCurveLength();
                                                   >> 743     G4cout << " G4PropagatorInField::LocateIntersectionPoint(): " << G4endl
                                                   >> 744      << " Undertaken only length " << done_len
                                                   >> 745      << "  out of " << full_len << " required." << G4endl;
                                                   >> 746     G4cout << "  Remaining length = " << full_len - done_len << " " << G4endl; 
                                                   >> 747 
                                                   >> 748     G4Exception("G4PropagatorInField::LocateIntersectionPoint()", "UnableToLocateIntersection",
                                                   >> 749     FatalException, "Too many substeps while trying to locate intersection.");
                                                   >> 750 
                                                   >> 751   }
                                                   >> 752   else if( substep_no >= warn_substeps ) {  
                                                   >> 753     int oldprc= G4cout.precision( 10 ); 
                                                   >> 754     G4cout << " G4PropagatorInField::LocateIntersectionPoint(): Undertaken length "  
                                                   >> 755      << CurrentB_PointVelocity.GetCurveLength(); 
                                                   >> 756     G4cout << "  Needed "  << substep_no << " substeps.  Warning level= " << warn_substeps
                                                   >> 757      << " and maximum substeps= " << max_substeps << G4endl;
                                                   >> 758     G4Exception("G4PropagatorInField::LocateIntersectionPoint()", "DifficultyToLocateIntersection",
                                                   >> 759     JustWarning, "Many substeps while trying to locate intersection.");
                                                   >> 760     G4cout.precision( oldprc ); 
                                                   >> 761   }
                                                   >> 762 
                                                   >> 763   return  !there_is_no_intersection; //  Success or failure
                                                   >> 764 }
                                                   >> 765 
                                                   >> 766 ///////////////////////////////////////////////////////////////////////////
531 //                                                767 //
                                                   >> 768 // Dumps status of propagator.
                                                   >> 769 
532 void                                              770 void
533 G4PropagatorInField::printStatus( const G4Fiel << 771 G4PropagatorInField::printStatus( const G4FieldTrack&        StartFT,
534                                   const G4Fiel << 772                                   const G4FieldTrack&        CurrentFT, 
535                                         G4doub << 773                                         G4double             requestStep, 
536                                         G4doub << 774                                         G4double             safety,
537                                         G4int  << 775                                         G4int                stepNo, 
538                                         G4VPhy << 776                                         G4VPhysicalVolume*   startVolume)
539 {                                                 777 {
540   const G4int verboseLevel = fVerboseLevel;    << 778   const G4int verboseLevel= fVerboseLevel;
541   const G4ThreeVector StartPosition       = St    779   const G4ThreeVector StartPosition       = StartFT.GetPosition();
542   const G4ThreeVector StartUnitVelocity   = St    780   const G4ThreeVector StartUnitVelocity   = StartFT.GetMomentumDir();
543   const G4ThreeVector CurrentPosition     = Cu    781   const G4ThreeVector CurrentPosition     = CurrentFT.GetPosition();
544   const G4ThreeVector CurrentUnitVelocity = Cu    782   const G4ThreeVector CurrentUnitVelocity = CurrentFT.GetMomentumDir();
545                                                   783 
546   G4double step_len = CurrentFT.GetCurveLength    784   G4double step_len = CurrentFT.GetCurveLength() - StartFT.GetCurveLength();
547                                                << 
548   G4long oldprec;   // cout/cerr precision set << 
549                                                   785       
550   if( ((stepNo == 0) && (verboseLevel <3)) ||  << 786   if( ((stepNo == 0) && (verboseLevel <3))
                                                   >> 787       || (verboseLevel >= 3) )
551   {                                               788   {
552     oldprec = G4cout.precision(4);             << 789     static G4int noPrecision= 4;
                                                   >> 790     G4cout.precision(noPrecision);
                                                   >> 791     // G4cout.setf(ios_base::fixed,ios_base::floatfield);
                                                   >> 792     G4cout << std::setw( 6)  << " " 
                                                   >> 793            << std::setw( 25) << " Current Position  and  Direction" << " "
                                                   >> 794            << G4endl; 
553     G4cout << std::setw( 5) << "Step#"            795     G4cout << std::setw( 5) << "Step#" 
554            << std::setw(10) << "  s  " << " "  << 796      << std::setw(10) << "  s  " << " "
555            << std::setw(10) << "X(mm)" << " "     797            << std::setw(10) << "X(mm)" << " "
556            << std::setw(10) << "Y(mm)" << " "     798            << std::setw(10) << "Y(mm)" << " "  
557            << std::setw(10) << "Z(mm)" << " "     799            << std::setw(10) << "Z(mm)" << " "
558            << std::setw( 7) << " N_x " << " "     800            << std::setw( 7) << " N_x " << " "
559            << std::setw( 7) << " N_y " << " "     801            << std::setw( 7) << " N_y " << " "
560            << std::setw( 7) << " N_z " << " "     802            << std::setw( 7) << " N_z " << " " ;
561     G4cout << std::setw( 7) << " Delta|N|" <<  << 803     //     << G4endl; 
                                                   >> 804     G4cout     // << " >>> "
                                                   >> 805      << std::setw( 7) << " Delta|N|" << " "
                                                   >> 806       //   << std::setw( 7) << " Delta(N_z) " << " "
562            << std::setw( 9) << "StepLen" << "     807            << std::setw( 9) << "StepLen" << " "  
563            << std::setw(12) << "StartSafety" <    808            << std::setw(12) << "StartSafety" << " "  
564            << std::setw( 9) << "PhsStep" << "     809            << std::setw( 9) << "PhsStep" << " ";  
565     if( startVolume != nullptr )               << 810     if( startVolume ) {
566       { G4cout << std::setw(18) << "NextVolume << 811       G4cout << std::setw(18) << "NextVolume" << " "; 
567     G4cout.precision(oldprec);                 << 812     }
568     G4cout << G4endl;                          << 
569   }                                            << 
570   if((stepNo == 0) && (verboseLevel <=3))      << 
571   {                                            << 
572     // Recurse to print the start values       << 
573     //                                         << 
574     printStatus( StartFT, StartFT, -1.0, safet << 
575   }                                            << 
576   if( verboseLevel <= 3 )                      << 
577   {                                            << 
578     if( stepNo >= 0)                           << 
579       { G4cout << std::setw( 4) << stepNo << " << 
580     else                                       << 
581       { G4cout << std::setw( 5) << "Start" ; } << 
582     oldprec = G4cout.precision(8);             << 
583     G4cout << std::setw(10) << CurrentFT.GetCu << 
584     G4cout.precision(8);                       << 
585     G4cout << std::setw(10) << CurrentPosition << 
586            << std::setw(10) << CurrentPosition << 
587            << std::setw(10) << CurrentPosition << 
588     G4cout.precision(4);                       << 
589     G4cout << std::setw( 7) << CurrentUnitVelo << 
590            << std::setw( 7) << CurrentUnitVelo << 
591            << std::setw( 7) << CurrentUnitVelo << 
592     G4cout.precision(3);                       << 
593     G4cout << std::setw( 7)                    << 
594            << CurrentFT.GetMomentum().mag()-St << 
595     G4cout << std::setw( 9) << step_len << " " << 
596     G4cout << std::setw(12) << safety << " ";  << 
597     if( requestStep != -1.0 )                  << 
598       { G4cout << std::setw( 9) << requestStep << 
599     else                                       << 
600       { G4cout << std::setw( 9) << "Init/NotKn << 
601     if( startVolume != nullptr)                << 
602       { G4cout << std::setw(12) << startVolume << 
603     G4cout.precision(oldprec);                 << 
604     G4cout << G4endl;                             813     G4cout << G4endl;
605   }                                               814   }
606   else // if( verboseLevel > 3 )               << 815   if((stepNo == 0) && (verboseLevel <=3)){
607   {                                            << 816      // Recurse to print the start values
608     //  Multi-line output                      << 817      //
609                                                << 818      printStatus( StartFT, StartFT, -1.0, safety, -1, startVolume);
610     G4cout << "Step taken was " << step_len    << 819    }
611            << " out of PhysicalStep = " <<  re << 820    if( verboseLevel <= 3 )
612     G4cout << "Final safety is: " << safety << << 821    {
613     G4cout << "Chord length = " << (CurrentPos << 822      if( stepNo >= 0)
614            << G4endl;                          << 823        G4cout << std::setw( 4) << stepNo << " ";
615     G4cout << G4endl;                          << 824      else
616   }                                            << 825        G4cout << std::setw( 5) << "Start" ;
                                                   >> 826      G4cout.precision(8);
                                                   >> 827      G4cout << std::setw(10) << CurrentFT.GetCurveLength() << " "; 
                                                   >> 828      G4cout.precision(8);
                                                   >> 829      G4cout << std::setw(10) << CurrentPosition.x() << " "
                                                   >> 830             << std::setw(10) << CurrentPosition.y() << " "
                                                   >> 831             << std::setw(10) << CurrentPosition.z() << " ";
                                                   >> 832      G4cout.precision(4);
                                                   >> 833      G4cout << std::setw( 7) << CurrentUnitVelocity.x() << " "
                                                   >> 834             << std::setw( 7) << CurrentUnitVelocity.y() << " "
                                                   >> 835             << std::setw( 7) << CurrentUnitVelocity.z() << " ";
                                                   >> 836      //  G4cout << G4endl; 
                                                   >> 837      //     G4cout << " >>> " ; 
                                                   >> 838      G4cout.precision(3); 
                                                   >> 839      G4cout << std::setw( 7) << CurrentFT.GetMomentum().mag()- StartFT.GetMomentum().mag() << " "; 
                                                   >> 840      //   << std::setw( 7) << CurrentUnitVelocity.z() - InitialUnitVelocity.z() << " ";
                                                   >> 841      G4cout << std::setw( 9) << step_len << " "; 
                                                   >> 842      G4cout << std::setw(12) << safety << " ";
                                                   >> 843      if( requestStep != -1.0 ) 
                                                   >> 844        G4cout << std::setw( 9) << requestStep << " ";
                                                   >> 845      else
                                                   >> 846        G4cout << std::setw( 9) << "Init/NotKnown" << " "; 
                                                   >> 847 
                                                   >> 848      if( startVolume != 0)
                                                   >> 849      {
                                                   >> 850        G4cout << std::setw(12) << startVolume->GetName() << " ";
                                                   >> 851      }
                                                   >> 852 #if 0
                                                   >> 853      else
                                                   >> 854      {
                                                   >> 855        if( step_len != -1 )
                                                   >> 856          G4cout << std::setw(12) << "OutOfWorld" << " ";
                                                   >> 857        else
                                                   >> 858          G4cout << std::setw(12) << "NotGiven" << " ";
                                                   >> 859      }
                                                   >> 860 #endif
                                                   >> 861 
                                                   >> 862      G4cout << G4endl;
                                                   >> 863    }
                                                   >> 864    else // if( verboseLevel > 3 )
                                                   >> 865    {
                                                   >> 866      //  Multi-line output
                                                   >> 867        
                                                   >> 868      G4cout << "Step taken was " << step_len  
                                                   >> 869             << " out of PhysicalStep= " <<  requestStep << G4endl;
                                                   >> 870      G4cout << "Final safety is: " << safety << G4endl;
                                                   >> 871 
                                                   >> 872      G4cout << "Chord length = " << (CurrentPosition-StartPosition).mag()
                                                   >> 873             << G4endl;
                                                   >> 874      G4cout << G4endl; 
                                                   >> 875    }
617 }                                                 876 }
618                                                   877 
619 // ------------------------------------------- << 878 ///////////////////////////////////////////////////////////////////////////
620 // Prints Step diagnostics                     << 
621 //                                                879 //
                                                   >> 880 // Prints Step diagnostics
                                                   >> 881 
622 void                                              882 void 
623 G4PropagatorInField::PrintStepLengthDiagnostic    883 G4PropagatorInField::PrintStepLengthDiagnostic(
624                           G4double CurrentProp    884                           G4double CurrentProposedStepLength,
625                           G4double decreaseFac    885                           G4double decreaseFactor,
626                           G4double stepTrial,     886                           G4double stepTrial,
627                     const G4FieldTrack& )         887                     const G4FieldTrack& )
628 {                                                 888 {
629   G4long iprec= G4cout.precision(8);           << 889   G4cout << " PiF: NoZeroStep= " << fNoZeroStep
630   G4cout << " " << std::setw(12) << " PiF: NoZ << 890          << " CurrentProposedStepLength= " << CurrentProposedStepLength
631          << " " << std::setw(20) << " CurrentP << 891          << " Full_curvelen_last=" << fFull_CurveLen_of_LastAttempt
632          << " " << std::setw(18) << " Full_cur << 892          << " last proposed step-length= " << fLast_ProposedStepLength 
633          << " " << std::setw(18) << " last pro << 893          << " decreate factor = " << decreaseFactor
634          << " " << std::setw(18) << " decrease << 894          << " step trial = " << stepTrial
635          << " " << std::setw(15) << " step tri << 
636          << G4endl;                               895          << G4endl;
                                                   >> 896 }
637                                                   897 
638   G4cout << " " << std::setw(10) << fNoZeroSte << 898 G4bool
639          << " " << std::setw(20) << CurrentPro << 899 G4PropagatorInField::IntersectChord( G4ThreeVector  StartPointA, 
640          << " " << std::setw(18) << fFull_Curv << 900                                      G4ThreeVector  EndPointB,
641          << " " << std::setw(18) << fLast_Prop << 901                                      G4double      &NewSafety,
642          << " " << std::setw(18) << decreaseFa << 902                                      G4double      &LinearStepLength,
643          << " " << std::setw(15) << stepTrial  << 903                                      G4ThreeVector &IntersectionPoint
644          << G4endl;                            << 904                                    )
645   G4cout.precision( iprec );                   << 905 {
                                                   >> 906     // Calculate the direction and length of the chord AB
                                                   >> 907     G4ThreeVector  ChordAB_Vector = EndPointB - StartPointA;
                                                   >> 908     G4double       ChordAB_Length = ChordAB_Vector.mag();  // Magnitude (norm)
                                                   >> 909     G4ThreeVector  ChordAB_Dir =    ChordAB_Vector.unit();
                                                   >> 910     G4bool intersects;
                                                   >> 911 
                                                   >> 912     G4ThreeVector OriginShift = StartPointA - fPreviousSftOrigin ;
                                                   >> 913     G4double      MagSqShift  = OriginShift.mag2() ;
                                                   >> 914     G4double      currentSafety;
                                                   >> 915     G4bool        doCallNav= false;
                                                   >> 916 
                                                   >> 917     if( MagSqShift >= sqr(fPreviousSafety) )
                                                   >> 918     {
                                                   >> 919         currentSafety = 0.0 ;
                                                   >> 920     }else{
                                                   >> 921         currentSafety = fPreviousSafety - std::sqrt(MagSqShift) ;
                                                   >> 922     }
                                                   >> 923 
                                                   >> 924     if( fUseSafetyForOptimisation && (ChordAB_Length <= currentSafety) )
                                                   >> 925     {
                                                   >> 926        // The Step is guaranteed to be taken
                                                   >> 927 
                                                   >> 928        LinearStepLength = ChordAB_Length;
                                                   >> 929        intersects = false;
                                                   >> 930 
                                                   >> 931        NewSafety= currentSafety;
                                                   >> 932     }
                                                   >> 933     else
                                                   >> 934     {
                                                   >> 935        doCallNav= true; 
                                                   >> 936        // Check whether any volumes are encountered by the chord AB
                                                   >> 937        LinearStepLength = 
                                                   >> 938         fNavigator->ComputeStep( StartPointA, ChordAB_Dir,
                                                   >> 939                                  ChordAB_Length, NewSafety );
                                                   >> 940        intersects = (LinearStepLength <= ChordAB_Length); 
                                                   >> 941        // G4Navigator contracts to return k_infinity if len==asked
                                                   >> 942        // and it did not find a surface boundary at that length
                                                   >> 943        LinearStepLength = std::min( LinearStepLength, ChordAB_Length);
                                                   >> 944 
                                                   >> 945        // Save the last calculated safety!
                                                   >> 946        fPreviousSftOrigin = StartPointA;
                                                   >> 947        fPreviousSafety= NewSafety;
                                                   >> 948 
                                                   >> 949        if( intersects ){
                                                   >> 950           // Intersection Point of chord AB and either volume A's surface 
                                                   >> 951           //                                or a daughter volume's surface ..
                                                   >> 952           IntersectionPoint = StartPointA + LinearStepLength * ChordAB_Dir;
                                                   >> 953        }
                                                   >> 954     }
                                                   >> 955 
                                                   >> 956 #ifdef DEBUG_INTERSECTS_CHORD
                                                   >> 957     // printIntersection( 
                                                   >> 958     // StartPointA, EndPointB, LinearStepLength, IntersectionPoint, NewSafety
                                                   >> 959 
                                                   >> 960     G4cout << "Start="  << std::setw(12) << StartPointA       << " "
                                                   >> 961            << "End= "   << std::setw(8) << EndPointB         << " "
                                                   >> 962            << "StepIn=" << std::setw(8) << LinearStepLength  << " "
                                                   >> 963            << "NewSft=" << std::setw(8) << NewSafety
                                                   >> 964            << "NavCall" << doCallNav      << "  "
                                                   >> 965            << "In T/F " << intersects     << "  " 
                                                   >> 966            << "IntrPt=" << std::setw(8) << IntersectionPoint << " " 
                                                   >> 967            << G4endl;
                                                   >> 968 #endif
                                                   >> 969 
                                                   >> 970     return intersects;
                                                   >> 971 }
                                                   >> 972 
                                                   >> 973 // --------------------- oooo000000000000oooo ----------------------------
                                                   >> 974 
                                                   >> 975 G4FieldTrack G4PropagatorInField::
                                                   >> 976 ReEstimateEndpoint( const G4FieldTrack &CurrentStateA,  
                                                   >> 977                     const G4FieldTrack &EstimatedEndStateB,
                                                   >> 978                           G4double      linearDistSq,
                                                   >> 979                           G4double      curveDist
                                                   >> 980                   )
                                                   >> 981 {
                                                   >> 982   // G4double checkCurveDist= EstimatedEndStateB.GetCurveLength()
                                                   >> 983   //   - CurrentStateA.GetCurveLength();
                                                   >> 984   // G4double checkLinDistSq= (EstimatedEndStateB.GetPosition()
                                                   >> 985   //        - CurrentStateA.GetPosition() ).mag2();
                                                   >> 986 
                                                   >> 987   G4FieldTrack newEndPoint( CurrentStateA );
                                                   >> 988   G4MagInt_Driver* integrDriver= GetChordFinder()->GetIntegrationDriver(); 
                                                   >> 989 
                                                   >> 990   G4FieldTrack retEndPoint( CurrentStateA );
                                                   >> 991   G4bool goodAdvance;
                                                   >> 992   G4int  itrial=0;
                                                   >> 993   const G4int no_trials= 20;
                                                   >> 994 
                                                   >> 995   G4double endCurveLen= EstimatedEndStateB.GetCurveLength();
                                                   >> 996   do
                                                   >> 997   {
                                                   >> 998      G4double currentCurveLen= newEndPoint.GetCurveLength();
                                                   >> 999      G4double advanceLength= endCurveLen - currentCurveLen ; 
                                                   >> 1000 
                                                   >> 1001      goodAdvance= 
                                                   >> 1002        integrDriver->AccurateAdvance(newEndPoint, advanceLength, fEpsilonStep);
                                                   >> 1003      //              ***************
                                                   >> 1004   }
                                                   >> 1005   while( !goodAdvance && (++itrial < no_trials) );
                                                   >> 1006 
                                                   >> 1007   if( goodAdvance ) {
                                                   >> 1008     retEndPoint= newEndPoint; 
                                                   >> 1009   }else{
                                                   >> 1010     retEndPoint= EstimatedEndStateB; // Could not improve without major work !!
                                                   >> 1011   }
                                                   >> 1012 
                                                   >> 1013   //  All the work is done
                                                   >> 1014   //   below are some diagnostics only -- before the return!
                                                   >> 1015   // 
                                                   >> 1016   static const G4String MethodName("G4PropagatorInField::ReEstimateEndpoint");
                                                   >> 1017 #ifdef G4VERBOSE
                                                   >> 1018   G4int  latest_good_trials=0;
                                                   >> 1019   if( itrial > 1) {
                                                   >> 1020     if( fVerboseLevel > 0 ) {
                                                   >> 1021       G4cout << MethodName << " called - goodAdv= " << goodAdvance
                                                   >> 1022    << " trials = " << itrial << " previous good= " << latest_good_trials
                                                   >> 1023    << G4endl;
                                                   >> 1024     }
                                                   >> 1025     latest_good_trials=0; 
                                                   >> 1026   }else{   
                                                   >> 1027     latest_good_trials++; 
                                                   >> 1028   }
                                                   >> 1029 #endif
                                                   >> 1030 
                                                   >> 1031 #ifdef G4DEBUG_FIELD
                                                   >> 1032   G4double lengthDone=  newEndPoint.GetCurveLength() 
                                                   >> 1033                            - CurrentStateA.GetCurveLength(); 
                                                   >> 1034   if( !goodAdvance ) {
                                                   >> 1035     if( fVerboseLevel >= 3 ){
                                                   >> 1036       G4cout << MethodName << "> AccurateAdvance failed " ;
                                                   >> 1037       G4cout << " in " << itrial << " integration trials/steps. " << G4endl
                                                   >> 1038       G4cout << " It went only " << lengthDone << " instead of " << curveDist 
                                                   >> 1039        << " -- a difference of " << curveDist - lengthDone  << G4endl;
                                                   >> 1040       G4cout << " ReEstimateEndpoint> Reset endPoint to original value!" << G4endl;
                                                   >> 1041     }
                                                   >> 1042   }
                                                   >> 1043 
                                                   >> 1044   static G4int noInaccuracyWarnings = 0; 
                                                   >> 1045   G4int maxNoWarnings = 10;
                                                   >> 1046   if (  (noInaccuracyWarnings < maxNoWarnings ) 
                                                   >> 1047        || (fVerboseLevel > 1) )
                                                   >> 1048     {
                                                   >> 1049       G4cerr << "G4PropagatorInField::LocateIntersectionPoint():"
                                                   >> 1050              << G4endl
                                                   >> 1051              << " Warning: Integration inaccuracy requires" 
                                                   >> 1052              <<   " an adjustment in the step's endpoint."  << G4endl
                                                   >> 1053              << "   Two mid-points are further apart than their"
                                                   >> 1054              <<   " curve length difference"                << G4endl 
                                                   >> 1055              << "   Dist = "       << std::sqrt(linearDistSq)
                                                   >> 1056              << " curve length = " << curveDist             << G4endl; 
                                                   >> 1057       G4cerr << " Correction applied is " 
                                                   >> 1058              << (newEndPoint.GetPosition()-EstimatedEndStateB.GetPosition()).mag()
                                                   >> 1059              << G4endl;
                                                   >> 1060     }
                                                   >> 1061 #else
                                                   >> 1062   // Statistics on the RMS value of the corrections
                                                   >> 1063   static G4int    noCorrections=0;
                                                   >> 1064   static G4double sumCorrectionsSq = 0;
                                                   >> 1065   noCorrections++; 
                                                   >> 1066   if( goodAdvance ){
                                                   >> 1067     sumCorrectionsSq += (EstimatedEndStateB.GetPosition() - 
                                                   >> 1068        newEndPoint.GetPosition()).mag2();
                                                   >> 1069   }
                                                   >> 1070   linearDistSq -= curveDist; // To use linearDistSq ... !
                                                   >> 1071 #endif
                                                   >> 1072 
                                                   >> 1073   return retEndPoint;
646 }                                                 1074 }
647                                                   1075 
648 // Access the points which have passed through    1076 // Access the points which have passed through the filter. The
649 // points are stored as ThreeVectors for the i    1077 // points are stored as ThreeVectors for the initial impelmentation
650 // only (jacek 30/10/2002)                        1078 // only (jacek 30/10/2002)
651 // Responsibility for deleting the points lies    1079 // Responsibility for deleting the points lies with
652 // SmoothTrajectoryPoint, which is the points'    1080 // SmoothTrajectoryPoint, which is the points' final
653 // destination. The points pointer is set to N    1081 // destination. The points pointer is set to NULL, to ensure that
654 // the points are not re-used in subsequent st    1082 // the points are not re-used in subsequent steps, therefore THIS
655 // METHOD MUST BE CALLED EXACTLY ONCE PER STEP    1083 // METHOD MUST BE CALLED EXACTLY ONCE PER STEP. (jacek 08/11/2002)
656                                                   1084 
                                                   >> 1085 
657 std::vector<G4ThreeVector>*                       1086 std::vector<G4ThreeVector>*
658 G4PropagatorInField::GimmeTrajectoryVectorAndF << 1087 G4PropagatorInField::GimmeTrajectoryVectorAndForgetIt() const {
659 {                                              << 
660   // NB, GimmeThePointsAndForgetThem really fo    1088   // NB, GimmeThePointsAndForgetThem really forgets them, so it can
661   // only be called (exactly) once for each st    1089   // only be called (exactly) once for each step.
662                                                << 1090   if (fpTrajectoryFilter) {
663   if (fpTrajectoryFilter != nullptr)           << 
664   {                                            << 
665     return fpTrajectoryFilter->GimmeThePointsA    1091     return fpTrajectoryFilter->GimmeThePointsAndForgetThem();
                                                   >> 1092   } else {
                                                   >> 1093     return NULL;
666   }                                               1094   }
667   return nullptr;                              << 
668 }                                                 1095 }
669                                                   1096 
670 // ------------------------------------------- << 
671 //                                             << 
672 void                                              1097 void 
673 G4PropagatorInField::SetTrajectoryFilter(G4VCu << 1098 G4PropagatorInField::SetTrajectoryFilter(G4VCurvedTrajectoryFilter* filter) {
674 {                                              << 
675   fpTrajectoryFilter = filter;                    1099   fpTrajectoryFilter = filter;
676 }                                                 1100 }
677                                                   1101 
678 // ------------------------------------------- << 1102 
679 //                                             << 
680 void G4PropagatorInField::ClearPropagatorState    1103 void G4PropagatorInField::ClearPropagatorState()
681 {                                                 1104 {
682   // Goal: Clear all memory of previous steps, << 1105   G4Exception("G4PropagatorInField::ClearPropagatorState()", "NotImplemented",
683                                                << 1106               FatalException, "Functionality not yet implemented.");
684   fParticleIsLooping = false;                  << 
685   fNoZeroStep = 0;                             << 
686                                                << 
687   fSetFieldMgr = false;  // Has field-manager  << 
688   fEpsilonStep= 1.0e-5;  // Relative accuracy  << 
689                                                << 
690   End_PointAndTangent= G4FieldTrack( G4ThreeVe << 
691                                      G4ThreeVe << 
692                                      0.0,0.0,0 << 
693   fFull_CurveLen_of_LastAttempt = -1;          << 
694   fLast_ProposedStepLength = -1;               << 
695                                                << 
696   fPreviousSftOrigin= G4ThreeVector(0.,0.,0.); << 
697   fPreviousSafety= 0.0;                        << 
698                                                << 
699   fNewTrack = true;                            << 
700 }                                                 1107 }
701                                                   1108 
702 // ------------------------------------------- << 1109 G4FieldManager* 
703 //                                             << 1110 G4PropagatorInField::FindAndSetFieldManager( G4VPhysicalVolume* pCurrentPhysicalVolume)
704 G4FieldManager* G4PropagatorInField::          << 
705 FindAndSetFieldManager( G4VPhysicalVolume* pCu << 
706 {                                                 1111 {
707   G4FieldManager* currentFieldMgr;                1112   G4FieldManager* currentFieldMgr;
708                                                   1113 
709   currentFieldMgr = fDetectorFieldMgr;            1114   currentFieldMgr = fDetectorFieldMgr;
710   if( pCurrentPhysicalVolume != nullptr )      << 1115   if( pCurrentPhysicalVolume)
711   {                                               1116   {
712      G4FieldManager *pRegionFieldMgr = nullptr << 1117      G4FieldManager *newFieldMgr = 0;
713      G4LogicalVolume* pLogicalVol = pCurrentPh << 1118      newFieldMgr= pCurrentPhysicalVolume->GetLogicalVolume()->GetFieldManager();
714                                                << 1119      if ( newFieldMgr ) 
715      if( pLogicalVol != nullptr )              << 1120         currentFieldMgr = newFieldMgr;
716      {                                         << 
717         // Value for Region, if any, overrides << 
718         //                                     << 
719         G4Region*  pRegion = pLogicalVol->GetR << 
720         if( pRegion != nullptr )               << 
721         {                                      << 
722            pRegionFieldMgr = pRegion->GetField << 
723            if( pRegionFieldMgr != nullptr )    << 
724            {                                   << 
725               currentFieldMgr= pRegionFieldMgr << 
726            }                                   << 
727         }                                      << 
728                                                << 
729         // 'Local' Value from logical volume,  << 
730         //                                     << 
731         localFieldMgr = pLogicalVol->GetFieldM << 
732         if ( localFieldMgr != nullptr )        << 
733         {                                      << 
734            currentFieldMgr = localFieldMgr;    << 
735         }                                      << 
736      }                                         << 
737   }                                               1121   }
738   fCurrentFieldMgr = currentFieldMgr;          << 1122   fCurrentFieldMgr= currentFieldMgr;
739                                                   1123 
740   // Flag that field manager has been set      << 1124   // Flag that field manager has been set.
741   //                                           << 1125   fSetFieldMgr= true;
742   fSetFieldMgr = true;                         << 
743                                                   1126 
744   return currentFieldMgr;                         1127   return currentFieldMgr;
745 }                                                 1128 }
746                                                   1129 
747 // ------------------------------------------- << 1130 G4int G4PropagatorInField::SetVerboseLevel( G4int Verbose )
748 //                                             << 
749 G4int G4PropagatorInField::SetVerboseLevel( G4 << 
750 {                                                 1131 {
751   G4int oldval = fVerboseLevel;                << 1132   G4int oldval= fVerboseLevel;
752   fVerboseLevel = level;                       << 1133   fVerboseLevel= Verbose;
753                                                   1134 
754   // Forward the verbose level 'reduced' to Ch << 1135   // Forward the verbose level 'reduced' to ChordFinder, MagIntegratorDriver ... ? 
755   // MagIntegratorDriver ... ?                 << 1136   G4MagInt_Driver* integrDriver= GetChordFinder()->GetIntegrationDriver(); 
756   //                                           << 1137   integrDriver->SetVerboseLevel( Verbose - 2 ); 
757   auto integrDriver = GetChordFinder()->GetInt << 1138   G4cout << "Set Driver verbosity to " << Verbose - 2 << G4endl;
758   integrDriver->SetVerboseLevel( fVerboseLevel << 
759   G4cout << "Set Driver verbosity to " << fVer << 
760                                                   1139 
761   return oldval;                                  1140   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 }                                                 1141 }
886                                                   1142