Index: trunk/source/geometry/magneticfield/History
===================================================================
--- trunk/source/geometry/magneticfield/History	(revision 1228)
+++ trunk/source/geometry/magneticfield/History	(revision 1231)
@@ -1,3 +1,3 @@
-$Id: History,v 1.135 2008/11/21 21:16:11 gum Exp $
+$Id: History,v 1.147 2009/11/12 18:45:02 japost Exp $
 -------------------------------------------------------------------
 
@@ -18,6 +18,75 @@
      ----------------------------------------------------------
 
+Nov 12th,  2009 J.Apostolakis - field-V09-02-09
+-----------------------------
+- G4MagIntegratorDriver:  Activate Peter Gumplinger's check on integration
+                          error for spin.
+
+Nov 12th,  2009 J.Apostolakis - field-V09-02-08
+-----------------------------  (fix only)
+- G4Nystrom:  Corrected interface method getField: array now has explicit dimension[4]
+                (Problem found by gcc 4.3 - it checked indices used in inline method! )
+
+Nov 6th,  2009 P.Gumplinger - field-V09-02-07
+---------------------------
+- bug fix in G4EqEMFieldWithSpin and G4EqEMFieldWithEDM
+  thanks to Hiromi Iinuma (KEK) see:
+  http://hypernews.slac.stanford.edu/HyperNews/geant4/get/emfields/161.html
+
+Nov 5th,  2009 J.Apostolakis - field-V09-02-06
+----------------------------
+- G4MagIntegratorDriver.cc : Enabled call to ComputeRightHandSide
+- G4NystromRK4.cc          : Disabled auxiliary code in Stepper (needed if
+                              ComputeRightHandSide is not called.)
+
+Nov 5th,  2009 J.Apostolakis - field-V09-02-05
+----------------------------
+- Added new virtual method CalculateRightHandSide to G4MagIntegratorStepper for use
+      in caching momentum (and field value) by G4NystromRK4
+      Default implementation in G4MagIntegratorStepper calls RightHandSide inline method.
+- G4Nystrom:  New Set/Get method for cache distance.
+              Changed private data members in G4NystromRK4.
+- G4MagIntegratorDriver:  alternative call to ComputeRightHandSide is not used (in comment)
+              As a result G4NystromRK4 operates without reusing 
+
+Nov 5th,  2009 J.Apostolakis - field-V09-02-04
+----------------------------
+- G4CachedMagneticField: New Simple class to cache value of Magnetic Field. 
+     Speeds up code when calculation of field value is complex.
+- G4NystromRK4 :         New Stepper with Nystrom for magnetic field
+     with analytic estimation of integration error.  
+     Greatly reduces number of field value per step.
+- Revised testPropagateMagField to use Cached Quadrupole field,
+     and to cover G4NystromRK4 and G4ConstRK4.
+
+Nov 4th,  2009 P.Gumplinger - field-V09-02-03
+---------------------------
+- (minor change) remove comment from G4EqEMFieldWithSpin.cc
+  add G4EqEMFieldWithEDM class: this is the RHS of EofM in a combined
+  electric and magnetic field, with spin tracking for both MDM and EDM terms.
+  Thanks to Kevin Lynch, Phys. Dept. at Boston University.
+
+May 18th, 2009 T.Nikitina - field-V09-02-02
+-------------------------
+- Enhanced algorithm G4ChordFinder::ApproxCurvePointS() in order to speedup
+  BrentLocator.
+
+March 25th, 2009 G.Cosmo - field-V09-02-01
+------------------------
+- Some code cleanup and formatting...
+
+March 6th, 2009 P.Gumplinger - field-V09-02-00
+----------------------------
+- Added 3rd term of BMT equation (Spin x Beta x Efield) to G4EqEMFieldWithSpin,
+  addresses emfields forum posting #155 (bug report). Thanks to Kevin Lynch,
+  Phys. Dept. at Boston University.
+- Moved renormalization of spin from G4EqEMFieldWithSpin and G4Mag_SpinEqRhs to
+  G4ClassicalRK4 and G4SimpleHeum.
+- Added Spin propagation errors to the criteria for 'OneGoodStep' in
+  G4MagIntegratorDriver but actually don't add it (yet) to the decision logic.
+
 November, 19th, 2008  P.Gumplinger - field-V09-01-05
-- renormalize the spin to ONE in G4EqEMFieldWithSpin.cc and G4Mag_SpinEqRhs.cc
+----------------------------------
+- Renormalized the spin to 1 in G4EqEMFieldWithSpin and G4Mag_SpinEqRhs.
 
 November, 7th, 2008   P.Gumplinger - field-V09-01-04
Index: trunk/source/geometry/magneticfield/include/G4CashKarpRKF45.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4CashKarpRKF45.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4CashKarpRKF45.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4CashKarpRKF45.hh,v 1.11 2008/01/11 15:23:54 japost Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4ChordFinder.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4ChordFinder.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4ChordFinder.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ChordFinder.hh,v 1.21 2008/10/29 14:17:42 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // 
Index: trunk/source/geometry/magneticfield/include/G4ChordFinder.icc
===================================================================
--- trunk/source/geometry/magneticfield/include/G4ChordFinder.icc	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4ChordFinder.icc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ChordFinder.icc,v 1.14 2008/10/29 14:34:35 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // G4ChordFinder inline implementations
Index: trunk/source/geometry/magneticfield/include/G4ChordFinderSaf.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4ChordFinderSaf.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4ChordFinderSaf.hh	(revision 1231)
@@ -25,5 +25,5 @@
 //
 // $Id: G4ChordFinderSaf.hh,v 1.4 2008/09/12 16:12:18 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // 
Index: trunk/source/geometry/magneticfield/include/G4ClassicalRK4.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4ClassicalRK4.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4ClassicalRK4.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ClassicalRK4.hh,v 1.10 2006/06/29 18:21:55 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4ConstRK4.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4ConstRK4.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4ConstRK4.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ConstRK4.hh,v 1.2 2008/10/29 14:17:42 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // 
Index: trunk/source/geometry/magneticfield/include/G4DELPHIMagField.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4DELPHIMagField.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4DELPHIMagField.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4DELPHIMagField.hh,v 1.4 2006/06/29 18:21:57 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4ElectricField.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4ElectricField.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4ElectricField.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ElectricField.hh,v 1.2 2006/06/29 18:21:59 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4ElectroMagneticField.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4ElectroMagneticField.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4ElectroMagneticField.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ElectroMagneticField.hh,v 1.11 2006/06/29 18:22:01 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4EqEMFieldWithSpin.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4EqEMFieldWithSpin.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4EqEMFieldWithSpin.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4EqEMFieldWithSpin.hh,v 1.3 2008/11/14 13:37:09 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4EqMagElectricField.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4EqMagElectricField.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4EqMagElectricField.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4EqMagElectricField.hh,v 1.9 2006/06/29 18:22:03 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4EquationOfMotion.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4EquationOfMotion.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4EquationOfMotion.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4EquationOfMotion.hh,v 1.10 2006/06/29 18:22:05 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4EquationOfMotion.icc
===================================================================
--- trunk/source/geometry/magneticfield/include/G4EquationOfMotion.icc	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4EquationOfMotion.icc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4EquationOfMotion.icc,v 1.9 2006/06/29 18:22:07 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4ErrorMag_UsualEqRhs.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4ErrorMag_UsualEqRhs.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4ErrorMag_UsualEqRhs.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ErrorMag_UsualEqRhs.hh,v 1.1 2007/05/16 12:54:02 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4ExactHelixStepper.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4ExactHelixStepper.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4ExactHelixStepper.hh	(revision 1231)
@@ -25,5 +25,5 @@
 //
 // $Id: G4ExactHelixStepper.hh,v 1.5 2007/05/18 12:50:31 tnikitin Exp $ 
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4ExplicitEuler.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4ExplicitEuler.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4ExplicitEuler.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ExplicitEuler.hh,v 1.9 2006/06/29 18:22:11 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4Field.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4Field.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4Field.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4Field.hh,v 1.10 2006/06/29 18:22:13 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4FieldManager.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4FieldManager.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4FieldManager.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4FieldManager.hh,v 1.16 2006/06/29 18:22:15 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //  
Index: trunk/source/geometry/magneticfield/include/G4FieldManager.icc
===================================================================
--- trunk/source/geometry/magneticfield/include/G4FieldManager.icc	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4FieldManager.icc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4FieldManager.icc,v 1.12 2006/06/29 18:22:18 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4FieldManagerStore.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4FieldManagerStore.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4FieldManagerStore.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4FieldManagerStore.hh,v 1.3 2008/01/17 09:39:08 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // class G4FieldManagerStore
Index: trunk/source/geometry/magneticfield/include/G4FieldTrack.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4FieldTrack.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4FieldTrack.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4FieldTrack.hh,v 1.21 2006/11/13 18:24:35 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4FieldTrack.icc
===================================================================
--- trunk/source/geometry/magneticfield/include/G4FieldTrack.icc	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4FieldTrack.icc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4FieldTrack.icc,v 1.21 2006/11/13 18:24:35 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // -------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/include/G4HarmonicPolMagField.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4HarmonicPolMagField.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4HarmonicPolMagField.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4HarmonicPolMagField.hh,v 1.4 2006/06/29 18:22:24 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // class G4HarmonicPolMagField
Index: trunk/source/geometry/magneticfield/include/G4HelixExplicitEuler.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4HelixExplicitEuler.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4HelixExplicitEuler.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4HelixExplicitEuler.hh,v 1.9 2007/08/21 08:52:00 tnikitin Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4HelixHeum.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4HelixHeum.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4HelixHeum.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4HelixHeum.hh,v 1.8 2006/06/29 18:22:36 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4HelixImplicitEuler.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4HelixImplicitEuler.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4HelixImplicitEuler.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4HelixImplicitEuler.hh,v 1.8 2006/06/29 18:22:38 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4HelixSimpleRunge.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4HelixSimpleRunge.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4HelixSimpleRunge.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4HelixSimpleRunge.hh,v 1.7 2006/06/29 18:22:41 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4ImplicitEuler.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4ImplicitEuler.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4ImplicitEuler.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ImplicitEuler.hh,v 1.8 2006/06/29 18:22:44 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4LineCurrentMagField.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4LineCurrentMagField.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4LineCurrentMagField.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4LineCurrentMagField.hh,v 1.4 2006/06/29 18:22:46 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4LineSection.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4LineSection.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4LineSection.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4LineSection.hh,v 1.9 2006/06/29 18:22:48 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4MagErrorStepper.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4MagErrorStepper.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4MagErrorStepper.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4MagErrorStepper.hh,v 1.11 2006/06/29 18:22:50 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4MagErrorStepper.icc
===================================================================
--- trunk/source/geometry/magneticfield/include/G4MagErrorStepper.icc	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4MagErrorStepper.icc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4MagErrorStepper.icc,v 1.13 2006/06/29 18:22:52 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // --------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/include/G4MagHelicalStepper.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4MagHelicalStepper.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4MagHelicalStepper.hh	(revision 1231)
@@ -27,5 +27,5 @@
 //
 // $Id: G4MagHelicalStepper.hh,v 1.15 2007/08/21 08:48:28 tnikitin Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4MagHelicalStepper.icc
===================================================================
--- trunk/source/geometry/magneticfield/include/G4MagHelicalStepper.icc	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4MagHelicalStepper.icc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4MagHelicalStepper.icc,v 1.13 2007/05/18 15:45:15 tnikitin Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // Linear Step in regions of no field
Index: trunk/source/geometry/magneticfield/include/G4MagIntegratorDriver.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4MagIntegratorDriver.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4MagIntegratorDriver.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4MagIntegratorDriver.hh,v 1.20 2007/05/10 10:10:05 japost Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4MagIntegratorDriver.icc
===================================================================
--- trunk/source/geometry/magneticfield/include/G4MagIntegratorDriver.icc	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4MagIntegratorDriver.icc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4MagIntegratorDriver.icc,v 1.13 2007/05/10 10:10:48 japost Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // --------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/include/G4MagIntegratorStepper.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4MagIntegratorStepper.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4MagIntegratorStepper.hh	(revision 1231)
@@ -25,5 +25,5 @@
 //
 // $Id: G4MagIntegratorStepper.hh,v 1.14 2009/11/05 18:31:15 japost Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4MagIntegratorStepper.icc
===================================================================
--- trunk/source/geometry/magneticfield/include/G4MagIntegratorStepper.icc	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4MagIntegratorStepper.icc	(revision 1231)
@@ -25,5 +25,5 @@
 //
 // $Id: G4MagIntegratorStepper.icc,v 1.12 2009/03/25 15:29:02 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 
Index: trunk/source/geometry/magneticfield/include/G4Mag_EqRhs.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4Mag_EqRhs.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4Mag_EqRhs.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4Mag_EqRhs.hh,v 1.9 2006/06/29 18:23:07 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4Mag_SpinEqRhs.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4Mag_SpinEqRhs.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4Mag_SpinEqRhs.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4Mag_SpinEqRhs.hh,v 1.11 2006/06/29 18:23:09 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4Mag_UsualEqRhs.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4Mag_UsualEqRhs.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4Mag_UsualEqRhs.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4Mag_UsualEqRhs.hh,v 1.7 2006/06/29 18:23:12 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4MagneticField.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4MagneticField.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4MagneticField.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4MagneticField.hh,v 1.14 2006/06/29 18:23:14 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4QuadrupoleMagField.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4QuadrupoleMagField.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4QuadrupoleMagField.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4QuadrupoleMagField.hh,v 1.4 2006/06/29 18:23:16 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4RKG3_Stepper.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4RKG3_Stepper.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4RKG3_Stepper.hh	(revision 1231)
@@ -27,5 +27,5 @@
 //
 // $Id: G4RKG3_Stepper.hh,v 1.13 2007/05/18 12:44:02 tnikitin Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4SimpleHeum.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4SimpleHeum.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4SimpleHeum.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4SimpleHeum.hh,v 1.8 2006/06/29 18:23:20 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4SimpleRunge.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4SimpleRunge.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4SimpleRunge.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4SimpleRunge.hh,v 1.8 2006/06/29 18:23:23 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/include/G4UniformElectricField.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4UniformElectricField.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4UniformElectricField.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4UniformElectricField.hh,v 1.9 2006/06/29 18:23:25 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // 
Index: trunk/source/geometry/magneticfield/include/G4UniformMagField.hh
===================================================================
--- trunk/source/geometry/magneticfield/include/G4UniformMagField.hh	(revision 1228)
+++ trunk/source/geometry/magneticfield/include/G4UniformMagField.hh	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4UniformMagField.hh,v 1.9 2006/06/29 18:23:27 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// GEANT4 tag $Name:  $
 //
 // 
Index: trunk/source/geometry/magneticfield/src/G4CashKarpRKF45.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4CashKarpRKF45.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4CashKarpRKF45.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4CashKarpRKF45.cc,v 1.15 2008/01/11 18:11:44 japost Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // The Cash-Karp Runge-Kutta-Fehlberg 4/5 method is an embedded fourth
Index: trunk/source/geometry/magneticfield/src/G4ChordFinder.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4ChordFinder.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4ChordFinder.cc	(revision 1231)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4ChordFinder.cc,v 1.51 2008/10/29 14:17:42 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// $Id: G4ChordFinder.cc,v 1.53 2009/05/18 14:22:43 gcosmo Exp $
+// GEANT4 tag $Name:  $
 //
 //
@@ -432,7 +432,11 @@
   // relative accuracy of each Step.
 
-  G4FieldTrack EndPoint( CurveA_PointVelocity);
-  G4ThreeVector Point_A=CurveA_PointVelocity.GetPosition();
-  G4ThreeVector Point_B=CurveB_PointVelocity.GetPosition();
+  G4FieldTrack EndPoint(CurveA_PointVelocity);
+  if(!first){EndPoint= ApproxCurveV;}
+
+  G4ThreeVector Point_A,Point_B;
+  Point_A=CurveA_PointVelocity.GetPosition();
+  Point_B=CurveB_PointVelocity.GetPosition();
+
   G4double xa,xb,xc,ya,yb,yc;
  
@@ -441,23 +445,30 @@
   if(first)
   {
-      xa=0.;
-      ya=(PointG-Point_A).mag();
-      xb=(Point_A-CurrentF_Point).mag();
-      yb=-(PointG-CurrentF_Point).mag();
-      xc=(Point_A-Point_B).mag();
-      yc=-(CurrentE_Point-Point_B).mag();
+    xa=0.;
+    ya=(PointG-Point_A).mag();
+    xb=(Point_A-CurrentF_Point).mag();
+    yb=-(PointG-CurrentF_Point).mag();
+    xc=(Point_A-Point_B).mag();
+    yc=-(CurrentE_Point-Point_B).mag();
   }    
   else
   {
-     xa=0.;
-     ya=(Point_A-PointG).mag();
-     xb=(Point_B-Point_A).mag();
-     yb=-(PointG-Point_B).mag();
-     xc=-(Point_A-CurrentF_Point).mag();
-     yc=-(Point_A-CurrentE_Point).mag();
-    
-  }
+    xa=0.;
+    ya=(Point_A-CurrentE_Point).mag();
+    xb=(Point_A-CurrentF_Point).mag();
+    yb=(PointG-CurrentF_Point).mag();
+    xc=(Point_A-Point_B).mag();
+    yc=-(Point_B-PointG).mag();
+    if(xb==0.)
+    {
+      EndPoint=
+      ApproxCurvePointV(CurveA_PointVelocity, CurveB_PointVelocity,
+                        CurrentE_Point, eps_step);
+      return EndPoint;
+    }
+  }
+
   const G4double tolerance= 1.e-12;
-  if(ya<=tolerance||std::abs(yc)<=tolerance)
+  if(std::abs(ya)<=tolerance||std::abs(yc)<=tolerance)
   {
     ; // What to do for the moment: return the same point as at start
@@ -475,6 +486,8 @@
     else
     {
+      test_step=(test_step-xb);
       curve=std::abs(EndPoint.GetCurveLength()
                     -CurveB_PointVelocity.GetCurveLength());
+      xb=(CurrentF_Point-Point_B).mag();
     }
       
Index: trunk/source/geometry/magneticfield/src/G4ClassicalRK4.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4ClassicalRK4.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4ClassicalRK4.cc	(revision 1231)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4ClassicalRK4.cc,v 1.12 2006/06/29 18:23:37 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// $Id: G4ClassicalRK4.cc,v 1.14 2009/03/25 15:29:02 gcosmo Exp $
+// GEANT4 tag $Name:  $
 //
 // -------------------------------------------------------------------
@@ -37,7 +37,7 @@
 // Constructor sets the number of variables (default = 6)
 
-G4ClassicalRK4::G4ClassicalRK4(G4EquationOfMotion* EqRhs, G4int numberOfVariables)
+G4ClassicalRK4::
+G4ClassicalRK4(G4EquationOfMotion* EqRhs, G4int numberOfVariables)
   : G4MagErrorStepper(EqRhs, numberOfVariables)
-    // fNumberOfVariables(numberOfVariables)
 {
    unsigned int noVariables= std::max(numberOfVariables,8); // For Time .. 7+1
@@ -108,5 +108,5 @@
     yOut[i] = yIn[i]+h6*(dydx[i]+dydxt[i]+2.0*dydxm[i]); //+K1/6+K4/6+(K2+K3)/3
   }
-  // NormaliseTangentVector( yOut );
+  if ( nvar == 12 )  { NormalisePolarizationVector ( yOut ); }
   
 }  // end of DumbStepper ....................................................
Index: trunk/source/geometry/magneticfield/src/G4ConstRK4.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4ConstRK4.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4ConstRK4.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ConstRK4.cc,v 1.2 2008/10/29 14:17:42 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/src/G4DELPHIMagField.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4DELPHIMagField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4DELPHIMagField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4DELPHIMagField.cc,v 1.6 2006/06/29 18:23:39 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 // -------------------------------------------------------------------
 
Index: trunk/source/geometry/magneticfield/src/G4ElectricField.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4ElectricField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4ElectricField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ElectricField.cc,v 1.2 2006/06/29 18:23:42 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // --------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4ElectroMagneticField.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4ElectroMagneticField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4ElectroMagneticField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ElectroMagneticField.cc,v 1.3 2006/06/29 18:23:44 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // --------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4EqEMFieldWithSpin.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4EqEMFieldWithSpin.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4EqEMFieldWithSpin.cc	(revision 1231)
@@ -25,15 +25,14 @@
 //
 //
-// $Id: G4EqEMFieldWithSpin.cc,v 1.4 2008/11/21 21:17:03 gum Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// $Id: G4EqEMFieldWithSpin.cc,v 1.8 2009/11/06 22:31:35 gum Exp $
+// GEANT4 tag $Name:  $
 //
 //
 //  This is the standard right-hand side for equation of motion.
 //
-//  The only case another is required is when using a moving reference
-//  frame ... or extending the class to include additional Forces,
-//  eg an electric field
-//
 //  30.08.2007 Chris Gong, Peter Gumplinger
+//  14.02.2009 Kevin Lynch
+//  06.11.2009 Hiromi Iinuma see:
+//  http://hypernews.slac.stanford.edu/HyperNews/geant4/get/emfields/161.html
 //
 // -------------------------------------------------------------------
@@ -45,6 +44,6 @@
 
 G4EqEMFieldWithSpin::G4EqEMFieldWithSpin(G4ElectroMagneticField *emField )
-      : G4EquationOfMotion( emField )
-{ 
+  : G4EquationOfMotion( emField )
+{
   anomaly = 0.0011659208;
 }
@@ -79,6 +78,19 @@
 
    // Components of y:
-   //    0-2 dr/ds, 
-   //    3-5 dp/ds - momentum derivatives 
+   //    0-2 dr/ds,
+   //    3-5 dp/ds - momentum derivatives
+   //    9-11 dSpin/ds = (1/beta) dSpin/dt - spin derivatives
+
+   // The BMT equation, following J.D.Jackson, Classical
+   // Electrodynamics, Second Edition,
+   // dS/dt = (e/mc) S \cross
+   //              [ (g/2-1 +1/\gamma) B
+   //               -(g/2-1)\gamma/(\gamma+1) (\beta \cdot B)\beta
+   //               -(g/2-\gamma/(\gamma+1) \beta \cross E ]
+   // where
+   // S = \vec{s}, where S^2 = 1
+   // B = \vec{B}
+   // \beta = \vec{\beta} = \beta \vec{u} with u^2 = 1
+   // E = \vec{E}
 
    G4double pSquared = y[3]*y[3] + y[4]*y[4] + y[5]*y[5] ;
@@ -89,11 +101,7 @@
    G4double pModuleInverse  = 1.0/std::sqrt(pSquared) ;
 
-   //  G4double inverse_velocity = Energy * c_light * pModuleInverse;
    G4double inverse_velocity = Energy * pModuleInverse / c_light;
 
    G4double cof1     = fElectroMagCof*pModuleInverse ;
-
-   //  G4double vDotE = y[3]*Field[3] + y[4]*Field[4] + y[5]*Field[5] ;
-
 
    dydx[0] = y[3]*pModuleInverse ;                         
@@ -113,4 +121,7 @@
    
    G4ThreeVector BField(Field[0],Field[1],Field[2]);
+   G4ThreeVector EField(Field[3],Field[4],Field[5]);
+
+   EField /= c_light;
 
    G4ThreeVector u(y[3], y[4], y[5]);
@@ -119,12 +130,14 @@
    G4double udb = anomaly*beta*gamma/(1.+gamma) * (BField * u);
    G4double ucb = (anomaly+1./gamma)/beta;
+   G4double uce = anomaly + 1./(gamma+1.);
 
    G4ThreeVector Spin(y[9],y[10],y[11]);
 
-   if (Spin.mag() > 0.) Spin = Spin.unit();
-
-   G4ThreeVector dSpin;
-
-   dSpin = ParticleCharge*omegac*(ucb*(Spin.cross(BField))-udb*(Spin.cross(u)));
+   G4ThreeVector dSpin
+     = ParticleCharge*omegac*( ucb*(Spin.cross(BField))-udb*(Spin.cross(u))
+                               // from Jackson
+                               // -uce*Spin.cross(u.cross(EField)) );
+                               // but this form has one less operation
+                               - uce*(u*(Spin*EField) - EField*(Spin*u)) );
 
    dydx[ 9] = dSpin.x();
Index: trunk/source/geometry/magneticfield/src/G4EqMagElectricField.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4EqMagElectricField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4EqMagElectricField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4EqMagElectricField.cc,v 1.14 2008/04/24 12:33:35 tnikitin Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/src/G4EquationOfMotion.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4EquationOfMotion.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4EquationOfMotion.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4EquationOfMotion.cc,v 1.9 2006/06/29 18:23:48 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // -------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4ErrorMag_UsualEqRhs.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4ErrorMag_UsualEqRhs.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4ErrorMag_UsualEqRhs.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ErrorMag_UsualEqRhs.cc,v 1.1 2007/05/16 12:54:02 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/src/G4ExactHelixStepper.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4ExactHelixStepper.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4ExactHelixStepper.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ExactHelixStepper.cc,v 1.9 2008/10/29 14:34:35 gcosmo Exp $ 
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //  Helix a-la-Explicity Euler: x_1 = x_0 + helix(h)
Index: trunk/source/geometry/magneticfield/src/G4ExplicitEuler.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4ExplicitEuler.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4ExplicitEuler.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ExplicitEuler.cc,v 1.8 2006/06/29 18:23:53 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/src/G4FieldManager.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4FieldManager.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4FieldManager.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4FieldManager.cc,v 1.15 2007/12/07 15:34:10 japost Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // -------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4FieldManagerStore.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4FieldManagerStore.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4FieldManagerStore.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4FieldManagerStore.cc,v 1.4 2008/01/17 10:56:23 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // G4FieldManagerStore
Index: trunk/source/geometry/magneticfield/src/G4FieldTrack.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4FieldTrack.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4FieldTrack.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4FieldTrack.cc,v 1.14 2007/10/03 15:34:42 japost Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // -------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4HarmonicPolMagField.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4HarmonicPolMagField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4HarmonicPolMagField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4HarmonicPolMagField.cc,v 1.6 2006/06/29 18:24:00 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // -------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4HelixExplicitEuler.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4HelixExplicitEuler.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4HelixExplicitEuler.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4HelixExplicitEuler.cc,v 1.8 2007/12/10 16:29:49 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/src/G4HelixHeum.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4HelixHeum.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4HelixHeum.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4HelixHeum.cc,v 1.6 2006/06/29 18:24:04 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/src/G4HelixImplicitEuler.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4HelixImplicitEuler.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4HelixImplicitEuler.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4HelixImplicitEuler.cc,v 1.6 2006/06/29 18:24:06 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/src/G4HelixSimpleRunge.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4HelixSimpleRunge.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4HelixSimpleRunge.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4HelixSimpleRunge.cc,v 1.7 2006/06/29 18:24:08 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/src/G4ImplicitEuler.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4ImplicitEuler.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4ImplicitEuler.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4ImplicitEuler.cc,v 1.9 2006/06/29 18:24:11 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/src/G4LineCurrentMagField.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4LineCurrentMagField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4LineCurrentMagField.cc	(revision 1231)
@@ -25,5 +25,5 @@
 //
 // $Id: G4LineCurrentMagField.cc,v 1.6 2006/06/29 18:24:13 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 // -------------------------------------------------------------------
 
Index: trunk/source/geometry/magneticfield/src/G4LineSection.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4LineSection.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4LineSection.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4LineSection.cc,v 1.10 2006/06/29 18:24:16 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // --------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4MagErrorStepper.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4MagErrorStepper.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4MagErrorStepper.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4MagErrorStepper.cc,v 1.13 2006/06/29 18:24:18 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // --------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4MagHelicalStepper.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4MagHelicalStepper.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4MagHelicalStepper.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4MagHelicalStepper.cc,v 1.23 2007/09/05 12:20:17 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // --------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4MagIntegratorDriver.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4MagIntegratorDriver.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4MagIntegratorDriver.cc	(revision 1231)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4MagIntegratorDriver.cc,v 1.49 2007/08/17 12:30:33 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// $Id: G4MagIntegratorDriver.cc,v 1.56 2009/11/12 18:41:03 japost Exp $
+// GEANT4 tag $Name:  $
 //
 // 
@@ -53,5 +53,6 @@
 const G4double G4MagInt_Driver::max_stepping_decrease = 0.1;
 
-//  The (default) maximum number of steps is Base divided by the order of Stepper
+//  The (default) maximum number of steps is Base
+//  divided by the order of Stepper
 //
 const G4int  G4MagInt_Driver::fMaxStepBase = 250;  // Was 5000
@@ -61,10 +62,12 @@
 #endif
 
+// ---------------------------------------------------------
+
 //  Constructor
 //
 G4MagInt_Driver::G4MagInt_Driver( G4double                hminimum, 
-				  G4MagIntegratorStepper *pItsStepper,
-				  G4int                   numComponents,
-				  G4int                   statisticsVerbose)
+                                  G4MagIntegratorStepper *pItsStepper,
+                                  G4int                   numComponents,
+                                  G4int                   statisticsVerbose)
   : fSmallestFraction( 1.0e-12 ), 
     fNoIntegrationVariables(numComponents), 
@@ -72,31 +75,34 @@
     fNoVars( std::max( fNoIntegrationVariables, fMinNoVars )),
     fVerboseLevel(0),
-    fNoTotalSteps(0),  fNoBadSteps(0), fNoSmallSteps(0), fNoInitialSmallSteps(0),
-    fDyerr_max(0.0), fDyerr_mx2(0.0), 
+    fNoTotalSteps(0),  fNoBadSteps(0), fNoSmallSteps(0),
+    fNoInitialSmallSteps(0), fDyerr_max(0.0), fDyerr_mx2(0.0), 
     fDyerrPos_smTot(0.0), fDyerrPos_lgTot(0.0), fDyerrVel_lgTot(0.0), 
     fSumH_sm(0.0),   fSumH_lg(0.0),
     fStatisticsVerboseLevel(statisticsVerbose)
 {  
-// In order to accomodate "Laboratory Time", which is [7], fMinNoVars=8 is required.
-// For proper time of flight and spin,  fMinNoVars must be 12
-
-      // fNoVars= std::max( fNoVars, fMinNoVars );  
-      RenewStepperAndAdjust( pItsStepper );
-      fMinimumStep= hminimum;
-      fMaxNoSteps = fMaxStepBase / pIntStepper->IntegratorOrder();
+  // In order to accomodate "Laboratory Time", which is [7], fMinNoVars=8
+  // is required. For proper time of flight and spin,  fMinNoVars must be 12
+
+  RenewStepperAndAdjust( pItsStepper );
+  fMinimumStep= hminimum;
+  fMaxNoSteps = fMaxStepBase / pIntStepper->IntegratorOrder();
 #ifdef G4DEBUG_FIELD
-      fVerboseLevel=2;
-#endif
-
-      if( (fVerboseLevel > 0) || (fStatisticsVerboseLevel > 1) ){
-	 G4cout << "MagIntDriver version: Accur-Adv: invE_nS, QuickAdv-2sqrt with Statistics "
+  fVerboseLevel=2;
+#endif
+
+  if( (fVerboseLevel > 0) || (fStatisticsVerboseLevel > 1) )
+  {
+    G4cout << "MagIntDriver version: Accur-Adv: "
+           << "invE_nS, QuickAdv-2sqrt with Statistics "
 #ifdef G4FLD_STATS
-		<< " enabled "
+           << " enabled "
 #else
-		<< " disabled "
-#endif
-		<< G4endl;
-      }
-}
+           << " disabled "
+#endif
+           << G4endl;
+  }
+}
+
+// ---------------------------------------------------------
 
 //  Destructor
@@ -104,32 +110,30 @@
 G4MagInt_Driver::~G4MagInt_Driver()
 { 
-     if( fStatisticsVerboseLevel > 1 ){
-        PrintStatisticsReport() ;
-     }
-     // Future: for default verbose level, print an understandable summary
-}
-
-
-// To add much printing for debugging purposes, uncomment this:
+  if( fStatisticsVerboseLevel > 1 )
+  {
+    PrintStatisticsReport();
+  }
+}
+
+// To add much printing for debugging purposes, uncomment the following
+// and set verbose level to 1 or higher value !
 // #define  G4DEBUG_FIELD 1    
-// and set verbose level to 1 or higher value !
+
+// ---------------------------------------------------------
 
 G4bool
 G4MagInt_Driver::AccurateAdvance(G4FieldTrack& y_current,
-		                 G4double     hstep,
-		                 G4double     eps,
-				 G4double hinitial )
-//		     const G4double dydx[6],    // We could may add this ??
-
-// Runge-Kutta driver with adaptive stepsize control. Integrate starting
-// values at y_current over hstep x2 with accuracy eps. 
-// On output ystart is replaced by values at the end of the integration 
-// interval.  
-// RightHandSide is the right-hand side of ODE system. 
-// The source is similar to odeint routine from NRC p.721-722 .
-
-{
-  G4int nstp, i, no_warnings=0;; 
-  G4double x, hnext, hdid, h ;
+                                 G4double     hstep,
+                                 G4double     eps,
+                                 G4double hinitial )
+{
+  // Runge-Kutta driver with adaptive stepsize control. Integrate starting
+  // values at y_current over hstep x2 with accuracy eps. 
+  // On output ystart is replaced by values at the end of the integration 
+  // interval. RightHandSide is the right-hand side of ODE system. 
+  // The source is similar to odeint routine from NRC p.721-722 .
+
+  G4int nstp, i, no_warnings=0;
+  G4double x, hnext, hdid, h;
 
 #ifdef G4DEBUG_FIELD
@@ -149,9 +153,10 @@
   G4int  noFullIntegr=0, noSmallIntegr = 0 ;
   static G4int  noGoodSteps =0 ;  // Bad = chord > curve-len 
-  const  int    nvar= fNoVars;
+  const  G4int  nvar= fNoVars;
 
   G4FieldTrack yStartFT(y_current);
 
-  //  Ensure that hstep > 0 
+  //  Ensure that hstep > 0
+  //
   if( hstep <= 0.0 )
   { 
@@ -181,10 +186,11 @@
   x2= x1 + hstep;
 
-  if( (hinitial > 0.0) 
-      && (hinitial < hstep)
-      && (hinitial > perMillion * hstep) ){
+  if ( (hinitial > 0.0) && (hinitial < hstep)
+    && (hinitial > perMillion * hstep) )
+  {
      h = hinitial;
-  }else{
-     //  Initial Step size "h" defaults to the full interval
+  }
+  else  //  Initial Step size "h" defaults to the full interval
+  {
      h = hstep;
   }
@@ -192,170 +198,199 @@
   x = x1;
 
-  for(i=0;i<nvar;i++) y[i] = ystart[i] ;
-
-  G4bool  lastStep= false;
+  for (i=0;i<nvar;i++)  { y[i] = ystart[i]; }
+
+  G4bool lastStep= false;
   nstp=1;
-  // G4double  lastStepThreshold = std::min( eps * hstep, Hmin() ); 
-
-  do{
-     G4ThreeVector StartPos( y[0], y[1], y[2] );   
-#    ifdef G4DEBUG_FIELD
-       for(i=0;i<nvar;i++) ySubStepStart[i] = y[i] ;
-       yFldTrkStart.LoadFromArray(y, fNoIntegrationVariables);
-       yFldTrkStart.SetCurveLength(x);
-#    endif
-
-     pIntStepper->RightHandSide( y, dydx );
-
-     fNoTotalSteps++;
-     // Perform the Integration
-     //      
-     if( h > fMinimumStep ){ 
-        OneGoodStep(y,dydx,x,h,eps,hdid,hnext) ;
-        //--------------------------------------
-        lastStepSucceeded= (hdid == h);   
+
+  do
+  {
+    G4ThreeVector StartPos( y[0], y[1], y[2] );
+
+#ifdef G4DEBUG_FIELD
+    G4double xSubStepStart= x; 
+    for (i=0;i<nvar;i++)  { ySubStepStart[i] = y[i]; }
+    yFldTrkStart.LoadFromArray(y, fNoIntegrationVariables);
+    yFldTrkStart.SetCurveLength(x);
+#endif
+
+    // Old method - inline call to Equation of Motion
+    //   pIntStepper->RightHandSide( y, dydx );
+    // New method allows to cache field, or state (eg momentum magnitude)
+    pIntStepper->ComputeRightHandSide( y, dydx );
+    fNoTotalSteps++;
+
+    // Perform the Integration
+    //      
+    if( h > fMinimumStep )
+    { 
+      OneGoodStep(y,dydx,x,h,eps,hdid,hnext) ;
+      //--------------------------------------
+      lastStepSucceeded= (hdid == h);   
+#ifdef G4DEBUG_FIELD
+      if (dbg>2) {
+        PrintStatus( ySubStepStart, xSubStepStart, y, x, h,  nstp); // Only
+      }
+#endif
+    }
+    else
+    {
+      G4FieldTrack yFldTrk( G4ThreeVector(0,0,0), 
+                            G4ThreeVector(0,0,0), 0., 0., 0., 0. );
+      G4double dchord_step, dyerr, dyerr_len;   // What to do with these ?
+      yFldTrk.LoadFromArray(y, fNoIntegrationVariables); 
+      yFldTrk.SetCurveLength( x );
+
+      QuickAdvance( yFldTrk, dydx, h, dchord_step, dyerr_len ); 
+      //-----------------------------------------------------
+
+      yFldTrk.DumpToArray(y);    
+
+#ifdef G4FLD_STATS
+      fNoSmallSteps++; 
+      if ( dyerr_len > fDyerr_max)  { fDyerr_max= dyerr_len; }
+      fDyerrPos_smTot += dyerr_len;
+      fSumH_sm += h;  // Length total for 'small' steps
+      if (nstp<=1)  { fNoInitialSmallSteps++; }
+#endif
+#ifdef G4DEBUG_FIELD
+      if (dbg>1)
+      {
+        if(fNoSmallSteps<2) { PrintStatus(ySubStepStart, x1, y, x, h, -nstp); }
+        G4cout << "Another sub-min step, no " << fNoSmallSteps 
+               << " of " << fNoTotalSteps << " this time " << nstp << G4endl; 
+        PrintStatus( ySubStepStart, x1, y, x, h,  nstp);   // Only this
+        G4cout << " dyerr= " << dyerr_len << " relative = " << dyerr_len / h 
+               << " epsilon= " << eps << " hstep= " << hstep 
+               << " h= " << h << " hmin= " << fMinimumStep << G4endl;
+      }
+#endif        
+      if( h == 0.0 )
+      { 
+        G4Exception("G4MagInt_Driver::AccurateAdvance()",
+                    "Integration Step became Zero",
+                    FatalException, "IntegrationStepUnderflow."); 
+      }
+      dyerr = dyerr_len / h;
+      hdid= h;
+      x += hdid;
+
+      // Compute suggested new step
+      hnext= ComputeNewStepSize( dyerr/eps, h);
+
+      // .. hnext= ComputeNewStepSize_WithinLimits( dyerr/eps, h);
+      lastStepSucceeded= (dyerr<= eps);
+    }
+
+    if (lastStepSucceeded)  { noFullIntegr++; }
+    else                    { noSmallIntegr++; }
+
+    G4ThreeVector EndPos( y[0], y[1], y[2] );
+
 #ifdef  G4DEBUG_FIELD
-  	  if(dbg>2) PrintStatus( ySubStepStart, xSubStart, y, x, h,  nstp); // Only
-#endif
-     }else{
-        G4FieldTrack yFldTrk( G4ThreeVector(0,0,0), 
-			      G4ThreeVector(0,0,0), 0., 0., 0., 0. );
-        G4double dchord_step, dyerr, dyerr_len;  //  Must figure what to do with these
-	yFldTrk.LoadFromArray(y, fNoIntegrationVariables); 
-        yFldTrk.SetCurveLength( x );
-
-        QuickAdvance( yFldTrk, dydx, h, dchord_step, dyerr_len ); 
-        //-----------------------------------------------------
-        // #ifdef G4DEBUG_FIELD
-	// if(dbg>1) OneGoodStep(y,dydx,x,h,2*eps,hdid,hnext) ;
-	// if(dbg>1) PrintStatus( ystart, x1, y, x, h, -nstp);  
-
-        yFldTrk.DumpToArray(y);    
-
-#ifdef G4FLD_STATS
-	fNoSmallSteps++; 
-        if( dyerr_len > fDyerr_max) fDyerr_max= dyerr_len;
-        fDyerrPos_smTot += dyerr_len;
-	fSumH_sm += h;  // Length total for 'small' steps
-        if(nstp<=1) fNoInitialSmallSteps++;
-#endif
+    if( (dbg>0) && (dbg<=2) && (nstp>nStpPr))
+    {
+      if( nstp==nStpPr )  { G4cout << "***** Many steps ****" << G4endl; }
+      G4cout << "MagIntDrv: " ; 
+      G4cout << "hdid="  << std::setw(12) << hdid  << " "
+             << "hnext=" << std::setw(12) << hnext << " " 
+	     << "hstep=" << std::setw(12) << hstep << " (requested) " 
+	     << G4endl;
+      PrintStatus( ystart, x1, y, x, h, (nstp==nStpPr) ? -nstp: nstp); 
+    }
+#endif
+
+    // Check the endpoint
+    G4double endPointDist= (EndPos-StartPos).mag(); 
+    if ( endPointDist >= hdid*(1.+perMillion) )
+    {
+      fNoBadSteps++;
+
+      // Issue a warning only for gross differences -
+      // we understand how small difference occur.
+      if ( endPointDist >= hdid*(1.+perThousand) )
+      { 
 #ifdef G4DEBUG_FIELD
-	if(dbg>1) {
-	   if(fNoSmallSteps<2) PrintStatus( ySubStepStart, x1, y, x, h, -nstp);
-	   G4cout << "Another sub-min step, no " << fNoSmallSteps 
-		  << " of " << fNoTotalSteps << " this time " << nstp << G4endl; 
-	   PrintStatus( ySubStepStart, x1, y, x, h,  nstp);   // Only this
-	   G4cout << " dyerr= " << dyerr_len << " relative = " << dyerr_len / h 
-		  << " epsilon= " << eps << " hstep= " << hstep 
-		  << " h= " << h << " hmin= " << fMinimumStep
-		  << G4endl;
+        if (dbg)
+        {
+          WarnEndPointTooFar ( endPointDist, hdid, eps, dbg ); 
+          G4cerr << "  Total steps:  bad " << fNoBadSteps
+                 << " good " << noGoodSteps << " current h= " << hdid
+                 << G4endl;
+          PrintStatus( ystart, x1, y, x, hstep, no_warnings?nstp:-nstp);  
         }
-#endif	
-	if( h == 0.0 ) { 
-	   G4Exception("G4MagInt_Driver::AccurateAdvance()", "Integration Step became Zero",
-		       FatalException, "IntegrationStepUnderflow."); 
-	}
-	dyerr = dyerr_len / h;
-	hdid= h;
-        x += hdid;
-        // Compute suggested new step
-	hnext= ComputeNewStepSize( dyerr/eps, h);
-	// .. hnext= ComputeNewStepSize_WithinLimits( dyerr/eps, h);
-	lastStepSucceeded= (dyerr<= eps);
-     }
-
-     if(lastStepSucceeded) noFullIntegr++ ; else noSmallIntegr++ ;
-     G4ThreeVector EndPos( y[0], y[1], y[2] );
-
+#endif
+        no_warnings++;
+      }
+    }
+    else
+    {
+      noGoodSteps ++;
+    } 
+// #endif
+
+    //  Avoid numerous small last steps
+    if( (h < eps * hstep) || (h < fSmallestFraction * startCurveLength) )
+    {
+      // No more integration -- the next step will not happen
+      lastStep = true;  
+    }
+    else
+    {
+      // Check the proposed next stepsize
+      if(std::fabs(hnext) <= Hmin())
+      {
 #ifdef  G4DEBUG_FIELD
-     if( (dbg>0) && (dbg<=2) && (nstp>nStpPr)) {
-       if( nstp==nStpPr ) G4cout << "***** Many steps ****" << G4endl;
-       G4cout << "hdid="  << std::setw(12) << hdid  << " "
-	      << "hnext=" << std::setw(12) << hnext << " " << G4endl;
-       PrintStatus( ystart, x1, y, x, h, (nstp==nStpPr) ? -nstp: nstp); 
-     }
-#endif
-
-     // Check the endpoint
-     G4double endPointDist= (EndPos-StartPos).mag(); 
-     if( endPointDist >= hdid*(1.+perMillion) ){
-        fNoBadSteps  ++;
-        // Issue a warning only for gross differences -
-        //   we understand how small difference occur.
-        if( endPointDist >= hdid*(1.+perThousand) ){ 
-#ifdef  G4DEBUG_FIELD
-           if(dbg){
-	      WarnEndPointTooFar ( endPointDist, hdid, eps, dbg ); 
-	      G4cerr << "  Total steps:  bad " << fNoBadSteps << " good " << noGoodSteps << " current h= " << hdid << G4endl;
-	      // G4cerr << "Mid:EndPtFar> ";
-	      PrintStatus( ystart, x1, y, x, hstep, no_warnings?nstp:-nstp);  
-                // Potentially add as arguments:  <dydx> - as Initial Force
-           }
-#endif
-	   no_warnings++;
-	}
-     } else { // ie (!dbg)
-        noGoodSteps ++;
-     } 
-// #endif
-
-     //  Avoid numerous small last steps
-     if( (h < eps * hstep) || (h < fSmallestFraction * startCurveLength) ) {
-       // No more integration -- the next step will not happen
-       lastStep = true;  
-       // fNoLastStep++; 
-     } else {
-
-        // Check the proposed next stepsize
-        if(std::fabs(hnext) <= Hmin())
+        // If simply a very small interval is being integrated, do not warn
+        if( (x < x2 * (1-eps) ) &&        // The last step can be small: OK
+            (std::fabs(hstep) > Hmin()) ) // and if we are asked, it's OK
         {
-#ifdef  G4DEBUG_FIELD
-           // If simply a very small interval is being integrated, do not warn
-	   if( (x < x2 * (1-eps) ) &&     //  The last step can be small: it's OK
-               (std::fabs(hstep) > Hmin())     //   and if we are asked, it's OK
-               //   && (hnext < hstep * PerThousand ) 
-	     )
-           {
-             if(dbg>0){    // G4cerr << "Mid:SmallStep> ";
-		WarnSmallStepSize( hnext, hstep, h, x-x1, nstp );  
-		PrintStatus( ystart, x1, y, x, hstep, no_warnings?nstp:-nstp);
-	     }
-	     no_warnings++;
-	   }
-#endif
-	   // Make sure that the next step is at least Hmin.
-	   h = Hmin();
-	}else{
-	   h = hnext ;
-	}
-
-        //  Ensure that the next step does not overshoot
-        if( x+h > x2 ) {
-           h = x2 - x ;     // When stepsize overshoots, decrease it!
-           //  Must cope with difficult rounding-error issues if hstep << x2
-	}
-        // if( h < smallestFraction * startCurveLength )
-	if( h == 0.0 ){
-	  // Cannot progress - accept this as last step - by default
-	  lastStep = true;
-#ifdef  G4DEBUG_FIELD
-           if(dbg){
-	     G4cout << "Warning: G4MagIntegratorDriver::AccurateAdvance" << G4endl
-	            << "  Integration step 'h' became " << h << " due to roundoff " << G4endl
-		    << "  Forcing termination of advance." << G4endl;
-	   }	  
-#endif
-	}
-     }
-
-  }while ( ((nstp++)<=fMaxNoSteps)
-          && (x < x2)           //  Have we reached the end ?
-                                //   --> a better test might be x-x2 > an_epsilon
-          && (!lastStep)
-         );
+          if(dbg>0)
+          {
+            WarnSmallStepSize( hnext, hstep, h, x-x1, nstp );  
+            PrintStatus( ystart, x1, y, x, hstep, no_warnings?nstp:-nstp);
+          }
+          no_warnings++;
+        }
+#endif
+        // Make sure that the next step is at least Hmin.
+        h = Hmin();
+      }
+      else
+      {
+        h = hnext;
+      }
+
+      //  Ensure that the next step does not overshoot
+      if ( x+h > x2 )
+      {                // When stepsize overshoots, decrease it!
+        h = x2 - x ;   // Must cope with difficult rounding-error
+      }                // issues if hstep << x2
+
+      if ( h == 0.0 )
+      {
+        // Cannot progress - accept this as last step - by default
+        lastStep = true;
+#ifdef G4DEBUG_FIELD
+        if (dbg>2)
+        {
+          int prec= G4cout.precision(12); 
+          G4cout << "Warning: G4MagIntegratorDriver::AccurateAdvance"
+                 << G4endl
+                 << "  Integration step 'h' became "
+                 << h << " due to roundoff. " << G4endl
+		 << " Calculated as difference of x2= "<< x2 << " and x=" << x
+                 << "  Forcing termination of advance." << G4endl;
+          G4cout.precision(prec);
+        }          
+#endif
+      }
+    }
+  } while ( ((nstp++)<=fMaxNoSteps) && (x < x2) && (!lastStep) );
+     // Have we reached the end ?
+     // --> a better test might be x-x2 > an_epsilon
 
   succeeded=  (x>=x2);  // If it was a "forced" last step
 
-  for(i=0;i<nvar;i++)  yEnd[i] = y[i] ;
+  for (i=0;i<nvar;i++)  { yEnd[i] = y[i]; }
 
   // Put back the values.
@@ -363,119 +398,132 @@
   y_current.SetCurveLength( x );
 
-  if(nstp > fMaxNoSteps){
-     no_warnings++;
-     succeeded = false;
-#ifdef  G4DEBUG_FIELD
-        if(dbg){
-	   WarnTooManyStep( x1, x2, x );  //  Issue WARNING
-	   PrintStatus( yEnd, x1, y, x, hstep, -nstp);
-        }
-#endif
-  }
-
+  if(nstp > fMaxNoSteps)
+  {
+    no_warnings++;
+    succeeded = false;
 #ifdef G4DEBUG_FIELD
-  if( dbg && no_warnings ){
-     G4cerr << "G4MagIntegratorDriver exit status: no-steps " << nstp <<G4endl;
-     PrintStatus( yEnd, x1, y, x, hstep, nstp);
+    if (dbg)
+    {
+      WarnTooManyStep( x1, x2, x );  //  Issue WARNING
+      PrintStatus( yEnd, x1, y, x, hstep, -nstp);
+    }
+#endif
+  }
+
+#ifdef G4DEBUG_FIELD
+  if( dbg && no_warnings )
+  {
+    G4cerr << "G4MagIntegratorDriver exit status: no-steps " << nstp <<G4endl;
+    PrintStatus( yEnd, x1, y, x, hstep, nstp);
   }
 #endif
 
   return succeeded;
-
 }  // end of AccurateAdvance ...........................
+
+// ---------------------------------------------------------
 
 void
 G4MagInt_Driver::WarnSmallStepSize( G4double hnext, G4double hstep, 
-				    G4double h, G4double xDone,
-				    G4int nstp)
+                                    G4double h, G4double xDone,
+                                    G4int nstp)
 {
   static G4int noWarningsIssued =0;
   const  G4int maxNoWarnings =  10;   // Number of verbose warnings
-  if( (noWarningsIssued < maxNoWarnings) || fVerboseLevel > 10 ){
-    G4cerr<< " Warning (G4MagIntegratorDriver::AccurateAdvance): The stepsize for the " 
-	  << " next iteration=" << hnext << " is too small " 
-	  << "- in Step number " << nstp << "." << G4endl;
-    G4cerr << "     The minimum for the driver is " << Hmin()  << G4endl ;
-    G4cerr << "     Requested integr. length was " << hstep << " ." << G4endl ;
-    G4cerr << "     The size of this sub-step was " << h     << " ." << G4endl ;
-    G4cerr << "     The integrations has already gone " << xDone << G4endl ;
-  }else{
-    G4cerr<< " G4MagInt_Driver: Too small 'next' step " << hnext 
-	  << " step-no "  << nstp ;                     // << G4setw(4)
+  if( (noWarningsIssued < maxNoWarnings) || fVerboseLevel > 10 )
+  {
+    G4cerr << " Warning (G4MagIntegratorDriver::AccurateAdvance):" << G4endl
+           << " The stepsize for the next iteration, " << hnext
+           << ", is too small - in Step number " << nstp << "." << G4endl;
+    G4cerr << "     The minimum for the driver is " << Hmin()  << G4endl;
+    G4cerr << "     Requested integr. length was " << hstep << " ." << G4endl;
+    G4cerr << "     The size of this sub-step was " << h     << " ." << G4endl;
+    G4cerr << "     The integrations has already gone " << xDone << G4endl;
+  }
+  else
+  {
+    G4cerr << " G4MagInt_Driver: Too small 'next' step " << hnext 
+           << " step-no "  << nstp << G4endl;
     G4cerr << "  this sub-step " << h     
-	   << "  req_tot_len " << hstep 
-	   << "  done " << xDone 
-	   << "  min " << Hmin() 
-	   << G4endl ;
+           << "  req_tot_len " << hstep 
+           << "  done " << xDone 
+           << "  min " << Hmin() 
+           << G4endl;
   }
   noWarningsIssued++;
 }
+
+// ---------------------------------------------------------
 
 void
 G4MagInt_Driver::WarnTooManyStep( G4double x1start, 
-				  G4double x2end, 
-				  G4double xCurrent)
-{
-    G4cerr << " Warning (G4MagIntegratorDriver): The number of steps " 
-         << "used in the Integration driver (Runge-Kutta) is too many.  "
-	 << G4endl ;
-    G4cerr << "Integration of the interval was not completed - only a " 
-         << (xCurrent-x1start)*100/(x2end-x1start)
-	   <<" % fraction of it was Done." << G4endl;
-}
+                                  G4double x2end, 
+                                  G4double xCurrent)
+{
+  G4cerr << " Warning (G4MagIntegratorDriver):" << G4endl
+         << " The number of steps used in the Integration driver"
+         << " (Runge-Kutta) is too many." << G4endl;
+  G4cerr << " Integration of the interval was not completed !" << G4endl
+         << " Only a " << (xCurrent-x1start)*100/(x2end-x1start)
+         <<" % fraction of it was done." << G4endl;
+}
+
+// ---------------------------------------------------------
 
 void
 G4MagInt_Driver::WarnEndPointTooFar (G4double endPointDist, 
-				     G4double   h , 
-				     G4double  eps,
-				     G4int     dbg)
-{
-	static G4double maxRelError= 0.0, maxRelError_last_printed=0.0;
-	G4bool isNewMax, prNewMax;
-
-        isNewMax = endPointDist > (1.0 + maxRelError) * h;
-        prNewMax = endPointDist > (1.0 + 1.05 * maxRelError) * h;
-	if( isNewMax )
-	   maxRelError= endPointDist / h - 1.0; 
-        if( prNewMax )
- 	   maxRelError_last_printed = maxRelError;
-
-        if(    dbg 
-	    && (h > G4GeometryTolerance::GetInstance()->GetSurfaceTolerance()) 
-	    && ( (dbg>1) || prNewMax || (endPointDist >= h*(1.+eps) ) ) 
-          ){ 
-           static G4int noWarnings = 0;
-           if( (noWarnings ++ < 10) || (dbg>2) ){
- 	      G4cerr << " Warning (G4MagIntegratorDriver): "
-		     << " The integration produced an endpoint which " << G4endl
-		     << "   is further from the startpoint than the curve length." << G4endl; 
+                                     G4double   h , 
+                                     G4double  eps,
+                                     G4int     dbg)
+{
+  static G4double maxRelError=0.0, maxRelError_last_printed=0.0;
+  G4bool isNewMax, prNewMax;
+
+  isNewMax = endPointDist > (1.0 + maxRelError) * h;
+  prNewMax = endPointDist > (1.0 + 1.05 * maxRelError) * h;
+  if( isNewMax ) { maxRelError= endPointDist / h - 1.0; }
+  if( prNewMax ) { maxRelError_last_printed = maxRelError; }
+
+  if( dbg && (h > G4GeometryTolerance::GetInstance()->GetSurfaceTolerance()) 
+          && ( (dbg>1) || prNewMax || (endPointDist >= h*(1.+eps) ) ) )
+  { 
+    static G4int noWarnings = 0;
+    if( (noWarnings ++ < 10) || (dbg>2) )
+    {
+      G4cerr << " Warning (G4MagIntegratorDriver): " << G4endl
+             << " The integration produced an endpoint which " << G4endl
+             << "   is further from the startpoint than the curve length."
+             << G4endl; 
           
-	      G4cerr << "   Distance of endpoints = " << endPointDist
-		     << "  curve length = " <<  h
-		     << "  Difference (curveLen-endpDist)= " << (h - endPointDist)
-		     << "  relative = " << (h-endPointDist) / h 
-		     << "  epsilon =  " << eps 
-		     << G4endl;
-	   }else{
- 	      G4cerr << " Warning:" 
-		     << "  dist_e= " << endPointDist
-		     << "  h_step = " <<  h
-		     << "  Diff (hs-ed)= " << (h - endPointDist)
-		     << "  rel = " << (h-endPointDist) / h 
-		     << "  eps = " << eps
-		     << " (from G4MagInt_Driver)" << G4endl;
-	   }
-	}
-}
+      G4cerr << "   Distance of endpoints = " << endPointDist
+             << "  curve length = " <<  h
+             << "  Difference (curveLen-endpDist)= " << (h - endPointDist)
+             << "  relative = " << (h-endPointDist) / h 
+             << "  epsilon =  " << eps 
+             << G4endl;
+    }
+    else
+    {
+      G4cerr << " Warning:" 
+             << "  dist_e= " << endPointDist
+             << "  h_step = " <<  h
+             << "  Diff (hs-ed)= " << (h - endPointDist)
+             << "  rel = " << (h-endPointDist) / h 
+             << "  eps = " << eps
+             << " (from G4MagInt_Driver)" << G4endl;
+    }
+  }
+}
+
 // ---------------------------------------------------------
 
 void
 G4MagInt_Driver::OneGoodStep(      G4double y[],        // InOut
-			     const G4double dydx[],
-				   G4double& x,         // InOut
-			           G4double htry,
-			           G4double eps_rel_max,
-				   G4double& hdid,      // Out
-				   G4double& hnext )    // Out
+                             const G4double dydx[],
+                                   G4double& x,         // InOut
+                                   G4double htry,
+                                   G4double eps_rel_max,
+                                   G4double& hdid,      // Out
+                                   G4double& hnext )    // Out
 
 // Driver for one Runge-Kutta Step with monitoring of local truncation error
@@ -493,223 +541,236 @@
 
 {
-      // G4double errpos_rel_sq, errvel_rel_sq
-      G4double errmax_sq;
-      // G4double errmax; 
-      G4double h, htemp, xnew ;
-
-      G4double yerr[G4FieldTrack::ncompSVEC], ytemp[G4FieldTrack::ncompSVEC];
-
-      h = htry ; // Set stepsize to the initial trial value
-
-      // G4double inv_epspos_sq = 1.0 / eps * eps; 
-      G4double inv_eps_vel_sq = 1.0 / (eps_rel_max*eps_rel_max); 
-
-      G4double errpos_sq=0.0;    // square of displacement error
-      G4double errvel_sq=0.0;    // square of momentum vector difference
-
-      G4int iter;
-
-      static G4int tot_no_trials=0; 
-      const G4int max_trials=100; 
-
-      for (iter=0; iter<max_trials ;iter++)
-      {
-	  tot_no_trials++;
-	  pIntStepper-> Stepper(y,dydx,h,ytemp,yerr); 
-          //            *******
-          G4double eps_pos = eps_rel_max * std::max(h, fMinimumStep); 
-	  G4double inv_eps_pos_sq = 1.0 / (eps_pos*eps_pos); 
-
-	  // Evaluate accuracy
-	  //
-	  errpos_sq =  sqr(yerr[0]) + sqr(yerr[1]) + sqr(yerr[2]) ;
-	  // errpos_sq /= eps_pos*eps_pos; // Scale to tolerance
-	  errpos_sq *= inv_eps_pos_sq; // Scale relative to required tolerance
-
-          // Accuracy for momentum
-          errvel_sq =  (sqr(yerr[3]) + sqr(yerr[4]) + sqr(yerr[5]) )
-                     / (sqr(y[3]) + sqr(y[4]) + sqr(y[5]) );
-          // errvel_sq /= eps_rel_max*eps_rel_max; 
-          errvel_sq *= inv_eps_vel_sq;
-
-          errmax_sq = std::max( errpos_sq, errvel_sq ); // Square of maximum error
-          // errmax = std::sqrt( errmax_sq );
-	  if(errmax_sq <= 1.0 ) break ; // Step succeeded. 
-
-	  // Step failed; compute the size of retrial Step.
-	  htemp = GetSafety()*h* std::pow( errmax_sq, 0.5*GetPshrnk() );
-
-	  if(htemp >= 0.1*h) h = htemp ;  // Truncation error too large,
-	  else h = 0.1*h ;                // reduce stepsize, but no more
-					  // than a factor of 10
-	  xnew = x + h ;
-	  if(xnew == x) {
-	     G4cerr<<"G4MagIntegratorDriver::OneGoodStep: Stepsize underflow in Stepper "<<G4endl ;
-	     G4cerr<<"  Step's start x=" << x << " and end x= " << xnew 
-		   << " are equal !! " << G4endl
-		   <<"  Due to step-size= " << h 
-                   << " . Note that input step was " << htry << G4endl;
-	     break;
-	  }
-      }
-      // tot_no_trials+= (iter+1); 
+  G4double errmax_sq;
+  G4double h, htemp, xnew ;
+
+  G4double yerr[G4FieldTrack::ncompSVEC], ytemp[G4FieldTrack::ncompSVEC];
+
+  h = htry ; // Set stepsize to the initial trial value
+
+  G4double inv_eps_vel_sq = 1.0 / (eps_rel_max*eps_rel_max);
+
+  G4double errpos_sq=0.0;    // square of displacement error
+  G4double errvel_sq=0.0;    // square of momentum vector difference
+  G4double errspin_sq=0.0;   // square of spin vector difference
+
+  G4int iter;
+
+  static G4int tot_no_trials=0; 
+  const G4int max_trials=100; 
+
+  G4ThreeVector Spin(y[9],y[10],y[11]);
+  G4bool     hasSpin= (Spin.mag2() > 0.0); 
+
+  for (iter=0; iter<max_trials ;iter++)
+  {
+    tot_no_trials++;
+    pIntStepper-> Stepper(y,dydx,h,ytemp,yerr); 
+    //            *******
+    G4double eps_pos = eps_rel_max * std::max(h, fMinimumStep); 
+    G4double inv_eps_pos_sq = 1.0 / (eps_pos*eps_pos); 
+
+    // Evaluate accuracy
+    //
+    errpos_sq =  sqr(yerr[0]) + sqr(yerr[1]) + sqr(yerr[2]) ;
+    errpos_sq *= inv_eps_pos_sq; // Scale relative to required tolerance
+
+    // Accuracy for momentum
+    errvel_sq =  (sqr(yerr[3]) + sqr(yerr[4]) + sqr(yerr[5]) )
+               / (sqr(y[3]) + sqr(y[4]) + sqr(y[5]) );
+    errvel_sq *= inv_eps_vel_sq;
+    errmax_sq = std::max( errpos_sq, errvel_sq ); // Square of maximum error
+
+    if( hasSpin )
+    { 
+      // Accuracy for spin
+      errspin_sq =  ( sqr(yerr[9]) + sqr(yerr[10]) + sqr(yerr[11]) )
+                 /  ( sqr(y[9]) + sqr(y[10]) + sqr(y[11]) );
+      errspin_sq *= inv_eps_vel_sq;
+      errmax_sq = std::max( errmax_sq, errspin_sq ); 
+   }
+
+    if ( errmax_sq <= 1.0 )  { break; } // Step succeeded. 
+
+    // Step failed; compute the size of retrial Step.
+    htemp = GetSafety()*h* std::pow( errmax_sq, 0.5*GetPshrnk() );
+
+    if (htemp >= 0.1*h)  { h = htemp; }  // Truncation error too large,
+    else  { h = 0.1*h; }                 // reduce stepsize, but no more
+                                         // than a factor of 10
+    xnew = x + h;
+    if(xnew == x)
+    {
+      G4cerr << "G4MagIntegratorDriver::OneGoodStep:" << G4endl
+             << "  Stepsize underflow in Stepper " << G4endl ;
+      G4cerr << "  Step's start x=" << x << " and end x= " << xnew 
+             << " are equal !! " << G4endl
+             <<"  Due to step-size= " << h 
+             << " . Note that input step was " << htry << G4endl;
+      break;
+    }
+  }
 
 #ifdef G4FLD_STATS
-      // Sum of squares of position error // and momentum dir (underestimated)
-      fSumH_lg += h; 
-      fDyerrPos_lgTot += errpos_sq;  //  + errvel_last_sq * h * h ; 
-      fDyerrVel_lgTot += errvel_sq * h * h; 
-#endif
-
-      // Compute size of next Step
-      if(errmax_sq > errcon*errcon) 
-               hnext = GetSafety()*h*std::pow(errmax_sq, 0.5*GetPgrow()) ;
-      else hnext = max_stepping_increase*h ;
-                     // No more than a factor of 5 increase
-
-      x += (hdid = h) ;
-
-      int i;
-      const int nvar= fNoIntegrationVariables;   
-      for(i=0;i<nvar;i++) y[i] = ytemp[i] ;
-
-      return ;
-
+  // Sum of squares of position error // and momentum dir (underestimated)
+  fSumH_lg += h; 
+  fDyerrPos_lgTot += errpos_sq;
+  fDyerrVel_lgTot += errvel_sq * h * h; 
+#endif
+
+  // Compute size of next Step
+  if (errmax_sq > errcon*errcon)
+  { 
+    hnext = GetSafety()*h*std::pow(errmax_sq, 0.5*GetPgrow());
+  }
+  else
+  {
+    hnext = max_stepping_increase*h ; // No more than a factor of 5 increase
+  }
+  x += (hdid = h);
+
+  for(G4int k=0;k<fNoIntegrationVariables;k++) { y[k] = ytemp[k]; }
+
+  return;
 }   // end of  OneGoodStep .............................
 
 //----------------------------------------------------------------------
+
 // QuickAdvance just tries one Step - it does not ensure accuracy
 //
 G4bool  G4MagInt_Driver::QuickAdvance(       
-			    G4FieldTrack& y_posvel,         // INOUT
-		            const G4double     dydx[],  
-		                  G4double     hstep,       // In
-			          G4double&    dchord_step,
-   			          G4double&    dyerr_pos_sq,
-			          G4double&    dyerr_mom_rel_sq
-			    //    G4double&    dyerr_ener_sq // Future
- )  
-{
-      G4Exception("G4MagInt_Driver::QuickAdvance()", "NotImplemented",
-                  FatalException, "Not yet implemented."); 
-
-      // Use the parameters of this method, to please compiler
-      dchord_step = dyerr_pos_sq = hstep * hstep * dydx[0]; 
-      dyerr_mom_rel_sq = y_posvel.GetPosition().mag2();
-      return true;
-}
+                            G4FieldTrack& y_posvel,         // INOUT
+                            const G4double     dydx[],  
+                                  G4double     hstep,       // In
+                                  G4double&    dchord_step,
+                                  G4double&    dyerr_pos_sq,
+                                  G4double&    dyerr_mom_rel_sq )  
+{
+  G4Exception("G4MagInt_Driver::QuickAdvance()", "NotImplemented",
+              FatalException, "Not yet implemented."); 
+
+  // Use the parameters of this method, to please compiler
+  dchord_step = dyerr_pos_sq = hstep * hstep * dydx[0]; 
+  dyerr_mom_rel_sq = y_posvel.GetPosition().mag2();
+  return true;
+}
+
+//----------------------------------------------------------------------
 
 G4bool  G4MagInt_Driver::QuickAdvance(       
-			    G4FieldTrack& y_posvel,         // INOUT
-		            const G4double     dydx[],  
-		                  G4double     hstep,       // In
-			          G4double&    dchord_step,
-			          G4double&    dyerr )
-{
-    G4double   dyerr_pos_sq,  dyerr_mom_rel_sq;  
-    G4double yerr_vec[G4FieldTrack::ncompSVEC], yarrin[G4FieldTrack::ncompSVEC], yarrout[G4FieldTrack::ncompSVEC]; 
-    G4double s_start;
-    // G4double dyerr_len=0.0;  // , dyerr_vel, vel_mag;
-    G4double dyerr_mom_sq, vel_mag_sq, inv_vel_mag_sq;
-
-    static G4int no_call=0; 
-    no_call ++; 
-
-    // Move data into array
-    y_posvel.DumpToArray( yarrin );      //  yarrin  <== y_posvel 
-    s_start = y_posvel.GetCurveLength();
-
-    // Do an Integration Step
-    pIntStepper-> Stepper(yarrin, dydx, hstep, yarrout, yerr_vec) ; 
-    //            *******
-
-    // Estimate curve-chord distance
-    dchord_step= pIntStepper-> DistChord();
-    //                         *********
-
-    // Put back the values.
-    y_posvel.LoadFromArray( yarrout, fNoIntegrationVariables );   //  yarrout ==> y_posvel
-    y_posvel.SetCurveLength( s_start + hstep );
+                            G4FieldTrack& y_posvel,         // INOUT
+                            const G4double     dydx[],  
+                                  G4double     hstep,       // In
+                                  G4double&    dchord_step,
+                                  G4double&    dyerr )
+{
+  G4double dyerr_pos_sq, dyerr_mom_rel_sq;  
+  G4double yerr_vec[G4FieldTrack::ncompSVEC],
+           yarrin[G4FieldTrack::ncompSVEC], yarrout[G4FieldTrack::ncompSVEC]; 
+  G4double s_start;
+  G4double dyerr_mom_sq, vel_mag_sq, inv_vel_mag_sq;
+
+  static G4int no_call=0; 
+  no_call ++; 
+
+  // Move data into array
+  y_posvel.DumpToArray( yarrin );      //  yarrin  <== y_posvel 
+  s_start = y_posvel.GetCurveLength();
+
+  // Do an Integration Step
+  pIntStepper-> Stepper(yarrin, dydx, hstep, yarrout, yerr_vec) ; 
+  //            *******
+
+  // Estimate curve-chord distance
+  dchord_step= pIntStepper-> DistChord();
+  //                         *********
+
+  // Put back the values.  yarrout ==> y_posvel
+  y_posvel.LoadFromArray( yarrout, fNoIntegrationVariables );
+  y_posvel.SetCurveLength( s_start + hstep );
 
 #ifdef  G4DEBUG_FIELD
-    if(fVerboseLevel>2) {
-       G4cout << "G4MagIntDrv: Quick Advance" << G4endl;
-       PrintStatus( yarrin, s_start, yarrout, s_start+hstep, hstep,  1); 
-    }
-#endif
-
-    // A single measure of the error   
-    //      TO-DO :  account for  energy,  spin, ... ? 
-    vel_mag_sq   = ( sqr(yarrout[3])+sqr(yarrout[4])+sqr(yarrout[5]) );
-    inv_vel_mag_sq = 1.0 / vel_mag_sq; 
-    dyerr_pos_sq = ( sqr(yerr_vec[0])+sqr(yerr_vec[1])+sqr(yerr_vec[2]));
-    dyerr_mom_sq = ( sqr(yerr_vec[3])+sqr(yerr_vec[4])+sqr(yerr_vec[5]));
-
-    dyerr_mom_rel_sq =  dyerr_mom_sq * inv_vel_mag_sq;
-
-    //// Calculate also the change in the momentum squared also ???
-    // G4double veloc_square = y_posvel.GetVelocity().mag2();
-    // ...
+  if(fVerboseLevel>2)
+  {
+    G4cout << "G4MagIntDrv: Quick Advance" << G4endl;
+    PrintStatus( yarrin, s_start, yarrout, s_start+hstep, hstep,  1); 
+  }
+#endif
+
+  // A single measure of the error   
+  //      TO-DO :  account for  energy,  spin, ... ? 
+  vel_mag_sq   = ( sqr(yarrout[3])+sqr(yarrout[4])+sqr(yarrout[5]) );
+  inv_vel_mag_sq = 1.0 / vel_mag_sq; 
+  dyerr_pos_sq = ( sqr(yerr_vec[0])+sqr(yerr_vec[1])+sqr(yerr_vec[2]));
+  dyerr_mom_sq = ( sqr(yerr_vec[3])+sqr(yerr_vec[4])+sqr(yerr_vec[5]));
+  dyerr_mom_rel_sq = dyerr_mom_sq * inv_vel_mag_sq;
+
+  // Calculate also the change in the momentum squared also ???
+  // G4double veloc_square = y_posvel.GetVelocity().mag2();
+  // ...
 
 #ifdef RETURN_A_NEW_STEP_LENGTH
-    // The following step cannot be done here because "eps" is not known.
-    dyerr_len = std::sqrt( dyerr_len_sq ); 
-    dyerr_len_sq /= eps ;
-
-    // Look at the velocity deviation ?
-    //  sqr(yerr_vec[3])+sqr(yerr_vec[4])+sqr(yerr_vec[5]));
-
-   // Set suggested new step
-    hstep= ComputeNewStepSize( dyerr_len, hstep);
-#endif
-
-    if( dyerr_pos_sq > ( dyerr_mom_rel_sq * sqr(hstep) ) ) {
-       dyerr = std::sqrt(dyerr_pos_sq);
-    }else{
-       // Scale it to the current step size - for now
-       dyerr = std::sqrt(dyerr_mom_rel_sq) * hstep;
-    }
-
-    return true;
-}
+  // The following step cannot be done here because "eps" is not known.
+  dyerr_len = std::sqrt( dyerr_len_sq ); 
+  dyerr_len_sq /= eps ;
+
+  // Look at the velocity deviation ?
+  //  sqr(yerr_vec[3])+sqr(yerr_vec[4])+sqr(yerr_vec[5]));
+
+  // Set suggested new step
+  hstep= ComputeNewStepSize( dyerr_len, hstep);
+#endif
+
+  if( dyerr_pos_sq > ( dyerr_mom_rel_sq * sqr(hstep) ) )
+  {
+    dyerr = std::sqrt(dyerr_pos_sq);
+  }
+  else
+  {
+    // Scale it to the current step size - for now
+    dyerr = std::sqrt(dyerr_mom_rel_sq) * hstep;
+  }
+
+  return true;
+}
+
+// --------------------------------------------------------------------------
 
 #ifdef QUICK_ADV_ARRAY_IN_AND_OUT
 G4bool  G4MagInt_Driver::QuickAdvance(       
-				  G4double     yarrin[],        // IN
-		            const G4double     dydx[],  
-		                  G4double     hstep,       // In
-				  G4double     yarrout[],
-			          G4double&    dchord_step,
-			          G4double&    dyerr )      // in length
-{
-   G4Exception("G4MagInt_Driver::QuickAdvance()", "NotImplemented",
-                FatalException, "Not yet implemented.");
-
-   dyerr = dchord_step = hstep * yarrin[0] * dydx[0];
-   yarrout[0]= yarrin[0];
+                                  G4double     yarrin[],    // In
+                            const G4double     dydx[],  
+                                  G4double     hstep,       // In
+                                  G4double     yarrout[],
+                                  G4double&    dchord_step,
+                                  G4double&    dyerr )      // In length
+{
+  G4Exception("G4MagInt_Driver::QuickAdvance()", "NotImplemented",
+              FatalException, "Not yet implemented.");
+  dyerr = dchord_step = hstep * yarrin[0] * dydx[0];
+  yarrout[0]= yarrin[0];
 }
 #endif 
 
 // --------------------------------------------------------------------------
+
 //  This method computes new step sizes - but does not limit changes to
 //   within  certain factors
 // 
-
 G4double 
 G4MagInt_Driver::ComputeNewStepSize( 
                           G4double  errMaxNorm,    // max error  (normalised)
-			  G4double  hstepCurrent)  // current step size
+                          G4double  hstepCurrent)  // current step size
 {
   G4double hnew;
 
   // Compute size of next Step for a failed step
-  if(errMaxNorm > 1.0 ) {
-
+  if(errMaxNorm > 1.0 )
+  {
     // Step failed; compute the size of retrial Step.
     hnew = GetSafety()*hstepCurrent*std::pow(errMaxNorm,GetPshrnk()) ;
-  }else if(errMaxNorm > 0.0 ){
+  } else if(errMaxNorm > 0.0 ) {
     // Compute size of next Step for a successful step
     hnew = GetSafety()*hstepCurrent*std::pow(errMaxNorm,GetPgrow()) ;
-  }else {
+  } else {
     // if error estimate is zero (possible) or negative (dubious)
     hnew = max_stepping_increase * hstepCurrent; 
@@ -719,45 +780,50 @@
 }
 
-// -----------------------------------------------------------------------------
-//  This method computes new step sizes limiting changes within certain factors
+// ---------------------------------------------------------------------------
+
+// This method computes new step sizes limiting changes within certain factors
 // 
-//   It shares its logic with AccurateAdvance.
-//    They are kept separate currently for optimisation.
-
+// It shares its logic with AccurateAdvance.
+// They are kept separate currently for optimisation.
+//
 G4double 
 G4MagInt_Driver::ComputeNewStepSize_WithinLimits( 
                           G4double  errMaxNorm,    // max error  (normalised)
-			  G4double  hstepCurrent)  // current step size
+                          G4double  hstepCurrent)  // current step size
 {
   G4double hnew;
 
   // Compute size of next Step for a failed step
-  if(errMaxNorm > 1.0 ) {
-
+  if (errMaxNorm > 1.0 )
+  {
     // Step failed; compute the size of retrial Step.
     hnew = GetSafety()*hstepCurrent*std::pow(errMaxNorm,GetPshrnk()) ;
   
-    if(hnew < max_stepping_decrease*hstepCurrent) 
-         hnew = max_stepping_decrease*hstepCurrent ;
+    if (hnew < max_stepping_decrease*hstepCurrent)
+    {
+      hnew = max_stepping_decrease*hstepCurrent ;
                          // reduce stepsize, but no more
                          // than this factor (value= 1/10)
-  }else{
+    }
+  }
+  else
+  {
     // Compute size of next Step for a successful step
-    if(errMaxNorm > errcon) hnew = GetSafety()*hstepCurrent*std::pow(errMaxNorm,GetPgrow()) ;
-    else                    hnew = max_stepping_increase * hstepCurrent ;
-      // No more than a factor of 5 increase
-  }
-
+    if (errMaxNorm > errcon)
+     { hnew = GetSafety()*hstepCurrent*std::pow(errMaxNorm,GetPgrow()); }
+    else  // No more than a factor of 5 increase
+     { hnew = max_stepping_increase * hstepCurrent; }
+  }
   return hnew;
 }
 
-
+// ---------------------------------------------------------------------------
 
 void G4MagInt_Driver::PrintStatus( const G4double*   StartArr,  
-				   G4double          xstart,
-				   const G4double*   CurrentArr, 
-				   G4double          xcurrent,
-				   G4double          requestStep, 
-				   G4int             subStepNo)
+                                   G4double          xstart,
+                                   const G4double*   CurrentArr, 
+                                   G4double          xcurrent,
+                                   G4double          requestStep, 
+                                   G4int             subStepNo)
   // Potentially add as arguments:  
   //                                 <dydx>           - as Initial Force
@@ -765,5 +831,6 @@
   //                                 nextStep (hnext) - proposal for size
 {
-   G4FieldTrack  StartFT(G4ThreeVector(0,0,0), G4ThreeVector(0,0,0), 0., 0., 0., 0. );
+   G4FieldTrack  StartFT(G4ThreeVector(0,0,0),
+                 G4ThreeVector(0,0,0), 0., 0., 0., 0. );
    G4FieldTrack  CurrentFT (StartFT);
 
@@ -776,11 +843,10 @@
 }
 
-
+// ---------------------------------------------------------------------------
 
 void G4MagInt_Driver::PrintStatus(
                   const G4FieldTrack&  StartFT,
-		  const G4FieldTrack&  CurrentFT, 
+                  const G4FieldTrack&  CurrentFT, 
                   G4double             requestStep, 
-                  // G4double             safety,
                   G4int                subStepNo)
 {
@@ -790,16 +856,13 @@
     // G4cout.setf(ios_base::fixed,ios_base::floatfield);
 
-    const G4ThreeVector StartPosition=      StartFT.GetPosition();
-    const G4ThreeVector StartUnitVelocity=  StartFT.GetMomentumDir();
-    const G4ThreeVector CurrentPosition=    CurrentFT.GetPosition();
-    const G4ThreeVector CurrentUnitVelocity=    CurrentFT.GetMomentumDir();
+    const G4ThreeVector StartPosition=       StartFT.GetPosition();
+    const G4ThreeVector StartUnitVelocity=   StartFT.GetMomentumDir();
+    const G4ThreeVector CurrentPosition=     CurrentFT.GetPosition();
+    const G4ThreeVector CurrentUnitVelocity= CurrentFT.GetMomentumDir();
 
     G4double  DotStartCurrentVeloc= StartUnitVelocity.dot(CurrentUnitVelocity);
 
-    G4double step_len= CurrentFT.GetCurveLength() 
-                         - StartFT.GetCurveLength();
+    G4double step_len= CurrentFT.GetCurveLength() - StartFT.GetCurveLength();
     G4double subStepSize = step_len;
-
-    // G4cout << " G4MagInt_Driver: Current Position  and  Direction" << G4endl;
      
     if( (subStepNo <= 1) || (verboseLevel > 3) )
@@ -807,37 +870,38 @@
        subStepNo = - subStepNo;        // To allow printing banner
 
-       G4cout << std::setw( 6)  << " " 
-	      << std::setw( 25) << " G4MagInt_Driver: Current Position  and  Direction" << " "
-	      << G4endl; 
+       G4cout << std::setw( 6)  << " " << std::setw( 25)
+              << " G4MagInt_Driver: Current Position  and  Direction" << " "
+              << G4endl; 
        G4cout << std::setw( 5) << "Step#" << " "
-	      << std::setw( 7) << "s-curve" << " "
-	      << std::setw( 9) << "X(mm)" << " "
-	      << std::setw( 9) << "Y(mm)" << " "  
-	      << std::setw( 9) << "Z(mm)" << " "
-	      << std::setw( 8) << " N_x " << " "
-	      << std::setw( 8) << " N_y " << " "
-	      << std::setw( 8) << " N_z " << " "
-	      << std::setw( 8) << " N^2-1 " << " "
-	      << std::setw(10) << " N(0).N " << " "
-	      << std::setw( 7) << "KinEner " << " "
-	      << std::setw(12) << "Track-l" << " "   // Add the Sub-step ??
-	      << std::setw(12) << "Step-len" << " " 
-	      << std::setw(12) << "Step-len" << " " 
-	      << std::setw( 9) << "ReqStep" << " "  
-	      << G4endl;
-    }
-
-    if( (subStepNo <= 0) ){
-       PrintStat_Aux( StartFT,  requestStep, 0., 
-		       0,        0.0,         1.0);
-        //*************
+              << std::setw( 7) << "s-curve" << " "
+              << std::setw( 9) << "X(mm)" << " "
+              << std::setw( 9) << "Y(mm)" << " "  
+              << std::setw( 9) << "Z(mm)" << " "
+              << std::setw( 8) << " N_x " << " "
+              << std::setw( 8) << " N_y " << " "
+              << std::setw( 8) << " N_z " << " "
+              << std::setw( 8) << " N^2-1 " << " "
+              << std::setw(10) << " N(0).N " << " "
+              << std::setw( 7) << "KinEner " << " "
+              << std::setw(12) << "Track-l" << " "   // Add the Sub-step ??
+              << std::setw(12) << "Step-len" << " " 
+              << std::setw(12) << "Step-len" << " " 
+              << std::setw( 9) << "ReqStep" << " "  
+              << G4endl;
+    }
+
+    if( (subStepNo <= 0) )
+    {
+      PrintStat_Aux( StartFT,  requestStep, 0., 
+                       0,        0.0,         1.0);
+      //*************
     }
 
     if( verboseLevel <= 3 )
     {
-       G4cout.precision(noPrecision);
-       PrintStat_Aux( CurrentFT, requestStep, step_len, 
-		      subStepNo, subStepSize, DotStartCurrentVeloc );
-       //*************
+      G4cout.precision(noPrecision);
+      PrintStat_Aux( CurrentFT, requestStep, step_len, 
+                     subStepNo, subStepSize, DotStartCurrentVeloc );
+      //*************
     }
 
@@ -851,18 +915,19 @@
        //    << " out of PhysicalStep= " <<  requestStep << G4endl;
        // G4cout << "Final safety is: " << safety << G4endl;
-
-       // G4cout << "Chord length = " << (CurrentPosition-StartPosition).mag() << G4endl;
-       // G4cout << G4endl; 
+       // G4cout << "Chord length = " << (CurrentPosition-StartPosition).mag()
+       //        << G4endl << G4endl; 
     }
     G4cout.precision(oldPrec);
 }
+
+// ---------------------------------------------------------------------------
 
 void G4MagInt_Driver::PrintStat_Aux(
                   const G4FieldTrack&  aFieldTrack,
                   G4double             requestStep, 
-		  G4double             step_len,
+                  G4double             step_len,
                   G4int                subStepNo,
-		  G4double             subStepSize,
-		  G4double             dotVeloc_StartCurr)
+                  G4double             subStepSize,
+                  G4double             dotVeloc_StartCurr)
 {
     const G4ThreeVector Position=      aFieldTrack.GetPosition();
@@ -870,15 +935,19 @@
  
     if( subStepNo >= 0)
+    {
        G4cout << std::setw( 5) << subStepNo << " ";
+    }
     else
+    {
        G4cout << std::setw( 5) << "Start" << " ";
+    }
     G4double curveLen= aFieldTrack.GetCurveLength();
     G4cout << std::setw( 7) << curveLen;
     G4cout << std::setw( 9) << Position.x() << " "
-	   << std::setw( 9) << Position.y() << " "
-	   << std::setw( 9) << Position.z() << " "
-	   << std::setw( 8) << UnitVelocity.x() << " "
-	   << std::setw( 8) << UnitVelocity.y() << " "
-	   << std::setw( 8) << UnitVelocity.z() << " ";
+           << std::setw( 9) << Position.y() << " "
+           << std::setw( 9) << Position.z() << " "
+           << std::setw( 8) << UnitVelocity.x() << " "
+           << std::setw( 8) << UnitVelocity.y() << " "
+           << std::setw( 8) << UnitVelocity.z() << " ";
     G4int oldprec= G4cout.precision(3);
     G4cout << std::setw( 8) << UnitVelocity.mag2()-1.0 << " ";
@@ -891,12 +960,15 @@
     static G4double oldCurveLength= 0.0;
     static G4double oldSubStepLength= 0.0;
-    static int oldSubStepNo= -1;
+    static G4int oldSubStepNo= -1;
 
     G4double subStep_len=0.0;
     if( curveLen > oldCurveLength )
-       subStep_len= curveLen - oldCurveLength;
+    {
+      subStep_len= curveLen - oldCurveLength;
+    }
     else if (subStepNo == oldSubStepNo)
-       subStep_len= oldSubStepLength;
-    //     else  subStepLen_NotAvail;
+    {
+      subStep_len= oldSubStepLength;
+    }
     oldCurveLength= curveLen;
     oldSubStepLength= subStep_len;
@@ -904,11 +976,16 @@
     G4cout << std::setw(12) << subStep_len << " "; 
     G4cout << std::setw(12) << subStepSize << " "; 
-    if( requestStep != -1.0 ) 
-       G4cout << std::setw( 9) << requestStep << " ";
+    if( requestStep != -1.0 )
+    {
+      G4cout << std::setw( 9) << requestStep << " ";
+    }
     else
-       G4cout << std::setw( 9) << " InitialStep " << " "; 
-    // G4cout << std::setw(12) << safety << " ";
+    {
+       G4cout << std::setw( 9) << " InitialStep " << " ";
+    }
     G4cout << G4endl;
 }
+
+// ---------------------------------------------------------------------------
 
 void G4MagInt_Driver::PrintStatisticsReport()
@@ -919,20 +996,19 @@
   G4cout << "G4MagInt_Driver Statistics of steps undertaken. " << G4endl;
   G4cout << "G4MagInt_Driver: Number of Steps: "
-	 << " Total= " <<  fNoTotalSteps
+         << " Total= " <<  fNoTotalSteps
          << " Bad= "   <<  fNoBadSteps 
          << " Small= " <<  fNoSmallSteps 
-	 << " Non-initial small= " << (fNoSmallSteps-fNoInitialSmallSteps)
-	 << G4endl;
-
- #ifdef G4FLD_STATS
- G4cout << "MID dyerr: " 
-	 << " maximum= " << fDyerr_max 
-	 // << " 2nd max= " << fDyerr_mx2
-	 << " Sum small= " << fDyerrPos_smTot 
-	 << " std::sqrt(Sum large^2): pos= " << std::sqrt(fDyerrPos_lgTot)
-	 << " vel= " << std::sqrt( fDyerrVel_lgTot )
-	 << " Total h-distance: small= " << fSumH_sm 
-	 << " large= " << fSumH_lg
-	 << G4endl;
+         << " Non-initial small= " << (fNoSmallSteps-fNoInitialSmallSteps)
+         << G4endl;
+
+#ifdef G4FLD_STATS
+  G4cout << "MID dyerr: " 
+         << " maximum= " << fDyerr_max 
+         << " Sum small= " << fDyerrPos_smTot 
+         << " std::sqrt(Sum large^2): pos= " << std::sqrt(fDyerrPos_lgTot)
+         << " vel= " << std::sqrt( fDyerrVel_lgTot )
+         << " Total h-distance: small= " << fSumH_sm 
+         << " large= " << fSumH_lg
+         << G4endl;
 
 #if 0
@@ -941,30 +1017,35 @@
   G4cout.precision(noPrecSmall);
   G4cout << "MIDnums: " << fMinimumStep
-	 << "   " << fNoTotalSteps 
-	 << "  "  <<  fNoSmallSteps
+         << "   " << fNoTotalSteps 
+         << "  "  <<  fNoSmallSteps
          << "  "  << fNoSmallSteps-fNoInitialSmallSteps
-	 << "  "  << fNoBadSteps         
-	 << "   " << fDyerr_max
-	 << "   " << fDyerr_mx2 
-	 << "   " << fDyerrPos_smTot 
-	 << "   " << fSumH_sm
-	 << "   " << fDyerrPos_lgTot
-	 << "   " << fDyerrVel_lgTot
-	 << "   " << fSumH_lg
-	 << G4endl;
- #endif 
- #endif 
+         << "  "  << fNoBadSteps         
+         << "   " << fDyerr_max
+         << "   " << fDyerr_mx2 
+         << "   " << fDyerrPos_smTot 
+         << "   " << fSumH_sm
+         << "   " << fDyerrPos_lgTot
+         << "   " << fDyerrVel_lgTot
+         << "   " << fSumH_lg
+         << G4endl;
+#endif 
+#endif 
 
  G4cout.precision(oldPrec);
 }
  
+// ---------------------------------------------------------------------------
+
 void G4MagInt_Driver::SetSmallestFraction(G4double newFraction)
 {
-  if( (newFraction > 1.e-16) && (newFraction < 1e-8) ) {
-     fSmallestFraction= newFraction;
-  }else{ 
-     G4cerr << "Warning: SmallestFraction not changed. " << G4endl
-	    << "  Proposed value was " << newFraction << G4endl
-	    << "  Value must be between 1.e-8 and 1.e-16" << G4endl;
-  }
-}
+  if( (newFraction > 1.e-16) && (newFraction < 1e-8) )
+  {
+    fSmallestFraction= newFraction;
+  }
+  else
+  { 
+    G4cerr << "Warning: SmallestFraction not changed. " << G4endl
+           << "  Proposed value was " << newFraction << G4endl
+           << "  Value must be between 1.e-8 and 1.e-16" << G4endl;
+  }
+}
Index: trunk/source/geometry/magneticfield/src/G4MagIntegratorStepper.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4MagIntegratorStepper.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4MagIntegratorStepper.cc	(revision 1231)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4MagIntegratorStepper.cc,v 1.11 2006/06/29 18:24:34 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// $Id: G4MagIntegratorStepper.cc,v 1.12 2009/11/05 18:31:15 japost Exp $
+// GEANT4 tag $Name:  $
 //
 // --------------------------------------------------------------------
@@ -48,2 +48,7 @@
 {
 }
+
+void G4MagIntegratorStepper::ComputeRightHandSide( const G4double y[], G4double dydx[] ) 
+{
+  this->RightHandSide( y, dydx );
+}
Index: trunk/source/geometry/magneticfield/src/G4Mag_EqRhs.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4Mag_EqRhs.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4Mag_EqRhs.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4Mag_EqRhs.cc,v 1.11 2006/06/29 18:24:36 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //  This is the standard right-hand side for equation of motion  
Index: trunk/source/geometry/magneticfield/src/G4Mag_SpinEqRhs.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4Mag_SpinEqRhs.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4Mag_SpinEqRhs.cc	(revision 1231)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4Mag_SpinEqRhs.cc,v 1.13 2008/11/21 21:18:26 gum Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// $Id: G4Mag_SpinEqRhs.cc,v 1.15 2009/03/25 15:29:02 gcosmo Exp $
+// GEANT4 tag $Name:  $
 //
 // This is the standard right-hand side for equation of motion.
@@ -48,5 +48,7 @@
 }
 
-G4Mag_SpinEqRhs::~G4Mag_SpinEqRhs() {}
+G4Mag_SpinEqRhs::~G4Mag_SpinEqRhs()
+{
+}
 
 void
@@ -70,6 +72,6 @@
 void
 G4Mag_SpinEqRhs::EvaluateRhsGivenB( const G4double y[],
-			            const G4double B[3],
-				    G4double dydx[] ) const
+                                    const G4double B[3],
+                                          G4double dydx[] ) const
 {
    G4double momentum_mag_square = sqr(y[3]) + sqr(y[4]) + sqr(y[5]);
@@ -97,6 +99,4 @@
    G4ThreeVector Spin(y[9],y[10],y[11]);
 
-   if (Spin.mag() > 0.) Spin = Spin.unit();
-
    G4ThreeVector dSpin;
 
Index: trunk/source/geometry/magneticfield/src/G4Mag_UsualEqRhs.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4Mag_UsualEqRhs.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4Mag_UsualEqRhs.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4Mag_UsualEqRhs.cc,v 1.12 2006/06/29 18:24:42 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/src/G4MagneticField.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4MagneticField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4MagneticField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4MagneticField.cc,v 1.3 2006/06/29 18:24:44 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // --------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4QuadrupoleMagField.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4QuadrupoleMagField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4QuadrupoleMagField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4QuadrupoleMagField.cc,v 1.4 2006/06/29 18:24:46 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // -------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4RKG3_Stepper.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4RKG3_Stepper.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4RKG3_Stepper.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4RKG3_Stepper.cc,v 1.15 2007/08/21 10:17:41 tnikitin Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // -------------------------------------------------------------------
Index: trunk/source/geometry/magneticfield/src/G4SimpleHeum.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4SimpleHeum.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4SimpleHeum.cc	(revision 1231)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4SimpleHeum.cc,v 1.8 2006/06/29 18:24:51 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// $Id: G4SimpleHeum.cc,v 1.10 2009/03/25 15:29:02 gcosmo Exp $
+// GEANT4 tag $Name:  $
 //
 //  Simple Heum:
@@ -75,12 +75,9 @@
 void
 G4SimpleHeum::DumbStepper( const G4double  yIn[],
-			   const G4double  dydx[],
-			         G4double  h,
-			 	 G4double  yOut[])
+                           const G4double  dydx[],
+                                 G4double  h,
+                                 G4double  yOut[])
 {
-  //  const G4int nvar = 6 ;
-
   G4int i;
-
   for( i = 0; i < fNumberOfVariables; i++ ) 
   {
@@ -99,8 +96,7 @@
   for( i = 0; i < fNumberOfVariables; i++ ) 
   {
-    yOut[i] = yIn[i] + h * ( 0.25 * dydx[i] +
-			     0.75 * dydxTemp2[i]);
+    yOut[i] = yIn[i] + h * (0.25 * dydx[i] + 0.75 * dydxTemp2[i]);
   }
       
-  // NormaliseTangentVector( yOut );           
+  if ( fNumberOfVariables == 12 ) { NormalisePolarizationVector( yOut ); }
 }  
Index: trunk/source/geometry/magneticfield/src/G4SimpleRunge.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4SimpleRunge.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4SimpleRunge.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4SimpleRunge.cc,v 1.10 2006/06/29 18:24:53 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //  Simple Runge:
Index: trunk/source/geometry/magneticfield/src/G4UniformElectricField.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4UniformElectricField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4UniformElectricField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4UniformElectricField.cc,v 1.12 2006/06/29 18:24:56 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 // 
Index: trunk/source/geometry/magneticfield/src/G4UniformMagField.cc
===================================================================
--- trunk/source/geometry/magneticfield/src/G4UniformMagField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/src/G4UniformMagField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: G4UniformMagField.cc,v 1.11 2006/06/29 18:24:58 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //
Index: trunk/source/geometry/magneticfield/test/NTST/src/NTSTDetectorConstruction.cc
===================================================================
--- trunk/source/geometry/magneticfield/test/NTST/src/NTSTDetectorConstruction.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/test/NTST/src/NTSTDetectorConstruction.cc	(revision 1231)
@@ -53,4 +53,5 @@
 #include "G4RKG3_Stepper.hh"
 #include "G4HelixMixedStepper.hh"
+#include "G4NystromRK4.hh"
 
 #include "G4DELPHIMagField.hh"
@@ -210,16 +211,17 @@
   pEquation = new G4Mag_UsualEqRhs( &field); 
  
-  // pStepper = 
-  //           new G4ClassicalRK4( pEquation ); 
-  //           new G4RKG3_Stepper( fEquation );  // Nystrom, like Geant3 
-  // pStepper= new G4SimpleRunge( pEquation );
-  // pStepper= new G4CashKarpRKF45( pEquation );
-  pStepper= new G4HelixMixedStepper( pEquation );
+  // pStepper =   
+  //           new G4ClassicalRK4( pEquation ); G4cout << "Stepper is " << "ClassicalRK4" << G4endl;
+  //           new G4RKG3_Stepper( pEquation );  // Nystrom, like Geant3 
+  // pStepper= new G4SimpleRunge( pEquation ); G4cout << "Stepper is " << "CashKarpRKF45" << G4endl;
+  // pStepper= new G4CashKarpRKF45( pEquation ); G4cout << "Stepper is " << "CashKarpRKF45" << G4endl;
+  // pStepper= new G4HelixMixedStepper( pEquation ); G4cout << "Stepper is " << "HelixMixed" << G4endl;
   // pStepper=  StepperFactory::CreateStepper( order ); 
 
-  G4cout << "Stepper is " 
-    //   << "CashKarpRKF45" << G4endl;
+  pStepper= new G4NystromRK4( pEquation ); G4cout << "Stepper is " << "NystromRK4" << G4endl;
+
+    // G4cout << "Stepper is " << "CashKarpRKF45" << G4endl;
     //	 << "ClassicalRK4" << G4endl;
-	 << " G4HelixMixedStepper " << G4endl;
+    //   << " G4HelixMixedStepper " << G4endl;
 
   // globalFieldManager->CreateChordFinder( (G4MagneticField *)&field );
Index: trunk/source/geometry/magneticfield/test/OtherFields/testDelphiField.cc
===================================================================
--- trunk/source/geometry/magneticfield/test/OtherFields/testDelphiField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/test/OtherFields/testDelphiField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: testDelphiField.cc,v 1.7 2006/06/29 18:26:40 gunter Exp $
-// GEANT4 tag $Name: HEAD $
+// GEANT4 tag $Name:  $
 //
 //  
Index: trunk/source/geometry/magneticfield/test/OtherFields/testHarmonicPolMagField.cc
===================================================================
--- trunk/source/geometry/magneticfield/test/OtherFields/testHarmonicPolMagField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/test/OtherFields/testHarmonicPolMagField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: testHarmonicPolMagField.cc,v 1.7 2006/06/29 18:26:43 gunter Exp $
-// GEANT4 tag $Name: HEAD $
+// GEANT4 tag $Name:  $
 //
 //  
Index: trunk/source/geometry/magneticfield/test/field02/field02.cc
===================================================================
--- trunk/source/geometry/magneticfield/test/field02/field02.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/test/field02/field02.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: field02.cc,v 1.2 2006/06/29 18:27:02 gunter Exp $
-// GEANT4 tag $Name: HEAD $
+// GEANT4 tag $Name:  $
 //
 // 
Index: trunk/source/geometry/magneticfield/test/field03/field03.cc
===================================================================
--- trunk/source/geometry/magneticfield/test/field03/field03.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/test/field03/field03.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: field03.cc,v 1.2 2006/06/29 18:28:57 gunter Exp $
-// GEANT4 tag $Name: HEAD $
+// GEANT4 tag $Name:  $
 //
 // 
Index: trunk/source/geometry/magneticfield/test/field06/exampleS5.cc
===================================================================
--- trunk/source/geometry/magneticfield/test/field06/exampleS5.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/test/field06/exampleS5.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: exampleS5.cc,v 1.2 2007/05/02 14:59:26 gunter Exp $
-// GEANT4 tag $Name: HEAD $
+// GEANT4 tag $Name:  $
 //
 // 
Index: trunk/source/geometry/magneticfield/test/testProElectroMagField.cc
===================================================================
--- trunk/source/geometry/magneticfield/test/testProElectroMagField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/test/testProElectroMagField.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: testProElectroMagField.cc,v 1.16 2006/06/29 18:25:00 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //  
Index: trunk/source/geometry/magneticfield/test/testProPerpSpin.cc
===================================================================
--- trunk/source/geometry/magneticfield/test/testProPerpSpin.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/test/testProPerpSpin.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: testProPerpSpin.cc,v 1.17 2006/06/29 18:25:02 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //  
Index: trunk/source/geometry/magneticfield/test/testPropagateMagField.cc
===================================================================
--- trunk/source/geometry/magneticfield/test/testPropagateMagField.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/test/testPropagateMagField.cc	(revision 1231)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: testPropagateMagField.cc,v 1.32 2007/07/06 14:16:47 japost Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// $Id: testPropagateMagField.cc,v 1.33 2009/11/05 13:18:05 japost Exp $
+// GEANT4 tag $Name:  $
 //
 //  
@@ -53,6 +53,4 @@
 #include "G4RotationMatrix.hh"
 #include "G4ThreeVector.hh"
-
-#include "G4UniformMagField.hh"
 
 #include "G4ios.hh"
@@ -222,4 +220,8 @@
     return worldPhys;
 }
+
+#include "G4UniformMagField.hh"
+#include "G4QuadrupoleMagField.hh"
+#include "G4CachedMagneticField.hh"
 
 #include "G4ChordFinder.hh"
@@ -240,8 +242,11 @@
 #include "G4CashKarpRKF45.hh"
 #include "G4RKG3_Stepper.hh"
+#include "G4ConstRK4.hh"
+#include "G4NystromRK4.hh"
 #include "G4HelixMixedStepper.hh"
 
-G4UniformMagField myMagField(10.*tesla, 0., 0.); 
-
+G4UniformMagField      uniformMagField(10.*tesla, 0., 0.); 
+G4QuadrupoleMagField   quadrupoleMagField( 10.*tesla/(50.*cm) ); 
+G4CachedMagneticField  myMagField( &quadrupoleMagField, 1.0 * cm); 
 
 G4FieldManager* SetupField(G4int type)
@@ -266,4 +271,6 @@
       case 10: pStepper = new G4RKG3_Stepper( fEquation );       break;
       case 11: pStepper = new G4HelixMixedStepper( fEquation );  break;
+      case 12: pStepper = new G4ConstRK4( fEquation ); break;
+      case 13: pStepper = new G4NystromRK4( fEquation ); break; 
       default: 
         pStepper = 0;
@@ -448,4 +455,7 @@
 	  physStep *= 2.; 
        } // ...........................  end for ( istep )
+
+       myMagField.ReportStatistics(); 
+
     }    // ..............................  end for ( iparticle )
 
Index: trunk/source/geometry/magneticfield/test/testPropagateSpin.cc
===================================================================
--- trunk/source/geometry/magneticfield/test/testPropagateSpin.cc	(revision 1228)
+++ trunk/source/geometry/magneticfield/test/testPropagateSpin.cc	(revision 1231)
@@ -26,5 +26,5 @@
 //
 // $Id: testPropagateSpin.cc,v 1.17 2006/06/29 18:25:06 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// GEANT4 tag $Name:  $
 //
 //  
