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 10.3)


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