Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/magneticfield/src/G4ChordFinder.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/magneticfield/src/G4ChordFinder.cc (Version 11.3.0) and /geometry/magneticfield/src/G4ChordFinder.cc (Version 10.6.p2)


  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 // G4ChordFinder implementation                    26 // G4ChordFinder implementation
 27 //                                                 27 //
 28 // Author: J.Apostolakis - Design and implemen     28 // Author: J.Apostolakis - Design and implementation - 25.02.1997
 29 // -------------------------------------------     29 // -------------------------------------------------------------------
 30                                                    30 
 31 #include <iomanip>                                 31 #include <iomanip>
 32                                                    32 
 33 #include "G4ChordFinder.hh"                        33 #include "G4ChordFinder.hh"
 34 #include "G4SystemOfUnits.hh"                      34 #include "G4SystemOfUnits.hh"
 35 #include "G4MagneticField.hh"                      35 #include "G4MagneticField.hh"
 36 #include "G4Mag_UsualEqRhs.hh"                     36 #include "G4Mag_UsualEqRhs.hh"
 37 #include "G4MagIntegratorDriver.hh"                37 #include "G4MagIntegratorDriver.hh"
 38 // #include "G4ClassicalRK4.hh"                    38 // #include "G4ClassicalRK4.hh"
 39 // #include "G4CashKarpRKF45.hh"                   39 // #include "G4CashKarpRKF45.hh"
 40 // #include "G4NystromRK4.hh"                  << 
 41 // #include "G4BogackiShampine23.hh"               40 // #include "G4BogackiShampine23.hh"
 42 // #include "G4BogackiShampine45.hh"               41 // #include "G4BogackiShampine45.hh"
 43                                                << 
 44 #include "G4DormandPrince745.hh"                   42 #include "G4DormandPrince745.hh"
 45                                                    43 
 46 // New templated stepper(s) -- avoid virtual c <<  44 // New FSAL type driver / steppers -----
 47 #include "G4TDormandPrince45.hh"               << 
 48                                                << 
 49 // FSAL type driver / steppers -----           << 
 50 #include "G4FSALIntegrationDriver.hh"              45 #include "G4FSALIntegrationDriver.hh"
 51 #include "G4VFSALIntegrationStepper.hh"            46 #include "G4VFSALIntegrationStepper.hh"
 52 #include "G4RK547FEq1.hh"                          47 #include "G4RK547FEq1.hh"
 53 // #include "G4RK547FEq2.hh"                       48 // #include "G4RK547FEq2.hh"
 54 // #include "G4RK547FEq3.hh"                       49 // #include "G4RK547FEq3.hh"
 55 // #include "G4FSALBogackiShampine45.hh"       <<  50 #include "G4NystromRK4.hh"
 56 // #include "G4FSALDormandPrince745.hh"        << 
 57                                                    51 
 58 // Templated type drivers -----                <<  52 // New FSAL type driver / steppers -----
 59 #include "G4IntegrationDriver.hh"                  53 #include "G4IntegrationDriver.hh"
 60 #include "G4InterpolationDriver.hh"                54 #include "G4InterpolationDriver.hh"
 61                                                <<  55 // #include "G4FSALBogackiShampine45.hh"
                                                   >>  56 // #include "G4FSALDormandPrince745.hh"
 62 #include "G4HelixHeum.hh"                          57 #include "G4HelixHeum.hh"
 63 #include "G4BFieldIntegrationDriver.hh"            58 #include "G4BFieldIntegrationDriver.hh"
 64                                                    59 
 65 #include "G4QSSDriverCreator.hh"               << 
 66                                                << 
 67 #include "G4CachedMagneticField.hh"            << 
 68                                                << 
 69 #include <cassert>                                 60 #include <cassert>
 70 #include <memory>                              << 
 71                                                    61 
 72 G4bool G4ChordFinder::gVerboseCtor = false;    << 
 73 // ...........................................     62 // ..........................................................................
 74                                                    63 
 75 G4ChordFinder::G4ChordFinder(G4VIntegrationDri     64 G4ChordFinder::G4ChordFinder(G4VIntegrationDriver* pIntegrationDriver)
 76   : fDefaultDeltaChord(0.25 * mm), fIntgrDrive     65   : fDefaultDeltaChord(0.25 * mm), fIntgrDriver(pIntegrationDriver)
 77 {                                                  66 {
 78   // Simple constructor -- it does not create      67   // Simple constructor -- it does not create equation
 79   if( gVerboseCtor )                           <<  68 
 80   {                                            << 
 81     G4cout << "G4ChordFinder: Simple construct << 
 82   }                                            << 
 83                                                << 
 84   fDeltaChord = fDefaultDeltaChord;       // P     69   fDeltaChord = fDefaultDeltaChord;       // Parameters
 85 }                                                  70 }
 86                                                    71 
                                                   >>  72 
 87 // ...........................................     73 // ..........................................................................
 88                                                    74 
 89 G4ChordFinder::G4ChordFinder( G4MagneticField*     75 G4ChordFinder::G4ChordFinder( G4MagneticField*        theMagField,
 90                               G4double         <<  76                               G4double                stepMinimum, 
 91                               G4MagIntegratorS     77                               G4MagIntegratorStepper* pItsStepper,
 92                               G4int            <<  78                               G4bool                  useFSALstepper )
 93   : fDefaultDeltaChord(0.25 * mm)                  79   : fDefaultDeltaChord(0.25 * mm)
 94 {                                                  80 {
 95   // Construct the Chord Finder                    81   // Construct the Chord Finder
 96   // by creating in inverse order the Driver,      82   // by creating in inverse order the Driver, the Stepper and EqRhs ...
 97   constexpr G4int nVar6 = 6;   // Components i << 
 98                                                << 
 99   fDeltaChord = fDefaultDeltaChord;       // P << 
100                                                << 
101   G4cout << " G4ChordFinder: stepperDriverId:  << 
102                                                    83 
103   G4bool useFSALstepper     = (stepperDriverId <<  84   fDeltaChord = fDefaultDeltaChord;       // Parameters
104   G4bool useTemplatedStepper= (stepperDriverId << 
105   G4bool useRegularStepper  = (stepperDriverId << 
106   G4bool useBfieldDriver    = (stepperDriverId << 
107   G4bool useG4QSSDriver     = (stepperDriverId << 
108                                                << 
109   if( stepperDriverId == kQss3DriverType)      << 
110   {                                            << 
111     stepperDriverId = kQss2DriverType;         << 
112     G4cout << " G4ChordFinder: QSS 3 is curren << 
113   }                                            << 
114                                                    85 
115   using EquationType = G4Mag_UsualEqRhs;       <<  86   using NewFsalStepperType = G4RK547FEq1; // or 2 or 3
116                                                <<  87   const char* NewFSALStepperName =
117   using TemplatedStepperType =                 <<  88       "G4RK574FEq1> FSAL 4th/5th order 7-stage 'Equilibrium-type' #1.";
118          G4TDormandPrince45<EquationType,nVar6 << 
119   const char* TemplatedStepperName =           << 
120       "G4TDormandPrince745 (templated Dormand- << 
121                                                << 
122   using RegularStepperType =                       89   using RegularStepperType =
123          G4DormandPrince745; // 5th order embe <<  90          G4DormandPrince745; // 5th order embedded method. High efficiency.
124          // G4ClassicalRK4;        // The old      91          // G4ClassicalRK4;        // The old default
125          // G4CashKarpRKF45;       // First em     92          // G4CashKarpRKF45;       // First embedded method in G4
126          // G4BogackiShampine45;   // High eff     93          // G4BogackiShampine45;   // High efficiency 5th order embedded method
127          // G4NystromRK4;          // Nystrom      94          // G4NystromRK4;          // Nystrom stepper 4th order 
128          // G4RK547FEq1;  // or 2 or 3             95          // G4RK547FEq1;  // or 2 or 3 
129   const char* RegularStepperName =                 96   const char* RegularStepperName = 
130       "G4DormandPrince745 (aka DOPRI5): 5th/4t <<  97       "G4DormandPrince745 (aka DOPRI5): 5th/4th Order 7-stage embedded stepper";
131       // "BogackiShampine 45 (Embedded 5th/4th     98       // "BogackiShampine 45 (Embedded 5th/4th Order, 7-stage)";
132       // "Nystrom stepper 4th order";              99       // "Nystrom stepper 4th order";
133                                                   100 
134   using NewFsalStepperType = G4DormandPrince74 << 101   // Configurable
135                                                << 102   G4bool forceFSALstepper = false; //  Choice - true to enable !!
136   const char* NewFSALStepperName =             << 103   G4bool recallFSALflag  = useFSALstepper;
137       "G4RK574FEq1> FSAL 4th/5th order 7-stage << 104   useFSALstepper   = forceFSALstepper || useFSALstepper;
138                                                << 105 
139 #ifdef G4DEBUG_FIELD                              106 #ifdef G4DEBUG_FIELD
140   static G4bool verboseDebug = true;           << 
141   if( verboseDebug )                           << 
142   {                                            << 
143      G4cout << "G4ChordFinder 2nd Constructor     107      G4cout << "G4ChordFinder 2nd Constructor called. " << G4endl;
144      G4cout << " Arguments: " << G4endl        << 108      G4cout << " Parameters: " << G4endl;
145             << " - min step = " << stepMinimum << 109      G4cout << "    useFSAL stepper= " << useFSALstepper
146             << " - stepper ptr provided : "    << 110             << " (request = " << recallFSALflag 
147             << ( pItsStepper==nullptr ? " no   << 111             << " force FSAL = " << forceFSALstepper << " )" << G4endl;
148      if( pItsStepper==nullptr )                << 
149         G4cout << " - stepper/driver Id = " << << 
150                << "  useFSAL = " << useFSALste << 
151                << "  , useTemplated = " << use << 
152                << "  , useRegular = " << useRe << 
153                << "  , useFSAL = " << useFSALs << 
154                << G4endl;                      << 
155   }                                            << 
156 #endif                                            112 #endif
157                                                   113 
158   // useHigherStepper = forceHigherEffiencySte    114   // useHigherStepper = forceHigherEffiencyStepper || useHigherStepper;
159                                                << 115   
160   auto  pEquation = new G4Mag_UsualEqRhs(theMa << 116   G4Mag_EqRhs* pEquation = new G4Mag_UsualEqRhs(theMagField);
161   fEquation = pEquation;                          117   fEquation = pEquation;                            
162                                                   118 
163   // G4MagIntegratorStepper* regularStepper =     119   // G4MagIntegratorStepper* regularStepper = nullptr;
164   // G4VFSALIntegrationStepper* fsalStepper =     120   // G4VFSALIntegrationStepper* fsalStepper = nullptr; // for FSAL steppers only
165   // G4MagIntegratorStepper* oldFSALStepper =     121   // G4MagIntegratorStepper* oldFSALStepper = nullptr;
166                                                   122 
167   G4bool errorInStepperCreation = false;          123   G4bool errorInStepperCreation = false;
168                                                   124 
169   std::ostringstream message;  // In case of f    125   std::ostringstream message;  // In case of failure, load with description !
170                                                   126 
171   if( pItsStepper != nullptr )                    127   if( pItsStepper != nullptr )
172   {                                               128   {
173      if( gVerboseCtor )                        << 129      // Type is not known - so must use old class
174      {                                         << 130      fIntgrDriver = new G4IntegrationDriver<G4MagIntegratorStepper>(
175        G4cout << " G4ChordFinder: Creating G4I << 131         stepMinimum, pItsStepper, pItsStepper->GetNumberOfVariables());
176               << " stepMinimum = " << stepMini << 
177               << " numVar= " << pItsStepper->G << 
178      }                                         << 
179                                                << 
180      // Stepper type is not known - so must us << 
181       if(pItsStepper->isQSS())                 << 
182       {                                        << 
183          // fIntgrDriver = pItsStepper->build_ << 
184          G4Exception("G4ChordFinder::G4ChordFi << 
185                       "GeomField1001", FatalEx << 
186                       "Cannot provide  QSS ste << 
187       }                                        << 
188       else                                     << 
189       {                                        << 
190          fIntgrDriver = new G4IntegrationDrive << 
191                                   pItsStepper, << 
192          // Stepper type is not known - so mus << 
193          // Non-interpolating driver used by d << 
194          // WAS:  fIntgrDriver = pItsStepper-> << 
195       }                                        << 
196      // -- Older:                              << 
197      // G4cout << " G4ChordFinder: Creating G4 << 
198      // Type is not known - so must use old cl << 
199      // fIntgrDriver = new G4MagInt_Driver( st << 
200      //                                 pItsSt << 
201   }                                               132   }
202   else if ( useTemplatedStepper )              << 133   else if ( !useFSALstepper )
203   {                                               134   {
204      if( gVerboseCtor )                        << 
205      {                                         << 
206         G4cout << " G4ChordFinder: Creating Te << 
207                << TemplatedStepperName << G4en << 
208      }                                         << 
209      // RegularStepperType* regularStepper = n    135      // RegularStepperType* regularStepper = nullptr; // To check the exception
210      auto templatedStepper = new TemplatedStep << 136      auto regularStepper = new RegularStepperType(pEquation);
211      //                    *** ***************    137      //                    *** ******************
212      //                                           138      //
213      // Alternative - for G4NystromRK4:           139      // Alternative - for G4NystromRK4:
214      // = new G4NystromRK4(pEquation, 0.1*mm )    140      // = new G4NystromRK4(pEquation, 0.1*mm );
215      fRegularStepperOwned = templatedStepper;  << 
216      if( templatedStepper == nullptr )         << 
217      {                                         << 
218         message << "Templated Stepper instanti << 
219         message << "G4ChordFinder: Attempted t << 
220                 << TemplatedStepperName << " t << 
221         errorInStepperCreation = true;         << 
222      }                                         << 
223      else                                      << 
224      {                                         << 
225         fIntgrDriver = new G4IntegrationDriver << 
226            stepMinimum, templatedStepper, nVar << 
227         if( gVerboseCtor )                     << 
228         {                                      << 
229            G4cout << " G4ChordFinder: Using G4 << 
230         }                                      << 
231      }                                         << 
232                                                << 
233   }                                            << 
234   else if ( useRegularStepper   )  // Plain st << 
235   {                                            << 
236      auto regularStepper = new RegularStepperT << 
237      //                    *** *************** << 
238      fRegularStepperOwned = regularStepper;       141      fRegularStepperOwned = regularStepper;
239                                                   142 
240      if( gVerboseCtor )                        << 
241      {                                         << 
242         G4cout << " G4ChordFinder: Creating Dr << 
243      }                                         << 
244                                                << 
245      if( regularStepper == nullptr )              143      if( regularStepper == nullptr )
246      {                                            144      {
247         message << "Regular Stepper instantiat << 145         message << "Stepper instantiation FAILED." << G4endl;        
248         message << "G4ChordFinder: Attempted t    146         message << "G4ChordFinder: Attempted to instantiate "
249                 << RegularStepperName << " typ    147                 << RegularStepperName << " type stepper " << G4endl;
                                                   >> 148         G4Exception("G4ChordFinder::G4ChordFinder()",
                                                   >> 149                     "GeomField1001", JustWarning, message);
250         errorInStepperCreation = true;            150         errorInStepperCreation = true;
251      }                                            151      }
252      else                                         152      else
253      {                                            153      {
254         auto dp5= dynamic_cast<G4DormandPrince << 
255         if( dp5 != nullptr )                   << 
256         {                                      << 
257            fIntgrDriver = new G4InterpolationD << 
258                                   stepMinimum, << 
259            if( gVerboseCtor )                  << 
260            {                                   << 
261               G4cout << " Using InterpolationD << 
262            }                                   << 
263         }                                      << 
264         else                                   << 
265         {                                      << 
266            fIntgrDriver = new G4IntegrationDri << 
267                                   stepMinimum, << 
268            if( gVerboseCtor )                  << 
269            {                                   << 
270               G4cout << " Using IntegrationDri << 
271            }                                   << 
272         }                                      << 
273      }                                         << 
274   }                                            << 
275   else if ( useBfieldDriver )                  << 
276   {                                            << 
277      auto regularStepper = new G4DormandPrince << 
278      //                    *** *************** << 
279      //                                        << 
280      fRegularStepperOwned = regularStepper;    << 
281                                                << 
282      {                                         << 
283         using SmallStepDriver = G4Interpolatio    154         using SmallStepDriver = G4InterpolationDriver<G4DormandPrince745>;
284         using LargeStepDriver = G4IntegrationD    155         using LargeStepDriver = G4IntegrationDriver<G4HelixHeum>;
285                                                   156 
286         fLongStepper = std::make_unique<G4Heli << 157         fLongStepper = std::unique_ptr<G4HelixHeum>(new G4HelixHeum(pEquation));
287                                                   158         
288         fIntgrDriver = new G4BFieldIntegration    159         fIntgrDriver = new G4BFieldIntegrationDriver(
289           std::make_unique<SmallStepDriver>(st << 160           std::unique_ptr<SmallStepDriver>(new SmallStepDriver(stepMinimum,
290               regularStepper, regularStepper-> << 161               regularStepper, regularStepper->GetNumberOfVariables())),
291           std::make_unique<LargeStepDriver>(st << 162           std::unique_ptr<LargeStepDriver>(new LargeStepDriver(stepMinimum,
292               fLongStepper.get(), regularStepp << 163               fLongStepper.get(), regularStepper->GetNumberOfVariables())) );
293                                                   164         
294         if( fIntgrDriver == nullptr)              165         if( fIntgrDriver == nullptr)
295         {                                         166         {        
296            message << "Using G4BFieldIntegrati    167            message << "Using G4BFieldIntegrationDriver with "
297                    << RegularStepperName << "     168                    << RegularStepperName << " type stepper " << G4endl;
298            message << "Driver instantiation FA    169            message << "Driver instantiation FAILED." << G4endl;
299            G4Exception("G4ChordFinder::G4Chord    170            G4Exception("G4ChordFinder::G4ChordFinder()",
300                        "GeomField1001", JustWa    171                        "GeomField1001", JustWarning, message);
301         }                                         172         }
302      }                                            173      }
303   }                                               174   }
304   else if( useG4QSSDriver )                    << 
305   {                                            << 
306      if( stepperDriverId == kQss2DriverType )  << 
307      {                                         << 
308        auto qssStepper2 = G4QSSDriverCreator:: << 
309        if( gVerboseCtor )                      << 
310        {                                       << 
311          G4cout << "-- Created QSS-2 stepper"  << 
312        }                                       << 
313        fIntgrDriver = G4QSSDriverCreator::Crea << 
314      }                                         << 
315      else                                      << 
316      {                                         << 
317        auto qssStepper3 = G4QSSDriverCreator:: << 
318        if( gVerboseCtor )                      << 
319        {                                       << 
320          G4cout << "-- Created QSS-3 stepper"  << 
321        }                                       << 
322        fIntgrDriver = G4QSSDriverCreator::Crea << 
323      }                                         << 
324      if( gVerboseCtor )                        << 
325      {                                         << 
326        G4cout << "-- G4ChordFinder: Using QSS  << 
327      }                                         << 
328   }                                            << 
329   else                                            175   else
330   {                                               176   {
331      auto fsalStepper=  new NewFsalStepperType    177      auto fsalStepper=  new NewFsalStepperType(pEquation);
332      //                 *** ******************    178      //                 *** ******************
333      fNewFSALStepperOwned = fsalStepper;          179      fNewFSALStepperOwned = fsalStepper;
334                                                   180 
335      if( fsalStepper == nullptr )                 181      if( fsalStepper == nullptr )
336      {                                            182      {
337         message << "Stepper instantiation FAIL    183         message << "Stepper instantiation FAILED." << G4endl;        
338         message << "Attempted to instantiate "    184         message << "Attempted to instantiate "
339                 << NewFSALStepperName << " typ    185                 << NewFSALStepperName << " type stepper " << G4endl;
340         G4Exception("G4ChordFinder::G4ChordFin    186         G4Exception("G4ChordFinder::G4ChordFinder()",
341                     "GeomField1001", JustWarni    187                     "GeomField1001", JustWarning, message);
342         errorInStepperCreation = true;            188         errorInStepperCreation = true;
343      }                                            189      }
344      else                                         190      else
345      {                                            191      {
346         fIntgrDriver = new                        192         fIntgrDriver = new
347            G4FSALIntegrationDriver<NewFsalStep    193            G4FSALIntegrationDriver<NewFsalStepperType>(stepMinimum, fsalStepper,
348                                           fsal    194                                           fsalStepper->GetNumberOfVariables() );
349            //  ====  Create the driver which k    195            //  ====  Create the driver which knows the class type
350                                                   196         
351         if( fIntgrDriver == nullptr )             197         if( fIntgrDriver == nullptr )
352         {                                         198         {
353            message << "Using G4FSALIntegration    199            message << "Using G4FSALIntegrationDriver with stepper type: "
354                    << NewFSALStepperName << G4    200                    << NewFSALStepperName << G4endl;
355            message << "Integration Driver inst    201            message << "Integration Driver instantiation FAILED." << G4endl;
356            G4Exception("G4ChordFinder::G4Chord    202            G4Exception("G4ChordFinder::G4ChordFinder()",
357                        "GeomField1001", JustWa    203                        "GeomField1001", JustWarning, message);
358         }                                         204         }
359      }                                            205      }
360   }                                               206   }
361                                                   207 
362   // -- Main work is now done                     208   // -- Main work is now done
363                                                   209   
364   //    Now check that no error occured, and r    210   //    Now check that no error occured, and report it if one did.
365                                                   211   
366   // To test failure to create driver             212   // To test failure to create driver
367   // delete fIntgrDriver;                         213   // delete fIntgrDriver;
368   // fIntgrDriver = nullptr;                      214   // fIntgrDriver = nullptr;
369                                                   215 
370   // Detect and report Error conditions           216   // Detect and report Error conditions
371   //                                              217   //
372   if( errorInStepperCreation || (fIntgrDriver     218   if( errorInStepperCreation || (fIntgrDriver == nullptr ))
373   {                                               219   {
374      std::ostringstream errmsg;                   220      std::ostringstream errmsg;
375                                                   221      
376      if( errorInStepperCreation )                 222      if( errorInStepperCreation )
377      {                                            223      {
378         errmsg  << "ERROR> Failure to create S    224         errmsg  << "ERROR> Failure to create Stepper object." << G4endl
379                 << "       -------------------    225                 << "       --------------------------------" << G4endl;
380      }                                            226      }
381      if (fIntgrDriver == nullptr )                227      if (fIntgrDriver == nullptr )
382      {                                            228      {
383         errmsg  << "ERROR> Failure to create I    229         errmsg  << "ERROR> Failure to create Integration-Driver object."
384                 << G4endl                         230                 << G4endl
385                 << "       -------------------    231                 << "       -------------------------------------------"
386                 << G4endl;                        232                 << G4endl;
387      }                                            233      }
388      const std::string BoolName[2]= { "False",    234      const std::string BoolName[2]= { "False", "True" }; 
389      errmsg << "  Configuration:  (constructor    235      errmsg << "  Configuration:  (constructor arguments) " << G4endl        
390             << "    provided Stepper = " << pI    236             << "    provided Stepper = " << pItsStepper << G4endl
391             << " stepper/driver Id = " << step << 237             << "    use FSAL stepper = " << BoolName[useFSALstepper]
392             << "   useTemplated = " << BoolNam << 238             << " (request = " << BoolName[recallFSALflag]
393             << "   useRegular = " << BoolName[ << 239             << " force FSAL = " << BoolName[forceFSALstepper] << " )"
394             << "   useFSAL = " << BoolName[use << 
395             << "   using combo BField Driver = << 
396                    BoolName[ ! (useFSALstepper << 
397                                || useRegularSt << 
398             << G4endl;                            240             << G4endl;
399      errmsg << message.str();                     241      errmsg << message.str(); 
400      errmsg << "Aborting.";                       242      errmsg << "Aborting.";
401      G4Exception("G4ChordFinder::G4ChordFinder    243      G4Exception("G4ChordFinder::G4ChordFinder() - constructor 2",
402                  "GeomField0003", FatalExcepti    244                  "GeomField0003", FatalException, errmsg);     
403   }                                               245   }
404                                                   246 
405   assert(    ( pItsStepper != nullptr )           247   assert(    ( pItsStepper != nullptr ) 
406           || ( fRegularStepperOwned != nullptr    248           || ( fRegularStepperOwned != nullptr )
407           || ( fNewFSALStepperOwned != nullptr    249           || ( fNewFSALStepperOwned != nullptr )
408           || useG4QSSDriver                    << 
409      );                                           250      );
410   assert( fIntgrDriver != nullptr );              251   assert( fIntgrDriver != nullptr );
411 }                                                 252 }
412                                                   253 
                                                   >> 254 
413 // ...........................................    255 // ......................................................................
414                                                   256 
415 G4ChordFinder::~G4ChordFinder()                   257 G4ChordFinder::~G4ChordFinder()
416 {                                                 258 {
417   delete fEquation;                               259   delete fEquation;
418   delete fRegularStepperOwned;                    260   delete fRegularStepperOwned;
419   delete fNewFSALStepperOwned;                    261   delete fNewFSALStepperOwned;
420   delete fCachedField;                            262   delete fCachedField;
421   delete fIntgrDriver;                            263   delete fIntgrDriver;
422 }                                                 264 }
423                                                   265 
424 // ...........................................    266 // ...........................................................................
425                                                   267 
426 G4FieldTrack                                      268 G4FieldTrack
427 G4ChordFinder::ApproxCurvePointS( const G4Fiel    269 G4ChordFinder::ApproxCurvePointS( const G4FieldTrack&  CurveA_PointVelocity, 
428                                   const G4Fiel    270                                   const G4FieldTrack&  CurveB_PointVelocity, 
429                                   const G4Fiel    271                                   const G4FieldTrack&  ApproxCurveV,
430                                   const G4Thre    272                                   const G4ThreeVector& CurrentE_Point,
431                                   const G4Thre    273                                   const G4ThreeVector& CurrentF_Point,
432                                   const G4Thre    274                                   const G4ThreeVector& PointG,
433                                         G4bool    275                                         G4bool first, G4double eps_step)
434 {                                                 276 {
435   // ApproxCurvePointS is 2nd implementation o    277   // ApproxCurvePointS is 2nd implementation of ApproxCurvePoint.
436   // Use Brent Algorithm (or InvParabolic) whe    278   // Use Brent Algorithm (or InvParabolic) when possible.
437   // Given a starting curve point A (CurveA_Po    279   // Given a starting curve point A (CurveA_PointVelocity), curve point B
438   // (CurveB_PointVelocity), a point E which i    280   // (CurveB_PointVelocity), a point E which is (generally) not on the curve
439   // and  a point F which is on the curve (fir    281   // and  a point F which is on the curve (first approximation), find new
440   // point S on the curve closer to point E.      282   // point S on the curve closer to point E. 
441   // While advancing towards S utilise 'eps_st    283   // While advancing towards S utilise 'eps_step' as a measure of the
442   // relative accuracy of each Step.              284   // relative accuracy of each Step.
443                                                   285 
444   G4FieldTrack EndPoint(CurveA_PointVelocity);    286   G4FieldTrack EndPoint(CurveA_PointVelocity);
445   if(!first) { EndPoint = ApproxCurveV; }         287   if(!first) { EndPoint = ApproxCurveV; }
446                                                   288 
447   G4ThreeVector Point_A,Point_B;                  289   G4ThreeVector Point_A,Point_B;
448   Point_A=CurveA_PointVelocity.GetPosition();     290   Point_A=CurveA_PointVelocity.GetPosition();
449   Point_B=CurveB_PointVelocity.GetPosition();     291   Point_B=CurveB_PointVelocity.GetPosition();
450                                                   292 
451   G4double xa,xb,xc,ya,yb,yc;                     293   G4double xa,xb,xc,ya,yb,yc;
452                                                   294  
453   // InverseParabolic. AF Intersects (First Pa    295   // InverseParabolic. AF Intersects (First Part of Curve) 
454                                                   296 
455   if(first)                                       297   if(first)
456   {                                               298   {
457     xa=0.;                                        299     xa=0.;
458     ya=(PointG-Point_A).mag();                    300     ya=(PointG-Point_A).mag();
459     xb=(Point_A-CurrentF_Point).mag();            301     xb=(Point_A-CurrentF_Point).mag();
460     yb=-(PointG-CurrentF_Point).mag();            302     yb=-(PointG-CurrentF_Point).mag();
461     xc=(Point_A-Point_B).mag();                   303     xc=(Point_A-Point_B).mag();
462     yc=-(CurrentE_Point-Point_B).mag();           304     yc=-(CurrentE_Point-Point_B).mag();
463   }                                               305   }    
464   else                                            306   else
465   {                                               307   {
466     xa=0.;                                        308     xa=0.;
467     ya=(Point_A-CurrentE_Point).mag();            309     ya=(Point_A-CurrentE_Point).mag();
468     xb=(Point_A-CurrentF_Point).mag();            310     xb=(Point_A-CurrentF_Point).mag();
469     yb=(PointG-CurrentF_Point).mag();             311     yb=(PointG-CurrentF_Point).mag();
470     xc=(Point_A-Point_B).mag();                   312     xc=(Point_A-Point_B).mag();
471     yc=-(Point_B-PointG).mag();                   313     yc=-(Point_B-PointG).mag();
472     if(xb==0.)                                    314     if(xb==0.)
473     {                                             315     {
474       EndPoint = ApproxCurvePointV(CurveA_Poin    316       EndPoint = ApproxCurvePointV(CurveA_PointVelocity, CurveB_PointVelocity,
475                                    CurrentE_Po    317                                    CurrentE_Point, eps_step);
476       return EndPoint;                            318       return EndPoint;
477     }                                             319     }
478   }                                               320   }
479                                                   321 
480   const G4double tolerance = 1.e-12;              322   const G4double tolerance = 1.e-12;
481   if(std::abs(ya)<=tolerance||std::abs(yc)<=to    323   if(std::abs(ya)<=tolerance||std::abs(yc)<=tolerance)
482   {                                               324   {
483     ; // What to do for the moment: return the    325     ; // What to do for the moment: return the same point as at start
484       // then PropagatorInField will take care    326       // then PropagatorInField will take care
485   }                                               327   }
486   else                                            328   else
487   {                                               329   {
488     G4double test_step = InvParabolic(xa,ya,xb    330     G4double test_step = InvParabolic(xa,ya,xb,yb,xc,yc);
489     G4double curve;                               331     G4double curve;
490     if(first)                                     332     if(first)
491     {                                             333     {
492       curve=std::abs(EndPoint.GetCurveLength()    334       curve=std::abs(EndPoint.GetCurveLength()
493                     -ApproxCurveV.GetCurveLeng    335                     -ApproxCurveV.GetCurveLength());
494     }                                             336     }
495     else                                          337     else
496     {                                             338     {
497       test_step = test_step - xb;                 339       test_step = test_step - xb;
498       curve=std::abs(EndPoint.GetCurveLength()    340       curve=std::abs(EndPoint.GetCurveLength()
499                     -CurveB_PointVelocity.GetC    341                     -CurveB_PointVelocity.GetCurveLength());
500       xb = (CurrentF_Point-Point_B).mag();        342       xb = (CurrentF_Point-Point_B).mag();
501     }                                             343     }
502                                                   344       
503     if(test_step<=0)    { test_step=0.1*xb; }     345     if(test_step<=0)    { test_step=0.1*xb; }
504     if(test_step>=xb)   { test_step=0.5*xb; }     346     if(test_step>=xb)   { test_step=0.5*xb; }
505     if(test_step>=curve){ test_step=0.5*curve;    347     if(test_step>=curve){ test_step=0.5*curve; } 
506                                                   348 
507     if(curve*(1.+eps_step)<xb) // Similar to R    349     if(curve*(1.+eps_step)<xb) // Similar to ReEstimate Step from
508     {                          // G4VIntersect    350     {                          // G4VIntersectionLocator
509       test_step=0.5*curve;                        351       test_step=0.5*curve;
510     }                                             352     }
511                                                   353 
512     fIntgrDriver->AccurateAdvance(EndPoint,tes    354     fIntgrDriver->AccurateAdvance(EndPoint,test_step, eps_step);
513                                                   355       
514 #ifdef G4DEBUG_FIELD                              356 #ifdef G4DEBUG_FIELD
515     // Printing Brent and Linear Approximation    357     // Printing Brent and Linear Approximation
516     //                                            358     //
517     G4cout << "G4ChordFinder::ApproxCurvePoint    359     G4cout << "G4ChordFinder::ApproxCurvePointS() - test-step ShF = "
518            << test_step << "  EndPoint = " <<     360            << test_step << "  EndPoint = " << EndPoint << G4endl;
519                                                   361 
520     //  Test Track                                362     //  Test Track
521     //                                            363     //
522     G4FieldTrack TestTrack( CurveA_PointVeloci    364     G4FieldTrack TestTrack( CurveA_PointVelocity);
523     TestTrack = ApproxCurvePointV( CurveA_Poin    365     TestTrack = ApproxCurvePointV( CurveA_PointVelocity, 
524                                    CurveB_Poin    366                                    CurveB_PointVelocity, 
525                                    CurrentE_Po    367                                    CurrentE_Point, eps_step );
526     G4cout.precision(14);                         368     G4cout.precision(14);
527     G4cout << "G4ChordFinder::BrentApprox = "     369     G4cout << "G4ChordFinder::BrentApprox = " << EndPoint  << G4endl;
528     G4cout << "G4ChordFinder::LinearApprox= "     370     G4cout << "G4ChordFinder::LinearApprox= " << TestTrack << G4endl; 
529 #endif                                            371 #endif
530   }                                               372   }
531   return EndPoint;                                373   return EndPoint;
532 }                                                 374 }
533                                                   375 
534                                                   376 
535 // ...........................................    377 // ...........................................................................
536                                                   378 
537 G4FieldTrack G4ChordFinder::                      379 G4FieldTrack G4ChordFinder::
538 ApproxCurvePointV( const G4FieldTrack& CurveA_    380 ApproxCurvePointV( const G4FieldTrack& CurveA_PointVelocity, 
539                    const G4FieldTrack& CurveB_    381                    const G4FieldTrack& CurveB_PointVelocity, 
540                    const G4ThreeVector& Curren    382                    const G4ThreeVector& CurrentE_Point,
541                          G4double eps_step)       383                          G4double eps_step)
542 {                                                 384 {
543   // If r=|AE|/|AB|, and s=true path lenght (A    385   // If r=|AE|/|AB|, and s=true path lenght (AB)
544   // return the point that is r*s along the cu    386   // return the point that is r*s along the curve!
545                                                   387  
546   G4FieldTrack   Current_PointVelocity = Curve    388   G4FieldTrack   Current_PointVelocity = CurveA_PointVelocity; 
547                                                   389 
548   G4ThreeVector  CurveA_Point= CurveA_PointVel    390   G4ThreeVector  CurveA_Point= CurveA_PointVelocity.GetPosition();
549   G4ThreeVector  CurveB_Point= CurveB_PointVel    391   G4ThreeVector  CurveB_Point= CurveB_PointVelocity.GetPosition();
550                                                   392 
551   G4ThreeVector  ChordAB_Vector= CurveB_Point     393   G4ThreeVector  ChordAB_Vector= CurveB_Point   - CurveA_Point;
552   G4ThreeVector  ChordAE_Vector= CurrentE_Poin    394   G4ThreeVector  ChordAE_Vector= CurrentE_Point - CurveA_Point;
553                                                   395 
554   G4double       ABdist= ChordAB_Vector.mag();    396   G4double       ABdist= ChordAB_Vector.mag();
555   G4double  curve_length;  //  A curve length     397   G4double  curve_length;  //  A curve length  of AB
556   G4double  AE_fraction;                          398   G4double  AE_fraction; 
557                                                   399   
558   curve_length= CurveB_PointVelocity.GetCurveL    400   curve_length= CurveB_PointVelocity.GetCurveLength()
559               - CurveA_PointVelocity.GetCurveL    401               - CurveA_PointVelocity.GetCurveLength();  
560                                                   402  
561   G4double integrationInaccuracyLimit= std::ma    403   G4double integrationInaccuracyLimit= std::max( perMillion, 0.5*eps_step ); 
562   if( curve_length < ABdist * (1. - integratio    404   if( curve_length < ABdist * (1. - integrationInaccuracyLimit) )
563   {                                               405   { 
564 #ifdef G4DEBUG_FIELD                              406 #ifdef G4DEBUG_FIELD
565     G4cerr << " Warning in G4ChordFinder::Appr    407     G4cerr << " Warning in G4ChordFinder::ApproxCurvePoint: "
566            << G4endl                              408            << G4endl
567            << " The two points are further apa    409            << " The two points are further apart than the curve length "
568            << G4endl                              410            << G4endl
569            << " Dist = "         << ABdist        411            << " Dist = "         << ABdist
570            << " curve length = " << curve_leng    412            << " curve length = " << curve_length 
571            << " relativeDiff = " << (curve_len    413            << " relativeDiff = " << (curve_length-ABdist)/ABdist 
572            << G4endl;                             414            << G4endl;
573     if( curve_length < ABdist * (1. - 10*eps_s    415     if( curve_length < ABdist * (1. - 10*eps_step) )
574     {                                             416     {
575       std::ostringstream message;                 417       std::ostringstream message;
576       message << "Unphysical curve length." <<    418       message << "Unphysical curve length." << G4endl
577               << "The size of the above differ    419               << "The size of the above difference exceeds allowed limits."
578               << G4endl                           420               << G4endl
579               << "Aborting.";                     421               << "Aborting.";
580       G4Exception("G4ChordFinder::ApproxCurveP    422       G4Exception("G4ChordFinder::ApproxCurvePointV()", "GeomField0003",
581                   FatalException, message);       423                   FatalException, message);
582     }                                             424     }
583 #endif                                            425 #endif
584     // Take default corrective action: adjust     426     // Take default corrective action: adjust the maximum curve length. 
585     // NOTE: this case only happens for relati    427     // NOTE: this case only happens for relatively straight paths.
586     // curve_length = ABdist;                     428     // curve_length = ABdist; 
587   }                                               429   }
588                                                   430 
589   G4double new_st_length;                         431   G4double new_st_length; 
590                                                   432 
591   if ( ABdist > 0.0 )                             433   if ( ABdist > 0.0 )
592   {                                               434   {
593      AE_fraction = ChordAE_Vector.mag() / ABdi    435      AE_fraction = ChordAE_Vector.mag() / ABdist;
594   }                                               436   }
595   else                                            437   else
596   {                                               438   {
597      AE_fraction = 0.5;                           439      AE_fraction = 0.5;                         // Guess .. ?; 
598 #ifdef G4DEBUG_FIELD                              440 #ifdef G4DEBUG_FIELD
599      G4cout << "Warning in G4ChordFinder::Appr    441      G4cout << "Warning in G4ChordFinder::ApproxCurvePointV():"
600             << " A and B are the same point!"     442             << " A and B are the same point!" << G4endl
601             << " Chord AB length = " << ChordA    443             << " Chord AB length = " << ChordAE_Vector.mag() << G4endl
602             << G4endl;                            444             << G4endl;
603 #endif                                            445 #endif
604   }                                               446   }
605                                                   447   
606   if( (AE_fraction> 1.0 + perMillion) || (AE_f    448   if( (AE_fraction> 1.0 + perMillion) || (AE_fraction< 0.) )
607   {                                               449   {
608 #ifdef G4DEBUG_FIELD                              450 #ifdef G4DEBUG_FIELD
609     G4cerr << " G4ChordFinder::ApproxCurvePoin    451     G4cerr << " G4ChordFinder::ApproxCurvePointV() - Warning:"
610            << " Anomalous condition:AE > AB or    452            << " Anomalous condition:AE > AB or AE/AB <= 0 " << G4endl
611            << "   AE_fraction = " <<  AE_fract    453            << "   AE_fraction = " <<  AE_fraction << G4endl
612            << "   Chord AE length = " << Chord    454            << "   Chord AE length = " << ChordAE_Vector.mag() << G4endl
613            << "   Chord AB length = " << ABdis    455            << "   Chord AB length = " << ABdist << G4endl << G4endl;
614     G4cerr << " OK if this condition occurs af    456     G4cerr << " OK if this condition occurs after a recalculation of 'B'"
615            << G4endl << " Otherwise it is an e    457            << G4endl << " Otherwise it is an error. " << G4endl ; 
616 #endif                                            458 #endif
617      // This course can now result if B has be    459      // This course can now result if B has been re-evaluated, 
618      // without E being recomputed (1 July 99)    460      // without E being recomputed (1 July 99).
619      // In this case this is not a "real error    461      // In this case this is not a "real error" - but it is undesired
620      // and we cope with it by a default corre    462      // and we cope with it by a default corrective action ...
621      //                                           463      //
622      AE_fraction = 0.5;                           464      AE_fraction = 0.5;                         // Default value
623   }                                               465   }
624                                                   466 
625   new_st_length = AE_fraction * curve_length;     467   new_st_length = AE_fraction * curve_length; 
626                                                   468 
627   if ( AE_fraction > 0.0 )                        469   if ( AE_fraction > 0.0 )
628   {                                               470   { 
629      fIntgrDriver->AccurateAdvance(Current_Poi    471      fIntgrDriver->AccurateAdvance(Current_PointVelocity, 
630                                    new_st_leng    472                                    new_st_length, eps_step );
631      //                                           473      //
632      // In this case it does not matter if it     474      // In this case it does not matter if it cannot advance the full distance
633   }                                               475   }
634                                                   476 
635   // If there was a memory of the step_length     477   // If there was a memory of the step_length actually required at the start 
636   // of the integration Step, this could be re    478   // of the integration Step, this could be re-used ...
637                                                   479 
638   G4cout.precision(14);                           480   G4cout.precision(14);
639                                                   481 
640   return Current_PointVelocity;                   482   return Current_PointVelocity;
641 }                                                 483 }
642                                                   484 
643 // ...........................................    485 // ...........................................................................
644                                                << 
645 std::ostream& operator<<( std::ostream& os, co << 
646 {                                              << 
647    // Dumping the state of G4ChordFinder       << 
648    os << "State of G4ChordFinder : " << std::e << 
649    os << "   delta_chord   = " <<  cf.fDeltaCh << 
650    os << "   Default d_c   = " <<  cf.fDefault << 
651                                                << 
652    os << "   stats-verbose = " <<  cf.fStatsVe << 
653                                                << 
654    return os;                                  << 
655 }                                              << 
656                                                   486