Index: /trunk/source/error_propagation/GNUmakefile
===================================================================
--- /trunk/source/error_propagation/GNUmakefile	(revision 815)
+++ /trunk/source/error_propagation/GNUmakefile	(revision 815)
@@ -0,0 +1,57 @@
+# $Id: GNUmakefile,v 1.6 2007/06/05 13:37:36 gcosmo Exp $
+# ----------------------------------------------------------
+# GNUmakefile for tracking library.  Katsuya Amako, 5/9/95.
+# ----------------------------------------------------------
+
+name := G4error_propagation
+
+ifndef G4INSTALL
+  G4INSTALL = ../..
+endif
+
+GLOBLIBS  = libG4run.lib libG4event.lib
+GLOBLIBS += libG4tracking.lib libG4processes.lib libG4digits_hits.lib
+GLOBLIBS += libG4track.lib libG4particles.lib libG4geometry.lib
+GLOBLIBS += libG4materials.lib libG4graphics_reps.lib
+GLOBLIBS += libG4intercoms.lib libG4global.lib
+
+include $(G4INSTALL)/config/architecture.gmk
+
+CPPFLAGS += -I$(G4BASE)/global/management/include \
+            -I$(G4BASE)/global/HEPRandom/include \
+            -I$(G4BASE)/global/HEPGeometry/include \
+            -I$(G4BASE)/geometry/management/include \
+            -I$(G4BASE)/geometry/volumes/include \
+            -I$(G4BASE)/geometry/solids/CSG/include \
+            -I$(G4BASE)/geometry/navigation/include \
+            -I$(G4BASE)/track/include \
+            -I$(G4BASE)/materials/include \
+            -I$(G4BASE)/geometry/magneticfield/include \
+            -I$(G4BASE)/tracking/include \
+            -I$(G4BASE)/event/include \
+            -I$(G4BASE)/run/include \
+            -I$(G4BASE)/particles/management/include \
+            -I$(G4BASE)/particles/bosons/include \
+            -I$(G4BASE)/particles/leptons/include \
+            -I$(G4BASE)/particles/hadrons/mesons/include \
+            -I$(G4BASE)/particles/hadrons/barions/include \
+            -I$(G4BASE)/particles/hadrons/ions/include \
+            -I$(G4BASE)/processes/management/include \
+            -I$(G4BASE)/processes/electromagnetic/utils/include \
+            -I$(G4BASE)/processes/electromagnetic/standard/include \
+            -I$(G4BASE)/processes/electromagnetic/muons/include \
+            -I$(G4BASE)/processes/transportation/include \
+            -I$(G4BASE)/processes/cuts/include \
+            -I$(G4BASE)/intercoms/include \
+            -I$(G4BASE)/digits_hits/hits/include \
+            -I$(G4BASE)/digits_hits/digits/include 
+
+ifdef G4EVERBOSE
+  CPPFLAGS += -DG4EVERBOSE
+endif
+
+include $(G4INSTALL)/config/common.gmk
+
+.PHONY: global
+
+global: lib
Index: /trunk/source/error_propagation/History
===================================================================
--- /trunk/source/error_propagation/History	(revision 815)
+++ /trunk/source/error_propagation/History	(revision 815)
@@ -0,0 +1,60 @@
+$Id: History,v 1.13 2007/11/14 17:03:06 gcosmo Exp $
+-------------------------------------------------------------------
+
+     =========================================================
+     Geant4 - an Object-Oriented Toolkit for Simulation in HEP
+     =========================================================
+
+                      Category History file
+                      ---------------------
+This file should be used by G4 developers and category coordinators
+to briefly summarize all major modifications introduced in the code
+and keep track of all category-tags.
+It DOES NOT substitute the  CVS log-message one should put at every
+committal in the CVS repository !
+
+     ----------------------------------------------------------
+     * Reverse chronological order (last date on top), please *
+     ----------------------------------------------------------
+
+14 November 2007 - G.Cosmo (error_propagation-V09-00-02)
+- G4ErrorPropagator: removed call to exit() and some cleanup.
+
+24 September 2007 - P.Arce (error_propagation-V09-00-01)
+- G4ErrorFreeTrajState: corrected bug in one of the transformation matrix
+  terms. Addresses problem report #971.
+- G4ErrorFreeTrajParam: corrected normalization of Y and Z coordinates.
+
+5 June 2007 - G.Cosmo (error_propagation-V08-03-09)
+- Added missing definition of GLOBLIBS in GNUmakefile to allow for
+  building DLLs on Windows.
+
+4 June 2007 - G.Cosmo (error_propagation-V08-03-08)
+- Fixed compilation errors and warnings on WIN32-VC platform: replaced
+  usage of M_PI with CLHEP::pi; replaced usage of 'uint' with 'size_t';
+  fixed boolean operation in conditional statement.
+
+1 June 2007 - G.Cosmo (error_propagation-V08-03-07)
+- Some cleanup and further simplification of matrices classes.
+
+31 May 2007 - P.Arce (error_propagation-V08-03-06)
+- Using G4ErrorMatrix instead of CLHEP Matrix.
+
+31 May 2007 - G.Cosmo (error_propagation-V08-03-05)
+- Fixed compilation problems on Windows/VC++.
+- Use G4bool for bool and CLHEP::pi for M_PI.
+
+31 May 2007 - P.Arce (error_propagation-V08-03-04)
+- Fixed problem of uninitialised variables.
+
+29 May 2007 - G.Cosmo (error_propagation-V08-03-03)
+- Fixed errors for unnecessary inclusion of non-existing headers.
+- Use G4GeometryTolerance for retrivial of kCarTolerance.
+- Fixed GNUmakefile for setting of debug verbosity.
+- Added CVS headers and some cleanup ...
+
+25 May 2007 - P.Arce (error_propagation-V08-03-00, 01, 02)
+- First version.
+
+12 May 2007 - G.Cosmo
+- Directory structure created.
Index: /trunk/source/error_propagation/include/G4ErrorFreeTrajParam.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorFreeTrajParam.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorFreeTrajParam.hh	(revision 815)
@@ -0,0 +1,88 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorFreeTrajParam.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// Class Description:
+//
+// Holds the 5 independent variables of the trajectory for a
+// G4ErrorFreeTrajState object. It is not used for anything but for
+// printing, but anyhow it is updated everytime the position and
+// momentum are updated.
+
+// History:
+// - Created: Pedro Arce, September 2004
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorFreeTrajParam_hh
+#define G4ErrorFreeTrajParam_hh
+
+#include "G4Point3D.hh"
+#include "G4Vector3D.hh"
+
+#include "globals.hh"
+#include "G4Track.hh"
+
+class G4ErrorFreeTrajParam
+{
+ public:  // with description
+
+  G4ErrorFreeTrajParam(){}
+  G4ErrorFreeTrajParam( const G4Point3D& pos, const G4Vector3D& mom );
+    // build parameters from position and momentum
+
+  virtual ~G4ErrorFreeTrajParam(){}
+
+  void Update( const G4Track* aTrack );
+    // update parameters from G4Track
+
+  friend
+    std::ostream& operator<<(std::ostream&, const G4ErrorFreeTrajParam& ts);
+  
+  // Set and Get methods 
+
+  void SetParameters( const G4Point3D& pos, const G4Vector3D& mom );
+
+  G4Vector3D GetDirection() const { return fDir;}
+
+  G4double GetInvP() const { return fInvP; }
+  G4double GetLambda() const { return fLambda; }
+  G4double GetPhi() const { return fPhi; }
+  G4double GetYPerp() const { return fYPerp; }
+  G4double GetZPerp() const { return fZPerp; }
+
+ private:
+
+  G4Vector3D fDir; //direction to which YPerp, ZPerp refer
+  G4double fInvP; // inverse of momentum
+  G4double fLambda; // 90 - theta angle of direction
+  G4double fPhi; // phi angle of direction
+  G4double fYPerp; // Y coordinate
+  G4double fZPerp; // Z coordinate
+};
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorFreeTrajState.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorFreeTrajState.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorFreeTrajState.hh	(revision 815)
@@ -0,0 +1,136 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorFreeTrajState.hh,v 1.4 2007/05/31 20:27:06 arce Exp $
+// GEANT4 tag $Name:  $
+//
+// Class Description:
+//
+// Represents a free G4ErrorTrajState
+// It can be represented by the 5 variables
+//     1/p, lambda, phi, y_perp, z_perp
+// where lambda and phi are the dip and azimuthal angles related
+// to the momentum components in the following way:
+//            p_x = p cos(lambda) cos(phi)  ! lambda = 90 - theta
+//            p_y = p cos(lambda) sin(phi)
+//            p_z = p sin(lambda)
+// y_perp and z_perp are the coordinates of the trajectory in a
+// local orthonormal reference frame with the x_perp axis along the
+// particle direction, the y_perp being parallel to the x-y plane.
+//
+// This class also takes care of propagating the error associated to 
+// the trajectory 
+
+// History:
+// - Created:   P. Arce
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorFreeTrajState_hh
+#define G4ErrorFreeTrajState_hh
+
+#include "globals.hh"
+
+#include "G4ErrorMatrix.hh"
+
+#include "G4ErrorTrajState.hh"
+#include "G4ErrorFreeTrajParam.hh"
+
+#include "G4Point3D.hh"
+#include "G4Vector3D.hh"
+
+class G4ErrorSurfaceTrajState;
+
+class G4ErrorFreeTrajState : public G4ErrorTrajState
+{
+ public:  // with description
+
+  G4ErrorFreeTrajState(){}
+  G4ErrorFreeTrajState( const G4String& partType,
+                        const G4Point3D& pos,
+                        const G4Vector3D& mom,
+                        const G4ErrorTrajErr& errmat = G4ErrorTrajErr(5,0) );
+    // Constructor by providing particle, position and momentum
+
+  G4ErrorFreeTrajState( const G4ErrorSurfaceTrajState& tpOS );
+    // Constructor by providing G4ErrorSurfaceTrajState
+
+  ~G4ErrorFreeTrajState(){}
+
+  virtual G4int Update( const G4Track* aTrack );
+    // update parameters from G4Track
+
+  virtual G4int PropagateError( const G4Track* aTrack );
+    // propagate the error along the step
+
+  virtual void Dump( std::ostream& out = G4cout ) const;
+    // dump TrajState parameters
+
+  friend
+    std::ostream& operator<<(std::ostream&, const G4ErrorFreeTrajState& ts);
+
+  // Set and Get methods 
+
+  virtual void SetPosition( const G4Point3D pos )
+    { SetParameters( pos, fMomentum ); }
+
+  virtual void SetMomentum( const G4Vector3D& mom )
+    { SetParameters( fPosition, mom ); }
+
+  void SetParameters( const G4Point3D& pos, const G4Vector3D& mom )
+    {
+      fPosition = pos;
+      fMomentum = mom;
+      fTrajParam.SetParameters( pos, mom );
+    }
+
+  G4ErrorFreeTrajParam GetParameters() const
+    { return fTrajParam; }
+
+ private:  
+
+  void Init();
+    // define TrajState type and build charge
+
+  G4int PropagateErrorMSC( const G4Track* aTrack );
+    // add the error associated to multiple scattering
+
+  void CalculateEffectiveZandA( const G4Material* mate, double& effZ, double& effA );
+    // calculate effective Z and A (needed by PropagateErrorMSC)
+  
+  G4int PropagateErrorIoni( const G4Track* aTrack );
+    // add the error associated to ionization energy loss
+
+
+ private:
+
+  G4ErrorFreeTrajParam fTrajParam;
+
+  G4ErrorMatrix theTransfMat;
+
+  G4bool theFirstStep; // to count if transf mat is updated or initialized
+};
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorGeomVolumeTarget.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorGeomVolumeTarget.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorGeomVolumeTarget.hh	(revision 815)
@@ -0,0 +1,66 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorGeomVolumeTarget.hh,v 1.3 2007/05/31 15:28:51 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// Class Description:
+//
+// G4ErrorTarget class: limits step when volume is reached.
+
+// History:
+// - Created:  P. Arce, September 2004
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorGeomVolumeTarget_HH
+#define G4ErrorGeomVolumeTarget_HH
+
+#include "globals.hh"
+#include "G4ThreeVector.hh"
+#include "G4ErrorTarget.hh"
+#include "G4Plane3D.hh"
+  
+class G4Step;
+class G4String;
+
+class G4ErrorGeomVolumeTarget : public G4ErrorTarget
+{
+ public:  // with description
+
+  G4ErrorGeomVolumeTarget( const G4String& name );
+  virtual ~G4ErrorGeomVolumeTarget(){}
+
+  virtual G4bool TargetReached(const G4Step* aStep);
+    // return true when particle is entering the volume
+
+  virtual void Dump( const G4String& msg ) const;
+
+ private:
+
+  G4String  theName;
+};
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorMagFieldLimitProcess.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorMagFieldLimitProcess.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorMagFieldLimitProcess.hh	(revision 815)
@@ -0,0 +1,72 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorMagFieldLimitProcess.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// Class description:
+//
+// Limits the step length if change of magnetic field is too big
+// (user defined limit).
+
+// History:
+// - Created:   P. Arce, September 2004
+//---------------------------------------------------------------------
+
+#ifndef G4ErrorMagFieldLimitProcess_h
+#define G4ErrorMagFieldLimitProcess_h 1
+
+#include "G4ios.hh" 
+#include "globals.hh"
+#include "G4VDiscreteProcess.hh"
+#include "G4PhysicsTable.hh"
+#include "G4PhysicsLogVector.hh"
+#include "G4ElementTable.hh"
+#include "G4Gamma.hh" 
+#include "G4Electron.hh"
+#include "G4Step.hh" 
+#include "G4VErrorLimitProcess.hh"
+
+//-----------------------------------------------------------------
+ 
+class G4ErrorMagFieldLimitProcess : public G4VErrorLimitProcess
+{
+
+ public:  // with description
+  
+  G4ErrorMagFieldLimitProcess(const G4String& processName
+                                  ="G4ErrorMagFieldLimit");
+  ~G4ErrorMagFieldLimitProcess();
+  
+  virtual G4double
+     PostStepGetPhysicalInteractionLength(const G4Track& track,
+                                                G4double previousStepSize,
+                                                G4ForceCondition* condition);
+    // Returns the step length.
+};
+  
+#endif
+ 
Index: /trunk/source/error_propagation/include/G4ErrorMatrix.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorMatrix.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorMatrix.hh	(revision 815)
@@ -0,0 +1,315 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorMatrix.hh,v 1.2 2007/06/01 12:43:28 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// Class Description:
+//
+// Simplified version of CLHEP HepMatrix class
+
+// History:
+// - Imported from CLHEP and modified:   P. Arce    May 2007
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorMatrix_hh
+#define G4ErrorMatrix_hh
+
+#include <vector>
+
+class G4ErrorSymMatrix;
+
+typedef std::vector<G4double >::iterator G4ErrorMatrixIter;
+typedef std::vector<G4double >::const_iterator G4ErrorMatrixConstIter;
+
+class G4ErrorMatrix
+{
+
+ public:  // with description
+
+   G4ErrorMatrix();
+   // Default constructor. Gives 0 x 0 matrix.
+   // Another G4ErrorMatrix can be assigned to it.
+
+   G4ErrorMatrix(G4int p, G4int q);
+   // Constructor. Gives an unitialized p x q matrix.
+
+   G4ErrorMatrix(G4int p, G4int q, G4int i);
+   // Constructor. Gives an initialized p x q matrix. 
+   // If i=0, it is initialized to all 0. If i=1, the diagonal elements
+   // are set to 1.0.
+
+   G4ErrorMatrix(const G4ErrorMatrix &m1);
+   // Copy constructor.
+
+   G4ErrorMatrix(const G4ErrorSymMatrix &m1);
+   // Constructors from G4ErrorSymG4ErrorMatrix, DiagG4ErrorMatrix and Vector.
+
+   virtual ~G4ErrorMatrix();
+   // Destructor.
+
+   inline virtual G4int num_row() const;
+   // Returns the number of rows.
+
+   inline virtual G4int num_col() const;
+   // Returns the number of columns.
+
+   inline virtual const G4double & operator()(G4int row, G4int col) const;
+   inline virtual G4double & operator()(G4int row, G4int col);
+   // Read or write a matrix element. 
+   // ** Note that the indexing starts from (1,1). **
+
+   G4ErrorMatrix & operator *= (G4double t);
+   // Multiply a G4ErrorMatrix by a floating number.
+
+   G4ErrorMatrix & operator /= (G4double t); 
+   // Divide a G4ErrorMatrix by a floating number.
+
+   G4ErrorMatrix & operator += ( const G4ErrorMatrix &m2);
+   G4ErrorMatrix & operator += ( const G4ErrorSymMatrix &m2);
+   G4ErrorMatrix & operator -= ( const G4ErrorMatrix &m2);
+   G4ErrorMatrix & operator -= ( const G4ErrorSymMatrix &m2);
+   // Add or subtract a G4ErrorMatrix. 
+   // When adding/subtracting Vector, G4ErrorMatrix must have num_col of one.
+
+   G4ErrorMatrix & operator = ( const G4ErrorMatrix &m2);
+   G4ErrorMatrix & operator = ( const G4ErrorSymMatrix &m2);
+   // Assignment operators.
+
+   G4ErrorMatrix operator- () const;
+   // unary minus, ie. flip the sign of each element.
+
+   G4ErrorMatrix apply(G4double (*f)(G4double, G4int, G4int)) const;
+   // Apply a function to all elements of the matrix.
+
+   G4ErrorMatrix T() const;
+   // Returns the transpose of a G4ErrorMatrix.
+
+   G4ErrorMatrix sub(G4int min_row, G4int max_row,
+                     G4int min_col, G4int max_col) const;
+   // Returns a sub matrix of a G4ErrorMatrix.
+   // WARNING: rows and columns are numbered from 1
+
+   void sub(G4int row, G4int col, const G4ErrorMatrix &m1);
+   // Sub matrix of this G4ErrorMatrix is replaced with m1.
+   // WARNING: rows and columns are numbered from 1
+
+   inline G4ErrorMatrix inverse(G4int& ierr) const;
+   // Invert a G4ErrorMatrix. G4ErrorMatrix must be square and is not changed.
+   // Returns ierr = 0 (zero) when successful, otherwise non-zero.
+
+   virtual void invert(G4int& ierr);
+   // Invert a G4ErrorMatrix. G4ErrorMatrix must be square.
+   // N.B. the contents of the matrix are replaced by the inverse.
+   // Returns ierr = 0 (zero) when successful, otherwise non-zero. 
+   // This method has less overhead then inverse().
+
+   G4double determinant() const;
+   // calculate the determinant of the matrix.
+
+   G4double trace() const;
+   // calculate the trace of the matrix (sum of diagonal elements).
+
+   class G4ErrorMatrix_row
+   {
+     typedef std::vector<G4double >::const_iterator G4ErrorMatrixConstIter;
+     public:
+       inline G4ErrorMatrix_row(G4ErrorMatrix&,G4int);
+       G4double & operator[](G4int);
+     private:
+       G4ErrorMatrix& _a;
+       G4int _r;
+   };
+   class G4ErrorMatrix_row_const
+   {
+     public:
+       inline G4ErrorMatrix_row_const (const G4ErrorMatrix&,G4int);
+       const G4double & operator[](G4int) const;
+     private:
+       const G4ErrorMatrix& _a;
+       G4int _r;
+   };
+   // helper classes for implementing m[i][j]
+
+   inline G4ErrorMatrix_row operator[] (G4int);
+   inline const G4ErrorMatrix_row_const operator[] (G4int) const;
+   // Read or write a matrix element.
+   // While it may not look like it, you simply do m[i][j] to get an element. 
+   // ** Note that the indexing starts from [0][0]. **
+
+ protected:
+
+   virtual inline G4int num_size() const;
+   virtual void invertHaywood4(G4int& ierr);
+   virtual void invertHaywood5(G4int& ierr);
+   virtual void invertHaywood6(G4int& ierr);
+
+ public:
+
+   static void error(const char *s);
+
+ private:
+
+   friend class G4ErrorMatrix_row;
+   friend class G4ErrorMatrix_row_const;
+   friend class G4ErrorSymMatrix;
+   // Friend classes.
+
+   friend G4ErrorMatrix operator+(const G4ErrorMatrix &m1,
+                                  const G4ErrorMatrix &m2);
+   friend G4ErrorMatrix operator-(const G4ErrorMatrix &m1,
+                                  const G4ErrorMatrix &m2);
+   friend G4ErrorMatrix operator*(const G4ErrorMatrix &m1,
+                                  const G4ErrorMatrix &m2);
+   friend G4ErrorMatrix operator*(const G4ErrorMatrix &m1,
+                                  const G4ErrorSymMatrix &m2);
+   friend G4ErrorMatrix operator*(const G4ErrorSymMatrix &m1,
+                                  const G4ErrorMatrix &m2);
+   friend G4ErrorMatrix operator*(const G4ErrorSymMatrix &m1,
+                                  const G4ErrorSymMatrix &m2);
+   // Multiply a G4ErrorMatrix by a G4ErrorMatrix or Vector.
+
+   // solve the system of linear eq
+
+   friend G4ErrorMatrix qr_solve(G4ErrorMatrix *, const G4ErrorMatrix &b);
+   friend void tridiagonal(G4ErrorSymMatrix *a,G4ErrorMatrix *hsm);
+   friend void row_house(G4ErrorMatrix *,const G4ErrorMatrix &, G4double,
+                         G4int, G4int, G4int, G4int);
+   friend void back_solve(const G4ErrorMatrix &R, G4ErrorMatrix *b);
+   friend void col_givens(G4ErrorMatrix *A, G4double c,
+                          G4double s, G4int k1, G4int k2, 
+                          G4int rowmin, G4int rowmax);
+   // Does a column Givens update.
+
+   friend void row_givens(G4ErrorMatrix *A, G4double c,
+                          G4double s, G4int k1, G4int k2, 
+                          G4int colmin, G4int colmax);
+   friend void col_house(G4ErrorMatrix *,const G4ErrorMatrix &, G4double,
+                         G4int, G4int, G4int, G4int);
+   friend void house_with_update(G4ErrorMatrix *a,G4int row,G4int col);
+   friend void house_with_update(G4ErrorMatrix *a,G4ErrorMatrix *v,
+                                 G4int row, G4int col);
+   friend void house_with_update2(G4ErrorSymMatrix *a,G4ErrorMatrix *v,
+                                  G4int row, G4int col); 
+
+   G4int dfact_matrix(G4double &det, G4int *ir);
+   // factorize the matrix. If successful, the return code is 0. On
+   // return, det is the determinant and ir[] is row-interchange
+   // matrix. See CERNLIB's DFACT routine.
+
+   G4int dfinv_matrix(G4int *ir);
+   // invert the matrix. See CERNLIB DFINV.
+
+   std::vector<G4double > m;
+
+   G4int nrow, ncol;
+   G4int size;
+};
+
+// Operations other than member functions for G4ErrorMatrix
+
+G4ErrorMatrix operator*(const G4ErrorMatrix &m1, const G4ErrorMatrix &m2);
+G4ErrorMatrix operator*(G4double t, const G4ErrorMatrix &m1);
+G4ErrorMatrix operator*(const G4ErrorMatrix &m1, G4double t);
+// Multiplication operators
+// Note that m *= m1 is always faster than m = m * m1.
+
+G4ErrorMatrix operator/(const G4ErrorMatrix &m1, G4double t);
+// m = m1 / t. (m /= t is faster if you can use it.)
+
+G4ErrorMatrix operator+(const G4ErrorMatrix &m1, const G4ErrorMatrix &m2);
+// m = m1 + m2;
+// Note that m += m1 is always faster than m = m + m1.
+
+G4ErrorMatrix operator-(const G4ErrorMatrix &m1, const G4ErrorMatrix &m2);
+// m = m1 - m2;
+// Note that m -= m1 is always faster than m = m - m1.
+
+G4ErrorMatrix dsum(const G4ErrorMatrix&, const G4ErrorMatrix&);
+// Direct sum of two matrices. The direct sum of A and B is the matrix 
+//        A 0
+//        0 B
+
+std::ostream& operator<<(std::ostream &s, const G4ErrorMatrix &q);
+// Read in, write out G4ErrorMatrix into a stream.
+ 
+//
+// Specialized linear algebra functions
+//
+
+G4ErrorMatrix qr_solve(const G4ErrorMatrix &A, const G4ErrorMatrix &b);
+G4ErrorMatrix qr_solve(G4ErrorMatrix *A, const G4ErrorMatrix &b);
+// Works like backsolve, except matrix does not need to be upper
+// triangular. For nonsquare matrix, it solves in the least square sense.
+
+G4ErrorMatrix qr_inverse(const G4ErrorMatrix &A);
+G4ErrorMatrix qr_inverse(G4ErrorMatrix *A);
+// Finds the inverse of a matrix using QR decomposition.  Note, often what
+// you really want is solve or backsolve, they can be much quicker than
+// inverse in many calculations.
+
+
+void qr_decomp(G4ErrorMatrix *A, G4ErrorMatrix *hsm);
+G4ErrorMatrix qr_decomp(G4ErrorMatrix *A);
+// Does a QR decomposition of a matrix.
+
+void back_solve(const G4ErrorMatrix &R, G4ErrorMatrix *b);
+// Solves R*x = b where R is upper triangular.  Also has a variation that
+// solves a number of equations of this form in one step, where b is a matrix
+// with each column a different vector. See also solve.
+
+void col_house(G4ErrorMatrix *a, const G4ErrorMatrix &v, G4double vnormsq,
+               G4int row, G4int col, G4int row_start, G4int col_start);
+void col_house(G4ErrorMatrix *a, const G4ErrorMatrix &v, G4int row, G4int col,
+               G4int row_start, G4int col_start);
+// Does a column Householder update.
+
+void col_givens(G4ErrorMatrix *A, G4double c, G4double s,
+                G4int k1, G4int k2, G4int row_min=1, G4int row_max=0);
+// do a column Givens update
+
+void row_givens(G4ErrorMatrix *A, G4double c, G4double s,
+                G4int k1, G4int k2, G4int col_min=1, G4int col_max=0);
+// do a row Givens update
+
+void givens(G4double a, G4double b, G4double *c, G4double *s);
+// algorithm 5.1.5 in Golub and Van Loan
+
+// Returns a Householder vector to zero elements.
+
+void house_with_update(G4ErrorMatrix *a, G4int row=1, G4int col=1);
+void house_with_update(G4ErrorMatrix *a, G4ErrorMatrix *v,
+                       G4int row=1, G4int col=1);
+// Finds and does Householder reflection on matrix.
+
+void row_house(G4ErrorMatrix *a, const G4ErrorMatrix &v, G4double vnormsq,
+               G4int row, G4int col, G4int row_start, G4int col_start);
+void row_house(G4ErrorMatrix *a, const G4ErrorMatrix &v, G4int row, G4int col,
+               G4int row_start, G4int col_start);
+// Does a row Householder update.
+
+#include "G4ErrorMatrix.icc"
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorMatrix.icc
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorMatrix.icc	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorMatrix.icc	(revision 815)
@@ -0,0 +1,106 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorMatrix.icc,v 1.2 2007/06/01 12:43:28 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class inline implementation
+// ------------------------------------------------------------
+
+inline G4ErrorMatrix::G4ErrorMatrix()
+  : m(0), nrow(0), ncol(0), size(0)
+{
+}
+
+inline G4int G4ErrorMatrix::num_row() const
+{
+  return nrow;
+}
+
+inline G4int G4ErrorMatrix::num_col() const
+{
+  return ncol;
+}
+
+inline G4int G4ErrorMatrix::num_size() const
+{
+  return size;
+}
+
+inline G4double & G4ErrorMatrix::operator()(G4int row, G4int col)
+{
+  return *(m.begin()+(row-1)*ncol+col-1);
+}
+
+inline const G4double & G4ErrorMatrix::operator()(G4int row, G4int col) const 
+{
+  return *(m.begin()+(row-1)*ncol+col-1);
+}
+
+inline G4ErrorMatrix::G4ErrorMatrix_row G4ErrorMatrix::operator[] (G4int r)
+{
+  G4ErrorMatrix_row b(*this,r);
+  return b;
+}
+
+inline const G4ErrorMatrix::G4ErrorMatrix_row_const
+G4ErrorMatrix::operator[] (G4int r) const
+{
+  G4ErrorMatrix_row_const b(*this,r);
+  return b;
+}
+
+inline G4double &G4ErrorMatrix::G4ErrorMatrix_row::operator[](G4int c)
+{
+  return *(_a.m.begin()+_r*_a.ncol+c);
+}
+
+inline const G4double &
+G4ErrorMatrix::G4ErrorMatrix_row_const::operator[](G4int c) const
+{
+  return *(_a.m.begin()+_r*_a.ncol+c);
+}
+
+inline G4ErrorMatrix::
+G4ErrorMatrix_row::G4ErrorMatrix_row(G4ErrorMatrix&a, G4int r)
+   : _a(a)
+{
+  _r = r;
+}
+
+inline G4ErrorMatrix::G4ErrorMatrix_row_const::G4ErrorMatrix_row_const 
+(const G4ErrorMatrix&a, G4int r) 
+   : _a(a) 
+{
+  _r = r;
+}
+
+inline G4ErrorMatrix G4ErrorMatrix::inverse(G4int &ierr) const
+{
+  G4ErrorMatrix mTmp(*this);
+  mTmp.invert(ierr);
+  return mTmp;
+}
Index: /trunk/source/error_propagation/include/G4ErrorMessenger.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorMessenger.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorMessenger.hh	(revision 815)
@@ -0,0 +1,79 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorMessenger.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// Class Description:
+//
+// Messenger class for Geant4e processes limiting the step.
+
+// History:
+// - Created:   P. Arce
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorMessenger_hh
+#define G4ErrorMessenger_hh
+
+#include "globals.hh"
+#include "G4UImessenger.hh"
+
+class G4UIdirectory;
+class G4UIcmdWithAString;
+class G4UIcmdWithADoubleAndUnit;
+class G4UIcmdWithADouble;
+class G4ErrorStepLengthLimitProcess;
+class G4ErrorMagFieldLimitProcess;
+class G4ErrorEnergyLoss;
+
+//-----------------------------------------------------------------
+
+class G4ErrorMessenger : public G4UImessenger
+{
+ public:  // with description
+
+  G4ErrorMessenger(G4ErrorStepLengthLimitProcess* lengthAct,
+                   G4ErrorMagFieldLimitProcess* magAct,
+                   G4ErrorEnergyLoss* elossAct);
+  ~G4ErrorMessenger();
+  
+  void SetNewValue(G4UIcommand*, G4String);
+
+ private:
+
+  G4ErrorStepLengthLimitProcess* StepLengthAction;
+  G4ErrorMagFieldLimitProcess* MagFieldAction;
+  G4ErrorEnergyLoss* EnergyLossAction;
+  
+  G4UIdirectory* myDir;
+  G4UIdirectory* myDirLimits;
+
+  G4UIcmdWithADoubleAndUnit* StepLengthLimitCmd;
+  G4UIcmdWithADouble* MagFieldLimitCmd;
+  G4UIcmdWithADouble* EnergyLossCmd;
+};
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorPhysicsList.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorPhysicsList.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorPhysicsList.hh	(revision 815)
@@ -0,0 +1,72 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorPhysicsList.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+//
+// Class Description:
+//
+//  Default physics list for GEANT4e (should not be overridden, unless by
+//  experts). No multiple scattering and no production of secondaries.
+//  The energy loss process is G4eMuIonisation or G4EnergyLossForExtrapolator
+//  (depending on the value of the enviromental variable G4EELOSSEXTRAP)
+//  It also defines the geant4e processes to limit the step:
+//  G4eMagneticFieldLimitProcess, G4eStepLimitProcess.
+
+// History:
+// - Created:   P. Arce
+// ---------------------------------------------------------------------
+
+#ifndef G4ErrorPhysicsList_hh
+#define G4ErrorPhysicsList_hh
+
+#include "globals.hh"
+#include "G4VUserPhysicsList.hh"
+
+class G4ErrorPhysicsList: public G4VUserPhysicsList
+{
+ public:  // with description
+
+  G4ErrorPhysicsList();
+  virtual ~G4ErrorPhysicsList();
+  
+ protected:
+
+  virtual void ConstructParticle();
+    // constructs gamma, e+/-, mu+/- and stable hadrons
+
+  virtual void ConstructProcess();
+    // construct physical processes
+
+  virtual void SetCuts();  
+    // SetCutsWithDefault
+
+  virtual void ConstructEM();
+    // constructs electromagnetic processes
+};
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorPropagator.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorPropagator.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorPropagator.hh	(revision 815)
@@ -0,0 +1,136 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorPropagator.hh,v 1.3 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+//
+// Class Description:
+//
+//  Manages the propagation of tracks. Creates a G4Track, asks to
+//  propagate it and takes also care to propagate the errors.
+//  Stops the track when GEANT4 stops it or a G4ErrorTarget is reached.
+
+// History:
+// - Created:   P. Arce
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorPropagator_hh
+#define G4ErrorPropagator_hh
+
+#include "globals.hh"
+#include "G4ErrorPropagatorData.hh"
+#include "G4SteppingManager.hh"
+
+class G4eErrorMatrix;
+class G4Track;
+class G4ErrorTrajState;
+class G4ErrorFreeTrajState;
+class G4ErrorTarget;
+#include "globals.hh"
+
+class G4ErrorPropagator 
+{
+ public:  // with description
+
+  G4ErrorPropagator();
+  ~G4ErrorPropagator(){}
+
+  G4Track* InitG4Track( G4ErrorTrajState& initialTS );
+    // Creates a G4Track from a G4ErrorTrajState
+
+  G4int Propagate( G4ErrorTrajState* currentTS,
+                   const G4ErrorTarget* target,
+                   G4ErrorMode mode = G4ErrorMode_PropForwards);
+    // Steers the GEANT4 propagation of a track:
+    // the particle will be extrapolated until the Target is reached.
+    // The final G4Track parameters will be passed to theFinalTrajState
+
+  G4int PropagateOneStep( G4ErrorTrajState* currentTS );
+    // Propagates a G4Track by one step, and then returns control to the user
+
+  G4int MakeOneStep( G4ErrorFreeTrajState* currentTS_FREE );
+    // Advance one step
+
+  G4ErrorFreeTrajState* InitFreeTrajState( G4ErrorTrajState* currentTS );
+    // Creates theCurrentTS_FREE (transforms the user G4ErrorSurfaceTrajState
+    // or copies the G4ErrorFreeTrajState)
+
+  void GetFinalTrajState( G4ErrorTrajState* currentTS, G4ErrorFreeTrajState* currentTS_FREE, const G4ErrorTarget* target );
+    // After steps are done, convert the G4ErrorFreeTrajState used for error
+    // propagation to the class of origin (G4ErrorFreeTrajState or
+    // G4eTrajStatOnSurface)
+
+  void InvokePreUserTrackingAction( G4Track* fpTrack );
+    // Invoke the G4UserTrackingAction::PreUserTrackingAction
+  void InvokePostUserTrackingAction( G4Track* fpTrack );
+    // Invoke the G4UserTrackingAction::PostUserTrackingAction
+
+  G4bool CheckIfLastStep( G4Track* aTrack );
+    // Check if it is the last step for error propagation:
+    //  - G4ErrorState is G4ErrorState_StoppedAtTarget
+    //  - Track is OutOfWorld
+    //  - G4TrackStatus is fStopAndKill
+
+  // Get and Set methods 
+
+  const G4ErrorTrajState* GetInitialTrajState() const
+    { return theInitialTrajState; }
+
+  G4double GetStepLength() const
+    { return theStepLength; }
+
+  void SetStepLength( const G4double sl )
+    { theStepLength = sl; }
+
+  void SetStepN( const G4int sn )
+    { theStepN = sn; }
+
+ private:
+
+  G4int MakeSteps( G4ErrorFreeTrajState* currentTS_FREE );
+    // Advance steps until target is reached
+
+ private:
+
+  G4double theStepLength;
+
+  G4ErrorTrajState* theInitialTrajState;
+  G4ErrorTrajState* theFinalTrajState;
+
+  G4int theStepN;
+
+  G4Track* theG4Track;
+
+  G4SteppingManager* fpSteppingManager;
+
+  G4int verbose;
+
+  G4bool thePropIsInitialized;
+
+};
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorPropagatorManager.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorPropagatorManager.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorPropagatorManager.hh	(revision 815)
@@ -0,0 +1,163 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorPropagatorManager.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// Class Description:
+//
+// This is the class manager of the GEANT4e package.
+// It is the main interface for the user to define the setup and
+// start the propagation. Initializes GEANT4 for the propagation.
+
+// History:
+// - Created:   Pedro Arce, February 2001
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorPropagatorManager_hh
+#define G4ErrorPropagatorManager_hh
+
+#include "globals.hh"
+#include "G4ErrorPropagatorData.hh"
+#include "G4ErrorPropagator.hh"
+#include "G4ApplicationState.hh"
+
+class G4ErrorPropagationNavigator;
+class G4ErrorRunManagerHelper;
+class G4ErrorTarget;
+class G4ErrorTrajState;
+
+class G4VUserDetectorConstruction;
+class G4VPhysicalVolume;
+class G4VUserPhysicsList;
+class G4UserRunAction;
+class G4UserEventAction;
+class G4UserStackingAction;
+class G4UserTrackingAction;
+class G4UserSteppingAction;
+class G4Mag_UsualEqRhs;
+class G4Track;
+
+class G4ErrorPropagatorManager
+{
+
+ public:  // with description
+
+  G4ErrorPropagatorManager();
+    // Initialise data to 0. Starts the G4ErrorRunManagerHelper and
+    // G4ErrorPropagationNavigator.
+
+  ~G4ErrorPropagatorManager();
+
+  static G4ErrorPropagatorManager* GetErrorPropagatorManager();
+    // Get only instance of G4ErrorPropagatorManager. If it does not exists,
+    // creates it
+
+  void EventTermination();
+    // Set state to G4ErrorState_Init
+
+  void RunTermination();
+    // Set state to G4ErrorState_Init and invoke
+    // G4ErrorRunManagerHelper::RunTermination()
+
+  void InitGeant4e();
+    // Initializes Geant4 and Geant4e
+
+  void InitTrackPropagation();
+    // Set the propagator step number to 0 and the G4ErrorState to Propagating
+ 
+  G4bool InitFieldForBackwards();
+    // Creates the G4ErrorMag_UsualEqRhs, that will control backwards tracking
+
+  G4int Propagate( G4ErrorTrajState* currentTS, const G4ErrorTarget* target, G4ErrorMode mode = G4ErrorMode_PropForwards );
+    // Inits track propagation, invokes G4ErrorPropagator::Propagate and
+    // terminates "event"
+
+  G4int PropagateOneStep( G4ErrorTrajState* currentTS,
+                          G4ErrorMode mode = G4ErrorMode_PropForwards );
+    // Invokes G4ErrorPropagator::PropagateOneStep
+
+  G4bool CloseGeometry();
+    // Close Geant4 geometry
+
+  void SetUserInitialization(G4VUserDetectorConstruction* userInit);
+    // Invokes G4ErrorRunManagerHelper to construct detector and set
+    // world volume
+  void SetUserInitialization(G4VPhysicalVolume* userInit);
+    // Invokes G4ErrorRunManagerHelper to  set world volume
+  void SetUserInitialization(G4VUserPhysicsList* userInit);
+    // Invokes G4ErrorRunManagerHelper to initialize physics
+
+  void SetUserAction(G4UserTrackingAction* userAction);
+    // Invokes G4EventManager to set a G4UserTrackingAction
+  void SetUserAction(G4UserSteppingAction* userAction);
+    // Invokes G4EventManager to set a G4UserSteppingAction
+
+  G4String PrintG4ErrorState();
+  G4String PrintG4ErrorState( G4ErrorState state );
+    // Print Geant4e state
+
+  G4String PrintG4State();
+  G4String PrintG4State( G4ApplicationState state );
+    // Print Geant4 state
+ 
+  // Set and Get methods 
+
+  G4ErrorRunManagerHelper* GetErrorRunManagerHelper() const
+    { return theG4ErrorRunManagerHelper; }
+
+  void SetSteppingManagerVerboseLevel();
+
+  G4ErrorPropagationNavigator* GetErrorPropagationNavigator() const
+    { return theG4ErrorPropagationNavigator; }
+
+  G4ErrorPropagator* GetPropagator() const
+    { return thePropagator; }
+
+ private:
+
+  void StartG4ErrorRunManagerHelper();
+    // Create a G4ErrorRunManagerHelper if it does not exist and set to it
+    // the G4ErrorPhysicsList
+ 
+  void StartNavigator();
+    // create a G4ErrorPropagationNavigator
+ 
+ private:
+
+  static G4ErrorPropagatorManager* theG4ErrorPropagatorManager;
+
+  G4ErrorRunManagerHelper* theG4ErrorRunManagerHelper;
+
+  G4ErrorPropagator* thePropagator;
+
+  G4Mag_UsualEqRhs* theEquationOfMotion;
+
+  G4ErrorPropagationNavigator* theG4ErrorPropagationNavigator;
+
+};
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorRunManagerHelper.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorRunManagerHelper.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorRunManagerHelper.hh	(revision 815)
@@ -0,0 +1,101 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorRunManagerHelper.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+//
+// Class Description:
+//
+// This class helps G4ErrorPropagatorManager with the initialization of 
+// geometry and physics, definition of actions and run termination
+// (things done by G4RunManager in an standard GEANT4 run)
+// It holds a pointer to G4RunManagerKernel
+
+// History:
+// - Created:  Pedro Arce, January 2005
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorRunManagerHelper_hh
+#define G4ErrorRunManagerHelper_hh
+
+class G4RunManagerKernel;
+class G4VUserDetectorConstruction;
+class G4VPhysicalVolume;
+class G4VUserPhysicsList;
+class G4UserTrackingAction;
+class G4UserSteppingAction;
+
+class G4ErrorRunManagerHelper 
+{
+
+ public:  // with description
+
+  G4ErrorRunManagerHelper();
+  virtual ~G4ErrorRunManagerHelper();
+
+  static G4ErrorRunManagerHelper* GetRunManagerKernel();
+    // Static method which returns the singleton pointer of
+    // G4ErrorRunManagerHelper 
+
+  void SetUserInitialization(G4VUserDetectorConstruction* userInit);
+    // Initialize geometry by passing a G4VUserDetectorConstruction
+  void SetUserInitialization(G4VPhysicalVolume* userInit);
+    // Initialize geometry by passing a G4VPhysicalVolume
+
+  void SetUserInitialization(G4VUserPhysicsList* userInit);
+    // Initializes physics
+
+  void SetUserAction(G4UserTrackingAction* userAction);
+    // Set the user tracking action
+  void SetUserAction(G4UserSteppingAction* userAction);
+    // Set the user stepping action
+
+  void RunInitialization();
+    // Invokes G4RunManagerKernel RunInitialization();
+
+  void InitializeGeometry();
+    // Initializes GEANT4 geometry
+  void InitializePhysics();
+    // Initializes GEANT4 physics
+
+  void RunTermination();
+    // Invokes G4RunManagerKernel RunTermination();
+
+  G4VUserPhysicsList* GetUserPhysicsList() const
+    { return theUserPhysicsList; }
+
+ private:
+
+  static G4ErrorRunManagerHelper* fRunManagerKernel;
+  
+  G4VUserPhysicsList* theUserPhysicsList;
+  G4VPhysicalVolume* theUserWorld;
+
+  G4RunManagerKernel* theG4RunManagerKernel;
+};
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorStepLengthLimitProcess.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorStepLengthLimitProcess.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorStepLengthLimitProcess.hh	(revision 815)
@@ -0,0 +1,72 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorStepLengthLimitProcess.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+//
+// Class Description:
+//
+// Limits the step length if change of direction due to magnetic field
+// is too big (user defined limit)
+
+// History:
+// - Created:   P. Arce, September 2004
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorStepLengthLimitProcess_hh
+#define G4ErrorStepLengthLimitProcess_hh
+
+#include "G4ios.hh" 
+#include "globals.hh"
+#include "G4VDiscreteProcess.hh"
+#include "G4PhysicsTable.hh"
+#include "G4PhysicsLogVector.hh"
+#include "G4ElementTable.hh"
+#include "G4Gamma.hh" 
+#include "G4Electron.hh"
+#include "G4Step.hh" 
+#include "G4VErrorLimitProcess.hh"
+
+//-----------------------------------------------------------------
+
+class G4ErrorStepLengthLimitProcess : public G4VErrorLimitProcess
+{
+
+ public:  // with description
+  
+  G4ErrorStepLengthLimitProcess(const G4String& processName =
+                                     "G4ErrorStepLengthLimit");
+  ~G4ErrorStepLengthLimitProcess();
+  
+  virtual G4double
+  PostStepGetPhysicalInteractionLength( const G4Track& track,
+                                              G4double previousStepSize,
+                                              G4ForceCondition* condition );
+    // returns the step length
+};
+  
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorSurfaceTrajParam.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorSurfaceTrajParam.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorSurfaceTrajParam.hh	(revision 815)
@@ -0,0 +1,96 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorSurfaceTrajParam.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+//
+// Class Description:
+//
+// Holds the 5 independent variables of the trajectory for a
+// G4ErrorSurfaceTrajState object. It is not used for anything but for
+// printing, but anyhow it is updated everytime the position and momentum
+// are updated 
+
+// History:
+// - Created:  P. Arce
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorSurfaceTrajParam_hh
+#define G4ErrorSurfaceTrajParam_hh
+
+#include "G4Point3D.hh"
+#include "G4Vector3D.hh"
+#include "G4Plane3D.hh"
+#include "G4ThreeVector.hh"
+
+#include "globals.hh"
+#include "G4Track.hh"
+
+class G4ErrorSurfaceTrajParam
+{
+ public:  // with description
+
+  G4ErrorSurfaceTrajParam(){}
+  G4ErrorSurfaceTrajParam( const G4Point3D& pos, const G4Vector3D& mom,
+                           const G4Vector3D& vecV, const G4Vector3D& vecW );
+  G4ErrorSurfaceTrajParam( const G4Point3D& pos, const G4Vector3D& mom,
+                           const G4Plane3D& plane );
+  virtual ~G4ErrorSurfaceTrajParam(){}
+
+  friend
+    std::ostream& operator<<(std::ostream&, const G4ErrorSurfaceTrajParam& ts);
+  
+  // Get and Set methods 
+
+  void SetParameters( const G4Point3D& pos, const G4Vector3D& mom,
+                      const G4Vector3D& vecV, const G4Vector3D& vecW );
+  void SetParameters( const G4Point3D& pos, const G4Vector3D& mom,
+                      const G4Plane3D& plane );
+
+  G4Vector3D GetDirection() const { return fDir; }
+  G4Vector3D GetPlaneNormal() const { return fVectorV.cross(fVectorW); }
+  G4Vector3D GetVectorV() const { return fVectorV; }
+  G4Vector3D GetVectorW() const { return fVectorW; }
+  G4double GetPV() const{ return fPV; }
+  G4double GetPW() const{ return fPW; }
+  G4double GetV() const{ return fV; }
+  G4double GetW() const{ return fW; }
+
+ private:
+
+  G4ThreeVector fDir;
+  G4Vector3D fVectorV; //one of the vectors defining the plane
+  G4Vector3D fVectorW; //one of the vectors defining the plane
+  G4double fInvP; // inverse of momentum
+  G4double fPV; // projection of momentum in one direction
+  G4double fPW; // projection of momentum in one direction
+  G4double fV; // projection of position in one direction
+  G4double fW; // projection of position in one direction
+
+};
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorSurfaceTrajState.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorSurfaceTrajState.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorSurfaceTrajState.hh	(revision 815)
@@ -0,0 +1,136 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorSurfaceTrajState.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+//
+// Class description:
+//
+// Represents a trajectory state on a surface.
+// It can be represented by the 5 variables:
+//      1/p, v', w', v, w
+// where v'=dv/du and w'=dw/du in an orthonormal coordinate system
+// with axis u, v and w.
+
+// History:
+//
+// - Created:   P. Arce 
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorSurfaceTrajState_hh
+#define G4ErrorSurfaceTrajState_hh
+
+#include "globals.hh"
+
+#include "G4ErrorTrajState.hh"
+#include "G4ErrorSurfaceTrajParam.hh"
+#include "G4ErrorFreeTrajState.hh"
+
+#include "G4Point3D.hh"
+#include "G4Vector3D.hh"
+#include "G4Plane3D.hh"
+
+class G4ErrorSurfaceTrajState : public G4ErrorTrajState
+{
+
+ public:  // with description
+
+  G4ErrorSurfaceTrajState( const G4String& partType, const G4Point3D& pos,
+                           const G4Vector3D& mom, const G4Plane3D& plane,
+                           const G4ErrorTrajErr& errmat = G4ErrorTrajErr(5,0) );
+    // Constructor by providing particle, position, momentum and
+    // G4Plane3D surface
+
+  G4ErrorSurfaceTrajState( const G4String& partType, const G4Point3D& pos,
+                           const G4Vector3D& mom, const G4Vector3D& vecV,
+                           const G4Vector3D& vecW,
+                           const G4ErrorTrajErr& errmat = G4ErrorTrajErr(5,0) );
+    // Constructor by providing particle, position, momentum and
+    // two vectors on surface
+
+  G4ErrorSurfaceTrajState( G4ErrorFreeTrajState& tpSC, const G4Plane3D& plane );
+    // Constructor by providing G4ErrorFreeTrajState and G4Plane3D surface
+
+  G4ErrorSurfaceTrajState( G4ErrorFreeTrajState& tpSC, const G4Vector3D& vecV,
+                           const G4Vector3D& vecW );
+    // Constructor by providing G4ErrorFreeTrajState and two vectors on surface
+
+  ~G4ErrorSurfaceTrajState(){}
+
+  void BuildErrorMatrix( G4ErrorFreeTrajState& tpSC, const G4Vector3D& vecV,
+                         const G4Vector3D& vecW );
+    // Build the error matrix from a free state plus the vectors of the surface
+
+  virtual void Dump( std::ostream& out = G4cout ) const;
+
+  friend
+    std::ostream& operator<<(std::ostream&, const G4ErrorSurfaceTrajState& ts);
+
+  // Set and Get methods 
+
+  G4ErrorSurfaceTrajParam GetParameters() const
+    { return fTrajParam; }
+  void SetParameters( const G4Point3D& pos, const G4Vector3D& mom,
+                      const G4Vector3D& vecV, const G4Vector3D& vecW )
+    {
+      fPosition = pos;
+      fMomentum = mom;
+      fTrajParam.SetParameters( pos, mom, vecV, vecW );
+    }
+
+  void SetParameters( const G4Point3D& pos, const G4Vector3D& mom,
+                      const G4Plane3D& plane )
+    {
+      fPosition = pos;
+      fMomentum = mom;
+      fTrajParam.SetParameters( pos, mom, plane );
+    }
+
+  G4Vector3D GetVectorV() const
+    { return fTrajParam.GetVectorV(); }
+
+  G4Vector3D GetVectorW() const
+    { return fTrajParam.GetVectorW(); }
+
+  virtual void SetPosition( const G4Point3D pos )
+    { SetParameters( pos, fMomentum, GetVectorV(), GetVectorW() ); }
+
+  virtual void SetMomentum( const G4Vector3D& mom )
+    { SetParameters( fPosition, mom, GetVectorV(), GetVectorW() ); }
+    
+ private:
+
+  void Init();
+    // Define Trajectory State type and build charge
+
+ private:
+
+  G4ErrorSurfaceTrajParam fTrajParam;
+
+};
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorSymMatrix.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorSymMatrix.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorSymMatrix.hh	(revision 815)
@@ -0,0 +1,301 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorSymMatrix.hh,v 1.2 2007/06/01 12:43:28 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// Class Description:
+//
+// Simplified version of CLHEP HepSymMatrix class.
+
+// History:
+// - Imported from CLHEP and modified:   P. Arce    May 2007
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorSymMatrix_hh
+#define G4ErrorSymMatrix_hh
+
+#include <vector>
+
+class G4ErrorMatrix;
+
+class G4ErrorSymMatrix
+{
+ public:  //with description
+
+   inline G4ErrorSymMatrix();
+   // Default constructor. Gives 0x0 symmetric matrix.
+   // Another G4ErrorSymMatrix can be assigned to it.
+
+   explicit G4ErrorSymMatrix(G4int p);
+   G4ErrorSymMatrix(G4int p, G4int);
+   // Constructor. Gives p x p symmetric matrix.
+   // With a second argument, the matrix is initialized. 0 means a zero
+   // matrix, 1 means the identity matrix.
+
+   G4ErrorSymMatrix(const G4ErrorSymMatrix &m1);
+   // Copy constructor.
+
+   // Constructor from DiagMatrix
+
+   virtual ~G4ErrorSymMatrix();
+   // Destructor.
+
+   inline G4int num_row() const;
+   inline G4int num_col() const;
+   // Returns number of rows/columns.
+
+   const G4double & operator()(G4int row, G4int col) const; 
+   G4double & operator()(G4int row, G4int col);
+   // Read and write a G4ErrorSymMatrix element.
+   // ** Note that indexing starts from (1,1). **
+
+   const G4double & fast(G4int row, G4int col) const;
+   G4double & fast(G4int row, G4int col);
+   // fast element access.
+   // Must be row>=col;
+   // ** Note that indexing starts from (1,1). **
+
+   void assign(const G4ErrorMatrix &m2);
+   // Assigns m2 to s, assuming m2 is a symmetric matrix.
+
+   void assign(const G4ErrorSymMatrix &m2);
+   // Another form of assignment. For consistency.
+
+   G4ErrorSymMatrix & operator*=(G4double t);
+   // Multiply a G4ErrorSymMatrix by a floating number.
+
+   G4ErrorSymMatrix & operator/=(G4double t); 
+   // Divide a G4ErrorSymMatrix by a floating number.
+
+   G4ErrorSymMatrix & operator+=( const G4ErrorSymMatrix &m2);
+   G4ErrorSymMatrix & operator-=( const G4ErrorSymMatrix &m2);
+   // Add or subtract a G4ErrorSymMatrix.
+
+   G4ErrorSymMatrix & operator=( const G4ErrorSymMatrix &m2);
+   // Assignment operators. Notice that there is no G4ErrorSymMatrix = Matrix.
+
+   G4ErrorSymMatrix operator- () const;
+   // unary minus, ie. flip the sign of each element.
+
+   G4ErrorSymMatrix T() const;
+   // Returns the transpose of a G4ErrorSymMatrix (which is itself).
+
+   G4ErrorSymMatrix apply(G4double (*f)(G4double, G4int, G4int)) const;
+   // Apply a function to all elements of the matrix.
+
+   G4ErrorSymMatrix similarity(const G4ErrorMatrix &m1) const;
+   G4ErrorSymMatrix similarity(const G4ErrorSymMatrix &m1) const;
+   // Returns m1*s*m1.T().
+
+   G4ErrorSymMatrix similarityT(const G4ErrorMatrix &m1) const;
+   // temporary. test of new similarity.
+   // Returns m1.T()*s*m1.
+
+   G4ErrorSymMatrix sub(G4int min_row, G4int max_row) const;
+   // Returns a sub matrix of a G4ErrorSymMatrix.
+
+   void sub(G4int row, const G4ErrorSymMatrix &m1);
+   // Sub matrix of this G4ErrorSymMatrix is replaced with m1.
+
+   G4ErrorSymMatrix sub(G4int min_row, G4int max_row);
+   // SGI CC bug. I have to have both with/without const. I should not need
+   // one without const.
+
+   inline G4ErrorSymMatrix inverse(G4int &ifail) const;
+   // Invert a Matrix. The matrix is not changed
+   // Returns 0 when successful, otherwise non-zero.
+
+   void invert(G4int &ifail);
+   // Invert a Matrix.
+   // N.B. the contents of the matrix are replaced by the inverse.
+   // Returns ierr = 0 when successful, otherwise non-zero. 
+   // This method has less overhead then inverse().
+
+   G4double determinant() const;
+   // calculate the determinant of the matrix.
+
+   G4double trace() const;
+   // calculate the trace of the matrix (sum of diagonal elements).
+
+   class G4ErrorSymMatrix_row
+   {
+     public:
+      inline G4ErrorSymMatrix_row(G4ErrorSymMatrix&,G4int);
+      inline G4double & operator[](G4int);
+     private:
+      G4ErrorSymMatrix& _a;
+      G4int _r;
+   };
+   class G4ErrorSymMatrix_row_const
+   {
+     public:
+      inline G4ErrorSymMatrix_row_const(const G4ErrorSymMatrix&,G4int);
+      inline const G4double & operator[](G4int) const;
+     private:
+      const G4ErrorSymMatrix& _a;
+      G4int _r;
+   };
+   // helper class to implement m[i][j]
+
+   inline G4ErrorSymMatrix_row operator[] (G4int);
+   inline G4ErrorSymMatrix_row_const operator[] (G4int) const;
+   // Read or write a matrix element.
+   // While it may not look like it, you simply do m[i][j] to get an
+   // element. 
+   // ** Note that the indexing starts from [0][0]. **
+
+   // Special-case inversions for 5x5 and 6x6 symmetric positive definite:
+   // These set ifail=0 and invert if the matrix was positive definite;
+   // otherwise ifail=1 and the matrix is left unaltered.
+
+   void invertCholesky5 (G4int &ifail);  
+   void invertCholesky6 (G4int &ifail);
+
+   // Inversions for 5x5 and 6x6 forcing use of specific methods:  The
+   // behavior (though not the speed) will be identical to invert(ifail).
+
+   void invertHaywood4 (G4int & ifail);  
+   void invertHaywood5 (G4int &ifail);  
+   void invertHaywood6 (G4int &ifail);
+   void invertBunchKaufman (G4int &ifail);  
+
+ protected:
+
+   inline G4int num_size() const;
+  
+ private:
+
+   friend class G4ErrorSymMatrix_row;
+   friend class G4ErrorSymMatrix_row_const;
+   friend class G4ErrorMatrix;
+
+   friend void tridiagonal(G4ErrorSymMatrix *a, G4ErrorMatrix *hsm);
+   friend G4double condition(const G4ErrorSymMatrix &m);
+   friend void diag_step(G4ErrorSymMatrix *t, G4int begin, G4int end);
+   friend void diag_step(G4ErrorSymMatrix *t, G4ErrorMatrix *u,
+                         G4int begin, G4int end);
+   friend G4ErrorMatrix diagonalize(G4ErrorSymMatrix *s);
+   friend void house_with_update2(G4ErrorSymMatrix *a, G4ErrorMatrix *v,
+                                  G4int row, G4int col);
+
+   friend G4ErrorSymMatrix operator+(const G4ErrorSymMatrix &m1, 
+                                     const G4ErrorSymMatrix &m2);
+   friend G4ErrorSymMatrix operator-(const G4ErrorSymMatrix &m1, 
+                                     const G4ErrorSymMatrix &m2);
+   friend G4ErrorMatrix operator*(const G4ErrorSymMatrix &m1,
+                                  const G4ErrorSymMatrix &m2);
+   friend G4ErrorMatrix operator*(const G4ErrorSymMatrix &m1,
+                                  const G4ErrorMatrix &m2);
+   friend G4ErrorMatrix operator*(const G4ErrorMatrix &m1,
+                                  const G4ErrorSymMatrix &m2);
+   // Multiply a Matrix by a Matrix or Vector.
+   
+   // Returns v * v.T();
+
+   std::vector<G4double > m;
+
+   G4int nrow;
+   G4int size;   // total number of elements
+
+   static G4double posDefFraction5x5;
+   static G4double adjustment5x5;
+   static const  G4double CHOLESKY_THRESHOLD_5x5;
+   static const  G4double CHOLESKY_CREEP_5x5;
+
+   static G4double posDefFraction6x6;
+   static G4double adjustment6x6;
+   static const G4double CHOLESKY_THRESHOLD_6x6;
+   static const G4double CHOLESKY_CREEP_6x6;
+
+   void invert4  (G4int & ifail);
+   void invert5  (G4int & ifail);
+   void invert6  (G4int & ifail);
+};
+
+//
+// Operations other than member functions for Matrix, G4ErrorSymMatrix,
+// DiagMatrix and Vectors
+//
+
+std::ostream& operator<<(std::ostream &s, const G4ErrorSymMatrix &q);
+// Write out Matrix, G4ErrorSymMatrix, DiagMatrix and Vector into ostream.
+
+G4ErrorMatrix operator*(const G4ErrorMatrix &m1,
+                        const G4ErrorSymMatrix &m2);
+G4ErrorMatrix operator*(const G4ErrorSymMatrix &m1,
+                        const G4ErrorMatrix &m2);
+G4ErrorMatrix operator*(const G4ErrorSymMatrix &m1,
+                        const G4ErrorSymMatrix &m2);
+G4ErrorSymMatrix operator*(G4double t, const G4ErrorSymMatrix &s1);
+G4ErrorSymMatrix operator*(const G4ErrorSymMatrix &s1, G4double t);
+// Multiplication operators.
+// Note that m *= m1 is always faster than m = m * m1
+
+G4ErrorSymMatrix operator/(const G4ErrorSymMatrix &m1, G4double t);
+// s = s1 / t. (s /= t is faster if you can use it.)
+
+G4ErrorMatrix operator+(const G4ErrorMatrix &m1,
+                        const G4ErrorSymMatrix &s2);
+G4ErrorMatrix operator+(const G4ErrorSymMatrix &s1,
+                        const G4ErrorMatrix &m2);
+G4ErrorSymMatrix operator+(const G4ErrorSymMatrix &s1,
+                           const G4ErrorSymMatrix &s2);
+// Addition operators
+
+G4ErrorMatrix operator-(const G4ErrorMatrix &m1,
+                        const G4ErrorSymMatrix &s2);
+G4ErrorMatrix operator-(const G4ErrorSymMatrix &m1,
+                        const G4ErrorMatrix &m2);
+G4ErrorSymMatrix operator-(const G4ErrorSymMatrix &s1,
+                           const G4ErrorSymMatrix &s2);
+// subtraction operators
+
+G4ErrorSymMatrix dsum(const G4ErrorSymMatrix &s1,
+                      const G4ErrorSymMatrix &s2);
+// Direct sum of two symmetric matrices;
+
+G4double condition(const G4ErrorSymMatrix &m);
+// Find the conditon number of a symmetric matrix.
+
+void diag_step(G4ErrorSymMatrix *t, G4int begin, G4int end);
+void diag_step(G4ErrorSymMatrix *t, G4ErrorMatrix *u, G4int begin, G4int end);
+// Implicit symmetric QR step with Wilkinson Shift
+
+G4ErrorMatrix diagonalize(G4ErrorSymMatrix *s);
+// Diagonalize a symmetric matrix.
+// It returns the matrix U so that s_old = U * s_diag * U.T()
+
+void house_with_update2(G4ErrorSymMatrix *a, G4ErrorMatrix *v,
+                        G4int row=1, G4int col=1);
+// Finds and does Householder reflection on matrix.
+
+void tridiagonal(G4ErrorSymMatrix *a, G4ErrorMatrix *hsm);
+G4ErrorMatrix tridiagonal(G4ErrorSymMatrix *a);
+// Does a Householder tridiagonalization of a symmetric matrix.
+
+#include "G4ErrorSymMatrix.icc"
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorSymMatrix.icc
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorSymMatrix.icc	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorSymMatrix.icc	(revision 815)
@@ -0,0 +1,141 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorSymMatrix.icc,v 1.2 2007/06/01 12:43:28 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class inline implementation
+// ------------------------------------------------------------
+
+
+inline G4ErrorSymMatrix::G4ErrorSymMatrix() 
+  : m(0), nrow(0), size(0)
+{
+}
+
+inline G4int G4ErrorSymMatrix::num_row() const
+{
+  return nrow;
+}
+
+inline G4int G4ErrorSymMatrix::num_col() const
+{
+  return nrow;
+}
+
+inline G4int G4ErrorSymMatrix::num_size() const
+{
+  return size;
+}
+
+inline G4double & G4ErrorSymMatrix::fast(G4int row,G4int col)
+{
+  return *(m.begin()+(row*(row-1))/2+(col-1));
+}
+
+inline const G4double & G4ErrorSymMatrix::fast(G4int row,G4int col) const
+{
+  return *(m.begin()+(row*(row-1))/2+(col-1));
+}
+
+inline G4double &
+G4ErrorSymMatrix::operator()(G4int row, G4int col)
+{
+  return (row>=col? fast(row,col) : fast(col,row));
+}
+
+inline const G4double &
+G4ErrorSymMatrix::operator()(G4int row, G4int col) const 
+{
+  return (row>=col? fast(row,col) : fast(col,row));
+}
+
+inline void G4ErrorSymMatrix::assign(const G4ErrorSymMatrix &m2) 
+{
+  (*this)=m2;
+}
+
+inline G4ErrorSymMatrix G4ErrorSymMatrix::T() const
+{
+  return G4ErrorSymMatrix(*this);
+}
+
+inline G4ErrorSymMatrix::G4ErrorSymMatrix_row
+G4ErrorSymMatrix::operator[] (G4int r)
+{
+  G4ErrorSymMatrix_row b(*this,r);
+  return b;
+}
+
+inline G4ErrorSymMatrix::G4ErrorSymMatrix_row_const
+G4ErrorSymMatrix::operator[] (G4int r) const
+{
+  const G4ErrorSymMatrix_row_const b(*this,r);
+  return b;
+}
+
+inline G4double &G4ErrorSymMatrix::G4ErrorSymMatrix_row::operator[](G4int c)
+{
+   if (_r >= c )
+   {
+      return *(_a.m.begin() + (_r+1)*_r/2 + c);
+   }
+   else
+   {
+      return *(_a.m.begin() + (c+1)*c/2 + _r);
+   }
+}
+
+inline const G4double &
+G4ErrorSymMatrix::G4ErrorSymMatrix_row_const::operator[](G4int c) const 
+{
+   if (_r >= c )
+   {
+      return *(_a.m.begin() + (_r+1)*_r/2 + c);
+   }
+   else
+   {
+      return *(_a.m.begin() + (c+1)*c/2 + _r);
+   }
+}
+
+inline G4ErrorSymMatrix::
+G4ErrorSymMatrix_row::G4ErrorSymMatrix_row(G4ErrorSymMatrix &a, G4int r) 
+   : _a(a), _r(r)
+{}
+
+inline G4ErrorSymMatrix::
+G4ErrorSymMatrix_row_const::G4ErrorSymMatrix_row_const
+(const G4ErrorSymMatrix&a,G4int r) 
+   : _a(a), _r(r)
+{}
+
+inline G4ErrorSymMatrix G4ErrorSymMatrix::inverse(G4int &ifail) const
+{
+  G4ErrorSymMatrix mTmp(*this);
+  mTmp.invert(ifail);
+  return mTmp;
+}
Index: /trunk/source/error_propagation/include/G4ErrorTrackLengthTarget.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorTrackLengthTarget.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorTrackLengthTarget.hh	(revision 815)
@@ -0,0 +1,92 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorTrackLengthTarget.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+//
+// Class Description:
+//
+// G4ErrorTarget class: limits step when track length is bigger than
+// theMaximumTrackLength. It is a G4VDiscreteProcess: limits the step in
+// PostStepGetPhysicalInteractionLength().
+
+// History:
+// - Created. P. Arce, September 2004
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorTrackLengthTarget_hh
+#define G4ErrorTrackLengthTarget_hh
+
+#include "G4ios.hh" 
+#include "globals.hh"
+#include "G4VDiscreteProcess.hh"
+#include "G4PhysicsTable.hh"
+#include "G4PhysicsLogVector.hh"
+#include "G4ElementTable.hh"
+#include "G4Step.hh" 
+#include "G4ErrorTarget.hh"
+
+//---------------------------------------------------------------------------- 
+
+class G4ErrorTrackLengthTarget : public G4VDiscreteProcess,
+                                 public G4ErrorTarget
+{
+ public:  // with description
+
+  G4ErrorTrackLengthTarget(const G4double maxTrkLength );
+    // Constructs and add this process to G4ProcessManager of all particles
+  virtual ~G4ErrorTrackLengthTarget(){}
+  
+    // These methods are dummy, as the step limitation is done in the
+    // PostStepGetPhysicalInteractionLength().
+
+  virtual G4double GetDistanceFromPoint( const G4ThreeVector&,
+                                         const G4ThreeVector& ) const
+    { return DBL_MAX; }   
+  virtual G4double GetDistanceFromPoint( const G4ThreeVector& ) const
+    { return DBL_MAX; } 
+
+  virtual G4double
+  PostStepGetPhysicalInteractionLength( const G4Track& track,
+                                              G4double previousStepSize,
+                                              G4ForceCondition* condition );
+    // Checks if the maximum track length has been reached
+
+  virtual  G4double GetMeanFreePath(const class G4Track & track,
+                                    G4double, G4ForceCondition *);
+    // Mean free path = theMaximumTrackLength - track.GetTrackLength()
+
+   virtual G4VParticleChange* PostStepDoIt( const G4Track&, const G4Step& );
+                       
+   virtual void Dump( const G4String& msg ) const;
+
+ private:
+
+  G4double theMaximumTrackLength;
+};
+   
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorTrajErr.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorTrajErr.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorTrajErr.hh	(revision 815)
@@ -0,0 +1,47 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorTrajErr.hh,v 1.3 2007/05/31 20:27:07 arce Exp $
+// GEANT4 tag $Name:  $
+//
+//
+// Class Description:
+//
+// Trajectory error. Implemented for the moment as a CLHEP HepG4ErrorSymMatrix,
+// until other possibly faster implementations are studied
+
+// History:
+// - Created:   P. Arce
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorTrajErr_hh
+#define G4ErrorTrajErr_hh
+
+#include "G4ErrorSymMatrix.hh"
+
+typedef G4ErrorSymMatrix G4ErrorTrajErr;
+
+#endif
Index: /trunk/source/error_propagation/include/G4ErrorTrajState.hh
===================================================================
--- /trunk/source/error_propagation/include/G4ErrorTrajState.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4ErrorTrajState.hh	(revision 815)
@@ -0,0 +1,138 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4ErrorTrajState.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+//
+// Class Description:
+//
+// Base class for the trajectory state
+
+// History:
+// - Created:   P. Arce
+// --------------------------------------------------------------------
+
+#ifndef G4ErrorTrajState_hh
+#define G4ErrorTrajState_hh
+
+#include "globals.hh"
+#include "G4Track.hh"
+#include "G4Point3D.hh"
+#include "G4Vector3D.hh"
+#include "G4ErrorTrajErr.hh"
+
+enum G4eTSType{ G4eTS_FREE, G4eTS_OS };
+
+class G4ErrorTrajState
+{
+ public:  // with description
+
+  G4ErrorTrajState(){}
+
+  G4ErrorTrajState( const G4String& partType, const G4Point3D& pos,
+                    const G4Vector3D& mom,
+                    const G4ErrorTrajErr& errmat = G4ErrorTrajErr(5,0) );
+    // Constructor by providing particle, position and momentum
+
+  virtual ~G4ErrorTrajState(){}
+
+  void SetData( const G4String& partType, const G4Point3D& pos,
+                const G4Vector3D& mom );
+    // Set particle, position and momentum
+
+  void BuildCharge();
+    // Build charge based on particle type
+
+  friend
+  std::ostream& operator<<(std::ostream&, const G4ErrorTrajState& ts);
+
+  virtual G4int PropagateError( const G4Track* ); 
+    // Propagate the error along the step
+
+  virtual G4int Update( const G4Track* ){ return -1; }
+    // Update parameters from G4Track
+ 
+  void UpdatePosMom( const G4Point3D& pos, const G4Vector3D& mom );
+    // Update position and momentum
+
+  void DumpPosMomError( std::ostream& out = G4cout ) const;
+    // Dump position, momentum and error
+
+  virtual void Dump( std::ostream& out = G4cout ) const = 0;
+    // Abstract method to dump all TrajState parameters
+  
+  // Set and Get methods 
+
+  const G4String& GetParticleType() const
+    { return fParticleType;}
+  void SetParticleType( const G4String& partType )
+    { fParticleType = partType;}
+
+  G4Point3D GetPosition() const
+    { return fPosition; }
+  virtual void SetPosition( const G4Point3D pos )
+    { fPosition = pos; }
+
+  G4Vector3D GetMomentum() const
+    { return fMomentum; }
+  virtual void SetMomentum( const G4Vector3D& mom )
+    { fMomentum = mom; }
+
+  G4ErrorTrajErr GetError() const
+    { return fError; }
+  virtual void SetError( G4ErrorTrajErr em )
+    { fError = em; }
+
+  G4Track* GetG4Track() const
+    { return theG4Track; }
+  void SetG4Track( G4Track* trk )
+    { theG4Track = trk; }
+
+  G4double GetCharge() const
+    { return fCharge; }
+  void SetCharge( G4double ch )
+    { fCharge = ch; }
+
+  virtual G4eTSType GetTSType() const
+    { return theTSType; }
+
+ protected:
+
+  G4String fParticleType;
+  G4Point3D fPosition;
+  G4Vector3D fMomentum;
+  G4double fCharge;
+  G4ErrorTrajErr fError;
+
+  G4eTSType theTSType;
+
+  G4Track* theG4Track;
+
+  G4int iverbose;
+};
+
+#endif
Index: /trunk/source/error_propagation/include/G4VErrorLimitProcess.hh
===================================================================
--- /trunk/source/error_propagation/include/G4VErrorLimitProcess.hh	(revision 815)
+++ /trunk/source/error_propagation/include/G4VErrorLimitProcess.hh	(revision 815)
@@ -0,0 +1,92 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4VErrorLimitProcess.hh,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+//
+// Class description:
+//
+// Base class for classes limiting the step.
+
+// History:
+//
+// Created:     P.Arce          May 2007
+// --------------------------------------------------------------------
+
+#ifndef G4VErrorLimitProcess_hh
+#define G4VErrorLimitProcess_hh
+
+#include "G4ios.hh" 
+#include "globals.hh"
+#include "G4VDiscreteProcess.hh"
+#include "G4PhysicsTable.hh"
+#include "G4PhysicsLogVector.hh"
+#include "G4ElementTable.hh"
+#include "G4Gamma.hh" 
+#include "G4Electron.hh"
+#include "G4Step.hh" 
+
+class G4ErrorLimitsMessenger;
+
+//-----------------------------------------------------------------
+ 
+class G4VErrorLimitProcess : public G4VDiscreteProcess
+{
+
+ public:  // with description
+  
+  G4VErrorLimitProcess(const G4String& processName);
+  
+  ~G4VErrorLimitProcess();
+  
+  virtual G4double
+  PostStepGetPhysicalInteractionLength( const G4Track& track,
+                                              G4double previousStepSize,
+                                              G4ForceCondition* condition ) = 0;
+    // Returns the step limit
+
+  virtual  G4double GetMeanFreePath(const class G4Track &, G4double,
+                                    enum G4ForceCondition *);
+    // Returns kInfinity
+
+  virtual G4VParticleChange* PostStepDoIt(const G4Track&, const G4Step& );
+    // No action but retrieving the G4VParticleChange
+    // extracted from the G4Track
+
+  // Get and Set methods
+
+  G4double GetStepLimit() const { return theStepLimit; }
+  void SetStepLimit( G4double val ) { theStepLimit = val; }
+
+ protected:
+
+  G4double theStepLimit;  // limit set by the user
+  G4double theStepLength; // step length extracted from the user step limit,
+                          // with the algorithms of each concrete class
+};
+  
+#endif
Index: /trunk/source/error_propagation/src/G4ErrorFreeTrajParam.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorFreeTrajParam.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorFreeTrajParam.cc	(revision 815)
@@ -0,0 +1,96 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorFreeTrajParam.cc,v 1.3 2007/09/24 16:24:45 arce Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4ErrorFreeTrajParam.hh"
+#include "G4ThreeVector.hh"
+
+#include <iomanip>
+
+//------------------------------------------------------------------------
+G4ErrorFreeTrajParam::G4ErrorFreeTrajParam( const G4Point3D& pos,
+                                            const G4Vector3D& mom )
+{
+  SetParameters( pos, mom );
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorFreeTrajParam::SetParameters( const G4Point3D& pos,
+                                          const G4Vector3D& mom )
+{
+  fDir = mom;
+  fInvP = 1./mom.mag();
+  fLambda = 90.*deg - mom.theta();
+  fPhi = mom.phi();
+  G4Vector3D vxPerp(0.,0.,0.);
+  if( mom.mag() > 0.) {
+    vxPerp = mom/mom.mag();
+  }
+  G4Vector3D vyPerp = G4Vector3D( -vxPerp.y(), vxPerp.x(), 0.);
+  vyPerp /= vyPerp.mag();
+  G4Vector3D vzPerp = vxPerp.cross( vyPerp );
+  vzPerp /= vzPerp.mag();
+  // check if right handed
+  //  fXPerp = pos.proj( mom );
+  G4ThreeVector posv(pos);
+  if( vyPerp.mag() != 0. ) {
+    fYPerp = posv.project( vyPerp ).mag();
+    fZPerp = posv.project( vzPerp ).mag();
+  } else {
+    fYPerp = 0.;
+    fZPerp = 0.;
+  }
+}
+
+//------------------------------------------------------------------------
+void G4ErrorFreeTrajParam::Update( const G4Track* aTrack )
+{
+  SetParameters( aTrack->GetPosition(), aTrack->GetMomentum() );
+
+}
+
+
+//------------------------------------------------------------------------
+std::ostream& operator<<(std::ostream& out, const G4ErrorFreeTrajParam& tp)
+{
+  //  long mode = out.setf(std::ios::fixed,std::ios::floatfield);
+  
+  //  out << tp.theType;
+  //  out << std::setprecision(5) << std::setw(10);
+  out << std::setprecision(8) << " InvP= " << tp.fInvP << " Theta= "
+      << tp.fLambda << " Phi= " << tp.fPhi << " YPerp= " << tp.fYPerp
+      << " ZPerp= " << tp.fZPerp << G4endl;
+  out << " momentum direction= " << tp.fDir << G4endl;
+    
+  return out;
+}
Index: /trunk/source/error_propagation/src/G4ErrorFreeTrajState.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorFreeTrajState.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorFreeTrajState.cc	(revision 815)
@@ -0,0 +1,702 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorFreeTrajState.cc,v 1.7 2007/09/24 16:25:57 arce Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+#include "G4ErrorFreeTrajState.hh"
+#include "G4ErrorFreeTrajParam.hh"
+#include "G4ErrorSurfaceTrajState.hh"
+
+#include "G4ErrorMatrix.hh"
+#include <iomanip>
+
+#include "G4Field.hh"
+#include "G4FieldManager.hh"
+#include "G4TransportationManager.hh"
+#include "G4GeometryTolerance.hh"
+#include "G4Material.hh"
+#include "G4ErrorPropagatorData.hh"
+
+//------------------------------------------------------------------------
+G4ErrorFreeTrajState::G4ErrorFreeTrajState( const G4String& partType, const G4Point3D& pos, const G4Vector3D& mom, const G4ErrorTrajErr& errmat) : G4ErrorTrajState( partType, pos, mom, errmat )
+{
+  fTrajParam = G4ErrorFreeTrajParam( pos, mom );
+  Init();
+}
+
+
+//------------------------------------------------------------------------
+G4ErrorFreeTrajState::G4ErrorFreeTrajState( const G4ErrorSurfaceTrajState& tpSD ) : G4ErrorTrajState( tpSD.GetParticleType(), tpSD.GetPosition(), tpSD.GetMomentum() )
+{
+  //  G4ThreeVector planeNormal = tpSD.GetPlaneNormal();
+  // G4double fPt = tpSD.GetMomentum()*planeNormal;//mom projected on normal to plane  
+  //  G4ErrorSurfaceTrajParam tpSDparam = tpSD.GetParameters();
+  //  G4ThreeVector Psc = fPt * planeNormal + tpSDparam.GetPU()*tpSDparam.GetVectorU() + tpSD.GetPV()*tpSD.GetVectorW();
+
+  fTrajParam = G4ErrorFreeTrajParam( fPosition, fMomentum );
+  Init();
+
+  //----- Get the error matrix in SC coordinates
+  G4ErrorSurfaceTrajParam tpSDparam = tpSD.GetParameters();
+  G4double mom = fMomentum.mag();
+  G4double mom2 = fMomentum.mag2();
+  G4double TVW1 = std::sqrt( mom2 / ( mom2 + tpSDparam.GetPV()*tpSDparam.GetPV() + tpSDparam.GetPV()*tpSDparam.GetPV()) );
+  G4ThreeVector vTVW( TVW1, tpSDparam.GetPV()/mom * TVW1, tpSDparam.GetPW()/mom * TVW1 );
+  G4Vector3D vectorU = tpSDparam.GetVectorV().cross(  tpSDparam.GetVectorW() );
+  G4Vector3D vTN = vTVW.x()*vectorU + vTVW.y()*tpSDparam.GetVectorV() + vTVW.z()*tpSDparam.GetVectorW();
+
+#ifdef G4EVERBOSE
+   if( iverbose >= 5){
+     G4double pc2 = std::asin( vTN.z() );
+     G4double pc3 = std::atan (vTN.y()/vTN.x());
+  
+     G4cout << " CHECK: pc2 " << pc2 << " = " << GetParameters().GetLambda() <<  " diff " << pc2-GetParameters().GetLambda() << G4endl;
+     G4cout << " CHECK: pc3 " << pc3 << " = " << GetParameters().GetPhi() <<  " diff " << pc3-GetParameters().GetPhi() << G4endl;
+   }
+#endif
+
+  //--- Get the unit vectors perp to P 
+  G4double cosl = std::cos( GetParameters().GetLambda() ); 
+  if (cosl < 1.E-30) cosl = 1.E-30;
+  G4double cosl1 = 1./cosl;
+  G4Vector3D vUN(-vTN.y()*cosl1, vTN.x()*cosl1, 0. );
+  G4Vector3D vVN(-vTN.z()*vUN.y(), vTN.z()*vUN.x(), cosl );
+
+  G4Vector3D vUperp = G4Vector3D( -fMomentum.y(), fMomentum.x(), 0.);
+  G4Vector3D vVperp = vUperp.cross( fMomentum );
+  vUperp *= 1./vUperp.mag();
+  vVperp *= 1./vVperp.mag();
+
+#ifdef G4EVERBOSE
+   if( iverbose >= 5){
+     G4cout << " CHECK: vUN " << vUN << " = " << vUperp <<  " diff " << (vUN-vUperp).mag() << G4endl;
+     G4cout << " CHECK: vVN " << vVN << " = " << vVperp <<  " diff " << (vVN-vVperp).mag() << G4endl;
+   }
+#endif
+
+  //get the dot products of vectors perpendicular to direction and vector defining SD plane
+  G4double dUU = vUperp * tpSD.GetVectorV();
+  G4double dUV = vUperp * tpSD.GetVectorW();
+  G4double dVU = vVperp * tpSD.GetVectorV();
+  G4double dVV = vVperp * tpSD.GetVectorW();
+
+
+  //--- Get transformation first
+  G4ErrorMatrix transfM(5, 5, 1 );
+  //--- Get magnetic field
+  const G4Field* field = G4TransportationManager::GetTransportationManager()->GetFieldManager()->GetDetectorField();
+  G4ThreeVector dir = fTrajParam.GetDirection();
+  G4double invCosTheta = 1./std::cos( dir.theta() );
+
+  if( fCharge != 0 
+&& field ) {
+    G4double pos1[3]; pos1[0] = fPosition.x()*cm; pos1[1] = fPosition.y()*cm; pos1[2] = fPosition.z()*cm;
+    G4double h1[3];
+    field->GetFieldValue( pos1, h1 );
+    G4ThreeVector HPre = G4ThreeVector( h1[0], h1[1], h1[2] ) / tesla *10.;
+    G4double magHPre = HPre.mag();
+    G4double invP = 1./fMomentum.mag();
+    G4double magHPreM = magHPre * invP;
+    if( magHPre != 0. ) {
+      G4double magHPreM2 = fCharge / magHPre;
+
+      G4double Q = -magHPreM * c_light;
+      G4double sinz = -HPre*vUperp * magHPreM2;
+      G4double cosz =  HPre*vVperp * magHPreM2;
+
+      transfM[1][3] = -Q*dir.y()*sinz;
+      transfM[1][4] = -Q*dir.z()*sinz;
+      transfM[2][3] = -Q*dir.y()*cosz*invCosTheta;
+      transfM[2][4] = -Q*dir.z()*cosz*invCosTheta;
+    }
+  }
+
+  transfM[0][0] = 1.;
+  transfM[1][1] = dir.x()*dVU;
+  transfM[1][2] = dir.x()*dVV;
+  transfM[2][1] = dir.x()*dUU*invCosTheta;
+  transfM[2][2] = dir.x()*dUV*invCosTheta;
+  transfM[3][3] = dUU;
+  transfM[3][4] = dUV;
+  transfM[4][3] = dVU;
+  transfM[4][4] = dVV;
+
+  fError = G4ErrorTrajErr( tpSD.GetError().similarity( transfM ) );
+
+#ifdef G4EVERBOSE
+  if( iverbose >= 1) G4cout << "error matrix SD2SC " << fError << G4endl;
+  if( iverbose >= 4) G4cout << "G4ErrorFreeTrajState from SD " << *this << G4endl;
+#endif
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorFreeTrajState::Init()
+{
+  theTSType = G4eTS_FREE;
+  BuildCharge();
+  theTransfMat = G4ErrorMatrix(5,5,0);
+  //-  theFirstStep = true;
+}
+
+//------------------------------------------------------------------------
+void G4ErrorFreeTrajState::Dump( std::ostream& out ) const
+{
+  out << *this;
+}
+
+//------------------------------------------------------------------------
+G4int G4ErrorFreeTrajState::Update( const G4Track* aTrack )
+{
+  G4int ierr = 0;
+  fTrajParam.Update( aTrack );
+  UpdatePosMom( aTrack->GetPosition(), aTrack->GetMomentum() );
+  return ierr;
+
+}
+
+
+//------------------------------------------------------------------------
+std::ostream& operator<<(std::ostream& out, const G4ErrorFreeTrajState& ts)
+{
+  out.setf(std::ios::fixed,std::ios::floatfield);
+
+  
+  ts.DumpPosMomError( out );
+ 
+  out << " G4ErrorFreeTrajState: Params: " << ts.fTrajParam << G4endl;
+
+  return out;
+
+}
+
+
+//------------------------------------------------------------------------
+G4int G4ErrorFreeTrajState::PropagateError( const G4Track* aTrack )
+{
+  G4double stepLengthCm = aTrack->GetStep()->GetStepLength()/cm;
+  G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
+
+  if( std::fabs(stepLengthCm) <= kCarTolerance/cm ) return 0;
+  
+#ifdef G4EVERBOSE
+  if( iverbose >= 2 )G4cout << "  G4ErrorFreeTrajState::PropagateError " << G4endl;
+#endif
+
+  // * *** ERROR PROPAGATION ON A HELIX ASSUMING SC VARIABLES
+  G4Point3D vposPost = aTrack->GetPosition()/cm;
+  G4Vector3D vpPost = aTrack->GetMomentum()/GeV;
+  //  G4Point3D vposPre = fPosition/cm;
+  //  G4Vector3D vpPre = fMomentum/GeV;
+  G4Point3D vposPre = aTrack->GetStep()->GetPreStepPoint()->GetPosition()/cm;
+  G4Vector3D vpPre = aTrack->GetStep()->GetPreStepPoint()->GetMomentum()/GeV;
+  //correct to avoid propagation along Z 
+  if( vpPre.mag() == vpPre.z() ) vpPre.setX( 1.E-6*MeV );
+  if( vpPost.mag() == vpPost.z() ) vpPost.setX( 1.E-6*MeV );
+
+  G4double pPre = vpPre.mag();
+  G4double pPost = vpPost.mag();
+#ifdef G4EVERBOSE
+  if( iverbose >= 2 ) {
+    G4cout << "G4EP: vposPre " << vposPre << G4endl
+              << "G4EP: vposPost " << vposPost << G4endl;
+    G4cout << "G4EP: vpPre " << vpPre << G4endl
+              << "G4EP: vpPost " << vpPost << G4endl;
+    G4cout << " err start step " << fError << G4endl;
+    G4cout << "G4EP: stepLengthCm " << stepLengthCm << G4endl;
+  }
+#endif
+
+  if( pPre == 0. || pPost == 0 ) return 2;
+  G4double pInvPre = 1./pPre;
+  G4double pInvPost = 1./pPost;
+  G4double deltaPInv = pInvPost - pInvPre;
+
+  G4Vector3D vpPreNorm = vpPre * pInvPre;
+  G4Vector3D vpPostNorm = vpPost * pInvPost;
+  //  if( iverbose >= 2 ) G4cout << "G4EP: vpPreNorm " << vpPreNorm << " vpPostNorm " << vpPostNorm << G4endl;
+  //return if propagation along Z??  
+  if( 1. - std::fabs(vpPostNorm.z()) < kCarTolerance ) return 4;
+  G4double sinpPre = std::sin( vpPreNorm.theta() ); //cosine perpendicular to pPre = sine pPre
+  G4double sinpPost = std::sin( vpPostNorm.theta() ); //cosine perpendicular to pPost = sine pPost
+  G4double sinpPostInv = 1./std::sin( vpPreNorm.theta() );
+
+#ifdef G4EVERBOSE
+  if( iverbose >= 2 ) G4cout << "G4EP: cosl " << sinpPre << " cosl0 " << sinpPost << G4endl;
+#endif
+  //* *** DEFINE TRANSFORMATION MATRIX BETWEEN X1 AND X2 FOR
+  //* *** NEUTRAL PARTICLE OR FIELDFREE REGION
+  G4ErrorMatrix transf(5, 5, 0 );
+
+  transf[3][2] = stepLengthCm * sinpPost;
+  transf[4][1] = stepLengthCm;
+  for( size_t ii=0;ii < 5; ii++ ){
+    transf[ii][ii] = 1.;
+  }
+#ifdef G4EVERBOSE
+  if( iverbose >= 2 ) {
+    G4cout << "G4EP: transf matrix neutral " << transf;
+  }
+#endif
+
+  //  charge X propagation direction
+  G4double charge = aTrack->GetDynamicParticle()->GetCharge();
+  if( G4ErrorPropagatorData::GetErrorPropagatorData()->GetMode() == G4ErrorMode_PropBackwards ) {
+    charge *= -1.; 
+  }
+  //  G4cout << " charge " << charge << G4endl;
+  //t check if particle has charge
+  //t  if( charge == 0 ) goto 45;
+  // check if the magnetic field is = 0.
+
+  //position is from geant4, it is assumed to be in mm (for debugging, eventually it will not be transformed)
+  G4double pos1[3]; pos1[0] = vposPre.x()*cm; pos1[1] = vposPre.y()*cm; pos1[2] = vposPre.z()*cm;
+  G4double pos2[3]; pos2[0] = vposPost.x()*cm; pos2[1] = vposPost.y()*cm; pos2[2] = vposPost.z()*cm;
+  G4double h1[3], h2[3];
+
+  const G4Field* field = G4TransportationManager::GetTransportationManager()->GetFieldManager()->GetDetectorField();
+  if( !field ) return 0; //goto 45
+ 
+  // calculate transformation except it NEUTRAL PARTICLE OR FIELDFREE REGION
+  if( charge != 0. && field ) {
+
+    field->GetFieldValue( pos1, h1 );
+    field->GetFieldValue( pos2, h2 );
+    G4ThreeVector HPre = G4ThreeVector( h1[0], h1[1], h1[2] ) / tesla *10.; //10. is to get same dimensions as GEANT3 (kilogauss)
+    G4ThreeVector HPost= G4ThreeVector( h2[0], h2[1], h2[2] ) / tesla *10.;
+    G4double magHPre = HPre.mag();
+    G4double magHPost = HPost.mag();
+#ifdef G4EVERBOSE
+    if( iverbose >= 2 ) G4cout << "G4EP: HPre " << HPre << G4endl
+                            << "G4EP: HPost " << HPost << G4endl;
+#endif
+    
+  if( magHPre + magHPost != 0. ) {
+      
+   //* *** CHECK WHETHER H*ALFA/P IS TOO DIFFERENT AT X1 AND X2
+    G4double gam;
+    if( magHPost != 0. ){ 
+      gam = HPost * vpPostNorm / magHPost;
+    }else {
+      gam = HPre * vpPreNorm / magHPre;
+    }
+    
+    // G4eMagneticLimitsProcess will limit the step, but based on an straight line trajectory
+    G4double alphaSqr = 1. - gam * gam;
+    G4double diffHSqr = ( HPre * pInvPre - HPost * pInvPost ).mag2();
+    G4double delhp6Sqr = 300.*300.; 
+#ifdef G4EVERBOSE
+    if( iverbose >= 2 ) G4cout << " G4EP: gam " << gam << " alphaSqr " << alphaSqr << " diffHSqr " << diffHSqr << G4endl;
+#endif
+    if( diffHSqr * alphaSqr > delhp6Sqr ) return 3;
+
+
+    //* *** DEFINE AVERAGE MAGNETIC FIELD AND GRADIENT
+    G4double pInvAver = 1./(pInvPre + pInvPost );
+    G4double CFACT8 = 2.997925E-4; 
+    //G4double HAver
+    G4ThreeVector vHAverNorm( (HPre*pInvPre + HPost*pInvPost ) * pInvAver * charge * CFACT8 );
+    G4double HAver = vHAverNorm.mag();
+    G4double invHAver = 1./HAver;
+    vHAverNorm *= invHAver;
+#ifdef G4EVERBOSE
+    if( iverbose >= 2 ) G4cout << " G4EP: HaverNorm " << vHAverNorm << " magHAver " << HAver << " charge " << charge<< G4endl;
+#endif
+
+    G4double pAver = (pPre+pPost)*0.5;
+    G4double QAver = -HAver/pAver;
+    G4double thetaAver = QAver * stepLengthCm;
+    G4double sinThetaAver = std::sin(thetaAver);
+    G4double cosThetaAver = std::cos(thetaAver);
+    G4double gamma = vHAverNorm * vpPostNorm;
+    G4ThreeVector AN2 = vHAverNorm.cross( vpPostNorm );
+    
+#ifdef G4EVERBOSE
+    if( iverbose >= 2 ) G4cout << " G4EP: AN2 " << AN2 << G4endl;
+#endif
+    G4double AU = 1./vpPreNorm.perp();
+    //t  G4ThreeVector vU( vpPreNorm.cross( G4ThreeVector(0.,0.,1.) ) * AU );
+    G4ThreeVector vUPre( -AU*vpPreNorm.y(), 
+                      AU*vpPreNorm.x(), 
+                      0. );
+    G4ThreeVector vVPre( -vpPreNorm.z()*vUPre.y(), 
+                      vpPreNorm.z()*vUPre.x(), 
+                      vpPreNorm.x()*vUPre.y() - vpPreNorm.y()*vUPre.x() );
+    
+    //
+    AU = 1./vpPostNorm.perp();
+    //t  G4ThreeVector vU( vpPostNorm.cross( G4ThreeVector(0.,0.,1.) ) * AU );
+    G4ThreeVector vUPost( -AU*vpPostNorm.y(), 
+                       AU*vpPostNorm.x(), 
+                       0. );
+    G4ThreeVector vVPost( -vpPostNorm.z()*vUPost.y(), 
+                       vpPostNorm.z()*vUPost.x(), 
+                       vpPostNorm.x()*vUPost.y() - vpPostNorm.y()*vUPost.x() );
+#ifdef G4EVERBOSE
+    //-    G4cout << " vpPostNorm " << vpPostNorm << G4endl;
+    if( iverbose >= 2 ) G4cout << " G4EP: AU " << AU << " vUPre " << vUPre << " vVPre " << vVPre << " vUPost " << vUPost << " vVPost " << vVPost << G4endl;
+#endif
+    G4Point3D deltaPos( vposPre - vposPost );
+
+    // * *** COMPLETE TRANSFORMATION MATRIX BETWEEN ERRORS AT X1 AND X2
+    // * *** FIELD GRADIENT PERPENDICULAR TO TRACK IS PRESENTLY NOT
+    // * *** TAKEN INTO ACCOUNT
+    
+    G4double QP = QAver * pAver; // = -HAver
+#ifdef G4EVERBOSE
+    if( iverbose >= 2) G4cout << " G4EP: QP " << QP << " QAver " << QAver << " pAver " << pAver << G4endl;
+#endif
+    G4double ANV = -( vHAverNorm.x()*vUPost.x() + vHAverNorm.y()*vUPost.y() );
+    G4double ANU = ( vHAverNorm.x()*vVPost.x() + vHAverNorm.y()*vVPost.y() + vHAverNorm.z()*vVPost.z() );
+    G4double OMcosThetaAver = 1. - cosThetaAver;
+#ifdef G4EVERBOSE
+    if( iverbose >= 2) G4cout << "G4EP: OMcosThetaAver " << OMcosThetaAver << " cosThetaAver " << cosThetaAver << " thetaAver " << thetaAver << " QAver " << QAver << " stepLengthCm " << stepLengthCm << G4endl;
+#endif
+    G4double TMSINT = thetaAver - sinThetaAver;
+#ifdef G4EVERBOSE
+    if( iverbose >= 2 ) G4cout << " G4EP: ANV " << ANV << " ANU " << ANU << G4endl;
+#endif
+    
+    G4ThreeVector vHUPre( -vHAverNorm.z() * vUPre.y(),
+                          vHAverNorm.z() * vUPre.x(),
+                          vHAverNorm.x() * vUPre.y() - vHAverNorm.y() * vUPre.x() );
+#ifdef G4EVERBOSE
+    //    if( iverbose >= 2 ) G4cout << "G4EP: HUPre(1) " << vHUPre.x() << " " << vHAverNorm.z() << " " << vUPre.y() << G4endl;
+#endif
+    G4ThreeVector vHVPre( vHAverNorm.y() * vVPre.z() - vHAverNorm.z() * vVPre.y(),
+                          vHAverNorm.z() * vVPre.x() - vHAverNorm.x() * vVPre.z(),
+                          vHAverNorm.x() * vVPre.y() - vHAverNorm.y() * vVPre.x() );
+#ifdef G4EVERBOSE
+    if( iverbose >= 2 ) G4cout << " G4EP: HUPre " << vHUPre << " HVPre " << vHVPre << G4endl;
+#endif
+    
+    //------------------- COMPUTE MATRIX
+    //---------- 1/P
+    
+    transf[0][0] = 1.-deltaPInv*pAver*(1.+(vpPostNorm.x()*deltaPos.x()+vpPostNorm.y()*deltaPos.y()+vpPostNorm.z()*deltaPos.z())/stepLengthCm)
+      +2.*deltaPInv*pAver;
+    
+    transf[0][1] =  -deltaPInv/thetaAver*
+      ( TMSINT*gamma*(vHAverNorm.x()*vVPre.x()+vHAverNorm.y()*vVPre.y()+vHAverNorm.z()*vVPre.z()) +
+        sinThetaAver*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z()) +
+        OMcosThetaAver*(vHVPre.x()*vpPostNorm.x()+vHVPre.y()*vpPostNorm.y()+vHVPre.z()*vpPostNorm.z()) );
+    
+    transf[0][2] =  -sinpPre*deltaPInv/thetaAver*
+      ( TMSINT*gamma*(vHAverNorm.x()*vUPre.x()+vHAverNorm.y()*vUPre.y()            ) +
+        sinThetaAver*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y()            ) +
+        OMcosThetaAver*(vHUPre.x()*vpPostNorm.x()+vHUPre.y()*vpPostNorm.y()+vHUPre.z()*vpPostNorm.z()) );
+    
+    transf[0][3] =  -deltaPInv/stepLengthCm*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y()            );
+    
+    transf[0][4] =  -deltaPInv/stepLengthCm*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z());
+    
+    // ***   Lambda
+    transf[1][0] = -QP*ANV*(vpPostNorm.x()*deltaPos.x()+vpPostNorm.y()*deltaPos.y()+vpPostNorm.z()*deltaPos.z())
+      *(1.+deltaPInv*pAver);
+#ifdef G4EVERBOSE
+     if(iverbose >= 3) G4cout << "ctransf10= " << transf[1][0]  << " " <<  -QP<< " " << ANV<< " " << vpPostNorm.x()<< " " << deltaPos.x()<< " " << vpPostNorm.y()<< " " << deltaPos.y()<< " " << vpPostNorm.z()<< " " << deltaPos.z()
+      << " " << deltaPInv<< " " << pAver << G4endl;
+#endif
+    
+    transf[1][1] = cosThetaAver*(vVPre.x()*vVPost.x()+vVPre.y()*vVPost.y()+vVPre.z()*vVPost.z()) +
+      sinThetaAver*(vHVPre.x()*vVPost.x()+vHVPre.y()*vVPost.y()+vHVPre.z()*vVPost.z()) +
+      OMcosThetaAver*(vHAverNorm.x()*vVPre.x()+vHAverNorm.y()*vVPre.y()+vHAverNorm.z()*vVPre.z())*
+      (vHAverNorm.x()*vVPost.x()+vHAverNorm.y()*vVPost.y()+vHAverNorm.z()*vVPost.z()) +
+      ANV*( -sinThetaAver*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z()) +
+            OMcosThetaAver*(vVPre.x()*AN2.x()+vVPre.y()*AN2.y()+vVPre.z()*AN2.z()) -
+            TMSINT*gamma*(vHAverNorm.x()*vVPre.x()+vHAverNorm.y()*vVPre.y()+vHAverNorm.z()*vVPre.z()) );
+    
+    transf[1][2] = cosThetaAver*(vUPre.x()*vVPost.x()+vUPre.y()*vVPost.y()            ) +
+      sinThetaAver*(vHUPre.x()*vVPost.x()+vHUPre.y()*vVPost.y()+vHUPre.z()*vVPost.z()) +
+      OMcosThetaAver*(vHAverNorm.x()*vUPre.x()+vHAverNorm.y()*vUPre.y()            )*
+      (vHAverNorm.x()*vVPost.x()+vHAverNorm.y()*vVPost.y()+vHAverNorm.z()*vVPost.z()) +
+      ANV*( -sinThetaAver*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y()            ) +
+            OMcosThetaAver*(vUPre.x()*AN2.x()+vUPre.y()*AN2.y()             ) -
+            TMSINT*gamma*(vHAverNorm.x()*vUPre.x()+vHAverNorm.y()*vUPre.y()            ) );
+    transf[1][2] = sinpPre*transf[1][2];
+    
+    transf[1][3] = -QAver*ANV*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y()            );
+    
+    transf[1][4] = -QAver*ANV*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z());
+    
+    // ***   Phi
+    
+    transf[2][0] = -QP*ANU*(vpPostNorm.x()*deltaPos.x()+vpPostNorm.y()*deltaPos.y()+vpPostNorm.z()*deltaPos.z())*sinpPostInv
+      *(1.+deltaPInv*pAver);
+#ifdef G4EVERBOSE
+   if(iverbose >= 3)G4cout <<"ctransf20= " << transf[2][0] <<" "<< -QP<<" "<<ANU<<" "<<vpPostNorm.x()<<" "<<deltaPos.x()<<" "<<vpPostNorm.y()<<" "<<deltaPos.y()<<" "<<vpPostNorm.z()<<" "<<deltaPos.z()<<" "<<sinpPostInv
+         <<" "<<deltaPInv<<" "<<pAver<< G4endl;
+#endif
+    transf[2][1] = cosThetaAver*(vVPre.x()*vUPost.x()+vVPre.y()*vUPost.y()            ) +
+      sinThetaAver*(vHVPre.x()*vUPost.x()+vHVPre.y()*vUPost.y()             ) +
+      OMcosThetaAver*(vHAverNorm.x()*vVPre.x()+vHAverNorm.y()*vVPre.y()+vHAverNorm.z()*vVPre.z())*
+      (vHAverNorm.x()*vUPost.x()+vHAverNorm.y()*vUPost.y()            ) +
+      ANU*( -sinThetaAver*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z()) +
+            OMcosThetaAver*(vVPre.x()*AN2.x()+vVPre.y()*AN2.y()+vVPre.z()*AN2.z()) -
+            TMSINT*gamma*(vHAverNorm.x()*vVPre.x()+vHAverNorm.y()*vVPre.y()+vHAverNorm.z()*vVPre.z()) );
+    transf[2][1] = sinpPostInv*transf[2][1];
+    
+    transf[2][2] = cosThetaAver*(vUPre.x()*vUPost.x()+vUPre.y()*vUPost.y()            ) +
+      sinThetaAver*(vHUPre.x()*vUPost.x()+vHUPre.y()*vUPost.y()             ) +
+      OMcosThetaAver*(vHAverNorm.x()*vUPre.x()+vHAverNorm.y()*vUPre.y()            )*
+      (vHAverNorm.x()*vUPost.x()+vHAverNorm.y()*vUPost.y()            ) +
+      ANU*( -sinThetaAver*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y()            ) +
+            OMcosThetaAver*(vUPre.x()*AN2.x()+vUPre.y()*AN2.y()             ) -
+            TMSINT*gamma*(vHAverNorm.x()*vUPre.x()+vHAverNorm.y()*vUPre.y()            ) );
+    transf[2][2] = sinpPostInv*sinpPre*transf[2][2];
+    
+    transf[2][3] = -QAver*ANU*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y()            )*sinpPostInv;
+#ifdef G4EVERBOSE
+    if(iverbose >= 3)G4cout <<"ctransf23= " << transf[2][3] <<" "<< -QAver<<" "<<ANU<<" "<<vUPre.x()<<" "<<vpPostNorm.x()<<" "<< vUPre.y()<<" "<<vpPostNorm.y()<<" "<<sinpPostInv<<G4endl;
+#endif
+    
+    transf[2][4] = -QAver*ANU*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z())*sinpPostInv;
+    
+    // ***   Yt
+    
+    transf[3][0] = pAver*(vUPost.x()*deltaPos.x()+vUPost.y()*deltaPos.y() )
+      *(1.+deltaPInv*pAver);
+#ifdef G4EVERBOSE
+   if(iverbose >= 3) G4cout <<"ctransf30= " << transf[3][0] <<" "<< pAver<<" "<<vUPost.x()<<" "<<deltaPos.x()<<" "<<vUPost.y()<<" "<<deltaPos.y()  
+      <<" "<<deltaPInv<<" "<<pAver<<G4endl;
+#endif
+
+    transf[3][1] = (   sinThetaAver*(vVPre.x()*vUPost.x()+vVPre.y()*vUPost.y()            ) +
+                       OMcosThetaAver*(vHVPre.x()*vUPost.x()+vHVPre.y()*vUPost.y()             ) +
+                       TMSINT*(vHAverNorm.x()*vUPost.x()+vHAverNorm.y()*vUPost.y()            )*
+                       (vHAverNorm.x()*vVPre.x()+vHAverNorm.y()*vVPre.y()+vHAverNorm.z()*vVPre.z()) )/QAver;
+    
+    transf[3][2] = (   sinThetaAver*(vUPre.x()*vUPost.x()+vUPre.y()*vUPost.y()            ) +
+                       OMcosThetaAver*(vHUPre.x()*vUPost.x()+vHUPre.y()*vUPost.y()             ) +
+                       TMSINT*(vHAverNorm.x()*vUPost.x()+vHAverNorm.y()*vUPost.y()            )*
+                       (vHAverNorm.x()*vUPre.x()+vHAverNorm.y()*vUPre.y()            ) )*sinpPre/QAver;
+#ifdef G4EVERBOSE 
+   if(iverbose >= 3) G4cout <<"ctransf32= " << transf[3][2] <<" "<< sinThetaAver<<" "<<vUPre.x()<<" "<<vUPost.x()<<" "<<vUPre.y()<<" "<<vUPost.y() <<" "<<
+                       OMcosThetaAver<<" "<<vHUPre.x()<<" "<<vUPost.x()<<" "<<vHUPre.y()<<" "<<vUPost.y() <<" "<<
+                       TMSINT<<" "<<vHAverNorm.x()<<" "<<vUPost.x()<<" "<<vHAverNorm.y()<<" "<<vUPost.y() <<" "<<
+      vHAverNorm.x()<<" "<<vUPre.x()<<" "<<vHAverNorm.y()<<" "<<vUPre.y() <<" "<<sinpPre<<" "<<QAver<<G4endl;
+#endif
+   
+    transf[3][3] = (vUPre.x()*vUPost.x()+vUPre.y()*vUPost.y()            );
+    
+    transf[3][4] = (vVPre.x()*vUPost.x()+vVPre.y()*vUPost.y()            );
+
+    // ***   Zt
+    transf[4][0] = pAver*(vVPost.x()*deltaPos.x()+vVPost.y()*deltaPos.y()+vVPost.z()*deltaPos.z())
+      *(1.+deltaPInv*pAver);
+   
+    transf[4][1] = (   sinThetaAver*(vVPre.x()*vVPost.x()+vVPre.y()*vVPost.y()+vVPre.z()*vVPost.z()) +
+                       OMcosThetaAver*(vHVPre.x()*vVPost.x()+vHVPre.y()*vVPost.y()+vHVPre.z()*vVPost.z()) +
+                       TMSINT*(vHAverNorm.x()*vVPost.x()+vHAverNorm.y()*vVPost.y()+vHAverNorm.z()*vVPost.z())*
+                       (vHAverNorm.x()*vVPre.x()+vHAverNorm.y()*vVPre.y()+vHAverNorm.z()*vVPre.z()) )/QAver;
+#ifdef G4EVERBOSE
+    if(iverbose >= 3)G4cout <<"ctransf41= " << transf[4][1] <<" "<< sinThetaAver<<" "<< OMcosThetaAver <<" "<<TMSINT<<" "<< vVPre <<" "<<vVPost <<" "<<vHVPre<<" "<<vHAverNorm <<" "<< QAver<<G4endl;
+#endif
+    
+    transf[4][2] = (   sinThetaAver*(vUPre.x()*vVPost.x()+vUPre.y()*vVPost.y()            ) +
+                       OMcosThetaAver*(vHUPre.x()*vVPost.x()+vHUPre.y()*vVPost.y()+vHUPre.z()*vVPost.z()) +
+                       TMSINT*(vHAverNorm.x()*vVPost.x()+vHAverNorm.y()*vVPost.y()+vHAverNorm.z()*vVPost.z())*
+                       (vHAverNorm.x()*vUPre.x()+vHAverNorm.y()*vUPre.y()            ) )*sinpPre/QAver;
+
+    transf[4][3] = (vUPre.x()*vVPost.x()+vUPre.y()*vVPost.y()  );
+
+    transf[4][4] = (vVPre.x()*vVPost.x()+vVPre.y()*vVPost.y()+vVPre.z()*vVPost.z()); 
+    //   if(iverbose >= 3) G4cout <<"ctransf44= " << transf[4][4] <<" "<< vVPre.x()  <<" "<<vVPost.x() <<" "<< vVPre.y() <<" "<< vVPost.y() <<" "<< vVPre.z() <<" "<< vVPost.z() << G4endl;
+
+  
+#ifdef G4EVERBOSE
+    if( iverbose >= 1 ) G4cout << "G4EP: transf matrix computed " << transf << G4endl;
+#endif
+    /*    for( G4int ii=0;ii<5;ii++){
+      for( G4int jj=0;jj<5;jj++){
+        G4cout << transf[ii][jj] << " ";
+      }
+      G4cout << G4endl;
+      } */
+   }
+  }
+  // end of calculate transformation except it NEUTRAL PARTICLE OR FIELDFREE REGION
+  /*  if( iverbose >= 1 ) G4cout << "G4EP: transf not updated but initialized " << theFirstStep << G4endl;
+  if( theFirstStep ) {
+    theTransfMat = transf;
+    theFirstStep = false;
+  }else{
+    theTransfMat = theTransfMat * transf;
+    if( iverbose >= 1 ) G4cout << "G4EP: transf matrix accumulated" << theTransfMat << G4endl;
+  } 
+  */
+    theTransfMat = transf;
+#ifdef G4EVERBOSE
+    if( iverbose >= 1 ) G4cout << "G4EP: error matrix before transformation " << fError << G4endl;
+    if( iverbose >= 2 ) G4cout << " tf * err " << theTransfMat * fError << G4endl
+                                  << " transf matrix " << theTransfMat.T() << G4endl;
+#endif
+    
+    fError = fError.similarity(theTransfMat).T();
+    //-    fError = transf * fError * transf.T();
+#ifdef G4EVERBOSE
+    if( iverbose >= 1 ) G4cout << "G4EP: error matrix propagated " << fError << G4endl;
+#endif
+
+    //? S = B*S*BT S.similarity(B)
+    //? R = S
+    // not needed * *** TRANSFORM ERROR MATRIX FROM INTERNAL TO EXTERNAL VARIABLES;
+    
+    PropagateErrorMSC( aTrack );
+    
+    PropagateErrorIoni( aTrack );
+    
+    return 0;
+}
+
+
+//------------------------------------------------------------------------
+G4int G4ErrorFreeTrajState::PropagateErrorMSC( const G4Track* aTrack )
+{ 
+  G4ThreeVector vpPre = aTrack->GetMomentum()/GeV;
+  G4double pPre = vpPre.mag();
+  G4double pBeta = pPre*pPre / (aTrack->GetTotalEnergy()/GeV);
+  G4double  stepLengthCm = aTrack->GetStep()->GetStepLength()/cm;
+
+  G4Material* mate = aTrack->GetVolume()->GetLogicalVolume()->GetMaterial();
+  G4double effZ, effA;
+  CalculateEffectiveZandA( mate, effZ, effA );
+
+#ifdef G4EVERBOSE
+  if( iverbose >= 4 ) G4cout << "material " << mate->GetName() 
+                     //<< " " << mate->GetZ() << " "  << mate->GetA() 
+                        << " " << effZ << " " << effA
+                        << " "  << mate->GetDensity()/g*mole << " " << mate->GetRadlen()/cm << " " << mate->GetNuclearInterLength()/cm << G4endl;
+#endif
+
+  G4double RI = stepLengthCm / (mate->GetRadlen()/cm);
+#ifdef G4EVERBOSE
+  if( iverbose >= 4 ) G4cout << std::setprecision(6) << std::setw(6) << "G4EP:MSC: RI " << RI << " stepLengthCm " << stepLengthCm << " radlen " << (mate->GetRadlen()/cm) << " " << RI*1.e10 << G4endl;
+#endif
+  G4double charge = aTrack->GetDynamicParticle()->GetCharge();
+  G4double DD = 1.8496E-4*RI*(charge/pBeta * charge/pBeta );
+#ifdef G4EVERBOSE
+  if( iverbose >= 3 ) G4cout << "G4EP:MSC: D*1E6= " << DD*1.E6 <<" pBeta " << pBeta << G4endl;
+#endif
+  G4double S1 = DD*stepLengthCm*stepLengthCm/3.;
+  G4double S2 = DD;
+  G4double S3 = DD*stepLengthCm/2.;
+
+  G4double CLA = std::sqrt( vpPre.x() * vpPre.x() + vpPre.y() * vpPre.y() )/pPre;
+#ifdef G4EVERBOSE
+  if( iverbose >= 2 ) G4cout << std::setw(6) << "G4EP:MSC: RI " << RI << " S1 " << S1 << " S2 "  << S2 << " S3 "  << S3 << " CLA " << CLA << G4endl;
+#endif
+  fError[1][1] += S2;
+  fError[1][4] -= S3;
+  fError[2][2] += S2/CLA/CLA;
+  fError[2][3] += S3/CLA;
+  fError[3][3] += S1;
+  fError[4][4] += S1;
+
+#ifdef G4EVERBOSE
+  if( iverbose >= 2 ) G4cout << "G4EP:MSC: error matrix propagated msc " << fError << G4endl;
+#endif
+
+  return 0;
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorFreeTrajState::CalculateEffectiveZandA( const G4Material* mate, G4double& effZ, G4double& effA )
+{ 
+  effZ = 0.;
+  effA = 0.;
+  G4int ii, nelem = mate->GetNumberOfElements();
+  const G4double* fracVec = mate->GetFractionVector();
+  for(ii=0; ii < nelem; ii++ ) {
+    effZ += mate->GetElement( ii )->GetZ() * fracVec[ii];
+    effA += mate->GetElement( ii )->GetA() * fracVec[ii] /g*mole;
+  }
+
+}
+
+
+//------------------------------------------------------------------------
+G4int G4ErrorFreeTrajState::PropagateErrorIoni( const G4Track* aTrack )
+{ 
+  G4double stepLengthCm = aTrack->GetStep()->GetStepLength()/cm;
+  G4double DEDX2;
+  if( stepLengthCm < 1.E-7 ) {
+    DEDX2=0.;
+  }
+  //  *     Calculate xi factor (KeV).
+  G4Material* mate = aTrack->GetVolume()->GetLogicalVolume()->GetMaterial();
+  G4double effZ, effA;
+  CalculateEffectiveZandA( mate, effZ, effA );
+
+  G4double Etot = aTrack->GetTotalEnergy()/GeV;
+  G4double beta = aTrack->GetMomentum().mag()/GeV / Etot;
+  G4double mass = aTrack->GetDynamicParticle()->GetMass() / GeV;
+  G4double gamma = Etot / mass;
+  
+  // *     Calculate xi factor (KeV).
+  G4double XI = 153.5*effZ*stepLengthCm*(mate->GetDensity()/mg*mole) / 
+    (effA*beta*beta);
+
+#ifdef G4EVERBOSE
+  if( iverbose >= 2 ){
+    G4cout << "G4EP:IONI: XI " << XI << " beta " << beta << " gamma " << gamma << G4endl;
+    G4cout << " density " << (mate->GetDensity()/mg*mole) << " effA " << effA << " step " << stepLengthCm << G4endl;
+  }
+#endif
+  // *     Maximum energy transfer to atomic electron (KeV).
+  G4double eta = beta*gamma;
+  G4double etasq = eta*eta;
+  G4double eMass = 0.51099906/GeV;
+  G4double massRatio = eMass / mass;
+  G4double F1 = 2*eMass*etasq;
+  G4double F2 = 1. + 2. * massRatio * gamma + massRatio * massRatio;
+  G4double Emax = 1.E+6*F1/F2;
+
+  //  * *** and now sigma**2  in GeV
+  G4double dedxSq = XI*Emax*(1.-(beta*beta/2.))*1.E-12;
+#ifdef G4EVERBOSE
+  if( iverbose >= 2 ) G4cout << "G4EP:IONI: DEDX2 " << dedxSq << " emass " << eMass << " Emax " << Emax << G4endl;
+#endif
+
+  //  if( iverbose >= 2 ) G4cout << "G4EP:IONI: Etot " << Etot << " DEDX2 " << dedxSq << " emass " << eMass << G4endl;
+  
+  G4double pPre6 = (aTrack->GetStep()->GetPreStepPoint()->GetMomentum()/GeV).mag();
+  pPre6 = std::pow(pPre6, 6 );
+  //Apply it to error 
+  fError[0][0] += Etot*Etot*dedxSq / pPre6;
+#ifdef G4EVERBOSE
+  if( iverbose >= 2 ) G4cout << "G4:IONI getot " << Etot << " dedx2 " << dedxSq << " p " << pPre6 << G4endl;
+  if( iverbose >= 2 ) G4cout << "G4EP:IONI: error_from_ionisation " << (Etot*Etot*dedxSq) / pPre6 << G4endl;
+#endif
+
+  return 0;
+}
+
Index: /trunk/source/error_propagation/src/G4ErrorGeomVolumeTarget.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorGeomVolumeTarget.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorGeomVolumeTarget.cc	(revision 815)
@@ -0,0 +1,77 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorGeomVolumeTarget.cc,v 1.3 2007/05/31 15:28:51 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4ErrorGeomVolumeTarget.hh"
+#include "G4Point3D.hh"
+#include "G4ThreeVector.hh"
+#include "G4Step.hh"
+
+#ifdef G4VERBOSE
+#include "G4ErrorPropagatorData.hh" //for verbosity checking
+#endif
+
+//------------------------------------------------------------------------
+G4ErrorGeomVolumeTarget::G4ErrorGeomVolumeTarget( const G4String& name )
+{
+  theType = G4ErrorTarget_GeomVolume;
+  theName = name; 
+}
+
+
+//------------------------------------------------------------------------
+G4bool G4ErrorGeomVolumeTarget::TargetReached( const G4Step* aStep )
+{
+  if( aStep->GetTrack()->GetNextVolume() != 0 ){
+#ifdef G4VERBOSE
+    if(G4ErrorPropagatorData::verbose() >= 3 ) { 
+      G4cout << " G4ErrorGeomVolumeTarget::TargetReached( "
+             << aStep->GetTrack()->GetNextVolume()->GetName()
+             << " =? " <<  theName  << G4endl;
+    }
+#endif
+    if( aStep->GetTrack()->GetNextVolume()->GetName() == theName ){
+      return 1;
+    } else {
+      return 0;
+    }
+  } else {
+    return 0;
+  }
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorGeomVolumeTarget::Dump( const G4String& msg ) const
+{
+  G4cout << msg << " G4ErrorGeomVolumeTarget:  Volume " << theName << G4endl;
+}
Index: /trunk/source/error_propagation/src/G4ErrorMagFieldLimitProcess.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorMagFieldLimitProcess.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorMagFieldLimitProcess.cc	(revision 815)
@@ -0,0 +1,93 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorMagFieldLimitProcess.cc,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4ErrorMagFieldLimitProcess.hh"
+#include "G4ErrorMessenger.hh"
+#include "G4TransportationManager.hh"
+#include "G4FieldManager.hh"
+#include "G4Field.hh"
+#include "G4Track.hh"
+
+#ifdef G4VERBOSE
+#include "G4ErrorPropagatorData.hh"
+#endif
+
+//------------------------------------------------------------------------
+G4ErrorMagFieldLimitProcess::
+G4ErrorMagFieldLimitProcess(const G4String& processName)
+  : G4VErrorLimitProcess(processName) 
+{
+  theStepLimit = kInfinity;
+}
+
+
+//------------------------------------------------------------------------
+G4ErrorMagFieldLimitProcess::~G4ErrorMagFieldLimitProcess()
+{ }
+
+
+//------------------------------------------------------------------------
+G4double G4ErrorMagFieldLimitProcess::
+PostStepGetPhysicalInteractionLength( const G4Track& aTrack, G4double ,
+                                            G4ForceCondition* condition )
+{
+  *condition = NotForced;
+  const G4Field* field =
+    G4TransportationManager::GetTransportationManager()->GetFieldManager()
+    ->GetDetectorField();
+
+  theStepLength = kInfinity;
+  if( field != 0 ) {
+    G4ThreeVector trkPosi = aTrack.GetPosition();
+    G4double pos1[3];
+       pos1[0] = trkPosi.x(); pos1[1] = trkPosi.y(); pos1[2] = trkPosi.z();
+
+    G4double h1[3];
+    field->GetFieldValue( pos1, h1 );
+
+    G4ThreeVector BVec(h1[0],h1[1],h1[2]);
+    G4double pmag = aTrack.GetMomentum().mag();
+    G4double BPerpMom = BVec.cross( pmag ).mag() / pmag;
+
+    theStepLength = theStepLimit * pmag / BPerpMom; 
+#ifdef G4VERBOSE
+  if(G4ErrorPropagatorData::verbose() >= 3 ) { 
+    G4cout <<  "G4ErrorMagFieldLimitProcess:: stepLength "
+           << theStepLength << " B " << BPerpMom << " BVec " << BVec
+           << " pmag " << pmag << G4endl;
+  }
+#endif
+  }
+
+  return theStepLength;
+}
Index: /trunk/source/error_propagation/src/G4ErrorMatrix.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorMatrix.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorMatrix.cc	(revision 815)
@@ -0,0 +1,1735 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorMatrix.cc,v 1.3 2007/06/21 15:04:06 gunter Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file
+// ------------------------------------------------------------
+
+#include "globals.hh"
+
+#include <cmath>
+#include <iostream>
+
+#include "G4ErrorMatrix.hh"
+#include "G4ErrorSymMatrix.hh"
+
+// Simple operation for all elements
+
+#define SIMPLE_UOP(OPER)                            \
+    G4ErrorMatrixIter a=m.begin();                  \
+    G4ErrorMatrixIter e=m.end();                    \
+   for(;a!=e; a++) (*a) OPER t;
+
+#define SIMPLE_BOP(OPER)                            \
+    G4ErrorMatrixIter a=m.begin();                  \
+    G4ErrorMatrixConstIter b=m2.m.begin();          \
+    G4ErrorMatrixIter e=m.end();                    \
+   for(;a!=e; a++, b++) (*a) OPER (*b);
+
+#define SIMPLE_TOP(OPER)                            \
+    G4ErrorMatrixConstIter a=m1.m.begin();          \
+    G4ErrorMatrixConstIter b=m2.m.begin();          \
+    G4ErrorMatrixIter t=mret.m.begin();             \
+    G4ErrorMatrixConstIter e=m1.m.end();            \
+   for(;a!=e; a++, b++, t++) (*t) = (*a) OPER (*b);
+
+// Static functions.
+
+#define CHK_DIM_2(r1,r2,c1,c2,fun) \
+   if (r1!=r2 || c1!=c2)  { \
+    G4ErrorMatrix::error("Range error in Matrix function " #fun "(1).");  \
+   }
+
+#define CHK_DIM_1(c1,r2,fun) \
+   if (c1!=r2) { \
+     G4ErrorMatrix::error("Range error in Matrix function " #fun "(2)."); \
+   }
+
+// Constructors. (Default constructors are inlined and in .icc file)
+
+G4ErrorMatrix::G4ErrorMatrix(G4int p,G4int q)
+   : m(p*q), nrow(p), ncol(q)
+{
+  size = nrow * ncol;
+}
+
+G4ErrorMatrix::G4ErrorMatrix(G4int p,G4int q,G4int init)
+   : m(p*q), nrow(p), ncol(q)
+{
+   size = nrow * ncol;
+
+   if (size > 0)
+   {
+      switch(init)
+      {
+      case 0:
+         break;
+
+      case 1:
+         {
+            if ( ncol == nrow )
+            {
+               G4ErrorMatrixIter a = m.begin();
+               G4ErrorMatrixIter b = m.end();
+               for( ; a<b; a+=(ncol+1)) *a = 1.0;
+            } else {
+               error("Invalid dimension in G4ErrorMatrix(G4int,G4int,1).");
+            }
+            break;
+         }
+      default:
+         error("G4ErrorMatrix: initialization must be either 0 or 1.");
+      }
+   }
+}
+
+//
+// Destructor
+//
+G4ErrorMatrix::~G4ErrorMatrix()
+{
+}
+
+G4ErrorMatrix::G4ErrorMatrix(const G4ErrorMatrix &m1)
+   : m(m1.size), nrow(m1.nrow), ncol(m1.ncol), size(m1.size)
+{
+   m = m1.m;
+}
+
+G4ErrorMatrix::G4ErrorMatrix(const G4ErrorSymMatrix &m1)
+   : m(m1.nrow*m1.nrow), nrow(m1.nrow), ncol(m1.nrow)
+{
+   size = nrow * ncol;
+
+   G4int n = ncol;
+   G4ErrorMatrixConstIter sjk = m1.m.begin();
+   G4ErrorMatrixIter m1j = m.begin();
+   G4ErrorMatrixIter mj  = m.begin();
+   // j >= k
+   for(G4int j=1;j<=nrow;j++)
+   {
+      G4ErrorMatrixIter mjk = mj;
+      G4ErrorMatrixIter mkj = m1j;
+      for(G4int k=1;k<=j;k++)
+      {
+         *(mjk++) = *sjk;
+         if(j!=k) *mkj = *sjk;
+         sjk++;
+         mkj += n;
+      }
+      mj += n;
+      m1j++;
+   }
+}
+
+//
+//
+// Sub matrix
+//
+//
+
+G4ErrorMatrix G4ErrorMatrix::sub(G4int min_row, G4int max_row,
+                         G4int min_col,G4int max_col) const
+{
+  G4ErrorMatrix mret(max_row-min_row+1,max_col-min_col+1);
+  if(max_row > num_row() || max_col >num_col())
+    { error("G4ErrorMatrix::sub: Index out of range"); }
+  G4ErrorMatrixIter a = mret.m.begin();
+  G4int nc = num_col();
+  G4ErrorMatrixConstIter b1 = m.begin() + (min_row - 1) * nc + min_col - 1;
+  
+  for(G4int irow=1; irow<=mret.num_row(); irow++)
+  {
+    G4ErrorMatrixConstIter brc = b1;
+    for(G4int icol=1; icol<=mret.num_col(); icol++)
+    {
+      *(a++) = *(brc++);
+    }
+    b1 += nc;
+  }
+  return mret;
+}
+
+void G4ErrorMatrix::sub(G4int row,G4int col,const G4ErrorMatrix &m1)
+{
+  if(row <1 || row+m1.num_row()-1 > num_row() || 
+     col <1 || col+m1.num_col()-1 > num_col()   )
+    { error("G4ErrorMatrix::sub: Index out of range"); }
+  G4ErrorMatrixConstIter a = m1.m.begin();
+  G4int nc = num_col();
+  G4ErrorMatrixIter b1 = m.begin() + (row - 1) * nc + col - 1;
+  
+  for(G4int irow=1; irow<=m1.num_row(); irow++)
+  {
+    G4ErrorMatrixIter brc = b1;
+    for(G4int icol=1; icol<=m1.num_col(); icol++)
+    {
+      *(brc++) = *(a++);
+    }
+    b1 += nc;
+  }
+}
+
+//
+// Direct sum of two matricies
+//
+
+G4ErrorMatrix dsum(const G4ErrorMatrix &m1, const G4ErrorMatrix &m2)
+{
+  G4ErrorMatrix mret(m1.num_row() + m2.num_row(), m1.num_col() + m2.num_col(),
+                 0);
+  mret.sub(1,1,m1);
+  mret.sub(m1.num_row()+1,m1.num_col()+1,m2);
+  return mret;
+}
+
+/* -----------------------------------------------------------------------
+   This section contains support routines for matrix.h. This section contains
+   The two argument functions +,-. They call the copy constructor and +=,-=.
+   ----------------------------------------------------------------------- */
+
+G4ErrorMatrix G4ErrorMatrix::operator- () const 
+{
+   G4ErrorMatrix m2(nrow, ncol);
+   G4ErrorMatrixConstIter a=m.begin();
+   G4ErrorMatrixIter b=m2.m.begin();
+   G4ErrorMatrixConstIter e=m.end();
+   for(;a<e; a++, b++) (*b) = -(*a);
+   return m2;
+}
+
+G4ErrorMatrix operator+(const G4ErrorMatrix &m1,const G4ErrorMatrix &m2)
+{
+  G4ErrorMatrix mret(m1.nrow, m1.ncol);
+  CHK_DIM_2(m1.num_row(),m2.num_row(), m1.num_col(),m2.num_col(),+);
+  SIMPLE_TOP(+)
+  return mret;
+}
+
+//
+// operator -
+//
+
+G4ErrorMatrix operator-(const G4ErrorMatrix &m1,const G4ErrorMatrix &m2)
+{
+  G4ErrorMatrix mret(m1.num_row(), m1.num_col());
+  CHK_DIM_2(m1.num_row(),m2.num_row(),
+                         m1.num_col(),m2.num_col(),-);
+  SIMPLE_TOP(-)
+  return mret;
+}
+
+/* -----------------------------------------------------------------------
+   This section contains support routines for matrix.h. This file contains
+   The two argument functions *,/. They call copy constructor and then /=,*=.
+   ----------------------------------------------------------------------- */
+
+G4ErrorMatrix operator/(const G4ErrorMatrix &m1,G4double t)
+{
+  G4ErrorMatrix mret(m1);
+  mret /= t;
+  return mret;
+}
+
+G4ErrorMatrix operator*(const G4ErrorMatrix &m1,G4double t)
+{
+  G4ErrorMatrix mret(m1);
+  mret *= t;
+  return mret;
+}
+
+G4ErrorMatrix operator*(G4double t,const G4ErrorMatrix &m1)
+{
+  G4ErrorMatrix mret(m1);
+  mret *= t;
+  return mret;
+}
+
+G4ErrorMatrix operator*(const G4ErrorMatrix &m1,const G4ErrorMatrix &m2)
+{
+  // initialize matrix to 0.0
+  G4ErrorMatrix mret(m1.nrow,m2.ncol,0);
+  CHK_DIM_1(m1.ncol,m2.nrow,*);
+
+  G4int m1cols = m1.ncol;
+  G4int m2cols = m2.ncol;
+
+  for (G4int i=0; i<m1.nrow; i++)
+  {
+     for (G4int j=0; j<m1cols; j++) 
+     {
+         G4double temp = m1.m[i*m1cols+j];
+         G4ErrorMatrixIter pt = mret.m.begin() + i*m2cols;
+
+        // Loop over k (the column index in matrix m2)
+        G4ErrorMatrixConstIter pb = m2.m.begin() + m2cols*j;
+        const G4ErrorMatrixConstIter pblast = pb + m2cols;
+        while (pb < pblast)
+        {
+           (*pt) += temp * (*pb);
+           pb++;
+           pt++;
+        }
+     }
+  }
+  return mret;
+}
+
+/* -----------------------------------------------------------------------
+   This section contains the assignment and inplace operators =,+=,-=,*=,/=.
+   ----------------------------------------------------------------------- */
+
+G4ErrorMatrix & G4ErrorMatrix::operator+=(const G4ErrorMatrix &m2)
+{
+  CHK_DIM_2(num_row(),m2.num_row(),num_col(),m2.num_col(),+=);
+  SIMPLE_BOP(+=)
+  return (*this);
+}
+
+G4ErrorMatrix & G4ErrorMatrix::operator-=(const G4ErrorMatrix &m2)
+{
+  CHK_DIM_2(num_row(),m2.num_row(),num_col(),m2.num_col(),-=);
+  SIMPLE_BOP(-=)
+  return (*this);
+}
+
+G4ErrorMatrix & G4ErrorMatrix::operator/=(G4double t)
+{
+  SIMPLE_UOP(/=)
+  return (*this);
+}
+
+G4ErrorMatrix & G4ErrorMatrix::operator*=(G4double t)
+{
+  SIMPLE_UOP(*=)
+  return (*this);
+}
+
+G4ErrorMatrix & G4ErrorMatrix::operator=(const G4ErrorMatrix &m1)
+{
+   if(m1.nrow*m1.ncol != size) //??fixme?? m1.size != size
+   {
+      size = m1.nrow * m1.ncol;
+      m.resize(size); //??fixme?? if (size < m1.size) m.resize(m1.size);
+   }
+   nrow = m1.nrow;
+   ncol = m1.ncol;
+   m = m1.m;
+   return (*this);
+}
+
+
+// Print the G4ErrorMatrix.
+
+std::ostream& operator<<(std::ostream &s, const G4ErrorMatrix &q)
+{
+  s << "\n";
+
+  // Fixed format needs 3 extra characters for field,
+  // while scientific needs 7
+
+  G4int width;
+  if(s.flags() & std::ios::fixed)
+    { width = s.precision()+3; }
+  else
+    { width = s.precision()+7; }
+  for(G4int irow = 1; irow<= q.num_row(); irow++)
+    {
+      for(G4int icol = 1; icol <= q.num_col(); icol++)
+        {
+          s.width(width);
+          s << q(irow,icol) << " ";
+        }
+      s << G4endl;
+    }
+  return s;
+}
+
+G4ErrorMatrix G4ErrorMatrix::T() const
+{
+   G4ErrorMatrix mret(ncol,nrow);
+    G4ErrorMatrixConstIter pl = m.end();
+    G4ErrorMatrixConstIter pme = m.begin();
+    G4ErrorMatrixIter pt = mret.m.begin();
+    G4ErrorMatrixIter ptl = mret.m.end();
+   for (; pme < pl; pme++, pt+=nrow)
+   {
+      if (pt >= ptl) { pt -= (size-1); }
+      (*pt) = (*pme);
+   }
+   return mret;
+}
+
+G4ErrorMatrix
+G4ErrorMatrix::apply(G4double (*f)(G4double, G4int, G4int)) const
+{
+  G4ErrorMatrix mret(num_row(),num_col());
+  G4ErrorMatrixConstIter a = m.begin();
+  G4ErrorMatrixIter b = mret.m.begin();
+  for(G4int ir=1;ir<=num_row();ir++)
+  {
+    for(G4int ic=1;ic<=num_col();ic++)
+    {
+      *(b++) = (*f)(*(a++), ir, ic);
+    }
+  }
+  return mret;
+}
+
+G4int G4ErrorMatrix::dfinv_matrix(G4int *ir) {
+  if (num_col()!=num_row())
+    { error("dfinv_matrix: G4ErrorMatrix is not NxN"); }
+  G4int n = num_col();
+  if (n==1) { return 0; }
+
+  G4double s31, s32;
+  G4double s33, s34;
+
+  G4ErrorMatrixIter m11 = m.begin();
+  G4ErrorMatrixIter m12 = m11 + 1;
+  G4ErrorMatrixIter m21 = m11 + n;
+  G4ErrorMatrixIter m22 = m12 + n;
+  *m21 = -(*m22) * (*m11) * (*m21);
+  *m12 = -(*m12);
+  if (n>2)
+  {
+    G4ErrorMatrixIter mi = m.begin() + 2 * n;
+    G4ErrorMatrixIter mii= m.begin() + 2 * n + 2;
+    G4ErrorMatrixIter mimim = m.begin() + n + 1;
+    for (G4int i=3;i<=n;i++)
+    {
+      G4int im2 = i - 2;
+      G4ErrorMatrixIter mj = m.begin();
+      G4ErrorMatrixIter mji = mj + i - 1;
+      G4ErrorMatrixIter mij = mi;
+      for (G4int j=1;j<=im2;j++)
+      { 
+        s31 = 0.0;
+        s32 = *mji;
+        G4ErrorMatrixIter mkj = mj + j - 1;
+        G4ErrorMatrixIter mik = mi + j - 1;
+        G4ErrorMatrixIter mjkp = mj + j;
+        G4ErrorMatrixIter mkpi = mj + n + i - 1;
+        for (G4int k=j;k<=im2;k++)
+        {
+          s31 += (*mkj) * (*(mik++));
+          s32 += (*(mjkp++)) * (*mkpi);
+          mkj += n;
+          mkpi += n;
+        }
+        *mij = -(*mii) * (((*(mij-n)))*( (*(mii-1)))+(s31));
+        *mji = -s32;
+        mj += n;
+        mji += n;
+        mij++;
+      }
+      *(mii-1) = -(*mii) * (*mimim) * (*(mii-1));
+      *(mimim+1) = -(*(mimim+1));
+      mi += n;
+      mimim += (n+1);
+      mii += (n+1);
+    }
+  }
+  G4ErrorMatrixIter mi = m.begin();
+  G4ErrorMatrixIter mii = m.begin();
+  for (G4int i=1;i<n;i++)
+  {
+    G4int ni = n - i;
+    G4ErrorMatrixIter mij = mi;
+    G4int j;
+    for (j=1; j<=i;j++)
+    {
+      s33 = *mij;
+      G4ErrorMatrixIter mikj = mi + n + j - 1;
+      G4ErrorMatrixIter miik = mii + 1;
+      G4ErrorMatrixIter min_end = mi + n;
+      for (;miik<min_end;)
+      {
+        s33 += (*mikj) * (*(miik++));
+        mikj += n;
+      }
+      *(mij++) = s33;
+    }
+    for (j=1;j<=ni;j++)
+    {
+      s34 = 0.0;
+      G4ErrorMatrixIter miik = mii + j;
+      G4ErrorMatrixIter mikij = mii + j * n + j;
+      for (G4int k=j;k<=ni;k++)
+      {
+        s34 += *mikij * (*(miik++));
+        mikij += n;
+      }
+      *(mii+j) = s34;
+    }
+    mi += n;
+    mii += (n+1);
+  }
+  G4int nxch = ir[n];
+  if (nxch==0) return 0;
+  for (G4int mm=1;mm<=nxch;mm++)
+  {
+    G4int k = nxch - mm + 1;
+    G4int ij = ir[k];
+    G4int i = ij >> 12;
+    G4int j = ij%4096;
+    G4ErrorMatrixIter mki = m.begin() + i - 1;
+    G4ErrorMatrixIter mkj = m.begin() + j - 1;
+    for (k=1; k<=n;k++)
+    {
+      // 2/24/05 David Sachs fix of improper swap bug that was present
+      // for many years:
+      G4double ti = *mki; // 2/24/05
+      *mki = *mkj;
+      *mkj = ti;        // 2/24/05
+      mki += n;
+      mkj += n;
+    }
+  }
+  return 0;
+}
+
+G4int G4ErrorMatrix::dfact_matrix(G4double &det, G4int *ir)
+{
+  if (ncol!=nrow)
+     error("dfact_matrix: G4ErrorMatrix is not NxN");
+
+  G4int ifail, jfail;
+  G4int n = ncol;
+
+  G4double tf;
+  G4double g1 = 1.0e-19, g2 = 1.0e19;
+
+  G4double p, q, t;
+  G4double s11, s12;
+
+  G4double epsilon = 8*DBL_EPSILON;
+  // could be set to zero (like it was before)
+  // but then the algorithm often doesn't detect
+  // that a matrix is singular
+
+  G4int normal = 0, imposs = -1;
+  G4int jrange = 0, jover = 1, junder = -1;
+  ifail = normal;
+  jfail = jrange;
+  G4int nxch = 0;
+  det = 1.0;
+  G4ErrorMatrixIter mj = m.begin();
+  G4ErrorMatrixIter mjj = mj;
+  for (G4int j=1;j<=n;j++)
+  {
+    G4int k = j;
+    p = (std::fabs(*mjj));
+    if (j!=n) {
+      G4ErrorMatrixIter mij = mj + n + j - 1; 
+      for (G4int i=j+1;i<=n;i++)
+      {
+        q = (std::fabs(*(mij)));
+        if (q > p)
+        {
+          k = i;
+          p = q;
+        }
+        mij += n;
+      }
+      if (k==j)
+      {
+        if (p <= epsilon)
+        {
+          det = 0;
+          ifail = imposs;
+          jfail = jrange;
+          return ifail;
+        }
+        det = -det; // in this case the sign of the determinant
+                    // must not change. So I change it twice. 
+      }
+      G4ErrorMatrixIter mjl = mj;
+      G4ErrorMatrixIter mkl = m.begin() + (k-1)*n;
+      for (G4int l=1;l<=n;l++)
+      {
+        tf = *mjl;
+        *(mjl++) = *mkl;
+        *(mkl++) = tf;
+      }
+      nxch = nxch + 1;  // this makes the determinant change its sign
+      ir[nxch] = (((j)<<12)+(k));
+    }
+    else
+    {
+      if (p <= epsilon)
+      {
+        det = 0.0;
+        ifail = imposs;
+        jfail = jrange;
+        return ifail;
+      }
+    }
+    det *= *mjj;
+    *mjj = 1.0 / *mjj;
+    t = (std::fabs(det));
+    if (t < g1)
+    {
+      det = 0.0;
+      if (jfail == jrange) jfail = junder;
+    }
+    else if (t > g2)
+    {
+      det = 1.0;
+      if (jfail==jrange) jfail = jover;
+    }
+    if (j!=n)
+    {
+      G4ErrorMatrixIter mk = mj + n;
+      G4ErrorMatrixIter mkjp = mk + j;
+      G4ErrorMatrixIter mjk = mj + j;
+      for (k=j+1;k<=n;k++)
+      {
+        s11 = - (*mjk);
+        s12 = - (*mkjp);
+        if (j!=1)
+        {
+          G4ErrorMatrixIter mik = m.begin() + k - 1;
+          G4ErrorMatrixIter mijp = m.begin() + j;
+          G4ErrorMatrixIter mki = mk;
+          G4ErrorMatrixIter mji = mj;
+          for (G4int i=1;i<j;i++)
+          {
+            s11 += (*mik) * (*(mji++));
+            s12 += (*mijp) * (*(mki++));
+            mik += n;
+            mijp += n;
+          }
+        }
+        *(mjk++) = -s11 * (*mjj);
+        *(mkjp) = -(((*(mjj+1)))*((*(mkjp-1)))+(s12));
+        mk += n;
+        mkjp += n;
+      }
+    }
+    mj += n;
+    mjj += (n+1);
+  }
+  if (nxch%2==1) det = -det;
+  if (jfail !=jrange) det = 0.0;
+  ir[n] = nxch;
+  return 0;
+}
+
+void G4ErrorMatrix::invert(G4int &ierr)
+{
+  if(ncol != nrow)
+     { error("G4ErrorMatrix::invert: G4ErrorMatrix is not NxN"); }
+
+  static G4int max_array = 20;
+  static G4int *ir = new G4int [max_array+1];
+
+  if (ncol > max_array)
+  {
+    delete [] ir;
+    max_array = nrow;
+    ir = new G4int [max_array+1];
+  }
+  G4double t1, t2, t3;
+  G4double det, temp, s;
+  G4int ifail;
+  switch(nrow)
+  {
+  case 3:
+    G4double c11,c12,c13,c21,c22,c23,c31,c32,c33;
+    ifail = 0;
+    c11 = (*(m.begin()+4)) * (*(m.begin()+8))
+        - (*(m.begin()+5)) * (*(m.begin()+7));
+    c12 = (*(m.begin()+5)) * (*(m.begin()+6))
+        - (*(m.begin()+3)) * (*(m.begin()+8));
+    c13 = (*(m.begin()+3)) * (*(m.begin()+7))
+        - (*(m.begin()+4)) * (*(m.begin()+6));
+    c21 = (*(m.begin()+7)) * (*(m.begin()+2))
+        - (*(m.begin()+8)) * (*(m.begin()+1));
+    c22 = (*(m.begin()+8)) * (*m.begin())
+        - (*(m.begin()+6)) * (*(m.begin()+2));
+    c23 = (*(m.begin()+6)) * (*(m.begin()+1))
+        - (*(m.begin()+7)) * (*m.begin());
+    c31 = (*(m.begin()+1)) * (*(m.begin()+5))
+        - (*(m.begin()+2)) * (*(m.begin()+4));
+    c32 = (*(m.begin()+2)) * (*(m.begin()+3))
+        - (*m.begin()) * (*(m.begin()+5));
+    c33 = (*m.begin()) * (*(m.begin()+4))
+        - (*(m.begin()+1)) * (*(m.begin()+3));
+    t1 = std::fabs(*m.begin());
+    t2 = std::fabs(*(m.begin()+3));
+    t3 = std::fabs(*(m.begin()+6));
+    if (t1 >= t2)
+    {
+      if (t3 >= t1)
+      {
+        temp = *(m.begin()+6);
+        det = c23*c12-c22*c13;
+      }
+      else
+      {
+        temp = *(m.begin());
+        det = c22*c33-c23*c32;
+      }
+    }
+    else if (t3 >= t2)
+    {
+      temp = *(m.begin()+6);
+      det = c23*c12-c22*c13;
+    }
+    else
+    {
+      temp = *(m.begin()+3);
+      det = c13*c32-c12*c33;
+    }
+    if (det==0)
+    {
+      ierr = 1;
+      return;
+    }
+    {
+      G4double s = temp/det;
+      G4ErrorMatrixIter mm = m.begin();
+      *(mm++) = s*c11;
+      *(mm++) = s*c21;
+      *(mm++) = s*c31;
+      *(mm++) = s*c12;
+      *(mm++) = s*c22;
+      *(mm++) = s*c32;
+      *(mm++) = s*c13;
+      *(mm++) = s*c23;
+      *(mm) = s*c33;
+    }
+    break;
+  case 2:
+    ifail = 0;
+    det = (*m.begin())*(*(m.begin()+3)) - (*(m.begin()+1))*(*(m.begin()+2));
+    if (det==0)
+    {
+      ierr = 1;
+      return;
+    }
+    s = 1.0/det;
+    temp = s*(*(m.begin()+3));
+    *(m.begin()+1) *= -s;
+    *(m.begin()+2) *= -s;
+    *(m.begin()+3) = s*(*m.begin());
+    *(m.begin()) = temp;
+    break;
+  case 1:
+    ifail = 0;
+    if ((*(m.begin()))==0)
+    {
+      ierr = 1;
+      return;
+    }
+    *(m.begin()) = 1.0/(*(m.begin()));
+    break;
+  case 4:
+    invertHaywood4(ierr);
+    return;
+  case 5:
+    invertHaywood5(ierr);
+    return;
+  case 6:
+    invertHaywood6(ierr);
+    return;
+  default:
+    ifail = dfact_matrix(det, ir);
+    if(ifail) {
+      ierr = 1;
+      return;
+    }
+    dfinv_matrix(ir);
+    break;
+  }
+  ierr = 0;
+  return;
+}
+
+G4double G4ErrorMatrix::determinant() const
+{
+  static G4int max_array = 20;
+  static G4int *ir = new G4int [max_array+1];
+  if(ncol != nrow)
+    { error("G4ErrorMatrix::determinant: G4ErrorMatrix is not NxN"); }
+  if (ncol > max_array)
+  {
+    delete [] ir;
+    max_array = nrow;
+    ir = new G4int [max_array+1];
+  }
+  G4double det;
+  G4ErrorMatrix mt(*this);
+  G4int i = mt.dfact_matrix(det, ir);
+  if(i==0) return det;
+  return 0;
+}
+
+G4double G4ErrorMatrix::trace() const
+{
+  G4double t = 0.0;
+  for (G4ErrorMatrixConstIter d = m.begin(); d < m.end(); d += (ncol+1) )
+  {
+    t += *d;
+  }
+  return t;
+}
+
+void G4ErrorMatrix::error(const char *s)
+{
+  G4cerr << s << G4endl;
+  G4cerr << "---Exiting to System." << G4endl;
+  abort();
+}
+
+
+// Aij are indices for a 6x6 matrix.
+// Mij are indices for a 5x5 matrix.
+// Fij are indices for a 4x4 matrix.
+
+#define A00 0
+#define A01 1
+#define A02 2
+#define A03 3
+#define A04 4
+#define A05 5
+
+#define A10 6
+#define A11 7
+#define A12 8
+#define A13 9
+#define A14 10
+#define A15 11
+
+#define A20 12
+#define A21 13
+#define A22 14
+#define A23 15
+#define A24 16
+#define A25 17
+
+#define A30 18
+#define A31 19
+#define A32 20
+#define A33 21
+#define A34 22
+#define A35 23
+
+#define A40 24
+#define A41 25
+#define A42 26
+#define A43 27
+#define A44 28
+#define A45 29
+
+#define A50 30
+#define A51 31
+#define A52 32
+#define A53 33
+#define A54 34
+#define A55 35
+
+#define M00 0
+#define M01 1
+#define M02 2
+#define M03 3
+#define M04 4
+
+#define M10 5
+#define M11 6
+#define M12 7
+#define M13 8
+#define M14 9
+
+#define M20 10
+#define M21 11
+#define M22 12
+#define M23 13
+#define M24 14
+
+#define M30 15
+#define M31 16
+#define M32 17
+#define M33 18
+#define M34 19
+
+#define M40 20
+#define M41 21
+#define M42 22
+#define M43 23
+#define M44 24
+
+#define F00 0
+#define F01 1
+#define F02 2
+#define F03 3
+
+#define F10 4
+#define F11 5
+#define F12 6
+#define F13 7
+
+#define F20 8
+#define F21 9
+#define F22 10
+#define F23 11
+
+#define F30 12
+#define F31 13
+#define F32 14
+#define F33 15
+
+
+void G4ErrorMatrix::invertHaywood4  (G4int & ifail)
+{
+  ifail = 0;
+
+  // Find all NECESSARY 2x2 dets:  (18 of them)
+
+  G4double Det2_12_01 = m[F10]*m[F21] - m[F11]*m[F20];
+  G4double Det2_12_02 = m[F10]*m[F22] - m[F12]*m[F20];
+  G4double Det2_12_03 = m[F10]*m[F23] - m[F13]*m[F20];
+  G4double Det2_12_13 = m[F11]*m[F23] - m[F13]*m[F21];
+  G4double Det2_12_23 = m[F12]*m[F23] - m[F13]*m[F22];
+  G4double Det2_12_12 = m[F11]*m[F22] - m[F12]*m[F21];
+  G4double Det2_13_01 = m[F10]*m[F31] - m[F11]*m[F30];
+  G4double Det2_13_02 = m[F10]*m[F32] - m[F12]*m[F30];
+  G4double Det2_13_03 = m[F10]*m[F33] - m[F13]*m[F30];
+  G4double Det2_13_12 = m[F11]*m[F32] - m[F12]*m[F31];
+  G4double Det2_13_13 = m[F11]*m[F33] - m[F13]*m[F31];
+  G4double Det2_13_23 = m[F12]*m[F33] - m[F13]*m[F32];
+  G4double Det2_23_01 = m[F20]*m[F31] - m[F21]*m[F30];
+  G4double Det2_23_02 = m[F20]*m[F32] - m[F22]*m[F30];
+  G4double Det2_23_03 = m[F20]*m[F33] - m[F23]*m[F30];
+  G4double Det2_23_12 = m[F21]*m[F32] - m[F22]*m[F31];
+  G4double Det2_23_13 = m[F21]*m[F33] - m[F23]*m[F31];
+  G4double Det2_23_23 = m[F22]*m[F33] - m[F23]*m[F32];
+
+  // Find all NECESSARY 3x3 dets:   (16 of them)
+
+  G4double Det3_012_012 = m[F00]*Det2_12_12 - m[F01]*Det2_12_02 
+                                + m[F02]*Det2_12_01;
+  G4double Det3_012_013 = m[F00]*Det2_12_13 - m[F01]*Det2_12_03 
+                                + m[F03]*Det2_12_01;
+  G4double Det3_012_023 = m[F00]*Det2_12_23 - m[F02]*Det2_12_03 
+                                + m[F03]*Det2_12_02;
+  G4double Det3_012_123 = m[F01]*Det2_12_23 - m[F02]*Det2_12_13 
+                                + m[F03]*Det2_12_12;
+  G4double Det3_013_012 = m[F00]*Det2_13_12 - m[F01]*Det2_13_02 
+                                + m[F02]*Det2_13_01;
+  G4double Det3_013_013 = m[F00]*Det2_13_13 - m[F01]*Det2_13_03
+                                + m[F03]*Det2_13_01;
+  G4double Det3_013_023 = m[F00]*Det2_13_23 - m[F02]*Det2_13_03
+                                + m[F03]*Det2_13_02;
+  G4double Det3_013_123 = m[F01]*Det2_13_23 - m[F02]*Det2_13_13
+                                + m[F03]*Det2_13_12;
+  G4double Det3_023_012 = m[F00]*Det2_23_12 - m[F01]*Det2_23_02 
+                                + m[F02]*Det2_23_01;
+  G4double Det3_023_013 = m[F00]*Det2_23_13 - m[F01]*Det2_23_03
+                                + m[F03]*Det2_23_01;
+  G4double Det3_023_023 = m[F00]*Det2_23_23 - m[F02]*Det2_23_03
+                                + m[F03]*Det2_23_02;
+  G4double Det3_023_123 = m[F01]*Det2_23_23 - m[F02]*Det2_23_13
+                                + m[F03]*Det2_23_12;
+  G4double Det3_123_012 = m[F10]*Det2_23_12 - m[F11]*Det2_23_02 
+                                + m[F12]*Det2_23_01;
+  G4double Det3_123_013 = m[F10]*Det2_23_13 - m[F11]*Det2_23_03 
+                                + m[F13]*Det2_23_01;
+  G4double Det3_123_023 = m[F10]*Det2_23_23 - m[F12]*Det2_23_03 
+                                + m[F13]*Det2_23_02;
+  G4double Det3_123_123 = m[F11]*Det2_23_23 - m[F12]*Det2_23_13 
+                                + m[F13]*Det2_23_12;
+
+  // Find the 4x4 det:
+
+  G4double det =    m[F00]*Det3_123_123 
+                - m[F01]*Det3_123_023 
+                + m[F02]*Det3_123_013 
+                - m[F03]*Det3_123_012;
+
+  if ( det == 0 )
+  {  
+    ifail = 1;
+    return;
+  } 
+
+  G4double oneOverDet = 1.0/det;
+  G4double mn1OverDet = - oneOverDet;
+
+  m[F00] =  Det3_123_123 * oneOverDet;
+  m[F01] =  Det3_023_123 * mn1OverDet;
+  m[F02] =  Det3_013_123 * oneOverDet;
+  m[F03] =  Det3_012_123 * mn1OverDet;
+
+  m[F10] =  Det3_123_023 * mn1OverDet;
+  m[F11] =  Det3_023_023 * oneOverDet;
+  m[F12] =  Det3_013_023 * mn1OverDet;
+  m[F13] =  Det3_012_023 * oneOverDet;
+
+  m[F20] =  Det3_123_013 * oneOverDet;
+  m[F21] =  Det3_023_013 * mn1OverDet;
+  m[F22] =  Det3_013_013 * oneOverDet;
+  m[F23] =  Det3_012_013 * mn1OverDet;
+
+  m[F30] =  Det3_123_012 * mn1OverDet;
+  m[F31] =  Det3_023_012 * oneOverDet;
+  m[F32] =  Det3_013_012 * mn1OverDet;
+  m[F33] =  Det3_012_012 * oneOverDet;
+
+  return;
+}
+
+void G4ErrorMatrix::invertHaywood5  (G4int & ifail)
+{
+  ifail = 0;
+
+  // Find all NECESSARY 2x2 dets:  (30 of them)
+
+  G4double Det2_23_01 = m[M20]*m[M31] - m[M21]*m[M30];
+  G4double Det2_23_02 = m[M20]*m[M32] - m[M22]*m[M30];
+  G4double Det2_23_03 = m[M20]*m[M33] - m[M23]*m[M30];
+  G4double Det2_23_04 = m[M20]*m[M34] - m[M24]*m[M30];
+  G4double Det2_23_12 = m[M21]*m[M32] - m[M22]*m[M31];
+  G4double Det2_23_13 = m[M21]*m[M33] - m[M23]*m[M31];
+  G4double Det2_23_14 = m[M21]*m[M34] - m[M24]*m[M31];
+  G4double Det2_23_23 = m[M22]*m[M33] - m[M23]*m[M32];
+  G4double Det2_23_24 = m[M22]*m[M34] - m[M24]*m[M32];
+  G4double Det2_23_34 = m[M23]*m[M34] - m[M24]*m[M33];
+  G4double Det2_24_01 = m[M20]*m[M41] - m[M21]*m[M40];
+  G4double Det2_24_02 = m[M20]*m[M42] - m[M22]*m[M40];
+  G4double Det2_24_03 = m[M20]*m[M43] - m[M23]*m[M40];
+  G4double Det2_24_04 = m[M20]*m[M44] - m[M24]*m[M40];
+  G4double Det2_24_12 = m[M21]*m[M42] - m[M22]*m[M41];
+  G4double Det2_24_13 = m[M21]*m[M43] - m[M23]*m[M41];
+  G4double Det2_24_14 = m[M21]*m[M44] - m[M24]*m[M41];
+  G4double Det2_24_23 = m[M22]*m[M43] - m[M23]*m[M42];
+  G4double Det2_24_24 = m[M22]*m[M44] - m[M24]*m[M42];
+  G4double Det2_24_34 = m[M23]*m[M44] - m[M24]*m[M43];
+  G4double Det2_34_01 = m[M30]*m[M41] - m[M31]*m[M40];
+  G4double Det2_34_02 = m[M30]*m[M42] - m[M32]*m[M40];
+  G4double Det2_34_03 = m[M30]*m[M43] - m[M33]*m[M40];
+  G4double Det2_34_04 = m[M30]*m[M44] - m[M34]*m[M40];
+  G4double Det2_34_12 = m[M31]*m[M42] - m[M32]*m[M41];
+  G4double Det2_34_13 = m[M31]*m[M43] - m[M33]*m[M41];
+  G4double Det2_34_14 = m[M31]*m[M44] - m[M34]*m[M41];
+  G4double Det2_34_23 = m[M32]*m[M43] - m[M33]*m[M42];
+  G4double Det2_34_24 = m[M32]*m[M44] - m[M34]*m[M42];
+  G4double Det2_34_34 = m[M33]*m[M44] - m[M34]*m[M43];
+
+  // Find all NECESSARY 3x3 dets:   (40 of them)
+
+  G4double Det3_123_012 = m[M10]*Det2_23_12 - m[M11]*Det2_23_02 
+                                + m[M12]*Det2_23_01;
+  G4double Det3_123_013 = m[M10]*Det2_23_13 - m[M11]*Det2_23_03 
+                                + m[M13]*Det2_23_01;
+  G4double Det3_123_014 = m[M10]*Det2_23_14 - m[M11]*Det2_23_04 
+                                + m[M14]*Det2_23_01;
+  G4double Det3_123_023 = m[M10]*Det2_23_23 - m[M12]*Det2_23_03 
+                                + m[M13]*Det2_23_02;
+  G4double Det3_123_024 = m[M10]*Det2_23_24 - m[M12]*Det2_23_04 
+                                + m[M14]*Det2_23_02;
+  G4double Det3_123_034 = m[M10]*Det2_23_34 - m[M13]*Det2_23_04 
+                                + m[M14]*Det2_23_03;
+  G4double Det3_123_123 = m[M11]*Det2_23_23 - m[M12]*Det2_23_13 
+                                + m[M13]*Det2_23_12;
+  G4double Det3_123_124 = m[M11]*Det2_23_24 - m[M12]*Det2_23_14 
+                                + m[M14]*Det2_23_12;
+  G4double Det3_123_134 = m[M11]*Det2_23_34 - m[M13]*Det2_23_14 
+                                + m[M14]*Det2_23_13;
+  G4double Det3_123_234 = m[M12]*Det2_23_34 - m[M13]*Det2_23_24 
+                                + m[M14]*Det2_23_23;
+  G4double Det3_124_012 = m[M10]*Det2_24_12 - m[M11]*Det2_24_02 
+                                + m[M12]*Det2_24_01;
+  G4double Det3_124_013 = m[M10]*Det2_24_13 - m[M11]*Det2_24_03 
+                                + m[M13]*Det2_24_01;
+  G4double Det3_124_014 = m[M10]*Det2_24_14 - m[M11]*Det2_24_04 
+                                + m[M14]*Det2_24_01;
+  G4double Det3_124_023 = m[M10]*Det2_24_23 - m[M12]*Det2_24_03 
+                                + m[M13]*Det2_24_02;
+  G4double Det3_124_024 = m[M10]*Det2_24_24 - m[M12]*Det2_24_04 
+                                + m[M14]*Det2_24_02;
+  G4double Det3_124_034 = m[M10]*Det2_24_34 - m[M13]*Det2_24_04 
+                                + m[M14]*Det2_24_03;
+  G4double Det3_124_123 = m[M11]*Det2_24_23 - m[M12]*Det2_24_13 
+                                + m[M13]*Det2_24_12;
+  G4double Det3_124_124 = m[M11]*Det2_24_24 - m[M12]*Det2_24_14 
+                                + m[M14]*Det2_24_12;
+  G4double Det3_124_134 = m[M11]*Det2_24_34 - m[M13]*Det2_24_14 
+                                + m[M14]*Det2_24_13;
+  G4double Det3_124_234 = m[M12]*Det2_24_34 - m[M13]*Det2_24_24 
+                                + m[M14]*Det2_24_23;
+  G4double Det3_134_012 = m[M10]*Det2_34_12 - m[M11]*Det2_34_02 
+                                + m[M12]*Det2_34_01;
+  G4double Det3_134_013 = m[M10]*Det2_34_13 - m[M11]*Det2_34_03 
+                                + m[M13]*Det2_34_01;
+  G4double Det3_134_014 = m[M10]*Det2_34_14 - m[M11]*Det2_34_04 
+                                + m[M14]*Det2_34_01;
+  G4double Det3_134_023 = m[M10]*Det2_34_23 - m[M12]*Det2_34_03 
+                                + m[M13]*Det2_34_02;
+  G4double Det3_134_024 = m[M10]*Det2_34_24 - m[M12]*Det2_34_04 
+                                + m[M14]*Det2_34_02;
+  G4double Det3_134_034 = m[M10]*Det2_34_34 - m[M13]*Det2_34_04 
+                                + m[M14]*Det2_34_03;
+  G4double Det3_134_123 = m[M11]*Det2_34_23 - m[M12]*Det2_34_13 
+                                + m[M13]*Det2_34_12;
+  G4double Det3_134_124 = m[M11]*Det2_34_24 - m[M12]*Det2_34_14 
+                                + m[M14]*Det2_34_12;
+  G4double Det3_134_134 = m[M11]*Det2_34_34 - m[M13]*Det2_34_14 
+                                + m[M14]*Det2_34_13;
+  G4double Det3_134_234 = m[M12]*Det2_34_34 - m[M13]*Det2_34_24 
+                                + m[M14]*Det2_34_23;
+  G4double Det3_234_012 = m[M20]*Det2_34_12 - m[M21]*Det2_34_02 
+                                + m[M22]*Det2_34_01;
+  G4double Det3_234_013 = m[M20]*Det2_34_13 - m[M21]*Det2_34_03 
+                                + m[M23]*Det2_34_01;
+  G4double Det3_234_014 = m[M20]*Det2_34_14 - m[M21]*Det2_34_04 
+                                + m[M24]*Det2_34_01;
+  G4double Det3_234_023 = m[M20]*Det2_34_23 - m[M22]*Det2_34_03 
+                                + m[M23]*Det2_34_02;
+  G4double Det3_234_024 = m[M20]*Det2_34_24 - m[M22]*Det2_34_04 
+                                + m[M24]*Det2_34_02;
+  G4double Det3_234_034 = m[M20]*Det2_34_34 - m[M23]*Det2_34_04 
+                                + m[M24]*Det2_34_03;
+  G4double Det3_234_123 = m[M21]*Det2_34_23 - m[M22]*Det2_34_13 
+                                + m[M23]*Det2_34_12;
+  G4double Det3_234_124 = m[M21]*Det2_34_24 - m[M22]*Det2_34_14 
+                                + m[M24]*Det2_34_12;
+  G4double Det3_234_134 = m[M21]*Det2_34_34 - m[M23]*Det2_34_14 
+                                + m[M24]*Det2_34_13;
+  G4double Det3_234_234 = m[M22]*Det2_34_34 - m[M23]*Det2_34_24 
+                                + m[M24]*Det2_34_23;
+
+  // Find all NECESSARY 4x4 dets:   (25 of them)
+
+  G4double Det4_0123_0123 = m[M00]*Det3_123_123 - m[M01]*Det3_123_023 
+                                + m[M02]*Det3_123_013 - m[M03]*Det3_123_012;
+  G4double Det4_0123_0124 = m[M00]*Det3_123_124 - m[M01]*Det3_123_024 
+                                + m[M02]*Det3_123_014 - m[M04]*Det3_123_012;
+  G4double Det4_0123_0134 = m[M00]*Det3_123_134 - m[M01]*Det3_123_034 
+                                + m[M03]*Det3_123_014 - m[M04]*Det3_123_013;
+  G4double Det4_0123_0234 = m[M00]*Det3_123_234 - m[M02]*Det3_123_034 
+                                + m[M03]*Det3_123_024 - m[M04]*Det3_123_023;
+  G4double Det4_0123_1234 = m[M01]*Det3_123_234 - m[M02]*Det3_123_134 
+                                + m[M03]*Det3_123_124 - m[M04]*Det3_123_123;
+  G4double Det4_0124_0123 = m[M00]*Det3_124_123 - m[M01]*Det3_124_023 
+                                + m[M02]*Det3_124_013 - m[M03]*Det3_124_012;
+  G4double Det4_0124_0124 = m[M00]*Det3_124_124 - m[M01]*Det3_124_024 
+                                + m[M02]*Det3_124_014 - m[M04]*Det3_124_012;
+  G4double Det4_0124_0134 = m[M00]*Det3_124_134 - m[M01]*Det3_124_034 
+                                + m[M03]*Det3_124_014 - m[M04]*Det3_124_013;
+  G4double Det4_0124_0234 = m[M00]*Det3_124_234 - m[M02]*Det3_124_034 
+                                + m[M03]*Det3_124_024 - m[M04]*Det3_124_023;
+  G4double Det4_0124_1234 = m[M01]*Det3_124_234 - m[M02]*Det3_124_134 
+                                + m[M03]*Det3_124_124 - m[M04]*Det3_124_123;
+  G4double Det4_0134_0123 = m[M00]*Det3_134_123 - m[M01]*Det3_134_023 
+                                + m[M02]*Det3_134_013 - m[M03]*Det3_134_012;
+  G4double Det4_0134_0124 = m[M00]*Det3_134_124 - m[M01]*Det3_134_024 
+                                + m[M02]*Det3_134_014 - m[M04]*Det3_134_012;
+  G4double Det4_0134_0134 = m[M00]*Det3_134_134 - m[M01]*Det3_134_034 
+                                + m[M03]*Det3_134_014 - m[M04]*Det3_134_013;
+  G4double Det4_0134_0234 = m[M00]*Det3_134_234 - m[M02]*Det3_134_034 
+                                + m[M03]*Det3_134_024 - m[M04]*Det3_134_023;
+  G4double Det4_0134_1234 = m[M01]*Det3_134_234 - m[M02]*Det3_134_134 
+                                + m[M03]*Det3_134_124 - m[M04]*Det3_134_123;
+  G4double Det4_0234_0123 = m[M00]*Det3_234_123 - m[M01]*Det3_234_023 
+                                + m[M02]*Det3_234_013 - m[M03]*Det3_234_012;
+  G4double Det4_0234_0124 = m[M00]*Det3_234_124 - m[M01]*Det3_234_024 
+                                + m[M02]*Det3_234_014 - m[M04]*Det3_234_012;
+  G4double Det4_0234_0134 = m[M00]*Det3_234_134 - m[M01]*Det3_234_034 
+                                + m[M03]*Det3_234_014 - m[M04]*Det3_234_013;
+  G4double Det4_0234_0234 = m[M00]*Det3_234_234 - m[M02]*Det3_234_034 
+                                + m[M03]*Det3_234_024 - m[M04]*Det3_234_023;
+  G4double Det4_0234_1234 = m[M01]*Det3_234_234 - m[M02]*Det3_234_134 
+                                + m[M03]*Det3_234_124 - m[M04]*Det3_234_123;
+  G4double Det4_1234_0123 = m[M10]*Det3_234_123 - m[M11]*Det3_234_023 
+                                + m[M12]*Det3_234_013 - m[M13]*Det3_234_012;
+  G4double Det4_1234_0124 = m[M10]*Det3_234_124 - m[M11]*Det3_234_024 
+                                + m[M12]*Det3_234_014 - m[M14]*Det3_234_012;
+  G4double Det4_1234_0134 = m[M10]*Det3_234_134 - m[M11]*Det3_234_034 
+                                + m[M13]*Det3_234_014 - m[M14]*Det3_234_013;
+  G4double Det4_1234_0234 = m[M10]*Det3_234_234 - m[M12]*Det3_234_034 
+                                + m[M13]*Det3_234_024 - m[M14]*Det3_234_023;
+  G4double Det4_1234_1234 = m[M11]*Det3_234_234 - m[M12]*Det3_234_134 
+                                + m[M13]*Det3_234_124 - m[M14]*Det3_234_123;
+
+  // Find the 5x5 det:
+
+  G4double det =  m[M00]*Det4_1234_1234 
+                - m[M01]*Det4_1234_0234 
+                + m[M02]*Det4_1234_0134 
+                - m[M03]*Det4_1234_0124 
+                + m[M04]*Det4_1234_0123;
+
+  if ( det == 0 )
+  {  
+    ifail = 1;
+    return;
+  } 
+
+  G4double oneOverDet = 1.0/det;
+  G4double mn1OverDet = - oneOverDet;
+
+  m[M00] =  Det4_1234_1234 * oneOverDet;
+  m[M01] =  Det4_0234_1234 * mn1OverDet;
+  m[M02] =  Det4_0134_1234 * oneOverDet;
+  m[M03] =  Det4_0124_1234 * mn1OverDet;
+  m[M04] =  Det4_0123_1234 * oneOverDet;
+
+  m[M10] =  Det4_1234_0234 * mn1OverDet;
+  m[M11] =  Det4_0234_0234 * oneOverDet;
+  m[M12] =  Det4_0134_0234 * mn1OverDet;
+  m[M13] =  Det4_0124_0234 * oneOverDet;
+  m[M14] =  Det4_0123_0234 * mn1OverDet;
+
+  m[M20] =  Det4_1234_0134 * oneOverDet;
+  m[M21] =  Det4_0234_0134 * mn1OverDet;
+  m[M22] =  Det4_0134_0134 * oneOverDet;
+  m[M23] =  Det4_0124_0134 * mn1OverDet;
+  m[M24] =  Det4_0123_0134 * oneOverDet;
+
+  m[M30] =  Det4_1234_0124 * mn1OverDet;
+  m[M31] =  Det4_0234_0124 * oneOverDet;
+  m[M32] =  Det4_0134_0124 * mn1OverDet;
+  m[M33] =  Det4_0124_0124 * oneOverDet;
+  m[M34] =  Det4_0123_0124 * mn1OverDet;
+
+  m[M40] =  Det4_1234_0123 * oneOverDet;
+  m[M41] =  Det4_0234_0123 * mn1OverDet;
+  m[M42] =  Det4_0134_0123 * oneOverDet;
+  m[M43] =  Det4_0124_0123 * mn1OverDet;
+  m[M44] =  Det4_0123_0123 * oneOverDet;
+
+  return;
+}
+
+void G4ErrorMatrix::invertHaywood6  (G4int & ifail)
+{
+  ifail = 0;
+
+  // Find all NECESSARY 2x2 dets:  (45 of them)
+
+  G4double Det2_34_01 = m[A30]*m[A41] - m[A31]*m[A40];
+  G4double Det2_34_02 = m[A30]*m[A42] - m[A32]*m[A40];
+  G4double Det2_34_03 = m[A30]*m[A43] - m[A33]*m[A40];
+  G4double Det2_34_04 = m[A30]*m[A44] - m[A34]*m[A40];
+  G4double Det2_34_05 = m[A30]*m[A45] - m[A35]*m[A40];
+  G4double Det2_34_12 = m[A31]*m[A42] - m[A32]*m[A41];
+  G4double Det2_34_13 = m[A31]*m[A43] - m[A33]*m[A41];
+  G4double Det2_34_14 = m[A31]*m[A44] - m[A34]*m[A41];
+  G4double Det2_34_15 = m[A31]*m[A45] - m[A35]*m[A41];
+  G4double Det2_34_23 = m[A32]*m[A43] - m[A33]*m[A42];
+  G4double Det2_34_24 = m[A32]*m[A44] - m[A34]*m[A42];
+  G4double Det2_34_25 = m[A32]*m[A45] - m[A35]*m[A42];
+  G4double Det2_34_34 = m[A33]*m[A44] - m[A34]*m[A43];
+  G4double Det2_34_35 = m[A33]*m[A45] - m[A35]*m[A43];
+  G4double Det2_34_45 = m[A34]*m[A45] - m[A35]*m[A44];
+  G4double Det2_35_01 = m[A30]*m[A51] - m[A31]*m[A50];
+  G4double Det2_35_02 = m[A30]*m[A52] - m[A32]*m[A50];
+  G4double Det2_35_03 = m[A30]*m[A53] - m[A33]*m[A50];
+  G4double Det2_35_04 = m[A30]*m[A54] - m[A34]*m[A50];
+  G4double Det2_35_05 = m[A30]*m[A55] - m[A35]*m[A50];
+  G4double Det2_35_12 = m[A31]*m[A52] - m[A32]*m[A51];
+  G4double Det2_35_13 = m[A31]*m[A53] - m[A33]*m[A51];
+  G4double Det2_35_14 = m[A31]*m[A54] - m[A34]*m[A51];
+  G4double Det2_35_15 = m[A31]*m[A55] - m[A35]*m[A51];
+  G4double Det2_35_23 = m[A32]*m[A53] - m[A33]*m[A52];
+  G4double Det2_35_24 = m[A32]*m[A54] - m[A34]*m[A52];
+  G4double Det2_35_25 = m[A32]*m[A55] - m[A35]*m[A52];
+  G4double Det2_35_34 = m[A33]*m[A54] - m[A34]*m[A53];
+  G4double Det2_35_35 = m[A33]*m[A55] - m[A35]*m[A53];
+  G4double Det2_35_45 = m[A34]*m[A55] - m[A35]*m[A54];
+  G4double Det2_45_01 = m[A40]*m[A51] - m[A41]*m[A50];
+  G4double Det2_45_02 = m[A40]*m[A52] - m[A42]*m[A50];
+  G4double Det2_45_03 = m[A40]*m[A53] - m[A43]*m[A50];
+  G4double Det2_45_04 = m[A40]*m[A54] - m[A44]*m[A50];
+  G4double Det2_45_05 = m[A40]*m[A55] - m[A45]*m[A50];
+  G4double Det2_45_12 = m[A41]*m[A52] - m[A42]*m[A51];
+  G4double Det2_45_13 = m[A41]*m[A53] - m[A43]*m[A51];
+  G4double Det2_45_14 = m[A41]*m[A54] - m[A44]*m[A51];
+  G4double Det2_45_15 = m[A41]*m[A55] - m[A45]*m[A51];
+  G4double Det2_45_23 = m[A42]*m[A53] - m[A43]*m[A52];
+  G4double Det2_45_24 = m[A42]*m[A54] - m[A44]*m[A52];
+  G4double Det2_45_25 = m[A42]*m[A55] - m[A45]*m[A52];
+  G4double Det2_45_34 = m[A43]*m[A54] - m[A44]*m[A53];
+  G4double Det2_45_35 = m[A43]*m[A55] - m[A45]*m[A53];
+  G4double Det2_45_45 = m[A44]*m[A55] - m[A45]*m[A54];
+
+  // Find all NECESSARY 3x3 dets:  (80 of them)
+
+  G4double Det3_234_012 = m[A20]*Det2_34_12 - m[A21]*Det2_34_02 
+                                                + m[A22]*Det2_34_01;
+  G4double Det3_234_013 = m[A20]*Det2_34_13 - m[A21]*Det2_34_03 
+                                                + m[A23]*Det2_34_01;
+  G4double Det3_234_014 = m[A20]*Det2_34_14 - m[A21]*Det2_34_04 
+                                                + m[A24]*Det2_34_01;
+  G4double Det3_234_015 = m[A20]*Det2_34_15 - m[A21]*Det2_34_05
+                                                + m[A25]*Det2_34_01;
+  G4double Det3_234_023 = m[A20]*Det2_34_23 - m[A22]*Det2_34_03 
+                                                + m[A23]*Det2_34_02;
+  G4double Det3_234_024 = m[A20]*Det2_34_24 - m[A22]*Det2_34_04 
+                                                + m[A24]*Det2_34_02;
+  G4double Det3_234_025 = m[A20]*Det2_34_25 - m[A22]*Det2_34_05 
+                                                + m[A25]*Det2_34_02;
+  G4double Det3_234_034 = m[A20]*Det2_34_34 - m[A23]*Det2_34_04 
+                                                + m[A24]*Det2_34_03;
+  G4double Det3_234_035 = m[A20]*Det2_34_35 - m[A23]*Det2_34_05                 
+                                                + m[A25]*Det2_34_03;
+  G4double Det3_234_045 = m[A20]*Det2_34_45 - m[A24]*Det2_34_05 
+                                                + m[A25]*Det2_34_04;
+  G4double Det3_234_123 = m[A21]*Det2_34_23 - m[A22]*Det2_34_13 
+                                                + m[A23]*Det2_34_12;
+  G4double Det3_234_124 = m[A21]*Det2_34_24 - m[A22]*Det2_34_14 
+                                                + m[A24]*Det2_34_12;
+  G4double Det3_234_125 = m[A21]*Det2_34_25 - m[A22]*Det2_34_15 
+                                                + m[A25]*Det2_34_12;
+  G4double Det3_234_134 = m[A21]*Det2_34_34 - m[A23]*Det2_34_14 
+                                                + m[A24]*Det2_34_13;
+  G4double Det3_234_135 = m[A21]*Det2_34_35 - m[A23]*Det2_34_15 
+                                                + m[A25]*Det2_34_13;
+  G4double Det3_234_145 = m[A21]*Det2_34_45 - m[A24]*Det2_34_15 
+                                                + m[A25]*Det2_34_14;
+  G4double Det3_234_234 = m[A22]*Det2_34_34 - m[A23]*Det2_34_24 
+                                                + m[A24]*Det2_34_23;
+  G4double Det3_234_235 = m[A22]*Det2_34_35 - m[A23]*Det2_34_25
+                                                + m[A25]*Det2_34_23;
+  G4double Det3_234_245 = m[A22]*Det2_34_45 - m[A24]*Det2_34_25
+                                                + m[A25]*Det2_34_24;
+  G4double Det3_234_345 = m[A23]*Det2_34_45 - m[A24]*Det2_34_35
+                                                + m[A25]*Det2_34_34;
+  G4double Det3_235_012 = m[A20]*Det2_35_12 - m[A21]*Det2_35_02 
+                                                + m[A22]*Det2_35_01;
+  G4double Det3_235_013 = m[A20]*Det2_35_13 - m[A21]*Det2_35_03 
+                                                + m[A23]*Det2_35_01;
+  G4double Det3_235_014 = m[A20]*Det2_35_14 - m[A21]*Det2_35_04 
+                                                + m[A24]*Det2_35_01;
+  G4double Det3_235_015 = m[A20]*Det2_35_15 - m[A21]*Det2_35_05 
+                                                + m[A25]*Det2_35_01;
+  G4double Det3_235_023 = m[A20]*Det2_35_23 - m[A22]*Det2_35_03 
+                                                + m[A23]*Det2_35_02;
+  G4double Det3_235_024 = m[A20]*Det2_35_24 - m[A22]*Det2_35_04 
+                                                + m[A24]*Det2_35_02;
+  G4double Det3_235_025 = m[A20]*Det2_35_25 - m[A22]*Det2_35_05 
+                                                + m[A25]*Det2_35_02;
+  G4double Det3_235_034 = m[A20]*Det2_35_34 - m[A23]*Det2_35_04 
+                                                + m[A24]*Det2_35_03;
+  G4double Det3_235_035 = m[A20]*Det2_35_35 - m[A23]*Det2_35_05 
+                                                + m[A25]*Det2_35_03;
+  G4double Det3_235_045 = m[A20]*Det2_35_45 - m[A24]*Det2_35_05 
+                                                + m[A25]*Det2_35_04;
+  G4double Det3_235_123 = m[A21]*Det2_35_23 - m[A22]*Det2_35_13 
+                                                + m[A23]*Det2_35_12;
+  G4double Det3_235_124 = m[A21]*Det2_35_24 - m[A22]*Det2_35_14 
+                                                + m[A24]*Det2_35_12;
+  G4double Det3_235_125 = m[A21]*Det2_35_25 - m[A22]*Det2_35_15 
+                                                + m[A25]*Det2_35_12;
+  G4double Det3_235_134 = m[A21]*Det2_35_34 - m[A23]*Det2_35_14 
+                                                + m[A24]*Det2_35_13;
+  G4double Det3_235_135 = m[A21]*Det2_35_35 - m[A23]*Det2_35_15 
+                                                + m[A25]*Det2_35_13;
+  G4double Det3_235_145 = m[A21]*Det2_35_45 - m[A24]*Det2_35_15 
+                                                + m[A25]*Det2_35_14;
+  G4double Det3_235_234 = m[A22]*Det2_35_34 - m[A23]*Det2_35_24 
+                                                + m[A24]*Det2_35_23;
+  G4double Det3_235_235 = m[A22]*Det2_35_35 - m[A23]*Det2_35_25 
+                                                + m[A25]*Det2_35_23;
+  G4double Det3_235_245 = m[A22]*Det2_35_45 - m[A24]*Det2_35_25 
+                                                + m[A25]*Det2_35_24;
+  G4double Det3_235_345 = m[A23]*Det2_35_45 - m[A24]*Det2_35_35 
+                                                + m[A25]*Det2_35_34;
+  G4double Det3_245_012 = m[A20]*Det2_45_12 - m[A21]*Det2_45_02 
+                                                + m[A22]*Det2_45_01;
+  G4double Det3_245_013 = m[A20]*Det2_45_13 - m[A21]*Det2_45_03 
+                                                + m[A23]*Det2_45_01;
+  G4double Det3_245_014 = m[A20]*Det2_45_14 - m[A21]*Det2_45_04 
+                                                + m[A24]*Det2_45_01;
+  G4double Det3_245_015 = m[A20]*Det2_45_15 - m[A21]*Det2_45_05 
+                                                + m[A25]*Det2_45_01;
+  G4double Det3_245_023 = m[A20]*Det2_45_23 - m[A22]*Det2_45_03 
+                                                + m[A23]*Det2_45_02;
+  G4double Det3_245_024 = m[A20]*Det2_45_24 - m[A22]*Det2_45_04 
+                                                + m[A24]*Det2_45_02;
+  G4double Det3_245_025 = m[A20]*Det2_45_25 - m[A22]*Det2_45_05 
+                                                + m[A25]*Det2_45_02;
+  G4double Det3_245_034 = m[A20]*Det2_45_34 - m[A23]*Det2_45_04 
+                                                + m[A24]*Det2_45_03;
+  G4double Det3_245_035 = m[A20]*Det2_45_35 - m[A23]*Det2_45_05 
+                                                + m[A25]*Det2_45_03;
+  G4double Det3_245_045 = m[A20]*Det2_45_45 - m[A24]*Det2_45_05 
+                                                + m[A25]*Det2_45_04;
+  G4double Det3_245_123 = m[A21]*Det2_45_23 - m[A22]*Det2_45_13 
+                                                + m[A23]*Det2_45_12;
+  G4double Det3_245_124 = m[A21]*Det2_45_24 - m[A22]*Det2_45_14 
+                                                + m[A24]*Det2_45_12;
+  G4double Det3_245_125 = m[A21]*Det2_45_25 - m[A22]*Det2_45_15 
+                                                + m[A25]*Det2_45_12;
+  G4double Det3_245_134 = m[A21]*Det2_45_34 - m[A23]*Det2_45_14 
+                                                + m[A24]*Det2_45_13;
+  G4double Det3_245_135 = m[A21]*Det2_45_35 - m[A23]*Det2_45_15 
+                                                + m[A25]*Det2_45_13;
+  G4double Det3_245_145 = m[A21]*Det2_45_45 - m[A24]*Det2_45_15 
+                                                + m[A25]*Det2_45_14;
+  G4double Det3_245_234 = m[A22]*Det2_45_34 - m[A23]*Det2_45_24 
+                                                + m[A24]*Det2_45_23;
+  G4double Det3_245_235 = m[A22]*Det2_45_35 - m[A23]*Det2_45_25 
+                                                + m[A25]*Det2_45_23;
+  G4double Det3_245_245 = m[A22]*Det2_45_45 - m[A24]*Det2_45_25 
+                                                + m[A25]*Det2_45_24;
+  G4double Det3_245_345 = m[A23]*Det2_45_45 - m[A24]*Det2_45_35 
+                                                + m[A25]*Det2_45_34;
+  G4double Det3_345_012 = m[A30]*Det2_45_12 - m[A31]*Det2_45_02 
+                                                + m[A32]*Det2_45_01;
+  G4double Det3_345_013 = m[A30]*Det2_45_13 - m[A31]*Det2_45_03 
+                                                + m[A33]*Det2_45_01;
+  G4double Det3_345_014 = m[A30]*Det2_45_14 - m[A31]*Det2_45_04 
+                                                + m[A34]*Det2_45_01;
+  G4double Det3_345_015 = m[A30]*Det2_45_15 - m[A31]*Det2_45_05 
+                                                + m[A35]*Det2_45_01;
+  G4double Det3_345_023 = m[A30]*Det2_45_23 - m[A32]*Det2_45_03 
+                                                + m[A33]*Det2_45_02;
+  G4double Det3_345_024 = m[A30]*Det2_45_24 - m[A32]*Det2_45_04 
+                                                + m[A34]*Det2_45_02;
+  G4double Det3_345_025 = m[A30]*Det2_45_25 - m[A32]*Det2_45_05 
+                                                + m[A35]*Det2_45_02;
+  G4double Det3_345_034 = m[A30]*Det2_45_34 - m[A33]*Det2_45_04 
+                                                + m[A34]*Det2_45_03;
+  G4double Det3_345_035 = m[A30]*Det2_45_35 - m[A33]*Det2_45_05 
+                                                + m[A35]*Det2_45_03;
+  G4double Det3_345_045 = m[A30]*Det2_45_45 - m[A34]*Det2_45_05 
+                                                + m[A35]*Det2_45_04;
+  G4double Det3_345_123 = m[A31]*Det2_45_23 - m[A32]*Det2_45_13 
+                                                + m[A33]*Det2_45_12;
+  G4double Det3_345_124 = m[A31]*Det2_45_24 - m[A32]*Det2_45_14 
+                                                + m[A34]*Det2_45_12;
+  G4double Det3_345_125 = m[A31]*Det2_45_25 - m[A32]*Det2_45_15 
+                                                + m[A35]*Det2_45_12;
+  G4double Det3_345_134 = m[A31]*Det2_45_34 - m[A33]*Det2_45_14 
+                                                + m[A34]*Det2_45_13;
+  G4double Det3_345_135 = m[A31]*Det2_45_35 - m[A33]*Det2_45_15 
+                                                + m[A35]*Det2_45_13;
+  G4double Det3_345_145 = m[A31]*Det2_45_45 - m[A34]*Det2_45_15 
+                                                + m[A35]*Det2_45_14;
+  G4double Det3_345_234 = m[A32]*Det2_45_34 - m[A33]*Det2_45_24 
+                                                + m[A34]*Det2_45_23;
+  G4double Det3_345_235 = m[A32]*Det2_45_35 - m[A33]*Det2_45_25 
+                                                + m[A35]*Det2_45_23;
+  G4double Det3_345_245 = m[A32]*Det2_45_45 - m[A34]*Det2_45_25 
+                                                + m[A35]*Det2_45_24;
+  G4double Det3_345_345 = m[A33]*Det2_45_45 - m[A34]*Det2_45_35 
+                                                + m[A35]*Det2_45_34;
+
+  // Find all NECESSARY 4x4 dets:  (75 of them)
+
+  G4double Det4_1234_0123 = m[A10]*Det3_234_123 - m[A11]*Det3_234_023 
+                        + m[A12]*Det3_234_013 - m[A13]*Det3_234_012;
+  G4double Det4_1234_0124 = m[A10]*Det3_234_124 - m[A11]*Det3_234_024 
+                        + m[A12]*Det3_234_014 - m[A14]*Det3_234_012;
+  G4double Det4_1234_0125 = m[A10]*Det3_234_125 - m[A11]*Det3_234_025 
+                        + m[A12]*Det3_234_015 - m[A15]*Det3_234_012;
+  G4double Det4_1234_0134 = m[A10]*Det3_234_134 - m[A11]*Det3_234_034 
+                        + m[A13]*Det3_234_014 - m[A14]*Det3_234_013;
+  G4double Det4_1234_0135 = m[A10]*Det3_234_135 - m[A11]*Det3_234_035
+                        + m[A13]*Det3_234_015 - m[A15]*Det3_234_013;
+  G4double Det4_1234_0145 = m[A10]*Det3_234_145 - m[A11]*Det3_234_045
+                        + m[A14]*Det3_234_015 - m[A15]*Det3_234_014;
+  G4double Det4_1234_0234 = m[A10]*Det3_234_234 - m[A12]*Det3_234_034 
+                        + m[A13]*Det3_234_024 - m[A14]*Det3_234_023;
+  G4double Det4_1234_0235 = m[A10]*Det3_234_235 - m[A12]*Det3_234_035 
+                        + m[A13]*Det3_234_025 - m[A15]*Det3_234_023;
+  G4double Det4_1234_0245 = m[A10]*Det3_234_245 - m[A12]*Det3_234_045 
+                        + m[A14]*Det3_234_025 - m[A15]*Det3_234_024;
+  G4double Det4_1234_0345 = m[A10]*Det3_234_345 - m[A13]*Det3_234_045 
+                        + m[A14]*Det3_234_035 - m[A15]*Det3_234_034;
+  G4double Det4_1234_1234 = m[A11]*Det3_234_234 - m[A12]*Det3_234_134 
+                        + m[A13]*Det3_234_124 - m[A14]*Det3_234_123;
+  G4double Det4_1234_1235 = m[A11]*Det3_234_235 - m[A12]*Det3_234_135 
+                        + m[A13]*Det3_234_125 - m[A15]*Det3_234_123;
+  G4double Det4_1234_1245 = m[A11]*Det3_234_245 - m[A12]*Det3_234_145 
+                        + m[A14]*Det3_234_125 - m[A15]*Det3_234_124;
+  G4double Det4_1234_1345 = m[A11]*Det3_234_345 - m[A13]*Det3_234_145 
+                        + m[A14]*Det3_234_135 - m[A15]*Det3_234_134;
+  G4double Det4_1234_2345 = m[A12]*Det3_234_345 - m[A13]*Det3_234_245 
+                        + m[A14]*Det3_234_235 - m[A15]*Det3_234_234;
+  G4double Det4_1235_0123 = m[A10]*Det3_235_123 - m[A11]*Det3_235_023 
+                        + m[A12]*Det3_235_013 - m[A13]*Det3_235_012;
+  G4double Det4_1235_0124 = m[A10]*Det3_235_124 - m[A11]*Det3_235_024 
+                        + m[A12]*Det3_235_014 - m[A14]*Det3_235_012;
+  G4double Det4_1235_0125 = m[A10]*Det3_235_125 - m[A11]*Det3_235_025 
+                        + m[A12]*Det3_235_015 - m[A15]*Det3_235_012;
+  G4double Det4_1235_0134 = m[A10]*Det3_235_134 - m[A11]*Det3_235_034 
+                        + m[A13]*Det3_235_014 - m[A14]*Det3_235_013;
+  G4double Det4_1235_0135 = m[A10]*Det3_235_135 - m[A11]*Det3_235_035 
+                        + m[A13]*Det3_235_015 - m[A15]*Det3_235_013;
+  G4double Det4_1235_0145 = m[A10]*Det3_235_145 - m[A11]*Det3_235_045 
+                        + m[A14]*Det3_235_015 - m[A15]*Det3_235_014;
+  G4double Det4_1235_0234 = m[A10]*Det3_235_234 - m[A12]*Det3_235_034 
+                        + m[A13]*Det3_235_024 - m[A14]*Det3_235_023;
+  G4double Det4_1235_0235 = m[A10]*Det3_235_235 - m[A12]*Det3_235_035 
+                        + m[A13]*Det3_235_025 - m[A15]*Det3_235_023;
+  G4double Det4_1235_0245 = m[A10]*Det3_235_245 - m[A12]*Det3_235_045 
+                        + m[A14]*Det3_235_025 - m[A15]*Det3_235_024;
+  G4double Det4_1235_0345 = m[A10]*Det3_235_345 - m[A13]*Det3_235_045 
+                        + m[A14]*Det3_235_035 - m[A15]*Det3_235_034;
+  G4double Det4_1235_1234 = m[A11]*Det3_235_234 - m[A12]*Det3_235_134 
+                        + m[A13]*Det3_235_124 - m[A14]*Det3_235_123;
+  G4double Det4_1235_1235 = m[A11]*Det3_235_235 - m[A12]*Det3_235_135 
+                        + m[A13]*Det3_235_125 - m[A15]*Det3_235_123;
+  G4double Det4_1235_1245 = m[A11]*Det3_235_245 - m[A12]*Det3_235_145 
+                        + m[A14]*Det3_235_125 - m[A15]*Det3_235_124;
+  G4double Det4_1235_1345 = m[A11]*Det3_235_345 - m[A13]*Det3_235_145 
+                        + m[A14]*Det3_235_135 - m[A15]*Det3_235_134;
+  G4double Det4_1235_2345 = m[A12]*Det3_235_345 - m[A13]*Det3_235_245 
+                        + m[A14]*Det3_235_235 - m[A15]*Det3_235_234;
+  G4double Det4_1245_0123 = m[A10]*Det3_245_123 - m[A11]*Det3_245_023 
+                        + m[A12]*Det3_245_013 - m[A13]*Det3_245_012;
+  G4double Det4_1245_0124 = m[A10]*Det3_245_124 - m[A11]*Det3_245_024 
+                        + m[A12]*Det3_245_014 - m[A14]*Det3_245_012;
+  G4double Det4_1245_0125 = m[A10]*Det3_245_125 - m[A11]*Det3_245_025 
+                        + m[A12]*Det3_245_015 - m[A15]*Det3_245_012;
+  G4double Det4_1245_0134 = m[A10]*Det3_245_134 - m[A11]*Det3_245_034 
+                        + m[A13]*Det3_245_014 - m[A14]*Det3_245_013;
+  G4double Det4_1245_0135 = m[A10]*Det3_245_135 - m[A11]*Det3_245_035 
+                        + m[A13]*Det3_245_015 - m[A15]*Det3_245_013;
+  G4double Det4_1245_0145 = m[A10]*Det3_245_145 - m[A11]*Det3_245_045 
+                        + m[A14]*Det3_245_015 - m[A15]*Det3_245_014;
+  G4double Det4_1245_0234 = m[A10]*Det3_245_234 - m[A12]*Det3_245_034 
+                        + m[A13]*Det3_245_024 - m[A14]*Det3_245_023;
+  G4double Det4_1245_0235 = m[A10]*Det3_245_235 - m[A12]*Det3_245_035 
+                        + m[A13]*Det3_245_025 - m[A15]*Det3_245_023;
+  G4double Det4_1245_0245 = m[A10]*Det3_245_245 - m[A12]*Det3_245_045 
+                        + m[A14]*Det3_245_025 - m[A15]*Det3_245_024;
+  G4double Det4_1245_0345 = m[A10]*Det3_245_345 - m[A13]*Det3_245_045 
+                        + m[A14]*Det3_245_035 - m[A15]*Det3_245_034;
+  G4double Det4_1245_1234 = m[A11]*Det3_245_234 - m[A12]*Det3_245_134 
+                        + m[A13]*Det3_245_124 - m[A14]*Det3_245_123;
+  G4double Det4_1245_1235 = m[A11]*Det3_245_235 - m[A12]*Det3_245_135 
+                        + m[A13]*Det3_245_125 - m[A15]*Det3_245_123;
+  G4double Det4_1245_1245 = m[A11]*Det3_245_245 - m[A12]*Det3_245_145 
+                        + m[A14]*Det3_245_125 - m[A15]*Det3_245_124;
+  G4double Det4_1245_1345 = m[A11]*Det3_245_345 - m[A13]*Det3_245_145 
+                        + m[A14]*Det3_245_135 - m[A15]*Det3_245_134;
+  G4double Det4_1245_2345 = m[A12]*Det3_245_345 - m[A13]*Det3_245_245 
+                        + m[A14]*Det3_245_235 - m[A15]*Det3_245_234;
+  G4double Det4_1345_0123 = m[A10]*Det3_345_123 - m[A11]*Det3_345_023 
+                        + m[A12]*Det3_345_013 - m[A13]*Det3_345_012;
+  G4double Det4_1345_0124 = m[A10]*Det3_345_124 - m[A11]*Det3_345_024 
+                        + m[A12]*Det3_345_014 - m[A14]*Det3_345_012;
+  G4double Det4_1345_0125 = m[A10]*Det3_345_125 - m[A11]*Det3_345_025 
+                        + m[A12]*Det3_345_015 - m[A15]*Det3_345_012;
+  G4double Det4_1345_0134 = m[A10]*Det3_345_134 - m[A11]*Det3_345_034 
+                        + m[A13]*Det3_345_014 - m[A14]*Det3_345_013;
+  G4double Det4_1345_0135 = m[A10]*Det3_345_135 - m[A11]*Det3_345_035 
+                        + m[A13]*Det3_345_015 - m[A15]*Det3_345_013;
+  G4double Det4_1345_0145 = m[A10]*Det3_345_145 - m[A11]*Det3_345_045 
+                        + m[A14]*Det3_345_015 - m[A15]*Det3_345_014;
+  G4double Det4_1345_0234 = m[A10]*Det3_345_234 - m[A12]*Det3_345_034 
+                        + m[A13]*Det3_345_024 - m[A14]*Det3_345_023;
+  G4double Det4_1345_0235 = m[A10]*Det3_345_235 - m[A12]*Det3_345_035 
+                        + m[A13]*Det3_345_025 - m[A15]*Det3_345_023;
+  G4double Det4_1345_0245 = m[A10]*Det3_345_245 - m[A12]*Det3_345_045 
+                        + m[A14]*Det3_345_025 - m[A15]*Det3_345_024;
+  G4double Det4_1345_0345 = m[A10]*Det3_345_345 - m[A13]*Det3_345_045 
+                        + m[A14]*Det3_345_035 - m[A15]*Det3_345_034;
+  G4double Det4_1345_1234 = m[A11]*Det3_345_234 - m[A12]*Det3_345_134 
+                        + m[A13]*Det3_345_124 - m[A14]*Det3_345_123;
+  G4double Det4_1345_1235 = m[A11]*Det3_345_235 - m[A12]*Det3_345_135 
+                        + m[A13]*Det3_345_125 - m[A15]*Det3_345_123;
+  G4double Det4_1345_1245 = m[A11]*Det3_345_245 - m[A12]*Det3_345_145 
+                        + m[A14]*Det3_345_125 - m[A15]*Det3_345_124;
+  G4double Det4_1345_1345 = m[A11]*Det3_345_345 - m[A13]*Det3_345_145 
+                        + m[A14]*Det3_345_135 - m[A15]*Det3_345_134;
+  G4double Det4_1345_2345 = m[A12]*Det3_345_345 - m[A13]*Det3_345_245 
+                        + m[A14]*Det3_345_235 - m[A15]*Det3_345_234;
+  G4double Det4_2345_0123 = m[A20]*Det3_345_123 - m[A21]*Det3_345_023 
+                        + m[A22]*Det3_345_013 - m[A23]*Det3_345_012;
+  G4double Det4_2345_0124 = m[A20]*Det3_345_124 - m[A21]*Det3_345_024 
+                        + m[A22]*Det3_345_014 - m[A24]*Det3_345_012;
+  G4double Det4_2345_0125 = m[A20]*Det3_345_125 - m[A21]*Det3_345_025 
+                        + m[A22]*Det3_345_015 - m[A25]*Det3_345_012;
+  G4double Det4_2345_0134 = m[A20]*Det3_345_134 - m[A21]*Det3_345_034 
+                        + m[A23]*Det3_345_014 - m[A24]*Det3_345_013;
+  G4double Det4_2345_0135 = m[A20]*Det3_345_135 - m[A21]*Det3_345_035 
+                        + m[A23]*Det3_345_015 - m[A25]*Det3_345_013;
+  G4double Det4_2345_0145 = m[A20]*Det3_345_145 - m[A21]*Det3_345_045 
+                        + m[A24]*Det3_345_015 - m[A25]*Det3_345_014;
+  G4double Det4_2345_0234 = m[A20]*Det3_345_234 - m[A22]*Det3_345_034 
+                        + m[A23]*Det3_345_024 - m[A24]*Det3_345_023;
+  G4double Det4_2345_0235 = m[A20]*Det3_345_235 - m[A22]*Det3_345_035 
+                        + m[A23]*Det3_345_025 - m[A25]*Det3_345_023;
+  G4double Det4_2345_0245 = m[A20]*Det3_345_245 - m[A22]*Det3_345_045 
+                        + m[A24]*Det3_345_025 - m[A25]*Det3_345_024;
+  G4double Det4_2345_0345 = m[A20]*Det3_345_345 - m[A23]*Det3_345_045 
+                        + m[A24]*Det3_345_035 - m[A25]*Det3_345_034;
+  G4double Det4_2345_1234 = m[A21]*Det3_345_234 - m[A22]*Det3_345_134 
+                        + m[A23]*Det3_345_124 - m[A24]*Det3_345_123;
+  G4double Det4_2345_1235 = m[A21]*Det3_345_235 - m[A22]*Det3_345_135 
+                        + m[A23]*Det3_345_125 - m[A25]*Det3_345_123;
+  G4double Det4_2345_1245 = m[A21]*Det3_345_245 - m[A22]*Det3_345_145 
+                        + m[A24]*Det3_345_125 - m[A25]*Det3_345_124;
+  G4double Det4_2345_1345 = m[A21]*Det3_345_345 - m[A23]*Det3_345_145 
+                        + m[A24]*Det3_345_135 - m[A25]*Det3_345_134;
+  G4double Det4_2345_2345 = m[A22]*Det3_345_345 - m[A23]*Det3_345_245 
+                        + m[A24]*Det3_345_235 - m[A25]*Det3_345_234;
+
+  // Find all NECESSARY 5x5 dets:  (36 of them)
+
+  G4double Det5_01234_01234 = m[A00]*Det4_1234_1234 - m[A01]*Det4_1234_0234 
+    + m[A02]*Det4_1234_0134 - m[A03]*Det4_1234_0124 + m[A04]*Det4_1234_0123;
+  G4double Det5_01234_01235 = m[A00]*Det4_1234_1235 - m[A01]*Det4_1234_0235
+    + m[A02]*Det4_1234_0135 - m[A03]*Det4_1234_0125 + m[A05]*Det4_1234_0123;
+  G4double Det5_01234_01245 = m[A00]*Det4_1234_1245 - m[A01]*Det4_1234_0245
+    + m[A02]*Det4_1234_0145 - m[A04]*Det4_1234_0125 + m[A05]*Det4_1234_0124;
+  G4double Det5_01234_01345 = m[A00]*Det4_1234_1345 - m[A01]*Det4_1234_0345
+    + m[A03]*Det4_1234_0145 - m[A04]*Det4_1234_0135 + m[A05]*Det4_1234_0134;
+  G4double Det5_01234_02345 = m[A00]*Det4_1234_2345 - m[A02]*Det4_1234_0345
+    + m[A03]*Det4_1234_0245 - m[A04]*Det4_1234_0235 + m[A05]*Det4_1234_0234;
+  G4double Det5_01234_12345 = m[A01]*Det4_1234_2345 - m[A02]*Det4_1234_1345
+    + m[A03]*Det4_1234_1245 - m[A04]*Det4_1234_1235 + m[A05]*Det4_1234_1234;
+  G4double Det5_01235_01234 = m[A00]*Det4_1235_1234 - m[A01]*Det4_1235_0234 
+    + m[A02]*Det4_1235_0134 - m[A03]*Det4_1235_0124 + m[A04]*Det4_1235_0123;
+  G4double Det5_01235_01235 = m[A00]*Det4_1235_1235 - m[A01]*Det4_1235_0235 
+    + m[A02]*Det4_1235_0135 - m[A03]*Det4_1235_0125 + m[A05]*Det4_1235_0123;
+  G4double Det5_01235_01245 = m[A00]*Det4_1235_1245 - m[A01]*Det4_1235_0245 
+    + m[A02]*Det4_1235_0145 - m[A04]*Det4_1235_0125 + m[A05]*Det4_1235_0124;
+  G4double Det5_01235_01345 = m[A00]*Det4_1235_1345 - m[A01]*Det4_1235_0345 
+    + m[A03]*Det4_1235_0145 - m[A04]*Det4_1235_0135 + m[A05]*Det4_1235_0134;
+  G4double Det5_01235_02345 = m[A00]*Det4_1235_2345 - m[A02]*Det4_1235_0345 
+    + m[A03]*Det4_1235_0245 - m[A04]*Det4_1235_0235 + m[A05]*Det4_1235_0234;
+  G4double Det5_01235_12345 = m[A01]*Det4_1235_2345 - m[A02]*Det4_1235_1345 
+    + m[A03]*Det4_1235_1245 - m[A04]*Det4_1235_1235 + m[A05]*Det4_1235_1234;
+  G4double Det5_01245_01234 = m[A00]*Det4_1245_1234 - m[A01]*Det4_1245_0234 
+    + m[A02]*Det4_1245_0134 - m[A03]*Det4_1245_0124 + m[A04]*Det4_1245_0123;
+  G4double Det5_01245_01235 = m[A00]*Det4_1245_1235 - m[A01]*Det4_1245_0235 
+    + m[A02]*Det4_1245_0135 - m[A03]*Det4_1245_0125 + m[A05]*Det4_1245_0123;
+  G4double Det5_01245_01245 = m[A00]*Det4_1245_1245 - m[A01]*Det4_1245_0245 
+    + m[A02]*Det4_1245_0145 - m[A04]*Det4_1245_0125 + m[A05]*Det4_1245_0124;
+  G4double Det5_01245_01345 = m[A00]*Det4_1245_1345 - m[A01]*Det4_1245_0345 
+    + m[A03]*Det4_1245_0145 - m[A04]*Det4_1245_0135 + m[A05]*Det4_1245_0134;
+  G4double Det5_01245_02345 = m[A00]*Det4_1245_2345 - m[A02]*Det4_1245_0345 
+    + m[A03]*Det4_1245_0245 - m[A04]*Det4_1245_0235 + m[A05]*Det4_1245_0234;
+  G4double Det5_01245_12345 = m[A01]*Det4_1245_2345 - m[A02]*Det4_1245_1345 
+    + m[A03]*Det4_1245_1245 - m[A04]*Det4_1245_1235 + m[A05]*Det4_1245_1234;
+  G4double Det5_01345_01234 = m[A00]*Det4_1345_1234 - m[A01]*Det4_1345_0234 
+    + m[A02]*Det4_1345_0134 - m[A03]*Det4_1345_0124 + m[A04]*Det4_1345_0123;
+  G4double Det5_01345_01235 = m[A00]*Det4_1345_1235 - m[A01]*Det4_1345_0235 
+    + m[A02]*Det4_1345_0135 - m[A03]*Det4_1345_0125 + m[A05]*Det4_1345_0123;
+  G4double Det5_01345_01245 = m[A00]*Det4_1345_1245 - m[A01]*Det4_1345_0245 
+    + m[A02]*Det4_1345_0145 - m[A04]*Det4_1345_0125 + m[A05]*Det4_1345_0124;
+  G4double Det5_01345_01345 = m[A00]*Det4_1345_1345 - m[A01]*Det4_1345_0345 
+    + m[A03]*Det4_1345_0145 - m[A04]*Det4_1345_0135 + m[A05]*Det4_1345_0134;
+  G4double Det5_01345_02345 = m[A00]*Det4_1345_2345 - m[A02]*Det4_1345_0345 
+    + m[A03]*Det4_1345_0245 - m[A04]*Det4_1345_0235 + m[A05]*Det4_1345_0234;
+  G4double Det5_01345_12345 = m[A01]*Det4_1345_2345 - m[A02]*Det4_1345_1345 
+    + m[A03]*Det4_1345_1245 - m[A04]*Det4_1345_1235 + m[A05]*Det4_1345_1234; //
+  G4double Det5_02345_01234 = m[A00]*Det4_2345_1234 - m[A01]*Det4_2345_0234 
+    + m[A02]*Det4_2345_0134 - m[A03]*Det4_2345_0124 + m[A04]*Det4_2345_0123;
+  G4double Det5_02345_01235 = m[A00]*Det4_2345_1235 - m[A01]*Det4_2345_0235 
+    + m[A02]*Det4_2345_0135 - m[A03]*Det4_2345_0125 + m[A05]*Det4_2345_0123;
+  G4double Det5_02345_01245 = m[A00]*Det4_2345_1245 - m[A01]*Det4_2345_0245 
+    + m[A02]*Det4_2345_0145 - m[A04]*Det4_2345_0125 + m[A05]*Det4_2345_0124;
+  G4double Det5_02345_01345 = m[A00]*Det4_2345_1345 - m[A01]*Det4_2345_0345 
+    + m[A03]*Det4_2345_0145 - m[A04]*Det4_2345_0135 + m[A05]*Det4_2345_0134;
+  G4double Det5_02345_02345 = m[A00]*Det4_2345_2345 - m[A02]*Det4_2345_0345 
+    + m[A03]*Det4_2345_0245 - m[A04]*Det4_2345_0235 + m[A05]*Det4_2345_0234;
+  G4double Det5_02345_12345 = m[A01]*Det4_2345_2345 - m[A02]*Det4_2345_1345 
+    + m[A03]*Det4_2345_1245 - m[A04]*Det4_2345_1235 + m[A05]*Det4_2345_1234;
+  G4double Det5_12345_01234 = m[A10]*Det4_2345_1234 - m[A11]*Det4_2345_0234 
+    + m[A12]*Det4_2345_0134 - m[A13]*Det4_2345_0124 + m[A14]*Det4_2345_0123;
+  G4double Det5_12345_01235 = m[A10]*Det4_2345_1235 - m[A11]*Det4_2345_0235 
+    + m[A12]*Det4_2345_0135 - m[A13]*Det4_2345_0125 + m[A15]*Det4_2345_0123;
+  G4double Det5_12345_01245 = m[A10]*Det4_2345_1245 - m[A11]*Det4_2345_0245 
+    + m[A12]*Det4_2345_0145 - m[A14]*Det4_2345_0125 + m[A15]*Det4_2345_0124;
+  G4double Det5_12345_01345 = m[A10]*Det4_2345_1345 - m[A11]*Det4_2345_0345 
+    + m[A13]*Det4_2345_0145 - m[A14]*Det4_2345_0135 + m[A15]*Det4_2345_0134;
+  G4double Det5_12345_02345 = m[A10]*Det4_2345_2345 - m[A12]*Det4_2345_0345 
+    + m[A13]*Det4_2345_0245 - m[A14]*Det4_2345_0235 + m[A15]*Det4_2345_0234;
+  G4double Det5_12345_12345 = m[A11]*Det4_2345_2345 - m[A12]*Det4_2345_1345 
+    + m[A13]*Det4_2345_1245 - m[A14]*Det4_2345_1235 + m[A15]*Det4_2345_1234;
+
+  // Find the determinant 
+
+  G4double det =  m[A00]*Det5_12345_12345 
+                - m[A01]*Det5_12345_02345 
+                + m[A02]*Det5_12345_01345 
+                - m[A03]*Det5_12345_01245 
+                + m[A04]*Det5_12345_01235 
+                - m[A05]*Det5_12345_01234;
+
+  if ( det == 0 )
+  {  
+    ifail = 1;
+    return;
+  } 
+
+  G4double oneOverDet = 1.0/det;
+  G4double mn1OverDet = - oneOverDet;
+
+  m[A00] =  Det5_12345_12345*oneOverDet;
+  m[A01] =  Det5_02345_12345*mn1OverDet;
+  m[A02] =  Det5_01345_12345*oneOverDet;
+  m[A03] =  Det5_01245_12345*mn1OverDet;
+  m[A04] =  Det5_01235_12345*oneOverDet;
+  m[A05] =  Det5_01234_12345*mn1OverDet;
+
+  m[A10] =  Det5_12345_02345*mn1OverDet;
+  m[A11] =  Det5_02345_02345*oneOverDet;
+  m[A12] =  Det5_01345_02345*mn1OverDet;
+  m[A13] =  Det5_01245_02345*oneOverDet;
+  m[A14] =  Det5_01235_02345*mn1OverDet;
+  m[A15] =  Det5_01234_02345*oneOverDet;
+
+  m[A20] =  Det5_12345_01345*oneOverDet;
+  m[A21] =  Det5_02345_01345*mn1OverDet;
+  m[A22] =  Det5_01345_01345*oneOverDet;
+  m[A23] =  Det5_01245_01345*mn1OverDet;
+  m[A24] =  Det5_01235_01345*oneOverDet;
+  m[A25] =  Det5_01234_01345*mn1OverDet;
+
+  m[A30] =  Det5_12345_01245*mn1OverDet;
+  m[A31] =  Det5_02345_01245*oneOverDet;
+  m[A32] =  Det5_01345_01245*mn1OverDet;
+  m[A33] =  Det5_01245_01245*oneOverDet;
+  m[A34] =  Det5_01235_01245*mn1OverDet;
+  m[A35] =  Det5_01234_01245*oneOverDet;
+
+  m[A40] =  Det5_12345_01235*oneOverDet;
+  m[A41] =  Det5_02345_01235*mn1OverDet;
+  m[A42] =  Det5_01345_01235*oneOverDet;
+  m[A43] =  Det5_01245_01235*mn1OverDet;
+  m[A44] =  Det5_01235_01235*oneOverDet;
+  m[A45] =  Det5_01234_01235*mn1OverDet;
+
+  m[A50] =  Det5_12345_01234*mn1OverDet;
+  m[A51] =  Det5_02345_01234*oneOverDet;
+  m[A52] =  Det5_01345_01234*mn1OverDet;
+  m[A53] =  Det5_01245_01234*oneOverDet;
+  m[A54] =  Det5_01235_01234*mn1OverDet;
+  m[A55] =  Det5_01234_01234*oneOverDet;
+
+  return;
+}
Index: /trunk/source/error_propagation/src/G4ErrorMessenger.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorMessenger.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorMessenger.cc	(revision 815)
@@ -0,0 +1,112 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorMessenger.cc,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4ErrorMessenger.hh"
+#include "G4ErrorStepLengthLimitProcess.hh"
+#include "G4ErrorMagFieldLimitProcess.hh"
+#include "G4ErrorEnergyLoss.hh"
+
+#include "G4UIdirectory.hh"
+#include "G4UIcmdWithADoubleAndUnit.hh"
+#include "G4UIcmdWithADouble.hh"
+#include "globals.hh"
+
+#ifdef G4VERBOSE
+#include "G4ErrorPropagatorData.hh" //for verbosity checking
+#endif
+
+//------------------------------------------------------------------------
+G4ErrorMessenger::G4ErrorMessenger(G4ErrorStepLengthLimitProcess* lengthAct, G4ErrorMagFieldLimitProcess* magAct, G4ErrorEnergyLoss* elossAct)
+  :StepLengthAction(lengthAct),MagFieldAction(magAct),EnergyLossAction(elossAct)
+{
+
+  myDir = new G4UIdirectory("/geant4e/");
+  myDir->SetGuidance("GEANT4e control commands");
+  
+  myDirLimits = new G4UIdirectory("/geant4e/limits/");
+  myDirLimits->SetGuidance("GEANT4e commands to limit the step");
+
+
+  StepLengthLimitCmd = new G4UIcmdWithADoubleAndUnit("/geant4e/limits/stepLength",this);  
+  StepLengthLimitCmd->SetGuidance("Limit the length of an step");
+  StepLengthLimitCmd->SetDefaultUnit("mm");
+  StepLengthLimitCmd->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
+
+  MagFieldLimitCmd = new G4UIcmdWithADouble("/geant4e/limits/magField",this);  
+  MagFieldLimitCmd->SetGuidance("Limit the length of an step");
+  MagFieldLimitCmd->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
+
+  EnergyLossCmd = new G4UIcmdWithADouble("/geant4e/limits/energyLoss",this);  
+  EnergyLossCmd->SetGuidance("Limit the length of an step");
+  EnergyLossCmd->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
+}
+
+
+//------------------------------------------------------------------------
+G4ErrorMessenger::~G4ErrorMessenger()
+{
+  delete StepLengthLimitCmd;
+  delete MagFieldLimitCmd;
+  delete EnergyLossCmd;
+  delete myDir;
+  delete myDirLimits;
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
+{   
+  if( command == StepLengthLimitCmd ) { 
+#ifdef G4VERBOSE
+    if(G4ErrorPropagatorData::verbose() >= 3 ) { 
+      G4cout << " G4ErrorMessenger::StepLengthAction SetStepLimit " << StepLengthLimitCmd->GetNewDoubleValue(newValue) << G4endl;
+    }
+#endif
+    StepLengthAction->SetStepLimit(StepLengthLimitCmd->GetNewDoubleValue(newValue));
+  } else if( command == MagFieldLimitCmd ) { 
+#ifdef G4VERBOSE
+    if(G4ErrorPropagatorData::verbose() >= 3 ) { 
+      G4cout << " G4ErrorMessenger::MagFieldAction SetStepLimit " << MagFieldLimitCmd->GetNewDoubleValue(newValue) << G4endl;
+    }
+#endif
+    MagFieldAction->SetStepLimit(MagFieldLimitCmd->GetNewDoubleValue(newValue));
+  } else if( command == EnergyLossCmd ) { 
+#ifdef G4VERBOSE
+    if(G4ErrorPropagatorData::verbose() >= 3 ) { 
+      G4cout << " G4ErrorMessenger::EnergyLossAction SetStepLimit " << EnergyLossCmd->GetNewDoubleValue(newValue) << G4endl;
+    }
+#endif
+    EnergyLossAction->SetStepLimit(EnergyLossCmd->GetNewDoubleValue(newValue));
+  }
+}
+
Index: /trunk/source/error_propagation/src/G4ErrorPhysicsList.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorPhysicsList.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorPhysicsList.cc	(revision 815)
@@ -0,0 +1,226 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorPhysicsList.cc,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+
+#include "globals.hh"
+
+#include "G4ErrorPhysicsList.hh"
+#include "G4ComptonScattering.hh"
+#include "G4GammaConversion.hh"
+#include "G4PhotoElectricEffect.hh"
+ 
+#include "G4eIonisation.hh"
+#include "G4eBremsstrahlung.hh"
+#include "G4eplusAnnihilation.hh"
+
+#include "G4MuIonisation.hh"
+#include "G4MuBremsstrahlung.hh"
+#include "G4MuPairProduction.hh"
+
+#include "G4hIonisation.hh"
+
+#include "G4MuIonisation.hh"
+#include "G4MuBremsstrahlung.hh"
+#include "G4MuPairProduction.hh"
+
+#include "G4hIonisation.hh"
+
+#include "G4ParticleDefinition.hh"
+#include "G4ProcessManager.hh"
+#include "G4ProcessVector.hh"
+#include "G4ParticleTypes.hh"
+#include "G4ParticleTable.hh"
+#include "G4Material.hh"
+#include "G4MaterialTable.hh"
+#include "G4ios.hh"
+#include "G4PhysicsTable.hh"
+#include "G4Transportation.hh"
+
+#include "G4ErrorEnergyLoss.hh"
+
+//------------------------------------------------------------------------
+G4ErrorPhysicsList::G4ErrorPhysicsList():  G4VUserPhysicsList()
+{
+  defaultCutValue = 1.0E+9*cm; // set big step so that AlongStep computes all the energy
+}
+
+
+//------------------------------------------------------------------------
+G4ErrorPhysicsList::~G4ErrorPhysicsList()
+{
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorPhysicsList::ConstructParticle()
+{
+// In this method, static member functions should be called
+  // for all particles which you want to use.
+  // This ensures that objects of these particle types will be
+  // created in the program. 
+  //  gamma
+  G4Gamma::GammaDefinition(); 
+  //  e+/-
+  G4Electron::ElectronDefinition();
+  G4Positron::PositronDefinition();
+  // mu+/-
+  G4MuonPlus::MuonPlusDefinition();
+  G4MuonMinus::MuonMinusDefinition();
+
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorPhysicsList::ConstructProcess()
+{
+  G4Transportation* theTransportationProcess= new G4Transportation();
+
+#ifdef G4VERBOSE
+    if (verboseLevel >= 4){
+      G4cout << "G4VUserPhysicsList::ConstructProcess()  "<< G4endl;
+    }
+#endif
+
+  // loop over all particles in G4ParticleTable
+  theParticleIterator->reset();
+  while( (*theParticleIterator)() ){
+    G4ParticleDefinition* particle = theParticleIterator->value();
+    G4ProcessManager* pmanager = particle->GetProcessManager();
+    if (!particle->IsShortLived()) {
+      G4cout << particle << "G4ErrorPhysicsList:: particle process manager " << particle->GetParticleName() << " = " << particle->GetProcessManager() << G4endl;
+      // Add transportation process for all particles other than  "shortlived"
+      if ( pmanager == 0) {
+        // Error !! no process manager
+        G4String particleName = particle->GetParticleName();
+        G4Exception("G4ErrorPhysicsList::ConstructProcess","No process manager",
+                    RunMustBeAborted, particleName );
+      } else {
+        // add transportation with ordering = ( -1, "first", "first" )
+        pmanager ->AddProcess(theTransportationProcess);
+        pmanager ->SetProcessOrderingToFirst(theTransportationProcess, idxAlongStep);
+        pmanager ->SetProcessOrderingToFirst(theTransportationProcess, idxPostStep);
+      }
+    } else {
+      // shortlived particle case
+    }
+  }
+
+  ConstructEM();
+}
+
+
+//------------------------------------------------------------------------
+#include "G4eBremsstrahlung.hh"
+#include "G4eIonisation.hh"
+
+#include "G4eIonisation.hh"
+
+#include "G4MuBremsstrahlung.hh"
+#include "G4MuIonisation.hh"
+#include "G4MuPairProduction.hh"
+
+#include "G4PhysicsTable.hh"
+
+#include "G4VEnergyLoss.hh"
+
+#include "G4MuIonisation.hh"
+
+#include "G4ErrorStepLengthLimitProcess.hh"
+#include "G4ErrorMagFieldLimitProcess.hh"
+#include "G4ErrorMessenger.hh"
+
+void G4ErrorPhysicsList::ConstructEM()
+{
+
+  G4ErrorEnergyLoss* eLossProcess = new G4ErrorEnergyLoss;
+  G4ErrorStepLengthLimitProcess* stepLengthLimitProcess = new G4ErrorStepLengthLimitProcess;
+  G4ErrorMagFieldLimitProcess* magFieldLimitProcess = new G4ErrorMagFieldLimitProcess;
+  new G4ErrorMessenger( stepLengthLimitProcess, magFieldLimitProcess, eLossProcess );
+
+  theParticleIterator->reset();
+  while( (*theParticleIterator)() ){
+    G4ParticleDefinition* particle = theParticleIterator->value();
+    G4ProcessManager* pmanager = particle->GetProcessManager();
+    G4String particleName = particle->GetParticleName();
+     
+    if (particleName == "gamma") {
+    // gamma
+      pmanager->AddDiscreteProcess(new G4GammaConversion());
+      pmanager->AddDiscreteProcess(new G4ComptonScattering());      
+      pmanager->AddDiscreteProcess(new G4PhotoElectricEffect());
+
+      //    } else if (particleName == "e-" || particleName == "e+"
+      //               || particleName == "mu+" || particleName == "mu-" ) {
+    }else if (!particle->IsShortLived() && particle->GetPDGCharge() != 0 ) {
+  
+      pmanager->AddContinuousProcess(eLossProcess,1);
+      pmanager->AddDiscreteProcess( stepLengthLimitProcess, 2 ); 
+      pmanager->AddDiscreteProcess( magFieldLimitProcess, 3 );     
+      
+    } else if ((!particle->IsShortLived()) &&
+               (particle->GetPDGCharge() != 0.0) && 
+               (particle->GetParticleName() != "chargedgeantino")) {
+     // all others charged particles except geantino
+      //   G4VProcess* aMultipleScattering = new G4MultipleScattering();
+     G4VProcess* anIonisation        = new G4hIonisation();     
+     ////G4VProcess*  theUserCuts = new G4UserSpecialCuts();
+     
+     //
+     // add processes
+     pmanager->AddProcess(anIonisation);
+     //   pmanager->AddProcess(aMultipleScattering);    
+     ////pmanager->AddProcess(theUserCuts);
+     
+     //
+     // set ordering for AlongStepDoIt
+     //   pmanager->SetProcessOrdering(aMultipleScattering, idxAlongStep,1);
+     pmanager->SetProcessOrdering(anIonisation, idxAlongStep,1);
+     
+     //
+     // set ordering for PostStepDoIt
+     //   pmanager->SetProcessOrdering(aMultipleScattering, idxPostStep,1);
+     pmanager->SetProcessOrdering(anIonisation, idxPostStep,1);
+     ////pmanager->SetProcessOrdering(theUserCuts,     idxPostStep,2);
+    }
+  }
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorPhysicsList::SetCuts()
+{
+  //  " G4VUserPhysicsList::SetCutsWithDefault" method sets 
+  //   the default cut value or all particle types 
+  SetCutsWithDefault(); 
+  // if (verboseLevel>0) 
+  //  DumpCutValuesTable();
+}
+
Index: /trunk/source/error_propagation/src/G4ErrorPropagator.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorPropagator.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorPropagator.cc	(revision 815)
@@ -0,0 +1,628 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorPropagator.cc,v 1.7 2007/11/14 17:01:14 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4ErrorPropagator.hh"
+#include "G4ErrorPropagatorData.hh"
+#include "G4ErrorFreeTrajState.hh"
+#include "G4ErrorSurfaceTrajState.hh"
+#include "G4ErrorGeomVolumeTarget.hh"
+#include "G4ErrorSurfaceTarget.hh"
+
+#include "G4DynamicParticle.hh"
+#include "G4Track.hh"
+#include "G4SteppingManager.hh"
+#include "G4EventManager.hh"
+#include "G4TrackingManager.hh"
+#include "G4ParticleTable.hh"
+#include "G4StateManager.hh"
+
+#include "G4VPhysicalVolume.hh"
+#include "G4PhysicalVolumeStore.hh"
+#include "G4UnitsTable.hh"
+
+#include <vector>
+
+
+//---------------------------------------------------------------------------
+G4ErrorPropagator::G4ErrorPropagator()
+{
+  verbose =  G4ErrorPropagatorData::verbose();
+#ifdef G4EVERBOSE
+   if(verbose >= 5) { G4cout << "G4ErrorPropagator " << this << G4endl; }
+#endif
+
+  theG4Track = 0;
+  fpSteppingManager = G4EventManager::GetEventManager()
+                    ->GetTrackingManager()->GetSteppingManager();
+  thePropIsInitialized = false;
+}
+
+
+//-----------------------------------------------------------------------
+G4int G4ErrorPropagator::Propagate( G4ErrorTrajState* currentTS,
+                              const G4ErrorTarget* target, G4ErrorMode mode )
+{
+  // to start ierror is set to 1 (= OK)
+  //
+  G4int ierr = 1;
+
+  G4ErrorPropagatorData* g4edata =
+    G4ErrorPropagatorData::GetErrorPropagatorData();
+
+  //----- Do not propagate zero or too low energy particles
+  //
+  if( currentTS->GetMomentum().mag() < 1.E-9*MeV )
+  {
+    G4cerr << "ERROR - G4ErrorPropagator::Propagate()" << G4endl
+           << "        Energy too low to be propagated: "
+           << G4BestUnit(currentTS->GetMomentum().mag(),"Energy") << G4endl;
+    return -3; 
+  }
+
+  g4edata->SetMode( mode );
+
+#ifdef G4EVERBOSE
+  if( verbose >= 1 )
+  {
+     G4cout << " =====> starting GEANT4E tracking for "
+            << currentTS->GetParticleType()
+            << "  Forwards= " << g4edata->GetMode() << G4endl;
+  }
+  if(verbose >= 1 )
+  {
+     G4cout << G4endl << "@@@@@@@@@@@@@@@@@@@@@@@@@ NEW STEP " << G4endl;
+  }
+
+  if( verbose >= 3 )
+  {
+    G4cout << " G4ErrorPropagator::Propagate initialTS ";
+    G4cout << *currentTS << G4endl;
+    target->Dump(G4String(" to target "));
+  }
+#endif
+
+  g4edata->SetTarget( target );
+
+  //----- Create a track
+  //
+  if( theG4Track != 0 ) { delete theG4Track; }
+  theG4Track = InitG4Track( *currentTS );
+
+  //----- Create a G4ErrorFreeTrajState
+  //
+  G4ErrorFreeTrajState* currentTS_FREE = InitFreeTrajState( currentTS );
+
+  //----- Track the particle
+  //
+  ierr = MakeSteps( currentTS_FREE );
+
+  //------ Tracking ended, check if target has been reached
+  //       if target not found
+  //
+  if( g4edata->GetState() != G4ErrorState_StoppedAtTarget )
+  {
+    if( theG4Track->GetKineticEnergy() > 0. )
+    {
+      ierr = -ierr - 10;
+    }
+    else
+    {
+      ierr = -ierr - 20;
+    }
+    *currentTS = *currentTS_FREE;
+    if(verbose >= 0 )
+    {
+       G4cerr << "ERROR - G4ErrorPropagator::Propagate()" << G4endl
+              << "        Particle does not reach target: " << *currentTS
+              << G4endl;
+    }
+  }
+  else
+  {
+    GetFinalTrajState( currentTS, currentTS_FREE, target );
+  }
+
+#ifdef G4EVERBOSE
+  if( verbose >= 1 )
+  {
+    G4cout << " G4ErrorPropagator: propagation ended " << G4endl;
+  }
+  if( verbose >= 2 )
+  {
+    G4cout << " Current TrajState " << currentTS << G4endl;
+  }
+#endif
+ 
+  // Inform end of tracking to physics processes
+  //
+  theG4Track->GetDefinition()->GetProcessManager()->EndTracking();
+
+  InvokePostUserTrackingAction( theG4Track );
+
+  return ierr;
+}
+
+
+//-----------------------------------------------------------------------
+G4int G4ErrorPropagator::PropagateOneStep( G4ErrorTrajState* currentTS )
+{
+  G4ErrorPropagatorData* g4edata =
+    G4ErrorPropagatorData::GetErrorPropagatorData();
+
+  if ( (g4edata->GetState() == G4ErrorState_PreInit)
+    || (G4StateManager::GetStateManager()->GetCurrentState()
+       != G4State_GeomClosed) )
+  {
+    G4cout << "ERROR - G4ErrorPropagator::PropagateOneStep()" << G4endl
+           << "        Called before initialization is done for this track."
+           << G4endl
+           << "        Please call G4ErrorPropagatorManager::InitGeant4e()."
+           << G4endl;
+    G4Exception("G4ErrorPropagator::PropagateOneStep()",
+                "InvalidCall", FatalException,
+                "Called before initialization is done for this track!");
+  }
+
+  // to start ierror is set to 0 (= OK)
+  //
+  G4int ierr = 0;
+
+  //--- Do not propagate zero or too low energy particles
+  //
+  if( currentTS->GetMomentum().mag() < 1.E-9*MeV )
+  {
+    G4cerr << "ERROR - G4ErrorPropagator::PropagateOneStep()" << G4endl
+           << "        Energy too low to be propagated: "
+           << G4BestUnit(currentTS->GetMomentum().mag(),"Energy") << G4endl;
+    return -3;   
+  }
+
+#ifdef G4EVERBOSE
+  if( verbose >= 1 )
+  {
+    G4cout << " =====> starting GEANT4E tracking for "
+           << currentTS->GetParticleType()
+           << "  Forwards= " << g4edata->GetMode() << G4endl;
+  }
+  if( verbose >= 3 )
+  {
+    G4cout << " G4ErrorPropagator::Propagate initialTS ";
+    G4cout << *currentTS << G4endl;
+  }
+#endif
+
+  //----- If it is the first step, create a track
+  //
+  if( theStepN == 0 ) { theG4Track = InitG4Track( *currentTS ); }
+    // set to 0 by the initialization in G4ErrorPropagatorManager
+  theStepN++;
+
+  //----- Create a G4ErrorFreeTrajState
+  //
+  G4ErrorFreeTrajState* currentTS_FREE = InitFreeTrajState( currentTS );
+
+  //----- Track the particle one step
+  //
+  ierr = MakeOneStep( currentTS_FREE );
+
+  //----- Get the state on target
+  //
+  GetFinalTrajState( currentTS, currentTS_FREE, g4edata->GetTarget() );
+
+  return ierr;
+}
+
+
+//---------------------------------------------------------------------------
+G4Track* G4ErrorPropagator::InitG4Track( G4ErrorTrajState& initialTS )
+{
+  if( verbose >= 5 ) { G4cout << "InitG4Track " << G4endl; }
+
+  //----- Create Particle
+  //
+  const G4String partType = initialTS.GetParticleType();
+  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
+  G4ParticleDefinition* particle = particleTable->FindParticle(partType); 
+  if( particle == 0)
+  {
+    G4cerr << "ERROR - G4ErrorPropagator::InitG4Track()" << G4endl
+           << "        Particle type not defined " + partType << G4endl;
+    G4Exception( "G4ErrorPropagator::InitG4Track()", "InvalidSetup",
+                 FatalException, "Particle type not defined !" );
+  }
+ 
+  G4DynamicParticle* DP = 
+    new G4DynamicParticle(particle,initialTS.GetMomentum());
+
+  DP->SetPolarization(0.,0.,0.);
+
+  // Set Charge
+  //
+  if( particle->GetPDGCharge() < 0 )
+  {
+    DP->SetCharge(-eplus);
+  }
+  else
+  {
+    DP->SetCharge(eplus);
+  }
+
+  //----- Create Track 
+  //
+  theG4Track = new G4Track(DP, 0., initialTS.GetPosition() );
+  theG4Track->SetParentID(0);
+
+#ifdef G4EVERBOSE
+  if(verbose >= 3)
+  {
+    G4cout << " G4ErrorPropagator new track of energy: "
+           << theG4Track->GetKineticEnergy() << G4endl;
+  }
+#endif
+  
+  //---- Reproduce G4TrackingManager::ProcessOneTrack initialization
+  InvokePreUserTrackingAction( theG4Track );  
+
+  if( fpSteppingManager == 0 )
+  {
+    G4Exception("G4ErrorPropagator::InitG4Track()", "InvalidSetup",
+                FatalException, "G4SteppingManager not initialized yet!");
+  }
+  else
+  {
+    fpSteppingManager->SetInitialStep(theG4Track);
+  }
+
+  // Give SteppingManger the maximum number of processes
+  //
+  fpSteppingManager->GetProcessNumber();
+
+  // Give track the pointer to the Step
+  //
+  theG4Track->SetStep(fpSteppingManager->GetStep());
+
+  // Inform beginning of tracking to physics processes
+  //
+  theG4Track->GetDefinition()->GetProcessManager()->StartTracking(theG4Track);
+
+  initialTS.SetG4Track( theG4Track );
+
+  return theG4Track;
+}
+
+
+//-----------------------------------------------------------------------
+G4int G4ErrorPropagator::MakeSteps( G4ErrorFreeTrajState* currentTS_FREE )
+{
+  G4int ierr = 0;
+
+  //----- Track the particle Step-by-Step while it is alive
+  //
+  theStepLength = 0.;
+  
+  while( (theG4Track->GetTrackStatus() == fAlive) ||
+         (theG4Track->GetTrackStatus() == fStopButAlive) )
+  {
+    ierr = MakeOneStep( currentTS_FREE );
+    if( ierr != 0 ) { break; }
+
+    //----- Check if last step for error propagation
+    //
+    if( CheckIfLastStep( theG4Track ) )
+    {
+      break;
+    }
+  }
+  return ierr;
+}
+
+
+//-----------------------------------------------------------------------
+G4int G4ErrorPropagator::MakeOneStep( G4ErrorFreeTrajState* currentTS_FREE )
+{
+  G4ErrorPropagatorData* g4edata =
+    G4ErrorPropagatorData::GetErrorPropagatorData();
+  G4int ierr = 0;
+
+  //---------- Track one step
+#ifdef G4EVERBOSE
+  if(verbose >= 2 )
+  {
+    G4cout << G4endl
+           << "@@@@@@@@@@@@@@@@@@@@@@@@@ NEW STEP " << G4endl;
+  }
+#endif
+  
+  theG4Track->IncrementCurrentStepNumber();
+
+  fpSteppingManager->Stepping();
+  
+  //---------- Check if Target has been reached (and then set G4ErrorState)
+
+  // G4ErrorPropagationNavigator limits the step if target is closer than
+  // boundary (but the winner process is always "Transportation": then
+  // error propagator will stop the track
+
+  if( theG4Track->GetStep()->GetPostStepPoint()
+      ->GetProcessDefinedStep()->GetProcessName() == "Transportation" )
+  {
+    if( g4edata->GetState()
+       == G4ErrorState(G4ErrorState_TargetCloserThanBoundary) )
+    {  // target or step length reached
+      
+#ifdef G4EVERBOSE
+      if(verbose >= 5 )
+      {
+        G4cout << " transportation determined by geant4e " << G4endl;
+      }
+#endif      
+      g4edata->SetState( G4ErrorState_StoppedAtTarget );
+    }
+    else if( g4edata->GetTarget()->GetType() == G4ErrorTarget_GeomVolume )
+    {
+      G4ErrorGeomVolumeTarget* target =
+        (G4ErrorGeomVolumeTarget*)(g4edata->GetTarget());
+      if( static_cast<G4ErrorGeomVolumeTarget*>( target )
+          ->TargetReached( theG4Track->GetStep() ) )
+      {
+        g4edata->SetState( G4ErrorState_StoppedAtTarget ); 
+      } 
+    }
+  }
+  else if( theG4Track->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()
+           ->GetProcessName() == "G4ErrorTrackLengthTarget" )
+  {
+    g4edata->SetState( G4ErrorState_StoppedAtTarget );
+  }
+
+  //---------- Propagate error  
+
+#ifdef G4EVERBOSE
+  if(verbose >= 2 )
+  {
+    G4cout << " propagating error " << *currentTS_FREE << G4endl;
+  }
+#endif
+  const G4Track* cTrack = const_cast<G4Track*>(theG4Track);
+  ierr = currentTS_FREE->PropagateError( cTrack );
+  
+#ifdef G4EVERBOSE
+  if(verbose >= 3 )
+  {
+    G4cout << " PropagateError returns " << ierr << G4endl;
+  }
+#endif
+
+  currentTS_FREE->Update( cTrack );
+  
+  theStepLength += theG4Track->GetStepLength();
+   
+  if(ierr != 0 )
+  {
+    G4cerr << "ERROR - G4ErrorPropagator:MakeOneStep()" << G4endl
+           << "        Error returned: " << ierr << G4endl
+           << "        Geant4 tracking will be stopped !" << G4endl;
+  }
+
+  return ierr; 
+}
+
+
+//-----------------------------------------------------------------------
+G4ErrorFreeTrajState*
+G4ErrorPropagator::InitFreeTrajState( G4ErrorTrajState* currentTS )
+{
+  G4ErrorFreeTrajState* currentTS_FREE = 0;
+
+  //----- Transform the TrajState to Free coordinates if it is OnSurface
+  //
+  if( currentTS->GetTSType() == G4eTS_OS )
+  {
+    G4ErrorSurfaceTrajState* tssd =
+      static_cast<G4ErrorSurfaceTrajState*>(currentTS);
+    currentTS_FREE = new G4ErrorFreeTrajState( *tssd );
+  }
+  else if( currentTS->GetTSType() == G4eTS_FREE )
+  {
+    currentTS_FREE = static_cast<G4ErrorFreeTrajState*>(currentTS);
+  }
+  else
+  {
+    G4cerr << "ERROR - G4ErrorPropagator::InitFreeTrajState()" << G4endl
+           << "WRONG TrajState " + currentTS->GetTSType() << G4endl;
+    G4Exception("G4ErrorPropagator::InitFreeTrajState()", "InvalidState",
+                FatalException, "WRONG trajectory state !");
+  }
+  return currentTS_FREE;
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorPropagator::GetFinalTrajState( G4ErrorTrajState* currentTS,
+                                           G4ErrorFreeTrajState* currentTS_FREE,
+                                           const G4ErrorTarget* target ) 
+{
+  G4ErrorPropagatorData* g4edata =
+    G4ErrorPropagatorData::GetErrorPropagatorData();
+
+#ifdef G4EVERBOSE
+  if(verbose >= 1 )
+  {
+    G4cout << " G4ErrorPropagator::Propagate: final state "
+           << G4int(g4edata->GetState()) << " TSType "
+           << currentTS->GetTSType() << G4endl;
+  }
+#endif
+
+  if( (currentTS->GetTSType() == G4eTS_FREE) || 
+      (g4edata->GetState() != G4ErrorState_StoppedAtTarget) )
+  {
+    currentTS = currentTS_FREE;
+  }
+  else if( currentTS->GetTSType() == G4eTS_OS )
+  {
+    if( target->GetType() == G4ErrorTarget_TrkL )
+    {
+      G4Exception("G4ErrorPropagator:GetFinalTrajState()",
+                  "InvalidSetup", FatalException,
+                  "Using a G4ErrorSurfaceTrajState with wrong target");
+    }
+    const G4ErrorTanPlaneTarget* targetWTP =
+      static_cast<const G4ErrorTanPlaneTarget*>(target);
+    *currentTS = G4ErrorSurfaceTrajState(
+                 *(static_cast<G4ErrorFreeTrajState*>(currentTS_FREE)),
+                 targetWTP->GetTangentPlane( currentTS_FREE->GetPosition() ) );
+#ifdef G4EVERBOSE
+    if(verbose >= 1 )
+    {
+      G4cout << currentTS << " returning tssd " << *currentTS << G4endl;
+    }
+#endif
+    delete currentTS_FREE;
+  }
+}
+
+
+//-------------------------------------------------------------------------
+G4bool G4ErrorPropagator::CheckIfLastStep( G4Track* aTrack )
+{
+  G4bool exception = 0;
+  G4bool lastG4eStep = false;
+  G4ErrorPropagatorData* g4edata =
+    G4ErrorPropagatorData::GetErrorPropagatorData();
+
+#ifdef G4EVERBOSE
+  if( verbose >= 4 )
+  {
+    G4cout << " G4ErrorPropagator::CheckIfLastStep G4ErrorState= "
+           << G4int(g4edata->GetState()) << G4endl;
+  }
+#endif
+  
+  //----- Check if this is the last step: track has reached the target
+  //      or the end of world
+  //
+  if(g4edata->GetState() == G4ErrorState(G4ErrorState_StoppedAtTarget) )
+  {
+    lastG4eStep = true;    
+#ifdef G4EVERBOSE
+    if(verbose >= 5 )
+    {
+      G4cout << " G4ErrorPropagator::CheckIfLastStep " << lastG4eStep
+             << " " << G4int(g4edata->GetState()) << G4endl;
+    }
+#endif
+  }
+  else if( aTrack->GetNextVolume() == 0 )
+  {
+    //----- If particle is out of world, without finding the G4ErrorTarget,
+    //      give a n error/warning
+    //
+    lastG4eStep = true;
+    if( exception )
+    {
+      G4cerr << "ERROR - G4ErrorPropagator::CheckIfLastStep()" << G4endl
+             << "        Track extrapolated until end of World" << G4endl
+             << "        without finding the defined target " << G4endl;
+      G4Exception("G4ErrorPropagator::CheckIfLastStep()",
+                  "InvalidSetup", FatalException,
+                  "Track extrapolated without finding the defined target.");
+    }
+    else
+    {
+      if( verbose >= 1 )
+      {
+        G4cerr << "ERROR - G4ErrorPropagator::CheckIfLastStep()" << G4endl
+               << "        Track extrapolated until end of World" << G4endl
+               << "        without finding the defined target " << G4endl;
+      }
+    }
+  }  //----- not last step from G4e, but track is stopped (energy exhausted)
+  else if( aTrack->GetTrackStatus() == fStopAndKill )
+  { 
+    if( exception )
+    {
+      G4cerr << "ERROR - G4ErrorPropagator::CheckIfLastStep()" << G4endl
+             << "        Track extrapolated until energy is exhausted" << G4endl
+             << "        without finding the defined target !" << G4endl;
+      G4Exception("G4ErrorPropagator::CheckIfLastStep()",
+                  "InvalidSetup", FatalException,
+                  "Track extrapolated without finding the defined target.");
+    }
+    else
+    {
+      if( verbose >= 1 )
+      {
+        G4cerr << "ERROR - G4ErrorPropagator::CheckIfLastStep()" << G4endl
+             << "        Track extrapolated until energy is exhausted" << G4endl
+             << "        without finding the defined target !" << G4endl;
+      }
+      lastG4eStep = 1;
+    }
+  }
+
+#ifdef G4EVERBOSE
+  if( verbose >= 5 )
+  {
+    G4cout << " return CheckIfLastStep " << lastG4eStep << G4endl;
+  }
+#endif
+
+  return  lastG4eStep;
+}
+
+
+//---------------------------------------------------------------------------
+void G4ErrorPropagator::InvokePreUserTrackingAction( G4Track* fpTrack )
+{
+  const G4UserTrackingAction* fpUserTrackingAction =
+    G4EventManager::GetEventManager()->GetUserTrackingAction();
+  if( fpUserTrackingAction != 0 )
+  {
+    const_cast<G4UserTrackingAction*>(fpUserTrackingAction)
+      ->PreUserTrackingAction((fpTrack) );
+  }
+}
+
+
+//---------------------------------------------------------------------------
+void G4ErrorPropagator::InvokePostUserTrackingAction( G4Track* fpTrack )
+{
+  const G4UserTrackingAction* fpUserTrackingAction =
+    G4EventManager::GetEventManager()->GetUserTrackingAction();
+  if( fpUserTrackingAction != 0 )
+  {
+    const_cast<G4UserTrackingAction*>(fpUserTrackingAction)
+      ->PostUserTrackingAction((fpTrack) );
+  }
+}
Index: /trunk/source/error_propagation/src/G4ErrorPropagatorManager.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorPropagatorManager.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorPropagatorManager.cc	(revision 815)
@@ -0,0 +1,435 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorPropagatorManager.cc,v 1.3 2007/05/31 15:28:51 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4MagIntegratorStepper.hh"
+#include "G4Mag_UsualEqRhs.hh"
+#include "G4Mag_EqRhs.hh"
+#include "G4MagIntegratorDriver.hh"
+
+#include "G4ClassicalRK4.hh"
+#include "G4ExactHelixStepper.hh"
+#include "G4HelixExplicitEuler.hh"
+
+#include "G4ErrorPropagatorManager.hh"
+
+#include "G4EventManager.hh"
+#include "G4ErrorRunManagerHelper.hh"
+#include "G4ErrorPropagator.hh"
+#include "G4ErrorMag_UsualEqRhs.hh"
+
+#include "G4VParticleChange.hh"
+#include "G4ParticleChangeForMSC.hh"
+#include "G4ParticleChange.hh"
+#include "G4Track.hh"
+#include "G4TransportationManager.hh"
+#include "G4ErrorPropagationNavigator.hh"
+#include "G4GeometryManager.hh"
+#include "G4StateManager.hh"
+#include "G4ChordFinder.hh"
+#include "G4EquationOfMotion.hh"
+#include "G4FieldManager.hh"
+#include "G4VParticleChange.hh"
+
+G4ErrorPropagatorManager*
+G4ErrorPropagatorManager::theG4ErrorPropagatorManager = 0;
+
+//-----------------------------------------------------------------------
+G4ErrorPropagatorManager* G4ErrorPropagatorManager::GetErrorPropagatorManager()
+{
+  if( theG4ErrorPropagatorManager == NULL ) {
+    theG4ErrorPropagatorManager = new G4ErrorPropagatorManager;
+  }
+
+  return theG4ErrorPropagatorManager;
+}
+
+
+//-----------------------------------------------------------------------
+G4ErrorPropagatorManager::G4ErrorPropagatorManager()
+{
+  //----- Initialize a few things
+  //o  theG4ErrorPropagatorManager = this;
+
+  char* g4emverb = getenv("G4EVERBOSE");
+  if( !g4emverb ) {
+    G4ErrorPropagatorData::GetErrorPropagatorData()->SetVerbose( 0 );
+  } else {
+    G4ErrorPropagatorData::GetErrorPropagatorData()->SetVerbose( atoi( g4emverb ) );
+  }
+
+  thePropagator = 0;
+
+  theEquationOfMotion = 0;
+
+  StartG4ErrorRunManagerHelper(); 
+  
+  G4ErrorPropagatorData::GetErrorPropagatorData()->SetState( G4ErrorState_PreInit );
+
+  theG4ErrorPropagationNavigator = 0;
+
+  StartNavigator(); //navigator has to be initialized at the beggining !?!?!
+
+
+}
+
+
+//-----------------------------------------------------------------------
+G4ErrorPropagatorManager::~G4ErrorPropagatorManager()
+{
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorPropagatorManager::StartG4ErrorRunManagerHelper()
+{
+  //----- Initialize G4ErrorRunManagerHelper
+  theG4ErrorRunManagerHelper = G4ErrorRunManagerHelper::GetRunManagerKernel();
+
+  if( theG4ErrorRunManagerHelper == 0 ) {
+    theG4ErrorRunManagerHelper = new G4ErrorRunManagerHelper();
+  }
+
+  //----- User Initialization classes 
+  //--- GEANT4e PhysicsList
+  if( G4ErrorPropagatorData::verbose() >= 4 ) G4cout << " G4ErrorPropagatorManager::StartG4eRunManager() done " << theG4ErrorRunManagerHelper << G4endl;
+  //-  theG4eRunManager->SetUserInitialization(new G4ErrorPhysicsList);
+
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorPropagatorManager::StartNavigator()
+{
+  if( theG4ErrorPropagationNavigator == 0 ) {
+    G4TransportationManager*transportationManager = G4TransportationManager::GetTransportationManager();
+    
+    G4Navigator* g4navi = transportationManager->GetNavigatorForTracking();
+   
+    G4VPhysicalVolume* world = g4navi->GetWorldVolume();
+    G4int verb = g4navi->GetVerboseLevel();
+    delete g4navi;
+
+    theG4ErrorPropagationNavigator = new G4ErrorPropagationNavigator();
+
+    if( world != 0 ) {
+      theG4ErrorPropagationNavigator->SetWorldVolume( world );
+    }
+    theG4ErrorPropagationNavigator->SetVerboseLevel( verb );   
+    
+    transportationManager->SetNavigatorForTracking(theG4ErrorPropagationNavigator);
+    //  G4ThreeVector center(0,0,0);
+    //  theG4ErrorPropagationNavigator->LocateGlobalPointAndSetup(center,0,false);
+    
+  }
+
+  if( G4ErrorPropagatorData::verbose() >= 2 ) G4cout << " theState at StartNavigator " << PrintG4ErrorState() << G4endl;
+
+}
+  
+
+//-----------------------------------------------------------------------
+void G4ErrorPropagatorManager::InitGeant4e()
+{
+  if( G4ErrorPropagatorData::verbose() >= 1 ) G4cout << "InitGeant4e GEANT4e State= " << PrintG4ErrorState() << " GEANT4 State= " << PrintG4State() << G4endl;
+  G4ApplicationState currentState = G4StateManager::GetStateManager()->GetCurrentState();
+  //----- Initialize run
+  //  if( G4StateManager::GetStateManager()->GetCurrentState() == G4State_PreInit) {
+  
+  if( G4ErrorPropagatorData::GetErrorPropagatorData()->GetState() == G4ErrorState_PreInit ) {
+    if ( currentState == G4State_PreInit || currentState == G4State_Idle) {
+      //    G4eRunManager::GetRunManager()->Initialize();
+      theG4ErrorRunManagerHelper->InitializeGeometry();
+      theG4ErrorRunManagerHelper->InitializePhysics();
+    }
+    
+    InitFieldForBackwards();
+    
+    //-    G4StateManager::GetStateManager()->SetNewState(G4State_Idle);
+    
+    if( G4ErrorPropagatorData::verbose() >= 4 )   G4cout << " bef  theG4ErrorPropagatorManager->RunInitialization() " <<  G4StateManager::GetStateManager()->GetCurrentState() << G4endl;
+    theG4ErrorRunManagerHelper->RunInitialization();
+    if( G4ErrorPropagatorData::verbose() >= 4 ) G4cout << " aft  theG4ErrorPropagatorManager->RunInitialization() " <<  G4StateManager::GetStateManager()->GetCurrentState() << G4endl;
+    
+    if( !thePropagator ) thePropagator = new G4ErrorPropagator();  // currently the only propagator possible
+    
+    InitTrackPropagation();
+  } else {
+    G4cerr << "G4ErrorPropagatorManager::InitGeant4e: Illegal application state - "
+           << "G4ErrorPropagatorManager::InitGeant4e() ignored." << G4endl;
+    G4cerr << " GEANT4e State= " << PrintG4ErrorState() 
+      //<< " GEANT4 State= " <<  PrintG4State() 
+           << G4endl;
+  }
+  
+  //----- Set the tracking geometry for this propagation
+  //t  SetTrackingGeometry();
+  //----- Set the physics list for this propagation
+  //t  SetPhysicsList();
+  //----- Set the field propagation parameters for this propagation
+  //t  SetFieldPropagationParameters();
+  G4ErrorPropagatorData::GetErrorPropagatorData()->SetState( G4ErrorState_Init );
+
+  if( G4ErrorPropagatorData::verbose() >= 2 ) G4cout << "End InitGeant4e GEANT4e State= " << PrintG4ErrorState() << " GEANT4 State= " << PrintG4State() << G4endl;
+
+
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorPropagatorManager::InitTrackPropagation()
+{
+  thePropagator->SetStepN( 0 );
+
+  G4ErrorPropagatorData::GetErrorPropagatorData()->SetState( G4ErrorState_Propagating );
+
+}
+
+
+//-----------------------------------------------------------------------
+G4bool G4ErrorPropagatorManager::InitFieldForBackwards()
+{
+
+  if( G4ErrorPropagatorData::verbose() >= 4 ) G4cout << " G4ErrorPropagatorManager::InitFieldForBackwards() " << G4endl;
+  //----- Gets the current equation of motion
+  G4FieldManager* fieldMgr= G4TransportationManager::GetTransportationManager()->GetFieldManager();
+  //  G4cout << " fieldMgr " << fieldMgr << G4endl;
+  if( !fieldMgr ) return 0;
+
+  //  G4Field* myfield = fieldMgr->GetDetectorField();
+  G4ChordFinder* cf = fieldMgr ->GetChordFinder();
+  if( !cf ) return 0;
+  G4MagInt_Driver* mid = cf->GetIntegrationDriver();
+  if( !mid ) return 0;
+  G4MagIntegratorStepper* stepper = const_cast<G4MagIntegratorStepper*>(mid->GetStepper());
+  if( !stepper ) return 0;
+  G4EquationOfMotion* equation = stepper->GetEquationOfMotion();
+
+  //----- Replaces the equation by a G4ErrorMag_UsualEqRhs to handle backwards tracking
+  if ( !dynamic_cast<G4ErrorMag_UsualEqRhs*>(equation) ) {
+
+    G4MagneticField* myfield = (G4MagneticField*)fieldMgr->GetDetectorField();
+    
+    //    G4Mag_UsualEqRhs* fEquation_usual = dynamic_cast<G4Mag_UsualEqRhs*>(equation);
+    if( theEquationOfMotion == 0 ) theEquationOfMotion = new G4ErrorMag_UsualEqRhs(myfield);
+ 
+    //---- Pass the equation of motion to the G4MagIntegratorStepper
+    stepper->SetEquationOfMotion( theEquationOfMotion );
+
+    //--- change stepper for speed tests
+   G4MagIntegratorStepper* g4eStepper = new G4ClassicalRK4(theEquationOfMotion);
+   // G4MagIntegratorStepper* g4eStepper = new G4ExactHelixStepper(theEquationOfMotion);
+    
+    //---- 
+    G4MagneticField* field = static_cast<G4MagneticField*>(const_cast<G4Field*>(fieldMgr->GetDetectorField()));
+    G4ChordFinder* pChordFinder = new G4ChordFinder(field, 1.0e-2*mm, g4eStepper);
+
+    fieldMgr->SetChordFinder(pChordFinder);
+
+  }
+
+  return 1;
+}
+
+
+//-----------------------------------------------------------------------
+G4int G4ErrorPropagatorManager::Propagate( G4ErrorTrajState* currentTS, const G4ErrorTarget* target, G4ErrorMode mode )
+{
+  G4ErrorPropagatorData::GetErrorPropagatorData()->SetMode( mode );
+  if( !thePropagator ) thePropagator = new G4ErrorPropagator();  // currently the only propagator possible
+
+  SetSteppingManagerVerboseLevel();
+  InitTrackPropagation();
+
+  G4int ierr = thePropagator->Propagate( currentTS, target, mode );
+
+  EventTermination();
+
+  return ierr;
+}
+
+
+//-----------------------------------------------------------------------
+G4int G4ErrorPropagatorManager::PropagateOneStep( G4ErrorTrajState* currentTS, G4ErrorMode mode )
+{
+  G4ErrorPropagatorData::GetErrorPropagatorData()->SetMode( mode );
+
+  if( !thePropagator ) thePropagator = new G4ErrorPropagator();  // currently the only propagator possible
+
+  SetSteppingManagerVerboseLevel();
+
+  return thePropagator->PropagateOneStep( currentTS );
+}
+
+
+//-----------------------------------------------------------------------
+G4bool G4ErrorPropagatorManager::CloseGeometry()
+{
+  G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
+  geomManager->OpenGeometry();
+  if(  G4StateManager::GetStateManager()->GetCurrentState() != G4State_GeomClosed) {
+    G4StateManager::GetStateManager()->SetNewState(G4State_Quit);
+  }
+
+  return TRUE;
+}
+
+
+//---------------------------------------------------------------------------
+void G4ErrorPropagatorManager::SetUserInitialization(G4VUserDetectorConstruction* userInit)
+{
+  theG4ErrorRunManagerHelper->SetUserInitialization( userInit); 
+}
+
+
+//---------------------------------------------------------------------------
+void G4ErrorPropagatorManager::SetUserInitialization(G4VPhysicalVolume* userInit)
+{ 
+  theG4ErrorRunManagerHelper->SetUserInitialization( userInit); 
+}
+ 
+
+//---------------------------------------------------------------------------
+void G4ErrorPropagatorManager::SetUserInitialization(G4VUserPhysicsList* userInit)
+{ 
+  theG4ErrorRunManagerHelper->SetUserInitialization( userInit); 
+}
+
+
+//---------------------------------------------------------------------------
+void G4ErrorPropagatorManager::SetUserAction(G4UserTrackingAction* userAction)
+{
+  G4EventManager::GetEventManager()->SetUserAction( userAction ); 
+}
+
+
+//---------------------------------------------------------------------------
+void G4ErrorPropagatorManager::SetUserAction(G4UserSteppingAction* userAction)
+{
+  G4EventManager::GetEventManager()->SetUserAction( userAction ); 
+}
+
+
+//---------------------------------------------------------------------------
+void G4ErrorPropagatorManager::SetSteppingManagerVerboseLevel()
+{
+  G4TrackingManager* trkmgr = G4EventManager::GetEventManager()->GetTrackingManager();
+  trkmgr->GetSteppingManager()->SetVerboseLevel( trkmgr->GetVerboseLevel() );
+}
+
+
+//---------------------------------------------------------------------------
+void G4ErrorPropagatorManager::EventTermination()
+{
+  G4ErrorPropagatorData::GetErrorPropagatorData()->SetState( G4ErrorState_Init );
+}
+
+
+//---------------------------------------------------------------------------
+void G4ErrorPropagatorManager::RunTermination()
+{
+G4ErrorPropagatorData::GetErrorPropagatorData()->SetState( G4ErrorState_PreInit );
+  theG4ErrorRunManagerHelper->RunTermination(); 
+}
+
+
+//---------------------------------------------------------------------------
+G4String G4ErrorPropagatorManager::PrintG4ErrorState() 
+{
+  return PrintG4ErrorState( G4ErrorPropagatorData::GetErrorPropagatorData()->GetState() );
+}
+
+
+//---------------------------------------------------------------------------
+G4String G4ErrorPropagatorManager::PrintG4ErrorState( G4ErrorState state ) 
+{
+  G4String nam = "";
+  switch (state){
+  case G4ErrorState_PreInit: 
+    nam = "G4ErrorState_PreInit"; 
+    break;
+  case G4ErrorState_Init: 
+    nam = "G4ErrorState_Init"; 
+    break;
+  case G4ErrorState_Propagating:
+    nam = "G4ErrorState_Propagating";
+    break;
+  case G4ErrorState_TargetCloserThanBoundary:
+    nam = "G4ErrorState_TargetCloserThanBoundary";
+    break;
+  case G4ErrorState_StoppedAtTarget:
+    nam = "G4ErrorState_StoppedAtTarget";
+    break;
+  }
+
+  return nam;
+}
+
+
+//---------------------------------------------------------------------------
+G4String G4ErrorPropagatorManager::PrintG4State()
+{
+  return PrintG4State(G4StateManager::GetStateManager()->GetCurrentState());
+}
+
+
+//---------------------------------------------------------------------------
+G4String G4ErrorPropagatorManager::PrintG4State( G4ApplicationState state )
+{
+  G4String nam = "";
+  switch ( state ){
+  case G4State_PreInit:
+    nam = "G4State_PreInit";
+    break;
+  case G4State_Init:
+    nam = "G4State_Init";
+    break;
+  case G4State_Idle:
+    nam = "G4State_Idle";
+    break;
+  case G4State_GeomClosed:
+    nam = "G4State_GeomClosed";
+    break;
+  case G4State_EventProc:
+    nam = "G4State_EventProc"; 
+    break;
+  case G4State_Quit:
+    nam = "G4State_Quit";
+    break;
+  case G4State_Abort:
+    nam = "G4State_Abort";
+    break;
+  }
+  
+  return nam;
+
+}
Index: /trunk/source/error_propagation/src/G4ErrorRunManagerHelper.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorRunManagerHelper.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorRunManagerHelper.cc	(revision 815)
@@ -0,0 +1,182 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorRunManagerHelper.cc,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4Navigator.hh"
+
+#include "G4Timer.hh"
+
+#include "G4ErrorRunManagerHelper.hh"
+
+#include "G4RunManagerKernel.hh"
+#include "G4VUserDetectorConstruction.hh"
+#include "G4ErrorPhysicsList.hh"
+#include "G4TransportationManager.hh"
+#include "G4RunManager.hh"
+
+//-----------------------------------------------------------------------
+
+G4ErrorRunManagerHelper* G4ErrorRunManagerHelper::fRunManagerKernel = 0;
+
+//-----------------------------------------------------------------------
+G4ErrorRunManagerHelper* G4ErrorRunManagerHelper::GetRunManagerKernel()
+{ return fRunManagerKernel; }
+
+
+//-----------------------------------------------------------------------
+G4ErrorRunManagerHelper::G4ErrorRunManagerHelper()
+{
+  if(fRunManagerKernel)
+  { G4Exception("G4eRunManageKernel constructed twice."); }
+  fRunManagerKernel = this;
+
+  //----- Look if somebody has created a G4RunManagerKernel
+  theG4RunManagerKernel = G4RunManagerKernel::GetRunManagerKernel();
+  if( theG4RunManagerKernel == 0 ) {
+    //--- if not create it
+    theG4RunManagerKernel = new G4RunManagerKernel();
+    G4cout << " creating G4RunManagerKernel " <<  theG4RunManagerKernel << G4endl;
+  }
+    
+  theG4RunManagerKernel->SetVerboseLevel(2);
+  theUserPhysicsList = 0;
+  theUserWorld = 0;
+
+}
+
+
+//-----------------------------------------------------------------------
+G4ErrorRunManagerHelper::~G4ErrorRunManagerHelper()
+{
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorRunManagerHelper::SetUserInitialization(G4VUserDetectorConstruction* userInit)
+{ 
+  theUserWorld = userInit->Construct();
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorRunManagerHelper::SetUserInitialization(G4VPhysicalVolume* userInit)
+{
+  theUserWorld = userInit;
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorRunManagerHelper::SetUserInitialization(G4VUserPhysicsList* userInit)
+{
+  theUserPhysicsList = userInit;
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorRunManagerHelper::InitializeGeometry()
+{
+  //check if user world has been directly called or someone initialized the world volume already 
+  //----- First option: geometry has been defined to GEANT4e 
+  if( theUserWorld != 0 ) {
+    theG4RunManagerKernel->DefineWorldVolume( theUserWorld );
+    
+    //----- Second option: geometry has been defined to GEANT4, do nothing GEANT4 should take care 
+  } else {
+    //  G4cerr << "G4 TM " << G4TransportationManager::GetTransportationManager() 
+    //      << " NAV " << G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking() 
+    //      << " WORLD " << G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume() << G4endl;
+    //--- Check that indeed geometry has been defined to GEANT4
+    if ( G4TransportationManager::GetTransportationManager()
+         ->GetNavigatorForTracking()->GetWorldVolume() == 0 ) {
+      G4Exception("G4ErrorRunManagerHelper::InitializeGeometry no world defined in your geometry!" );
+    }
+    
+  }
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorRunManagerHelper::InitializePhysics()
+{
+
+  G4cout << "  G4ErrorRunManagerHelper::InitializePhysics "  << G4endl;
+
+  //----- First option: physics list has been defined to GEANT4e 
+  if( theUserPhysicsList != 0 ) {
+    theG4RunManagerKernel->SetPhysics(theUserPhysicsList);
+    theG4RunManagerKernel->InitializePhysics();
+  }else {
+  //----- Second option: physics list has been defined to GEANT4, do nothing GEANT4 should take care 
+    if( G4RunManager::GetRunManager() != 0 && G4RunManager::GetRunManager()->GetUserPhysicsList() != 0 ){ 
+      //--- Physics should be G4ErrorPhysicsList, else send a warning
+      if( static_cast<const G4ErrorPhysicsList*>(G4RunManager::GetRunManager()->GetUserPhysicsList()) != 0 ) {
+        G4cerr << " WARNING G4ErrorRunManagerHelper::InitializePhysics() physics list is not G4ErrorPhysicsList. Are you sure? " << G4endl;
+      }
+    } else {
+      //----- Third option: no physics list has been defined, define a G4ErrorPhysicsList
+      theG4RunManagerKernel->SetPhysics(new G4ErrorPhysicsList);
+      //    theG4RunManagerKernel->SetPhysics(new ExN02PhysicsList);
+      theG4RunManagerKernel->InitializePhysics();
+    }
+  }
+ 
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorRunManagerHelper::RunInitialization()
+{
+  theG4RunManagerKernel->RunInitialization();
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorRunManagerHelper::SetUserAction(G4UserTrackingAction* userAction)
+{
+
+  G4EventManager::GetEventManager()->SetUserAction( userAction );
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorRunManagerHelper::SetUserAction(G4UserSteppingAction* userAction)
+{
+  G4EventManager::GetEventManager()->SetUserAction( userAction );
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorRunManagerHelper::RunTermination()
+{
+  theG4RunManagerKernel->RunTermination();
+}
+
Index: /trunk/source/error_propagation/src/G4ErrorStepLengthLimitProcess.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorStepLengthLimitProcess.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorStepLengthLimitProcess.cc	(revision 815)
@@ -0,0 +1,71 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorStepLengthLimitProcess.cc,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4ErrorStepLengthLimitProcess.hh"
+#include "G4ErrorMessenger.hh"
+
+#ifdef G4VERBOSE
+#include "G4ErrorPropagatorData.hh"
+#endif
+
+//------------------------------------------------------------------------
+G4ErrorStepLengthLimitProcess::
+G4ErrorStepLengthLimitProcess(const G4String& processName)
+  : G4VErrorLimitProcess(processName) 
+{
+  theStepLimit = 1000.*mm; // kInfinity;
+}
+
+
+//------------------------------------------------------------------------
+G4ErrorStepLengthLimitProcess::~G4ErrorStepLengthLimitProcess()
+{ }
+
+
+//------------------------------------------------------------------------
+G4double G4ErrorStepLengthLimitProcess::
+PostStepGetPhysicalInteractionLength( const G4Track&, G4double,
+                                      G4ForceCondition* condition )
+{
+  *condition = NotForced;
+
+#ifdef G4VERBOSE
+  if(G4ErrorPropagatorData::verbose() >= 3 )
+  { 
+     G4cout << "G4ErrorStepLengthLimitProcess::PostStepGetPhysicalInteractionLength "
+            << theStepLimit << G4endl;
+  }
+#endif
+
+  return theStepLimit;
+}
Index: /trunk/source/error_propagation/src/G4ErrorSurfaceTrajParam.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorSurfaceTrajParam.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorSurfaceTrajParam.cc	(revision 815)
@@ -0,0 +1,121 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorSurfaceTrajParam.cc,v 1.3 2007/05/31 20:22:45 arce Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4ErrorSurfaceTrajParam.hh"
+#include <iomanip>
+
+#include "G4ThreeVector.hh"
+#include "G4GeometryTolerance.hh"
+
+//------------------------------------------------------------------------
+G4ErrorSurfaceTrajParam::
+G4ErrorSurfaceTrajParam( const G4Point3D& pos, const G4Vector3D& mom,
+                         const G4Vector3D& vecV, const G4Vector3D& vecW )
+{
+  SetParameters( pos, mom, vecV, vecW );
+}
+
+
+//------------------------------------------------------------------------
+G4ErrorSurfaceTrajParam::
+G4ErrorSurfaceTrajParam( const G4Point3D& pos, const G4Vector3D& mom,
+                         const G4Plane3D& plane )
+{
+  SetParameters( pos, mom, plane );
+}
+
+//------------------------------------------------------------------------
+void G4ErrorSurfaceTrajParam::
+SetParameters( const G4Point3D& pos, const G4Vector3D& mom,
+               const G4Plane3D& plane )
+{
+  //--- Get two perpendicular vectors: first parallel X
+  //    (unless normal is parallel to X, then take Y)
+
+  G4double kCarTolerance =
+    G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
+
+  G4ThreeVector Xvec(1.,0.,0.);
+  G4Vector3D vecV = -Xvec.cross(plane.normal());
+  if( vecV.mag() < kCarTolerance )
+  {
+    G4ThreeVector Zvec(0.,0.,1.);
+    vecV = Zvec.cross(plane.normal());
+  }
+
+  G4Vector3D vecW = plane.normal().cross( vecV );
+
+  SetParameters( pos, mom, vecV, vecW );
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorSurfaceTrajParam::
+SetParameters( const G4Point3D& pos, const G4Vector3D& mom,
+               const G4Vector3D& vecV, const G4Vector3D& vecW )
+{
+  if( mom.mag() > 0. ) {
+    fDir = mom;
+    fDir /= mom.mag();
+  } else {
+    fDir = G4Vector3D(0.,0.,0.);
+  }
+  fVectorV = vecV / vecV.mag();
+  fVectorW = vecW / vecW.mag();
+  fInvP = 1./mom.mag();
+  G4ThreeVector momv(mom);
+  //check 3 vectors are ortogonal and right handed
+
+  fPV = momv.project( vecV ).mag();
+  fPW = momv.project( vecW ).mag();
+
+  G4ThreeVector posv(pos);
+  fV = posv.project( vecV ).mag();
+  fW = posv.project( vecW ).mag();
+}
+
+
+//------------------------------------------------------------------------
+std::ostream& operator<<(std::ostream& out, const G4ErrorSurfaceTrajParam& tp)
+{
+  //  long mode = out.setf(std::ios::fixed,std::ios::floatfield);
+  
+  //  out << tp.theType;
+  //  out << std::setprecision(5) << std::setw(10);
+  out << " InvP= " << tp.fInvP << " PV= " << tp.fPV
+      << " PW= " << tp.fPW << " V= " << tp.fV << " W= " << tp.fW << G4endl;
+  out << " vectorV direction= " << tp.fVectorV
+      << " vectorW direction= " << tp.fVectorW << G4endl;
+    
+  return out;
+}
Index: /trunk/source/error_propagation/src/G4ErrorSurfaceTrajState.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorSurfaceTrajState.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorSurfaceTrajState.cc	(revision 815)
@@ -0,0 +1,231 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorSurfaceTrajState.cc,v 1.6 2007/06/21 15:04:08 gunter Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4ErrorSurfaceTrajState.hh"
+#include "G4ErrorPropagatorData.hh"
+
+#include "G4Field.hh"
+#include "G4FieldManager.hh"
+#include "G4TransportationManager.hh"
+
+#include "G4ErrorMatrix.hh"
+
+#include <iomanip>
+
+
+//------------------------------------------------------------------------
+G4ErrorSurfaceTrajState::
+G4ErrorSurfaceTrajState( const G4String& partType, const G4Point3D& pos,
+                         const G4Vector3D& mom, const G4Vector3D& vecU,
+                         const G4Vector3D& vecV, const G4ErrorTrajErr& errmat)
+  : G4ErrorTrajState( partType, pos, mom, errmat )
+{
+  Init();
+  fTrajParam = G4ErrorSurfaceTrajParam( pos, mom, vecU, vecV );
+}
+
+
+//------------------------------------------------------------------------
+G4ErrorSurfaceTrajState::
+G4ErrorSurfaceTrajState( const G4String& partType, const G4Point3D& pos,
+                         const G4Vector3D& mom, const G4Plane3D& plane,
+                         const G4ErrorTrajErr& errmat )
+  : G4ErrorTrajState( partType, pos, mom, errmat )
+{
+  Init();
+  fTrajParam = G4ErrorSurfaceTrajParam( pos, mom, plane );
+
+}
+
+
+//------------------------------------------------------------------------
+G4ErrorSurfaceTrajState::
+G4ErrorSurfaceTrajState( G4ErrorFreeTrajState& tpSC, const G4Plane3D& plane )
+  : G4ErrorTrajState( tpSC.GetParticleType(), tpSC.GetPosition(),
+                      tpSC.GetMomentum() )
+{
+  //  fParticleType = tpSC.GetParticleType();
+  //  fPosition = tpSC.GetPosition();
+  //  fMomentum = tpSC.GetMomentum();
+  fTrajParam = G4ErrorSurfaceTrajParam( fPosition, fMomentum, plane );
+  Init();
+
+  //----- Get the error matrix in SC coordinates
+  BuildErrorMatrix( tpSC, GetVectorV(), GetVectorW() );
+}
+
+
+//------------------------------------------------------------------------
+G4ErrorSurfaceTrajState::
+G4ErrorSurfaceTrajState( G4ErrorFreeTrajState& tpSC, const G4Vector3D& vecU,
+                         const G4Vector3D& vecV )
+  : G4ErrorTrajState( tpSC.GetParticleType(), tpSC.GetPosition(),
+                      tpSC.GetMomentum() )
+{
+  fTrajParam = G4ErrorSurfaceTrajParam( fPosition, fMomentum, vecU, vecV );
+  theTSType = G4eTS_OS;
+  //----- Get the error matrix in SC coordinates
+  BuildErrorMatrix( tpSC, vecU, vecV );
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorSurfaceTrajState::
+BuildErrorMatrix( G4ErrorFreeTrajState& tpSC, const G4Vector3D&,
+                  const G4Vector3D& )
+{
+  G4double sclambda = tpSC.GetParameters().GetLambda();
+  G4double scphi = tpSC.GetParameters().GetPhi();
+  if( G4ErrorPropagatorData::GetErrorPropagatorData()->GetMode() == G4ErrorMode_PropBackwards ){
+    sclambda *= -1;
+    scphi += CLHEP::pi;
+  }
+  G4double cosLambda = std::cos( sclambda );
+  G4double sinLambda = std::sin( sclambda );
+  G4double sinPhi = std::sin( scphi );
+  G4double cosPhi = std::cos( scphi );
+
+#ifdef G4EVERBOSE
+  if( iverbose >= 4) G4cout << " PM " << fMomentum.mag() << " pLambda " << sclambda << " pPhi " << scphi << G4endl;
+#endif
+
+  G4ThreeVector vTN( cosLambda*cosPhi, cosLambda*sinPhi,sinLambda );
+  G4ThreeVector vUN( -sinPhi, cosPhi, 0. );
+  G4ThreeVector vVN( -vTN.z()*vUN.y(),vTN.z()*vUN.x(), cosLambda );
+  
+#ifdef G4EVERBOSE
+  if( iverbose >= 4) G4cout << " SC2SD: vTN " << vTN << " vUN " << vUN << " vVN " << vVN << G4endl;
+#endif
+  G4double UJ = vUN*GetVectorV();
+  G4double UK = vUN*GetVectorW();
+  G4double VJ = vVN*GetVectorV();
+  G4double VK = vVN*GetVectorW();
+
+
+  //--- Get transformation first
+  G4ErrorMatrix transfM(5, 5, 0 );
+  //--- Get magnetic field
+  const G4Field* field = G4TransportationManager::GetTransportationManager()->GetFieldManager()->GetDetectorField();
+
+  G4Vector3D vectorU = GetVectorV().cross( GetVectorW() );
+
+#ifdef G4EVERBOSE
+  if( iverbose >= 4) G4cout << "vectors " << vectorU << " " <<  GetVectorV() << " " << GetVectorW() << G4endl;
+#endif
+  G4double T1R = 1. / ( vTN * vectorU );
+
+  if( fCharge != 0 && field ) {
+    G4double pos[3]; pos[0] = fPosition.x()*cm; pos[1] = fPosition.y()*cm; pos[2] = fPosition.z()*cm;
+    G4double Hd[3];
+    field->GetFieldValue( pos, Hd );
+    G4ThreeVector H = G4ThreeVector( Hd[0], Hd[1], Hd[2] ) / tesla *10.;  //in kilogauus
+    G4double magH = H.mag();
+    G4double invP = 1./(fMomentum.mag()/GeV);
+    G4double magHM = magH * invP;
+    if( magH != 0. ) {
+      G4double magHM2 = fCharge / magH;
+      G4double Q = -magHM * c_light/ (km/ns);
+#ifdef G4EVERBOSE
+      if( iverbose >= 4) G4cout << GeV <<  " Q " << Q << " magHM " << magHM << " c_light/(km/ns) " << c_light/(km/ns) << G4endl;      
+#endif
+
+      G4double sinz = -H*vUN * magHM2;
+      G4double cosz =  H*vVN * magHM2;
+      G4double T3R = Q * std::pow(T1R,3);
+      G4double UI = vUN * vectorU;
+      G4double VI = vVN * vectorU;
+#ifdef G4EVERBOSE
+      if( iverbose >= 4) {
+        G4cout << " T1R " << T1R << " T3R " << T3R << G4endl;
+        G4cout << " UI " << UI << " VI " << VI << " vectorU " << vectorU << G4endl;
+        G4cout << " UJ " << UJ << " VJ " << VJ << G4endl;
+        G4cout << " UK " << UK << " VK " << VK << G4endl;
+      }
+#endif
+
+      transfM[1][3] = -UI*( VK*cosz-UK*sinz)*T3R;
+      transfM[1][4] = -VI*( VK*cosz-UK*sinz)*T3R;
+      transfM[2][3] = UI*( VJ*cosz-UJ*sinz)*T3R;
+      transfM[2][4] = VI*( VJ*cosz-UJ*sinz)*T3R;
+    }
+  }
+
+  G4double T2R = T1R * T1R;
+  transfM[0][0] = 1.;
+  transfM[1][1] = -UK*T2R;
+  transfM[1][2] = VK*cosLambda*T2R;
+  transfM[2][1] = UJ*T2R;
+  transfM[2][2] = -VJ*cosLambda*T2R;
+  transfM[3][3] = VK*T1R;
+  transfM[3][4] = -UK*T1R;
+  transfM[4][3] = -VJ*T1R;
+  transfM[4][4] = UJ*T1R;
+
+#ifdef G4EVERBOSE
+  if( iverbose >= 4) G4cout << " SC2SD transf matrix A= " << transfM << G4endl;
+#endif
+  fError = G4ErrorTrajErr( tpSC.GetError().similarity( transfM ) );
+
+#ifdef G4EVERBOSE
+  if( iverbose >= 1) G4cout << "G4EP: error matrix SC2SD " << fError << G4endl;
+  if( iverbose >= 4) G4cout << "G4ErrorSurfaceTrajState from SC " << *this << G4endl;
+#endif
+
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorSurfaceTrajState::Init()
+{
+ theTSType = G4eTS_OS;
+ BuildCharge();
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorSurfaceTrajState::Dump( std::ostream& out ) const
+{
+  out << *this;
+}
+
+
+//------------------------------------------------------------------------
+std::ostream& operator<<(std::ostream& out, const G4ErrorSurfaceTrajState& ts)
+{
+  out.setf(std::ios::fixed,std::ios::floatfield);
+  
+  ts.DumpPosMomError( out );
+ 
+  out << " G4ErrorSurfaceTrajState: Params: " << ts.fTrajParam << G4endl;
+  return out;
+}
Index: /trunk/source/error_propagation/src/G4ErrorSymMatrix.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorSymMatrix.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorSymMatrix.cc	(revision 815)
@@ -0,0 +1,2264 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorSymMatrix.cc,v 1.3 2007/06/21 15:04:10 gunter Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file
+// ------------------------------------------------------------
+
+#include "globals.hh"
+#include <iostream>
+#include <cmath>
+
+#include "G4ErrorSymMatrix.hh"
+#include "G4ErrorMatrix.hh"
+
+// Simple operation for all elements
+
+#define SIMPLE_UOP(OPER)                      \
+    G4ErrorMatrixIter a=m.begin();            \
+    G4ErrorMatrixIter e=m.begin()+num_size(); \
+   for(;a<e; a++) (*a) OPER t;
+
+#define SIMPLE_BOP(OPER)                           \
+    G4ErrorMatrixIter a=m.begin();                 \
+    G4ErrorMatrixConstIter b=m2.m.begin();         \
+    G4ErrorMatrixConstIter e=m.begin()+num_size(); \
+   for(;a<e; a++, b++) (*a) OPER (*b);
+
+#define SIMPLE_TOP(OPER)                                 \
+    G4ErrorMatrixConstIter a=m1.m.begin();               \
+    G4ErrorMatrixConstIter b=m2.m.begin();               \
+    G4ErrorMatrixIter t=mret.m.begin();                  \
+    G4ErrorMatrixConstIter e=m1.m.begin()+m1.num_size(); \
+   for( ;a<e; a++, b++, t++) (*t) = (*a) OPER (*b);
+
+#define CHK_DIM_2(r1,r2,c1,c2,fun) \
+   if (r1!=r2 || c1!=c2)  { \
+    G4ErrorMatrix::error("Range error in Matrix function " #fun "(1)."); \
+   }
+
+#define CHK_DIM_1(c1,r2,fun) \
+   if (c1!=r2) { \
+     G4ErrorMatrix::error("Range error in Matrix function " #fun "(2)."); \
+   }
+
+// Constructors. (Default constructors are inlined and in .icc file)
+
+G4ErrorSymMatrix::G4ErrorSymMatrix(G4int p)
+   : m(p*(p+1)/2), nrow(p)
+{
+   size = nrow * (nrow+1) / 2;
+   m.assign(size,0);
+}
+
+G4ErrorSymMatrix::G4ErrorSymMatrix(G4int p, G4int init)
+   : m(p*(p+1)/2), nrow(p)
+{
+   size = nrow * (nrow+1) / 2;
+
+   m.assign(size,0);
+   switch(init)
+   {
+   case 0:
+      break;
+      
+   case 1:
+      {
+         G4ErrorMatrixIter a = m.begin();
+         for(G4int i=1;i<=nrow;i++)
+         {
+            *a = 1.0;
+            a += (i+1);
+         }
+         break;
+      }
+   default:
+      G4ErrorMatrix::error("G4ErrorSymMatrix: initialization must be 0 or 1.");
+   }
+}
+
+//
+// Destructor
+//
+
+G4ErrorSymMatrix::~G4ErrorSymMatrix()
+{
+}
+
+G4ErrorSymMatrix::G4ErrorSymMatrix(const G4ErrorSymMatrix &m1)
+   : m(m1.size), nrow(m1.nrow), size(m1.size)
+{
+   m = m1.m;
+}
+
+//
+//
+// Sub matrix
+//
+//
+
+G4ErrorSymMatrix G4ErrorSymMatrix::sub(G4int min_row, G4int max_row) const
+{
+  G4ErrorSymMatrix mret(max_row-min_row+1);
+  if(max_row > num_row())
+    { G4ErrorMatrix::error("G4ErrorSymMatrix::sub: Index out of range"); }
+  G4ErrorMatrixIter a = mret.m.begin();
+  G4ErrorMatrixConstIter b1 = m.begin() + (min_row+2)*(min_row-1)/2;
+  for(G4int irow=1; irow<=mret.num_row(); irow++)
+  {
+    G4ErrorMatrixConstIter b = b1;
+    for(G4int icol=1; icol<=irow; icol++)
+    {
+      *(a++) = *(b++);
+    }
+    b1 += irow+min_row-1;
+  }
+  return mret;
+}
+
+G4ErrorSymMatrix G4ErrorSymMatrix::sub(G4int min_row, G4int max_row) 
+{
+  G4ErrorSymMatrix mret(max_row-min_row+1);
+  if(max_row > num_row())
+    { G4ErrorMatrix::error("G4ErrorSymMatrix::sub: Index out of range"); }
+  G4ErrorMatrixIter a = mret.m.begin();
+  G4ErrorMatrixIter b1 = m.begin() + (min_row+2)*(min_row-1)/2;
+  for(G4int irow=1; irow<=mret.num_row(); irow++)
+  {
+    G4ErrorMatrixIter b = b1;
+    for(G4int icol=1; icol<=irow; icol++)
+    {
+      *(a++) = *(b++);
+    }
+    b1 += irow+min_row-1;
+  }
+  return mret;
+}
+
+void G4ErrorSymMatrix::sub(G4int row,const G4ErrorSymMatrix &m1)
+{
+  if(row <1 || row+m1.num_row()-1 > num_row() )
+    { G4ErrorMatrix::error("G4ErrorSymMatrix::sub: Index out of range"); }
+  G4ErrorMatrixConstIter a = m1.m.begin();
+  G4ErrorMatrixIter b1 = m.begin() + (row+2)*(row-1)/2;
+  for(G4int irow=1; irow<=m1.num_row(); irow++)
+  {
+    G4ErrorMatrixIter b = b1;
+    for(G4int icol=1; icol<=irow; icol++)
+    {
+      *(b++) = *(a++);
+    }
+    b1 += irow+row-1;
+  }
+}
+
+//
+// Direct sum of two matricies
+//
+
+G4ErrorSymMatrix dsum(const G4ErrorSymMatrix &m1,
+                      const G4ErrorSymMatrix &m2)
+{
+  G4ErrorSymMatrix mret(m1.num_row() + m2.num_row(), 0);
+  mret.sub(1,m1);
+  mret.sub(m1.num_row()+1,m2);
+  return mret;
+}
+
+/* -----------------------------------------------------------------------
+   This section contains support routines for matrix.h. This section contains
+   The two argument functions +,-. They call the copy constructor and +=,-=.
+   ----------------------------------------------------------------------- */
+
+G4ErrorSymMatrix G4ErrorSymMatrix::operator- () const 
+{
+  G4ErrorSymMatrix m2(nrow);
+  G4ErrorMatrixConstIter a=m.begin();
+  G4ErrorMatrixIter b=m2.m.begin();
+  G4ErrorMatrixConstIter e=m.begin()+num_size();
+  for(;a<e; a++, b++) { (*b) = -(*a); }
+  return m2;
+}
+
+G4ErrorMatrix operator+(const G4ErrorMatrix &m1, const G4ErrorSymMatrix &m2)
+{
+  G4ErrorMatrix mret(m1);
+  CHK_DIM_2(m1.num_row(),m2.num_row(), m1.num_col(),m2.num_col(),+);
+  mret += m2;
+  return mret;
+}
+
+G4ErrorMatrix operator+(const G4ErrorSymMatrix &m1, const G4ErrorMatrix &m2)
+{
+  G4ErrorMatrix mret(m2);
+  CHK_DIM_2(m1.num_row(),m2.num_row(),m1.num_col(),m2.num_col(),+);
+  mret += m1;
+  return mret;
+}
+
+G4ErrorSymMatrix operator+(const G4ErrorSymMatrix &m1,
+                           const G4ErrorSymMatrix &m2)
+{
+  G4ErrorSymMatrix mret(m1.nrow);
+  CHK_DIM_1(m1.nrow, m2.nrow,+);
+  SIMPLE_TOP(+)
+  return mret;
+}
+
+//
+// operator -
+//
+
+G4ErrorMatrix operator-(const G4ErrorMatrix &m1, const G4ErrorSymMatrix &m2)
+{
+  G4ErrorMatrix mret(m1);
+  CHK_DIM_2(m1.num_row(),m2.num_row(),m1.num_col(),m2.num_col(),-);
+  mret -= m2;
+  return mret;
+}
+
+G4ErrorMatrix operator-(const G4ErrorSymMatrix &m1, const G4ErrorMatrix &m2)
+{
+  G4ErrorMatrix mret(m1);
+  CHK_DIM_2(m1.num_row(),m2.num_row(),m1.num_col(),m2.num_col(),-);
+  mret -= m2;
+  return mret;
+}
+
+G4ErrorSymMatrix operator-(const G4ErrorSymMatrix &m1,
+                           const G4ErrorSymMatrix &m2)
+{
+  G4ErrorSymMatrix mret(m1.num_row());
+  CHK_DIM_1(m1.num_row(),m2.num_row(),-);
+  SIMPLE_TOP(-)
+  return mret;
+}
+
+/* -----------------------------------------------------------------------
+   This section contains support routines for matrix.h. This file contains
+   The two argument functions *,/. They call copy constructor and then /=,*=.
+   ----------------------------------------------------------------------- */
+
+G4ErrorSymMatrix operator/(const G4ErrorSymMatrix &m1,G4double t)
+{
+  G4ErrorSymMatrix mret(m1);
+  mret /= t;
+  return mret;
+}
+
+G4ErrorSymMatrix operator*(const G4ErrorSymMatrix &m1,G4double t)
+{
+  G4ErrorSymMatrix mret(m1);
+  mret *= t;
+  return mret;
+}
+
+G4ErrorSymMatrix operator*(G4double t,const G4ErrorSymMatrix &m1)
+{
+  G4ErrorSymMatrix mret(m1);
+  mret *= t;
+  return mret;
+}
+
+G4ErrorMatrix operator*(const G4ErrorMatrix &m1, const G4ErrorSymMatrix &m2)
+{
+  G4ErrorMatrix mret(m1.num_row(),m2.num_col());
+  CHK_DIM_1(m1.num_col(),m2.num_row(),*);
+  G4ErrorMatrixConstIter mit1, mit2, sp,snp; //mit2=0
+  G4double temp;
+  G4ErrorMatrixIter mir=mret.m.begin();
+  G4int step,stept;
+  for(mit1=m1.m.begin();
+      mit1<m1.m.begin()+m1.num_row()*m1.num_col(); mit1 = mit2)
+  {
+    for(step=1,snp=m2.m.begin();step<=m2.num_row();)
+    {
+      mit2=mit1;
+      sp=snp;
+      snp+=step;
+      temp=0;
+      while(sp<snp)
+      {
+        temp+=*(sp++)*(*(mit2++));
+      }
+      sp+=step-1;
+      for(stept=++step;stept<=m2.num_row();stept++)
+      {
+        temp+=*sp*(*(mit2++));
+        sp+=stept;
+      }
+      *(mir++)=temp;
+    }
+  }
+  return mret;
+}
+
+G4ErrorMatrix operator*(const G4ErrorSymMatrix &m1, const G4ErrorMatrix &m2)
+{
+  G4ErrorMatrix mret(m1.num_row(),m2.num_col());
+  CHK_DIM_1(m1.num_col(),m2.num_row(),*);
+  G4int step,stept;
+  G4ErrorMatrixConstIter mit1,mit2,sp,snp;
+  G4double temp;
+  G4ErrorMatrixIter mir=mret.m.begin();
+  for(step=1,snp=m1.m.begin();step<=m1.num_row();snp+=step++)
+  {
+    for(mit1=m2.m.begin();mit1<m2.m.begin()+m2.num_col();mit1++)
+    {
+      mit2=mit1;
+      sp=snp;
+      temp=0;
+      while(sp<snp+step)
+      {
+        temp+=*mit2*(*(sp++));
+        mit2+=m2.num_col();
+      }
+      sp+=step-1;
+      for(stept=step+1;stept<=m1.num_row();stept++)
+      {
+        temp+=*mit2*(*sp);
+        mit2+=m2.num_col();
+        sp+=stept;
+      }
+      *(mir++)=temp;
+    }
+  }
+  return mret;
+}
+
+G4ErrorMatrix operator*(const G4ErrorSymMatrix &m1, const G4ErrorSymMatrix &m2)
+{
+  G4ErrorMatrix mret(m1.num_row(),m1.num_row());
+  CHK_DIM_1(m1.num_col(),m2.num_row(),*);
+  G4int step1,stept1,step2,stept2;
+  G4ErrorMatrixConstIter snp1,sp1,snp2,sp2;
+  G4double temp;
+  G4ErrorMatrixIter mr = mret.m.begin();
+  for(step1=1,snp1=m1.m.begin();step1<=m1.num_row();snp1+=step1++)
+  {
+    for(step2=1,snp2=m2.m.begin();step2<=m2.num_row();)
+    {
+      sp1=snp1;
+      sp2=snp2;
+      snp2+=step2;
+      temp=0;
+      if(step1<step2)
+      {
+        while(sp1<snp1+step1)
+          { temp+=(*(sp1++))*(*(sp2++)); }
+        sp1+=step1-1;
+        for(stept1=step1+1;stept1!=step2+1;sp1+=stept1++)
+          { temp+=(*sp1)*(*(sp2++)); }
+        sp2+=step2-1;
+        for(stept2=++step2;stept2<=m2.num_row();sp1+=stept1++,sp2+=stept2++)
+          { temp+=(*sp1)*(*sp2); }
+      }
+      else
+      {
+        while(sp2<snp2)
+          { temp+=(*(sp1++))*(*(sp2++)); }
+        sp2+=step2-1;
+        for(stept2=++step2;stept2!=step1+1;sp2+=stept2++)
+          { temp+=(*(sp1++))*(*sp2); }
+        sp1+=step1-1;
+        for(stept1=step1+1;stept1<=m1.num_row();sp1+=stept1++,sp2+=stept2++)
+          { temp+=(*sp1)*(*sp2); }
+      }
+      *(mr++)=temp;
+    }
+  }
+  return mret;
+}
+
+/* -----------------------------------------------------------------------
+   This section contains the assignment and inplace operators =,+=,-=,*=,/=.
+   ----------------------------------------------------------------------- */
+
+G4ErrorMatrix & G4ErrorMatrix::operator+=(const G4ErrorSymMatrix &m2)
+{
+  CHK_DIM_2(num_row(),m2.num_row(),num_col(),m2.num_col(),+=);
+  G4int n = num_col();
+  G4ErrorMatrixConstIter sjk = m2.m.begin();
+  G4ErrorMatrixIter m1j = m.begin();
+  G4ErrorMatrixIter mj = m.begin();
+  // j >= k
+  for(G4int j=1;j<=num_row();j++)
+  {
+    G4ErrorMatrixIter mjk = mj;
+    G4ErrorMatrixIter mkj = m1j;
+    for(G4int k=1;k<=j;k++)
+    {
+      *(mjk++) += *sjk;
+      if(j!=k) *mkj += *sjk;
+      sjk++;
+      mkj += n;
+    }
+    mj += n;
+    m1j++;
+  }
+  return (*this);
+}
+
+G4ErrorSymMatrix & G4ErrorSymMatrix::operator+=(const G4ErrorSymMatrix &m2)
+{
+  CHK_DIM_2(num_row(),m2.num_row(),num_col(),m2.num_col(),+=);
+  SIMPLE_BOP(+=)
+  return (*this);
+}
+
+G4ErrorMatrix & G4ErrorMatrix::operator-=(const G4ErrorSymMatrix &m2)
+{
+  CHK_DIM_2(num_row(),m2.num_row(),num_col(),m2.num_col(),-=);
+  G4int n = num_col();
+  G4ErrorMatrixConstIter sjk = m2.m.begin();
+  G4ErrorMatrixIter m1j = m.begin();
+  G4ErrorMatrixIter mj = m.begin();
+  // j >= k
+  for(G4int j=1;j<=num_row();j++)
+  {
+    G4ErrorMatrixIter mjk = mj;
+    G4ErrorMatrixIter mkj = m1j;
+    for(G4int k=1;k<=j;k++)
+    {
+      *(mjk++) -= *sjk;
+      if(j!=k) *mkj -= *sjk;
+      sjk++;
+      mkj += n;
+    }
+    mj += n;
+    m1j++;
+  }
+  return (*this);
+}
+
+G4ErrorSymMatrix & G4ErrorSymMatrix::operator-=(const G4ErrorSymMatrix &m2)
+{
+  CHK_DIM_2(num_row(),m2.num_row(),num_col(),m2.num_col(),-=);
+  SIMPLE_BOP(-=)
+  return (*this);
+}
+
+G4ErrorSymMatrix & G4ErrorSymMatrix::operator/=(G4double t)
+{
+  SIMPLE_UOP(/=)
+  return (*this);
+}
+
+G4ErrorSymMatrix & G4ErrorSymMatrix::operator*=(G4double t)
+{
+  SIMPLE_UOP(*=)
+  return (*this);
+}
+
+G4ErrorMatrix & G4ErrorMatrix::operator=(const G4ErrorSymMatrix &m1)
+{
+   if(m1.nrow*m1.nrow != size)
+   {
+      size = m1.nrow * m1.nrow;
+      m.resize(size);
+   }
+   nrow = m1.nrow;
+   ncol = m1.nrow;
+   G4int n = ncol;
+   G4ErrorMatrixConstIter sjk = m1.m.begin();
+   G4ErrorMatrixIter m1j = m.begin();
+   G4ErrorMatrixIter mj = m.begin();
+   // j >= k
+   for(G4int j=1;j<=num_row();j++)
+   {
+      G4ErrorMatrixIter mjk = mj;
+      G4ErrorMatrixIter mkj = m1j;
+      for(G4int k=1;k<=j;k++)
+      {
+         *(mjk++) = *sjk;
+         if(j!=k) *mkj = *sjk;
+         sjk++;
+         mkj += n;
+      }
+      mj += n;
+      m1j++;
+   }
+   return (*this);
+}
+
+G4ErrorSymMatrix & G4ErrorSymMatrix::operator=(const G4ErrorSymMatrix &m1)
+{
+   if(m1.nrow != nrow)
+   {
+      nrow = m1.nrow;
+      size = m1.size;
+      m.resize(size);
+   }
+   m = m1.m;
+   return (*this);
+}
+
+// Print the Matrix.
+
+std::ostream& operator<<(std::ostream &s, const G4ErrorSymMatrix &q)
+{
+  s << G4endl;
+
+  // Fixed format needs 3 extra characters for field,
+  // while scientific needs 7
+
+  G4int width;
+  if(s.flags() & std::ios::fixed)
+  {
+    width = s.precision()+3;
+  }
+  else
+  {
+    width = s.precision()+7;
+  }
+  for(G4int irow = 1; irow<= q.num_row(); irow++)
+  {
+    for(G4int icol = 1; icol <= q.num_col(); icol++)
+    {
+      s.width(width);
+      s << q(irow,icol) << " ";
+    }
+    s << G4endl;
+  }
+  return s;
+}
+
+G4ErrorSymMatrix G4ErrorSymMatrix::
+apply(G4double (*f)(G4double, G4int, G4int)) const
+{
+  G4ErrorSymMatrix mret(num_row());
+  G4ErrorMatrixConstIter a = m.begin();
+  G4ErrorMatrixIter b = mret.m.begin();
+  for(G4int ir=1;ir<=num_row();ir++)
+  {
+    for(G4int ic=1;ic<=ir;ic++)
+    {
+      *(b++) = (*f)(*(a++), ir, ic);
+    }
+  }
+  return mret;
+}
+
+void G4ErrorSymMatrix::assign (const G4ErrorMatrix &m1)
+{
+   if(m1.nrow != nrow)
+   {
+      nrow = m1.nrow;
+      size = nrow * (nrow+1) / 2;
+      m.resize(size);
+   }
+   G4ErrorMatrixConstIter a = m1.m.begin();
+   G4ErrorMatrixIter b = m.begin();
+   for(G4int r=1;r<=nrow;r++)
+   {
+      G4ErrorMatrixConstIter d = a;
+      for(G4int c=1;c<=r;c++)
+      {
+         *(b++) = *(d++);
+      }
+      a += nrow;
+   }
+}
+
+G4ErrorSymMatrix G4ErrorSymMatrix::similarity(const G4ErrorMatrix &m1) const
+{
+  G4ErrorSymMatrix mret(m1.num_row());
+  G4ErrorMatrix temp = m1*(*this);
+
+// If m1*(*this) has correct dimensions, then so will the m1.T multiplication.
+// So there is no need to check dimensions again.
+
+  G4int n = m1.num_col();
+  G4ErrorMatrixIter mr = mret.m.begin();
+  G4ErrorMatrixIter tempr1 = temp.m.begin();
+  for(G4int r=1;r<=mret.num_row();r++)
+  {
+    G4ErrorMatrixConstIter m1c1 = m1.m.begin();
+    for(G4int c=1;c<=r;c++)
+    {
+      G4double tmp = 0.0;
+      G4ErrorMatrixIter tempri = tempr1;
+      G4ErrorMatrixConstIter m1ci = m1c1;
+      for(G4int i=1;i<=m1.num_col();i++)
+      {
+        tmp+=(*(tempri++))*(*(m1ci++));
+      }
+      *(mr++) = tmp;
+      m1c1 += n;
+    }
+    tempr1 += n;
+  }
+  return mret;
+}
+
+G4ErrorSymMatrix G4ErrorSymMatrix::similarity(const G4ErrorSymMatrix &m1) const
+{
+  G4ErrorSymMatrix mret(m1.num_row());
+  G4ErrorMatrix temp = m1*(*this);
+  G4int n = m1.num_col();
+  G4ErrorMatrixIter mr = mret.m.begin();
+  G4ErrorMatrixIter tempr1 = temp.m.begin();
+  for(G4int r=1;r<=mret.num_row();r++)
+  {
+    G4ErrorMatrixConstIter m1c1 = m1.m.begin();
+    G4int c;
+    for(c=1;c<=r;c++)
+    {
+      G4double tmp = 0.0;
+      G4ErrorMatrixIter tempri = tempr1;
+      G4ErrorMatrixConstIter m1ci = m1c1;
+      G4int i;
+      for(i=1;i<c;i++)
+      {
+        tmp+=(*(tempri++))*(*(m1ci++));
+      }
+      for(i=c;i<=m1.num_col();i++)
+      {
+        tmp+=(*(tempri++))*(*(m1ci));
+        m1ci += i;
+      }
+      *(mr++) = tmp;
+      m1c1 += c;
+    }
+    tempr1 += n;
+  }
+  return mret;
+}
+
+G4ErrorSymMatrix G4ErrorSymMatrix::similarityT(const G4ErrorMatrix &m1) const
+{
+  G4ErrorSymMatrix mret(m1.num_col());
+  G4ErrorMatrix temp = (*this)*m1;
+  G4int n = m1.num_col();
+  G4ErrorMatrixIter mrc = mret.m.begin();
+  G4ErrorMatrixIter temp1r = temp.m.begin();
+  for(G4int r=1;r<=mret.num_row();r++)
+  {
+    G4ErrorMatrixConstIter m11c = m1.m.begin();
+    for(G4int c=1;c<=r;c++)
+    {
+      G4double tmp = 0.0;
+      G4ErrorMatrixIter tempir = temp1r;
+      G4ErrorMatrixConstIter m1ic = m11c;
+      for(G4int i=1;i<=m1.num_row();i++)
+      {
+        tmp+=(*(tempir))*(*(m1ic));
+        tempir += n;
+        m1ic += n;
+      }
+      *(mrc++) = tmp;
+      m11c++;
+    }
+    temp1r++;
+  }
+  return mret;
+}
+
+void G4ErrorSymMatrix::invert(G4int &ifail)
+{  
+  ifail = 0;
+
+  switch(nrow)
+  {
+  case 3:
+    {
+      G4double det, temp;
+      G4double t1, t2, t3;
+      G4double c11,c12,c13,c22,c23,c33;
+      c11 = (*(m.begin()+2)) * (*(m.begin()+5))
+          - (*(m.begin()+4)) * (*(m.begin()+4));
+      c12 = (*(m.begin()+4)) * (*(m.begin()+3))
+          - (*(m.begin()+1)) * (*(m.begin()+5));
+      c13 = (*(m.begin()+1)) * (*(m.begin()+4))
+          - (*(m.begin()+2)) * (*(m.begin()+3));
+      c22 = (*(m.begin()+5)) * (*m.begin())
+          - (*(m.begin()+3)) * (*(m.begin()+3));
+      c23 = (*(m.begin()+3)) * (*(m.begin()+1))
+          - (*(m.begin()+4)) * (*m.begin());
+      c33 = (*m.begin()) * (*(m.begin()+2))
+          - (*(m.begin()+1)) * (*(m.begin()+1));
+      t1 = std::fabs(*m.begin());
+      t2 = std::fabs(*(m.begin()+1));
+      t3 = std::fabs(*(m.begin()+3));
+      if (t1 >= t2)
+      {
+        if (t3 >= t1)
+        {
+          temp = *(m.begin()+3);
+          det = c23*c12-c22*c13;
+        }
+        else
+        {
+          temp = *m.begin();
+          det = c22*c33-c23*c23;
+        }
+      }
+      else if (t3 >= t2)
+      {
+        temp = *(m.begin()+3);
+        det = c23*c12-c22*c13;
+      }
+      else
+      {
+        temp = *(m.begin()+1);
+        det = c13*c23-c12*c33;
+      }
+      if (det==0)
+      {
+        ifail = 1;
+        return;
+      }
+      {
+        G4double s = temp/det;
+        G4ErrorMatrixIter mm = m.begin();
+        *(mm++) = s*c11;
+        *(mm++) = s*c12;
+        *(mm++) = s*c22;
+        *(mm++) = s*c13;
+        *(mm++) = s*c23;
+        *(mm) = s*c33;
+      }
+    }
+    break;
+ case 2:
+    {
+      G4double det, temp, s;
+      det = (*m.begin())*(*(m.begin()+2)) - (*(m.begin()+1))*(*(m.begin()+1));
+      if (det==0)
+      {
+        ifail = 1;
+        return;
+      }
+      s = 1.0/det;
+      *(m.begin()+1) *= -s;
+      temp = s*(*(m.begin()+2));
+      *(m.begin()+2) = s*(*m.begin());
+      *m.begin() = temp;
+      break;
+    }
+ case 1:
+    {
+      if ((*m.begin())==0)
+      {
+        ifail = 1;
+        return;
+      }
+      *m.begin() = 1.0/(*m.begin());
+      break;
+    }
+ case 5:
+    {
+      invert5(ifail);
+      return;
+    }
+ case 6:
+    {
+      invert6(ifail);
+      return;
+    }
+ case 4:
+    {
+      invert4(ifail);
+      return;
+    }
+ default:
+    {
+      invertBunchKaufman(ifail);
+      return;
+    }
+  }
+  return; // inversion successful
+}
+
+G4double G4ErrorSymMatrix::determinant() const
+{
+  static const G4int max_array = 20;
+
+  // ir must point to an array which is ***1 longer than*** nrow
+
+  static std::vector<G4int> ir_vec (max_array+1); 
+  if (ir_vec.size() <= static_cast<unsigned int>(nrow))
+  {
+    ir_vec.resize(nrow+1);
+  }
+  G4int * ir = &ir_vec[0];   
+
+  G4double det;
+  G4ErrorMatrix mt(*this);
+  G4int i = mt.dfact_matrix(det, ir);
+  if(i==0) { return det; }
+  return 0.0;
+}
+
+G4double G4ErrorSymMatrix::trace() const
+{
+   G4double t = 0.0;
+   for (G4int i=0; i<nrow; i++) 
+     { t += *(m.begin() + (i+3)*i/2); }
+   return t;
+}
+
+void G4ErrorSymMatrix::invertBunchKaufman(G4int &ifail)
+{
+  // Bunch-Kaufman diagonal pivoting method
+  // It is decribed in J.R. Bunch, L. Kaufman (1977). 
+  // "Some Stable Methods for Calculating Inertia and Solving Symmetric 
+  // Linear Systems", Math. Comp. 31, p. 162-179. or in Gene H. Golub, 
+  // Charles F. van Loan, "Matrix Computations" (the second edition 
+  // has a bug.) and implemented in "lapack"
+  // Mario Stanke, 09/97
+
+  G4int i, j, k, s;
+  G4int pivrow;
+
+  // Establish the two working-space arrays needed:  x and piv are
+  // used as pointers to arrays of doubles and ints respectively, each
+  // of length nrow.  We do not want to reallocate each time through
+  // unless the size needs to grow.  We do not want to leak memory, even
+  // by having a new without a delete that is only done once.
+  
+  static const G4int max_array = 25;
+  static std::vector<G4double> xvec (max_array);
+  static std::vector<G4int>    pivv (max_array);
+  typedef std::vector<G4int>::iterator pivIter; 
+  if (xvec.size() < static_cast<unsigned int>(nrow)) xvec.resize(nrow);
+  if (pivv.size() < static_cast<unsigned int>(nrow)) pivv.resize(nrow);
+    // Note - resize should do  nothing if the size is already larger than nrow,
+    //        but on VC++ there are indications that it does so we check.
+    // Note - the data elements in a vector are guaranteed to be contiguous,
+    //        so x[i] and piv[i] are optimally fast.
+  G4ErrorMatrixIter   x   = xvec.begin();
+    // x[i] is used as helper storage, needs to have at least size nrow.
+  pivIter piv = pivv.begin();
+    // piv[i] is used to store details of exchanges
+      
+  G4double temp1, temp2;
+  G4ErrorMatrixIter ip, mjj, iq;
+  G4double lambda, sigma;
+  const G4double alpha = .6404; // = (1+sqrt(17))/8
+  const G4double epsilon = 32*DBL_EPSILON;
+    // whenever a sum of two doubles is below or equal to epsilon
+    // it is set to zero.
+    // this constant could be set to zero but then the algorithm
+    // doesn't neccessarily detect that a matrix is singular
+  
+  for (i = 0; i < nrow; i++)
+  {
+    piv[i] = i+1;
+  }
+      
+  ifail = 0;
+      
+  // compute the factorization P*A*P^T = L * D * L^T 
+  // L is unit lower triangular, D is direct sum of 1x1 and 2x2 matrices
+  // L and D^-1 are stored in A = *this, P is stored in piv[]
+        
+  for (j=1; j < nrow; j+=s)  // main loop over columns
+  {
+          mjj = m.begin() + j*(j-1)/2 + j-1;
+          lambda = 0;           // compute lambda = max of A(j+1:n,j)
+          pivrow = j+1;
+          ip = m.begin() + (j+1)*j/2 + j-1;
+          for (i=j+1; i <= nrow ; ip += i++)
+          {
+            if (std::fabs(*ip) > lambda)
+              {
+                lambda = std::fabs(*ip);
+                pivrow = i;
+              }
+          }
+          if (lambda == 0 )
+            {
+              if (*mjj == 0)
+                {
+                  ifail = 1;
+                  return;
+                }
+              s=1;
+              *mjj = 1./ *mjj;
+            }
+          else
+            {
+              if (std::fabs(*mjj) >= lambda*alpha)
+                {
+                  s=1;
+                  pivrow=j;
+                }
+              else
+                {
+                  sigma = 0;  // compute sigma = max A(pivrow, j:pivrow-1)
+                  ip = m.begin() + pivrow*(pivrow-1)/2+j-1;
+                  for (k=j; k < pivrow; k++)
+                    {
+                      if (std::fabs(*ip) > sigma)
+                        sigma = std::fabs(*ip);
+                      ip++;
+                    }
+                  if (sigma * std::fabs(*mjj) >= alpha * lambda * lambda)
+                    {
+                      s=1;
+                      pivrow = j;
+                    }
+                  else if (std::fabs(*(m.begin()+pivrow*(pivrow-1)/2+pivrow-1)) 
+                                >= alpha * sigma)
+                    { s=1; }
+                  else
+                    { s=2; }
+                }
+              if (pivrow == j)  // no permutation neccessary
+                {
+                  piv[j-1] = pivrow;
+                  if (*mjj == 0)
+                    {
+                      ifail=1;
+                      return;
+                    }
+                  temp2 = *mjj = 1./ *mjj; // invert D(j,j)
+                  
+                  // update A(j+1:n, j+1,n)
+                  for (i=j+1; i <= nrow; i++)
+                    {
+                      temp1 = *(m.begin() + i*(i-1)/2 + j-1) * temp2;
+                      ip = m.begin()+i*(i-1)/2+j;
+                      for (k=j+1; k<=i; k++)
+                        {
+                          *ip -= temp1 * *(m.begin() + k*(k-1)/2 + j-1);
+                          if (std::fabs(*ip) <= epsilon)
+                            { *ip=0; }
+                          ip++;
+                        }
+                    }
+                  // update L 
+                  ip = m.begin() + (j+1)*j/2 + j-1; 
+                  for (i=j+1; i <= nrow; ip += i++)
+                  {
+                    *ip *= temp2;
+                  }
+                }
+              else if (s==1) // 1x1 pivot 
+                {
+                  piv[j-1] = pivrow;
+                  
+                  // interchange rows and columns j and pivrow in
+                  // submatrix (j:n,j:n)
+                  ip = m.begin() + pivrow*(pivrow-1)/2 + j;
+                  for (i=j+1; i < pivrow; i++, ip++)
+                    {
+                      temp1 = *(m.begin() + i*(i-1)/2 + j-1);
+                      *(m.begin() + i*(i-1)/2 + j-1)= *ip;
+                      *ip = temp1;
+                    }
+                  temp1 = *mjj;
+                  *mjj = *(m.begin()+pivrow*(pivrow-1)/2+pivrow-1);
+                  *(m.begin()+pivrow*(pivrow-1)/2+pivrow-1) = temp1;
+                  ip = m.begin() + (pivrow+1)*pivrow/2 + j-1;
+                  iq = ip + pivrow-j;
+                  for (i = pivrow+1; i <= nrow; ip += i, iq += i++)
+                    {
+                      temp1 = *iq;
+                      *iq = *ip;
+                      *ip = temp1;
+                    }
+                  
+                  if (*mjj == 0)
+                    {
+                      ifail = 1;
+                      return;
+                    }
+                  temp2 = *mjj = 1./ *mjj; // invert D(j,j)
+                  
+                  // update A(j+1:n, j+1:n)
+                  for (i = j+1; i <= nrow; i++)
+                    {
+                      temp1 = *(m.begin() + i*(i-1)/2 + j-1) * temp2;
+                      ip = m.begin()+i*(i-1)/2+j;
+                      for (k=j+1; k<=i; k++)
+                        {
+                          *ip -= temp1 * *(m.begin() + k*(k-1)/2 + j-1);
+                          if (std::fabs(*ip) <= epsilon)
+                            { *ip=0; }
+                          ip++;
+                        }
+                    }
+                  // update L
+                  ip = m.begin() + (j+1)*j/2 + j-1;
+                  for (i=j+1; i<=nrow; ip += i++)
+                  {
+                    *ip *= temp2;
+                  }
+                }
+              else // s=2, ie use a 2x2 pivot
+                {
+                  piv[j-1] = -pivrow;
+                  piv[j] = 0; // that means this is the second row of a 2x2 pivot
+                  
+                  if (j+1 != pivrow) 
+                    {
+                      // interchange rows and columns j+1 and pivrow in
+                      // submatrix (j:n,j:n) 
+                      ip = m.begin() + pivrow*(pivrow-1)/2 + j+1;
+                      for (i=j+2; i < pivrow; i++, ip++)
+                        {
+                          temp1 = *(m.begin() + i*(i-1)/2 + j);
+                          *(m.begin() + i*(i-1)/2 + j) = *ip;
+                          *ip = temp1;
+                        }
+                      temp1 = *(mjj + j + 1);
+                      *(mjj + j + 1) = 
+                        *(m.begin() + pivrow*(pivrow-1)/2 + pivrow-1);
+                      *(m.begin() + pivrow*(pivrow-1)/2 + pivrow-1) = temp1;
+                      temp1 = *(mjj + j);
+                      *(mjj + j) = *(m.begin() + pivrow*(pivrow-1)/2 + j-1);
+                      *(m.begin() + pivrow*(pivrow-1)/2 + j-1) = temp1;
+                      ip = m.begin() + (pivrow+1)*pivrow/2 + j;
+                      iq = ip + pivrow-(j+1);
+                      for (i = pivrow+1; i <= nrow; ip += i, iq += i++)
+                        {
+                          temp1 = *iq;
+                          *iq = *ip;
+                          *ip = temp1;
+                        }
+                    } 
+                  // invert D(j:j+1,j:j+1)
+                  temp2 = *mjj * *(mjj + j + 1) - *(mjj + j) * *(mjj + j); 
+                  if (temp2 == 0)
+                  {
+                    G4cerr
+                      << "G4ErrorSymMatrix::bunch_invert: error in pivot choice"
+                      << G4endl;
+                  }
+                  temp2 = 1. / temp2;
+
+                  // this quotient is guaranteed to exist by the choice 
+                  // of the pivot
+
+                  temp1 = *mjj;
+                  *mjj = *(mjj + j + 1) * temp2;
+                  *(mjj + j + 1) = temp1 * temp2;
+                  *(mjj + j) = - *(mjj + j) * temp2;
+                  
+                  if (j < nrow-1) // otherwise do nothing
+                    {
+                      // update A(j+2:n, j+2:n)
+                      for (i=j+2; i <= nrow ; i++)
+                        {
+                          ip = m.begin() + i*(i-1)/2 + j-1;
+                          temp1 = *ip * *mjj + *(ip + 1) * *(mjj + j);
+                          if (std::fabs(temp1 ) <= epsilon)
+                            { temp1 = 0; }
+                          temp2 = *ip * *(mjj + j) + *(ip + 1) * *(mjj + j + 1);
+                          if (std::fabs(temp2 ) <= epsilon)
+                            { temp2 = 0; }
+                          for (k = j+2; k <= i ; k++)
+                            {
+                              ip = m.begin() + i*(i-1)/2 + k-1;
+                              iq = m.begin() + k*(k-1)/2 + j-1;
+                              *ip -= temp1 * *iq + temp2 * *(iq+1);
+                              if (std::fabs(*ip) <= epsilon)
+                                { *ip = 0; }
+                            }
+                        }
+                      // update L
+                      for (i=j+2; i <= nrow ; i++)
+                        {
+                          ip = m.begin() + i*(i-1)/2 + j-1;
+                          temp1 = *ip * *mjj + *(ip+1) * *(mjj + j);
+                          if (std::fabs(temp1) <= epsilon)
+                            { temp1 = 0; }
+                          *(ip+1) = *ip * *(mjj + j) + *(ip+1) * *(mjj + j + 1);
+                          if (std::fabs(*(ip+1)) <= epsilon)
+                            { *(ip+1) = 0; }
+                          *ip = temp1;
+                        }
+                    }
+                }
+            }
+  } // end of main loop over columns
+
+  if (j == nrow) // the the last pivot is 1x1
+  {
+    mjj = m.begin() + j*(j-1)/2 + j-1;
+    if (*mjj == 0)
+    {
+      ifail = 1;
+      return;
+    }
+    else
+    {
+      *mjj = 1. / *mjj;
+    }
+  } // end of last pivot code
+
+  // computing the inverse from the factorization
+         
+  for (j = nrow ; j >= 1 ; j -= s) // loop over columns
+  {
+          mjj = m.begin() + j*(j-1)/2 + j-1;
+          if (piv[j-1] > 0) // 1x1 pivot, compute column j of inverse
+            {
+              s = 1; 
+              if (j < nrow)
+                {
+                  ip = m.begin() + (j+1)*j/2 + j-1;
+                  for (i=0; i < nrow-j; ip += 1+j+i++)
+                  {
+                    x[i] = *ip;
+                  }
+                  for (i=j+1; i<=nrow ; i++)
+                  {
+                    temp2=0;
+                    ip = m.begin() + i*(i-1)/2 + j;
+                    for (k=0; k <= i-j-1; k++)
+                      { temp2 += *ip++ * x[k]; }
+                    for (ip += i-1; k < nrow-j; ip += 1+j+k++) 
+                      { temp2 += *ip * x[k]; }
+                    *(m.begin()+ i*(i-1)/2 + j-1) = -temp2;
+                  }
+                  temp2 = 0;
+                  ip = m.begin() + (j+1)*j/2 + j-1;
+                  for (k=0; k < nrow-j; ip += 1+j+k++)
+                    { temp2 += x[k] * *ip; }
+                  *mjj -= temp2;
+                }
+            }
+          else //2x2 pivot, compute columns j and j-1 of the inverse
+            {
+              if (piv[j-1] != 0)
+                { G4cerr << "error in piv" << piv[j-1] << G4endl; }
+              s=2; 
+              if (j < nrow)
+                {
+                  ip = m.begin() + (j+1)*j/2 + j-1;
+                  for (i=0; i < nrow-j; ip += 1+j+i++)
+                  {
+                    x[i] = *ip;
+                  }
+                  for (i=j+1; i<=nrow ; i++)
+                  {
+                    temp2 = 0;
+                    ip = m.begin() + i*(i-1)/2 + j;
+                    for (k=0; k <= i-j-1; k++)
+                      { temp2 += *ip++ * x[k]; }
+                    for (ip += i-1; k < nrow-j; ip += 1+j+k++)
+                      { temp2 += *ip * x[k]; }
+                    *(m.begin()+ i*(i-1)/2 + j-1) = -temp2;
+                  }    
+                  temp2 = 0;
+                  ip = m.begin() + (j+1)*j/2 + j-1;
+                  for (k=0; k < nrow-j; ip += 1+j+k++)
+                    { temp2 += x[k] * *ip; }
+                  *mjj -= temp2;
+                  temp2 = 0;
+                  ip = m.begin() + (j+1)*j/2 + j-2;
+                  for (i=j+1; i <= nrow; ip += i++)
+                    { temp2 += *ip * *(ip+1); }
+                  *(mjj-1) -= temp2;
+                  ip = m.begin() + (j+1)*j/2 + j-2;
+                  for (i=0; i < nrow-j; ip += 1+j+i++)
+                  {
+                    x[i] = *ip;
+                  }
+                  for (i=j+1; i <= nrow ; i++)
+                  {
+                    temp2 = 0;
+                    ip = m.begin() + i*(i-1)/2 + j;
+                    for (k=0; k <= i-j-1; k++)
+                      { temp2 += *ip++ * x[k]; }
+                    for (ip += i-1; k < nrow-j; ip += 1+j+k++)
+                      { temp2 += *ip * x[k]; }
+                    *(m.begin()+ i*(i-1)/2 + j-2)= -temp2;
+                  }
+                  temp2 = 0;
+                  ip = m.begin() + (j+1)*j/2 + j-2;
+                  for (k=0; k < nrow-j; ip += 1+j+k++)
+                    { temp2 += x[k] * *ip; }
+                  *(mjj-j) -= temp2;
+                }
+            }  
+          
+          // interchange rows and columns j and piv[j-1] 
+          // or rows and columns j and -piv[j-2]
+          
+          pivrow = (piv[j-1]==0)? -piv[j-2] : piv[j-1];
+          ip = m.begin() + pivrow*(pivrow-1)/2 + j;
+          for (i=j+1;i < pivrow; i++, ip++)
+            {
+              temp1 = *(m.begin() + i*(i-1)/2 + j-1);
+              *(m.begin() + i*(i-1)/2 + j-1) = *ip;
+              *ip = temp1;
+            }
+          temp1 = *mjj;
+          *mjj = *(m.begin() + pivrow*(pivrow-1)/2 + pivrow-1);
+          *(m.begin() + pivrow*(pivrow-1)/2 + pivrow-1) = temp1;
+          if (s==2)
+            {
+              temp1 = *(mjj-1);
+              *(mjj-1) = *( m.begin() + pivrow*(pivrow-1)/2 + j-2);
+              *( m.begin() + pivrow*(pivrow-1)/2 + j-2) = temp1;
+            }
+          
+          ip = m.begin() + (pivrow+1)*pivrow/2 + j-1;  // &A(i,j)
+          iq = ip + pivrow-j;
+          for (i = pivrow+1; i <= nrow; ip += i, iq += i++)
+            {
+              temp1 = *iq;
+              *iq = *ip;
+              *ip = temp1;
+            } 
+  } // end of loop over columns (in computing inverse from factorization)
+
+  return; // inversion successful
+}
+
+G4double G4ErrorSymMatrix::posDefFraction5x5 = 1.0;
+G4double G4ErrorSymMatrix::posDefFraction6x6 = 1.0;
+G4double G4ErrorSymMatrix::adjustment5x5 = 0.0;
+G4double G4ErrorSymMatrix::adjustment6x6 = 0.0;
+const G4double G4ErrorSymMatrix::CHOLESKY_THRESHOLD_5x5 = .5;
+const G4double G4ErrorSymMatrix::CHOLESKY_THRESHOLD_6x6 = .2;
+const G4double G4ErrorSymMatrix::CHOLESKY_CREEP_5x5 = .005;
+const G4double G4ErrorSymMatrix::CHOLESKY_CREEP_6x6 = .002;
+
+// Aij are indices for a 6x6 symmetric matrix.
+//     The indices for 5x5 or 4x4 symmetric matrices are the same, 
+//     ignoring all combinations with an index which is inapplicable.
+
+#define A00 0
+#define A01 1
+#define A02 3
+#define A03 6
+#define A04 10
+#define A05 15
+
+#define A10 1
+#define A11 2
+#define A12 4
+#define A13 7
+#define A14 11
+#define A15 16
+
+#define A20 3
+#define A21 4
+#define A22 5
+#define A23 8
+#define A24 12
+#define A25 17
+
+#define A30 6
+#define A31 7
+#define A32 8
+#define A33 9
+#define A34 13
+#define A35 18
+
+#define A40 10
+#define A41 11
+#define A42 12
+#define A43 13
+#define A44 14
+#define A45 19
+
+#define A50 15
+#define A51 16
+#define A52 17
+#define A53 18
+#define A54 19
+#define A55 20
+
+void G4ErrorSymMatrix::invert5(G4int & ifail)
+{ 
+      if (posDefFraction5x5 >= CHOLESKY_THRESHOLD_5x5)
+      {
+        invertCholesky5(ifail);
+        posDefFraction5x5 = .9*posDefFraction5x5 + .1*(1-ifail);
+        if (ifail!=0)    // Cholesky failed -- invert using Haywood
+        {
+          invertHaywood5(ifail);      
+        }
+      }
+      else
+      {
+        if (posDefFraction5x5 + adjustment5x5 >= CHOLESKY_THRESHOLD_5x5)
+        {
+          invertCholesky5(ifail);
+          posDefFraction5x5 = .9*posDefFraction5x5 + .1*(1-ifail);
+          if (ifail!=0)    // Cholesky failed -- invert using Haywood
+          {
+            invertHaywood5(ifail);      
+            adjustment5x5 = 0;
+          }
+        }
+        else
+        {
+          invertHaywood5(ifail);      
+          adjustment5x5 += CHOLESKY_CREEP_5x5;
+        }
+      }
+      return;
+}
+
+void G4ErrorSymMatrix::invert6(G4int & ifail)
+{
+      if (posDefFraction6x6 >= CHOLESKY_THRESHOLD_6x6)
+      {
+        invertCholesky6(ifail);
+        posDefFraction6x6 = .9*posDefFraction6x6 + .1*(1-ifail);
+        if (ifail!=0)    // Cholesky failed -- invert using Haywood
+        {
+          invertHaywood6(ifail);      
+        }
+      }
+      else
+      {
+        if (posDefFraction6x6 + adjustment6x6 >= CHOLESKY_THRESHOLD_6x6)
+        {
+          invertCholesky6(ifail);
+          posDefFraction6x6 = .9*posDefFraction6x6 + .1*(1-ifail);
+          if (ifail!=0)    // Cholesky failed -- invert using Haywood
+          {
+            invertHaywood6(ifail);      
+            adjustment6x6 = 0;
+          }
+        }
+        else
+        {
+          invertHaywood6(ifail);      
+          adjustment6x6 += CHOLESKY_CREEP_6x6;
+        }
+      }
+      return;
+}
+
+void G4ErrorSymMatrix::invertHaywood5  (G4int & ifail)
+{
+  ifail = 0;
+
+  // Find all NECESSARY 2x2 dets:  (25 of them)
+
+  G4double Det2_23_01 = m[A20]*m[A31] - m[A21]*m[A30];
+  G4double Det2_23_02 = m[A20]*m[A32] - m[A22]*m[A30];
+  G4double Det2_23_03 = m[A20]*m[A33] - m[A23]*m[A30];
+  G4double Det2_23_12 = m[A21]*m[A32] - m[A22]*m[A31];
+  G4double Det2_23_13 = m[A21]*m[A33] - m[A23]*m[A31];
+  G4double Det2_23_23 = m[A22]*m[A33] - m[A23]*m[A32];
+  G4double Det2_24_01 = m[A20]*m[A41] - m[A21]*m[A40];
+  G4double Det2_24_02 = m[A20]*m[A42] - m[A22]*m[A40];
+  G4double Det2_24_03 = m[A20]*m[A43] - m[A23]*m[A40];
+  G4double Det2_24_04 = m[A20]*m[A44] - m[A24]*m[A40];
+  G4double Det2_24_12 = m[A21]*m[A42] - m[A22]*m[A41];
+  G4double Det2_24_13 = m[A21]*m[A43] - m[A23]*m[A41];
+  G4double Det2_24_14 = m[A21]*m[A44] - m[A24]*m[A41];
+  G4double Det2_24_23 = m[A22]*m[A43] - m[A23]*m[A42];
+  G4double Det2_24_24 = m[A22]*m[A44] - m[A24]*m[A42];
+  G4double Det2_34_01 = m[A30]*m[A41] - m[A31]*m[A40];
+  G4double Det2_34_02 = m[A30]*m[A42] - m[A32]*m[A40];
+  G4double Det2_34_03 = m[A30]*m[A43] - m[A33]*m[A40];
+  G4double Det2_34_04 = m[A30]*m[A44] - m[A34]*m[A40];
+  G4double Det2_34_12 = m[A31]*m[A42] - m[A32]*m[A41];
+  G4double Det2_34_13 = m[A31]*m[A43] - m[A33]*m[A41];
+  G4double Det2_34_14 = m[A31]*m[A44] - m[A34]*m[A41];
+  G4double Det2_34_23 = m[A32]*m[A43] - m[A33]*m[A42];
+  G4double Det2_34_24 = m[A32]*m[A44] - m[A34]*m[A42];
+  G4double Det2_34_34 = m[A33]*m[A44] - m[A34]*m[A43];
+
+  // Find all NECESSARY 3x3 dets:   (30 of them)
+
+  G4double Det3_123_012 = m[A10]*Det2_23_12 - m[A11]*Det2_23_02 
+                                + m[A12]*Det2_23_01;
+  G4double Det3_123_013 = m[A10]*Det2_23_13 - m[A11]*Det2_23_03 
+                                + m[A13]*Det2_23_01;
+  G4double Det3_123_023 = m[A10]*Det2_23_23 - m[A12]*Det2_23_03 
+                                + m[A13]*Det2_23_02;
+  G4double Det3_123_123 = m[A11]*Det2_23_23 - m[A12]*Det2_23_13 
+                                + m[A13]*Det2_23_12;
+  G4double Det3_124_012 = m[A10]*Det2_24_12 - m[A11]*Det2_24_02 
+                                + m[A12]*Det2_24_01;
+  G4double Det3_124_013 = m[A10]*Det2_24_13 - m[A11]*Det2_24_03 
+                                + m[A13]*Det2_24_01;
+  G4double Det3_124_014 = m[A10]*Det2_24_14 - m[A11]*Det2_24_04 
+                                + m[A14]*Det2_24_01;
+  G4double Det3_124_023 = m[A10]*Det2_24_23 - m[A12]*Det2_24_03 
+                                + m[A13]*Det2_24_02;
+  G4double Det3_124_024 = m[A10]*Det2_24_24 - m[A12]*Det2_24_04 
+                                + m[A14]*Det2_24_02;
+  G4double Det3_124_123 = m[A11]*Det2_24_23 - m[A12]*Det2_24_13 
+                                + m[A13]*Det2_24_12;
+  G4double Det3_124_124 = m[A11]*Det2_24_24 - m[A12]*Det2_24_14 
+                                + m[A14]*Det2_24_12;
+  G4double Det3_134_012 = m[A10]*Det2_34_12 - m[A11]*Det2_34_02 
+                                + m[A12]*Det2_34_01;
+  G4double Det3_134_013 = m[A10]*Det2_34_13 - m[A11]*Det2_34_03 
+                                + m[A13]*Det2_34_01;
+  G4double Det3_134_014 = m[A10]*Det2_34_14 - m[A11]*Det2_34_04 
+                                + m[A14]*Det2_34_01;
+  G4double Det3_134_023 = m[A10]*Det2_34_23 - m[A12]*Det2_34_03 
+                                + m[A13]*Det2_34_02;
+  G4double Det3_134_024 = m[A10]*Det2_34_24 - m[A12]*Det2_34_04 
+                                + m[A14]*Det2_34_02;
+  G4double Det3_134_034 = m[A10]*Det2_34_34 - m[A13]*Det2_34_04 
+                                + m[A14]*Det2_34_03;
+  G4double Det3_134_123 = m[A11]*Det2_34_23 - m[A12]*Det2_34_13 
+                                + m[A13]*Det2_34_12;
+  G4double Det3_134_124 = m[A11]*Det2_34_24 - m[A12]*Det2_34_14 
+                                + m[A14]*Det2_34_12;
+  G4double Det3_134_134 = m[A11]*Det2_34_34 - m[A13]*Det2_34_14 
+                                + m[A14]*Det2_34_13;
+  G4double Det3_234_012 = m[A20]*Det2_34_12 - m[A21]*Det2_34_02 
+                                + m[A22]*Det2_34_01;
+  G4double Det3_234_013 = m[A20]*Det2_34_13 - m[A21]*Det2_34_03 
+                                + m[A23]*Det2_34_01;
+  G4double Det3_234_014 = m[A20]*Det2_34_14 - m[A21]*Det2_34_04 
+                                + m[A24]*Det2_34_01;
+  G4double Det3_234_023 = m[A20]*Det2_34_23 - m[A22]*Det2_34_03 
+                                + m[A23]*Det2_34_02;
+  G4double Det3_234_024 = m[A20]*Det2_34_24 - m[A22]*Det2_34_04 
+                                + m[A24]*Det2_34_02;
+  G4double Det3_234_034 = m[A20]*Det2_34_34 - m[A23]*Det2_34_04 
+                                + m[A24]*Det2_34_03;
+  G4double Det3_234_123 = m[A21]*Det2_34_23 - m[A22]*Det2_34_13 
+                                + m[A23]*Det2_34_12;
+  G4double Det3_234_124 = m[A21]*Det2_34_24 - m[A22]*Det2_34_14 
+                                + m[A24]*Det2_34_12;
+  G4double Det3_234_134 = m[A21]*Det2_34_34 - m[A23]*Det2_34_14 
+                                + m[A24]*Det2_34_13;
+  G4double Det3_234_234 = m[A22]*Det2_34_34 - m[A23]*Det2_34_24 
+                                + m[A24]*Det2_34_23;
+
+  // Find all NECESSARY 4x4 dets:   (15 of them)
+
+  G4double Det4_0123_0123 = m[A00]*Det3_123_123 - m[A01]*Det3_123_023 
+                                + m[A02]*Det3_123_013 - m[A03]*Det3_123_012;
+  G4double Det4_0124_0123 = m[A00]*Det3_124_123 - m[A01]*Det3_124_023 
+                                + m[A02]*Det3_124_013 - m[A03]*Det3_124_012;
+  G4double Det4_0124_0124 = m[A00]*Det3_124_124 - m[A01]*Det3_124_024 
+                                + m[A02]*Det3_124_014 - m[A04]*Det3_124_012;
+  G4double Det4_0134_0123 = m[A00]*Det3_134_123 - m[A01]*Det3_134_023 
+                                + m[A02]*Det3_134_013 - m[A03]*Det3_134_012;
+  G4double Det4_0134_0124 = m[A00]*Det3_134_124 - m[A01]*Det3_134_024 
+                                + m[A02]*Det3_134_014 - m[A04]*Det3_134_012;
+  G4double Det4_0134_0134 = m[A00]*Det3_134_134 - m[A01]*Det3_134_034 
+                                + m[A03]*Det3_134_014 - m[A04]*Det3_134_013;
+  G4double Det4_0234_0123 = m[A00]*Det3_234_123 - m[A01]*Det3_234_023 
+                                + m[A02]*Det3_234_013 - m[A03]*Det3_234_012;
+  G4double Det4_0234_0124 = m[A00]*Det3_234_124 - m[A01]*Det3_234_024 
+                                + m[A02]*Det3_234_014 - m[A04]*Det3_234_012;
+  G4double Det4_0234_0134 = m[A00]*Det3_234_134 - m[A01]*Det3_234_034 
+                                + m[A03]*Det3_234_014 - m[A04]*Det3_234_013;
+  G4double Det4_0234_0234 = m[A00]*Det3_234_234 - m[A02]*Det3_234_034 
+                                + m[A03]*Det3_234_024 - m[A04]*Det3_234_023;
+  G4double Det4_1234_0123 = m[A10]*Det3_234_123 - m[A11]*Det3_234_023 
+                                + m[A12]*Det3_234_013 - m[A13]*Det3_234_012;
+  G4double Det4_1234_0124 = m[A10]*Det3_234_124 - m[A11]*Det3_234_024 
+                                + m[A12]*Det3_234_014 - m[A14]*Det3_234_012;
+  G4double Det4_1234_0134 = m[A10]*Det3_234_134 - m[A11]*Det3_234_034 
+                                + m[A13]*Det3_234_014 - m[A14]*Det3_234_013;
+  G4double Det4_1234_0234 = m[A10]*Det3_234_234 - m[A12]*Det3_234_034 
+                                + m[A13]*Det3_234_024 - m[A14]*Det3_234_023;
+  G4double Det4_1234_1234 = m[A11]*Det3_234_234 - m[A12]*Det3_234_134 
+                                + m[A13]*Det3_234_124 - m[A14]*Det3_234_123;
+
+  // Find the 5x5 det:
+
+  G4double det =  m[A00]*Det4_1234_1234 
+                - m[A01]*Det4_1234_0234 
+                + m[A02]*Det4_1234_0134 
+                - m[A03]*Det4_1234_0124 
+                + m[A04]*Det4_1234_0123;
+
+  if ( det == 0 )
+  {  
+    ifail = 1;
+    return;
+  } 
+
+  G4double oneOverDet = 1.0/det;
+  G4double mn1OverDet = - oneOverDet;
+
+  m[A00] =  Det4_1234_1234 * oneOverDet;
+  m[A01] =  Det4_1234_0234 * mn1OverDet;
+  m[A02] =  Det4_1234_0134 * oneOverDet;
+  m[A03] =  Det4_1234_0124 * mn1OverDet;
+  m[A04] =  Det4_1234_0123 * oneOverDet;
+
+  m[A11] =  Det4_0234_0234 * oneOverDet;
+  m[A12] =  Det4_0234_0134 * mn1OverDet;
+  m[A13] =  Det4_0234_0124 * oneOverDet;
+  m[A14] =  Det4_0234_0123 * mn1OverDet;
+
+  m[A22] =  Det4_0134_0134 * oneOverDet;
+  m[A23] =  Det4_0134_0124 * mn1OverDet;
+  m[A24] =  Det4_0134_0123 * oneOverDet;
+
+  m[A33] =  Det4_0124_0124 * oneOverDet;
+  m[A34] =  Det4_0124_0123 * mn1OverDet;
+
+  m[A44] =  Det4_0123_0123 * oneOverDet;
+
+  return;
+}
+
+void G4ErrorSymMatrix::invertHaywood6  (G4int & ifail)
+{
+  ifail = 0;
+
+  // Find all NECESSARY 2x2 dets:  (39 of them)
+
+  G4double Det2_34_01 = m[A30]*m[A41] - m[A31]*m[A40];
+  G4double Det2_34_02 = m[A30]*m[A42] - m[A32]*m[A40];
+  G4double Det2_34_03 = m[A30]*m[A43] - m[A33]*m[A40];
+  G4double Det2_34_04 = m[A30]*m[A44] - m[A34]*m[A40];
+  G4double Det2_34_12 = m[A31]*m[A42] - m[A32]*m[A41];
+  G4double Det2_34_13 = m[A31]*m[A43] - m[A33]*m[A41];
+  G4double Det2_34_14 = m[A31]*m[A44] - m[A34]*m[A41];
+  G4double Det2_34_23 = m[A32]*m[A43] - m[A33]*m[A42];
+  G4double Det2_34_24 = m[A32]*m[A44] - m[A34]*m[A42];
+  G4double Det2_34_34 = m[A33]*m[A44] - m[A34]*m[A43];
+  G4double Det2_35_01 = m[A30]*m[A51] - m[A31]*m[A50];
+  G4double Det2_35_02 = m[A30]*m[A52] - m[A32]*m[A50];
+  G4double Det2_35_03 = m[A30]*m[A53] - m[A33]*m[A50];
+  G4double Det2_35_04 = m[A30]*m[A54] - m[A34]*m[A50];
+  G4double Det2_35_05 = m[A30]*m[A55] - m[A35]*m[A50];
+  G4double Det2_35_12 = m[A31]*m[A52] - m[A32]*m[A51];
+  G4double Det2_35_13 = m[A31]*m[A53] - m[A33]*m[A51];
+  G4double Det2_35_14 = m[A31]*m[A54] - m[A34]*m[A51];
+  G4double Det2_35_15 = m[A31]*m[A55] - m[A35]*m[A51];
+  G4double Det2_35_23 = m[A32]*m[A53] - m[A33]*m[A52];
+  G4double Det2_35_24 = m[A32]*m[A54] - m[A34]*m[A52];
+  G4double Det2_35_25 = m[A32]*m[A55] - m[A35]*m[A52];
+  G4double Det2_35_34 = m[A33]*m[A54] - m[A34]*m[A53];
+  G4double Det2_35_35 = m[A33]*m[A55] - m[A35]*m[A53];
+  G4double Det2_45_01 = m[A40]*m[A51] - m[A41]*m[A50];
+  G4double Det2_45_02 = m[A40]*m[A52] - m[A42]*m[A50];
+  G4double Det2_45_03 = m[A40]*m[A53] - m[A43]*m[A50];
+  G4double Det2_45_04 = m[A40]*m[A54] - m[A44]*m[A50];
+  G4double Det2_45_05 = m[A40]*m[A55] - m[A45]*m[A50];
+  G4double Det2_45_12 = m[A41]*m[A52] - m[A42]*m[A51];
+  G4double Det2_45_13 = m[A41]*m[A53] - m[A43]*m[A51];
+  G4double Det2_45_14 = m[A41]*m[A54] - m[A44]*m[A51];
+  G4double Det2_45_15 = m[A41]*m[A55] - m[A45]*m[A51];
+  G4double Det2_45_23 = m[A42]*m[A53] - m[A43]*m[A52];
+  G4double Det2_45_24 = m[A42]*m[A54] - m[A44]*m[A52];
+  G4double Det2_45_25 = m[A42]*m[A55] - m[A45]*m[A52];
+  G4double Det2_45_34 = m[A43]*m[A54] - m[A44]*m[A53];
+  G4double Det2_45_35 = m[A43]*m[A55] - m[A45]*m[A53];
+  G4double Det2_45_45 = m[A44]*m[A55] - m[A45]*m[A54];
+
+  // Find all NECESSARY 3x3 dets:  (65 of them)
+
+  G4double Det3_234_012 = m[A20]*Det2_34_12 - m[A21]*Det2_34_02 
+                                                + m[A22]*Det2_34_01;
+  G4double Det3_234_013 = m[A20]*Det2_34_13 - m[A21]*Det2_34_03 
+                                                + m[A23]*Det2_34_01;
+  G4double Det3_234_014 = m[A20]*Det2_34_14 - m[A21]*Det2_34_04 
+                                                + m[A24]*Det2_34_01;
+  G4double Det3_234_023 = m[A20]*Det2_34_23 - m[A22]*Det2_34_03 
+                                                + m[A23]*Det2_34_02;
+  G4double Det3_234_024 = m[A20]*Det2_34_24 - m[A22]*Det2_34_04 
+                                                + m[A24]*Det2_34_02;
+  G4double Det3_234_034 = m[A20]*Det2_34_34 - m[A23]*Det2_34_04 
+                                                + m[A24]*Det2_34_03;
+  G4double Det3_234_123 = m[A21]*Det2_34_23 - m[A22]*Det2_34_13 
+                                                + m[A23]*Det2_34_12;
+  G4double Det3_234_124 = m[A21]*Det2_34_24 - m[A22]*Det2_34_14 
+                                                + m[A24]*Det2_34_12;
+  G4double Det3_234_134 = m[A21]*Det2_34_34 - m[A23]*Det2_34_14 
+                                                + m[A24]*Det2_34_13;
+  G4double Det3_234_234 = m[A22]*Det2_34_34 - m[A23]*Det2_34_24 
+                                                + m[A24]*Det2_34_23;
+  G4double Det3_235_012 = m[A20]*Det2_35_12 - m[A21]*Det2_35_02 
+                                                + m[A22]*Det2_35_01;
+  G4double Det3_235_013 = m[A20]*Det2_35_13 - m[A21]*Det2_35_03 
+                                                + m[A23]*Det2_35_01;
+  G4double Det3_235_014 = m[A20]*Det2_35_14 - m[A21]*Det2_35_04 
+                                                + m[A24]*Det2_35_01;
+  G4double Det3_235_015 = m[A20]*Det2_35_15 - m[A21]*Det2_35_05 
+                                                + m[A25]*Det2_35_01;
+  G4double Det3_235_023 = m[A20]*Det2_35_23 - m[A22]*Det2_35_03 
+                                                + m[A23]*Det2_35_02;
+  G4double Det3_235_024 = m[A20]*Det2_35_24 - m[A22]*Det2_35_04 
+                                                + m[A24]*Det2_35_02;
+  G4double Det3_235_025 = m[A20]*Det2_35_25 - m[A22]*Det2_35_05 
+                                                + m[A25]*Det2_35_02;
+  G4double Det3_235_034 = m[A20]*Det2_35_34 - m[A23]*Det2_35_04 
+                                                + m[A24]*Det2_35_03;
+  G4double Det3_235_035 = m[A20]*Det2_35_35 - m[A23]*Det2_35_05 
+                                                + m[A25]*Det2_35_03;
+  G4double Det3_235_123 = m[A21]*Det2_35_23 - m[A22]*Det2_35_13 
+                                                + m[A23]*Det2_35_12;
+  G4double Det3_235_124 = m[A21]*Det2_35_24 - m[A22]*Det2_35_14 
+                                                + m[A24]*Det2_35_12;
+  G4double Det3_235_125 = m[A21]*Det2_35_25 - m[A22]*Det2_35_15 
+                                                + m[A25]*Det2_35_12;
+  G4double Det3_235_134 = m[A21]*Det2_35_34 - m[A23]*Det2_35_14 
+                                                + m[A24]*Det2_35_13;
+  G4double Det3_235_135 = m[A21]*Det2_35_35 - m[A23]*Det2_35_15 
+                                                + m[A25]*Det2_35_13;
+  G4double Det3_235_234 = m[A22]*Det2_35_34 - m[A23]*Det2_35_24 
+                                                + m[A24]*Det2_35_23;
+  G4double Det3_235_235 = m[A22]*Det2_35_35 - m[A23]*Det2_35_25 
+                                                + m[A25]*Det2_35_23;
+  G4double Det3_245_012 = m[A20]*Det2_45_12 - m[A21]*Det2_45_02 
+                                                + m[A22]*Det2_45_01;
+  G4double Det3_245_013 = m[A20]*Det2_45_13 - m[A21]*Det2_45_03 
+                                                + m[A23]*Det2_45_01;
+  G4double Det3_245_014 = m[A20]*Det2_45_14 - m[A21]*Det2_45_04 
+                                                + m[A24]*Det2_45_01;
+  G4double Det3_245_015 = m[A20]*Det2_45_15 - m[A21]*Det2_45_05 
+                                                + m[A25]*Det2_45_01;
+  G4double Det3_245_023 = m[A20]*Det2_45_23 - m[A22]*Det2_45_03 
+                                                + m[A23]*Det2_45_02;
+  G4double Det3_245_024 = m[A20]*Det2_45_24 - m[A22]*Det2_45_04 
+                                                + m[A24]*Det2_45_02;
+  G4double Det3_245_025 = m[A20]*Det2_45_25 - m[A22]*Det2_45_05 
+                                                + m[A25]*Det2_45_02;
+  G4double Det3_245_034 = m[A20]*Det2_45_34 - m[A23]*Det2_45_04 
+                                                + m[A24]*Det2_45_03;
+  G4double Det3_245_035 = m[A20]*Det2_45_35 - m[A23]*Det2_45_05 
+                                                + m[A25]*Det2_45_03;
+  G4double Det3_245_045 = m[A20]*Det2_45_45 - m[A24]*Det2_45_05 
+                                                + m[A25]*Det2_45_04;
+  G4double Det3_245_123 = m[A21]*Det2_45_23 - m[A22]*Det2_45_13 
+                                                + m[A23]*Det2_45_12;
+  G4double Det3_245_124 = m[A21]*Det2_45_24 - m[A22]*Det2_45_14 
+                                                + m[A24]*Det2_45_12;
+  G4double Det3_245_125 = m[A21]*Det2_45_25 - m[A22]*Det2_45_15 
+                                                + m[A25]*Det2_45_12;
+  G4double Det3_245_134 = m[A21]*Det2_45_34 - m[A23]*Det2_45_14 
+                                                + m[A24]*Det2_45_13;
+  G4double Det3_245_135 = m[A21]*Det2_45_35 - m[A23]*Det2_45_15 
+                                                + m[A25]*Det2_45_13;
+  G4double Det3_245_145 = m[A21]*Det2_45_45 - m[A24]*Det2_45_15 
+                                                + m[A25]*Det2_45_14;
+  G4double Det3_245_234 = m[A22]*Det2_45_34 - m[A23]*Det2_45_24 
+                                                + m[A24]*Det2_45_23;
+  G4double Det3_245_235 = m[A22]*Det2_45_35 - m[A23]*Det2_45_25 
+                                                + m[A25]*Det2_45_23;
+  G4double Det3_245_245 = m[A22]*Det2_45_45 - m[A24]*Det2_45_25 
+                                                + m[A25]*Det2_45_24;
+  G4double Det3_345_012 = m[A30]*Det2_45_12 - m[A31]*Det2_45_02 
+                                                + m[A32]*Det2_45_01;
+  G4double Det3_345_013 = m[A30]*Det2_45_13 - m[A31]*Det2_45_03 
+                                                + m[A33]*Det2_45_01;
+  G4double Det3_345_014 = m[A30]*Det2_45_14 - m[A31]*Det2_45_04 
+                                                + m[A34]*Det2_45_01;
+  G4double Det3_345_015 = m[A30]*Det2_45_15 - m[A31]*Det2_45_05 
+                                                + m[A35]*Det2_45_01;
+  G4double Det3_345_023 = m[A30]*Det2_45_23 - m[A32]*Det2_45_03 
+                                                + m[A33]*Det2_45_02;
+  G4double Det3_345_024 = m[A30]*Det2_45_24 - m[A32]*Det2_45_04 
+                                                + m[A34]*Det2_45_02;
+  G4double Det3_345_025 = m[A30]*Det2_45_25 - m[A32]*Det2_45_05 
+                                                + m[A35]*Det2_45_02;
+  G4double Det3_345_034 = m[A30]*Det2_45_34 - m[A33]*Det2_45_04 
+                                                + m[A34]*Det2_45_03;
+  G4double Det3_345_035 = m[A30]*Det2_45_35 - m[A33]*Det2_45_05 
+                                                + m[A35]*Det2_45_03;
+  G4double Det3_345_045 = m[A30]*Det2_45_45 - m[A34]*Det2_45_05 
+                                                + m[A35]*Det2_45_04;
+  G4double Det3_345_123 = m[A31]*Det2_45_23 - m[A32]*Det2_45_13 
+                                                + m[A33]*Det2_45_12;
+  G4double Det3_345_124 = m[A31]*Det2_45_24 - m[A32]*Det2_45_14 
+                                                + m[A34]*Det2_45_12;
+  G4double Det3_345_125 = m[A31]*Det2_45_25 - m[A32]*Det2_45_15 
+                                                + m[A35]*Det2_45_12;
+  G4double Det3_345_134 = m[A31]*Det2_45_34 - m[A33]*Det2_45_14 
+                                                + m[A34]*Det2_45_13;
+  G4double Det3_345_135 = m[A31]*Det2_45_35 - m[A33]*Det2_45_15 
+                                                + m[A35]*Det2_45_13;
+  G4double Det3_345_145 = m[A31]*Det2_45_45 - m[A34]*Det2_45_15 
+                                                + m[A35]*Det2_45_14;
+  G4double Det3_345_234 = m[A32]*Det2_45_34 - m[A33]*Det2_45_24 
+                                                + m[A34]*Det2_45_23;
+  G4double Det3_345_235 = m[A32]*Det2_45_35 - m[A33]*Det2_45_25 
+                                                + m[A35]*Det2_45_23;
+  G4double Det3_345_245 = m[A32]*Det2_45_45 - m[A34]*Det2_45_25 
+                                                + m[A35]*Det2_45_24;
+  G4double Det3_345_345 = m[A33]*Det2_45_45 - m[A34]*Det2_45_35 
+                                                + m[A35]*Det2_45_34;
+
+  // Find all NECESSARY 4x4 dets:  (55 of them)
+
+  G4double Det4_1234_0123 = m[A10]*Det3_234_123 - m[A11]*Det3_234_023 
+                        + m[A12]*Det3_234_013 - m[A13]*Det3_234_012;
+  G4double Det4_1234_0124 = m[A10]*Det3_234_124 - m[A11]*Det3_234_024 
+                        + m[A12]*Det3_234_014 - m[A14]*Det3_234_012;
+  G4double Det4_1234_0134 = m[A10]*Det3_234_134 - m[A11]*Det3_234_034 
+                        + m[A13]*Det3_234_014 - m[A14]*Det3_234_013;
+  G4double Det4_1234_0234 = m[A10]*Det3_234_234 - m[A12]*Det3_234_034 
+                        + m[A13]*Det3_234_024 - m[A14]*Det3_234_023;
+  G4double Det4_1234_1234 = m[A11]*Det3_234_234 - m[A12]*Det3_234_134 
+                        + m[A13]*Det3_234_124 - m[A14]*Det3_234_123;
+  G4double Det4_1235_0123 = m[A10]*Det3_235_123 - m[A11]*Det3_235_023 
+                        + m[A12]*Det3_235_013 - m[A13]*Det3_235_012;
+  G4double Det4_1235_0124 = m[A10]*Det3_235_124 - m[A11]*Det3_235_024 
+                        + m[A12]*Det3_235_014 - m[A14]*Det3_235_012;
+  G4double Det4_1235_0125 = m[A10]*Det3_235_125 - m[A11]*Det3_235_025 
+                        + m[A12]*Det3_235_015 - m[A15]*Det3_235_012;
+  G4double Det4_1235_0134 = m[A10]*Det3_235_134 - m[A11]*Det3_235_034 
+                        + m[A13]*Det3_235_014 - m[A14]*Det3_235_013;
+  G4double Det4_1235_0135 = m[A10]*Det3_235_135 - m[A11]*Det3_235_035 
+                        + m[A13]*Det3_235_015 - m[A15]*Det3_235_013;
+  G4double Det4_1235_0234 = m[A10]*Det3_235_234 - m[A12]*Det3_235_034 
+                        + m[A13]*Det3_235_024 - m[A14]*Det3_235_023;
+  G4double Det4_1235_0235 = m[A10]*Det3_235_235 - m[A12]*Det3_235_035 
+                        + m[A13]*Det3_235_025 - m[A15]*Det3_235_023;
+  G4double Det4_1235_1234 = m[A11]*Det3_235_234 - m[A12]*Det3_235_134 
+                        + m[A13]*Det3_235_124 - m[A14]*Det3_235_123;
+  G4double Det4_1235_1235 = m[A11]*Det3_235_235 - m[A12]*Det3_235_135 
+                        + m[A13]*Det3_235_125 - m[A15]*Det3_235_123;
+  G4double Det4_1245_0123 = m[A10]*Det3_245_123 - m[A11]*Det3_245_023 
+                        + m[A12]*Det3_245_013 - m[A13]*Det3_245_012;
+  G4double Det4_1245_0124 = m[A10]*Det3_245_124 - m[A11]*Det3_245_024 
+                        + m[A12]*Det3_245_014 - m[A14]*Det3_245_012;
+  G4double Det4_1245_0125 = m[A10]*Det3_245_125 - m[A11]*Det3_245_025 
+                        + m[A12]*Det3_245_015 - m[A15]*Det3_245_012;
+  G4double Det4_1245_0134 = m[A10]*Det3_245_134 - m[A11]*Det3_245_034 
+                        + m[A13]*Det3_245_014 - m[A14]*Det3_245_013;
+  G4double Det4_1245_0135 = m[A10]*Det3_245_135 - m[A11]*Det3_245_035 
+                        + m[A13]*Det3_245_015 - m[A15]*Det3_245_013;
+  G4double Det4_1245_0145 = m[A10]*Det3_245_145 - m[A11]*Det3_245_045 
+                        + m[A14]*Det3_245_015 - m[A15]*Det3_245_014;
+  G4double Det4_1245_0234 = m[A10]*Det3_245_234 - m[A12]*Det3_245_034 
+                        + m[A13]*Det3_245_024 - m[A14]*Det3_245_023;
+  G4double Det4_1245_0235 = m[A10]*Det3_245_235 - m[A12]*Det3_245_035 
+                        + m[A13]*Det3_245_025 - m[A15]*Det3_245_023;
+  G4double Det4_1245_0245 = m[A10]*Det3_245_245 - m[A12]*Det3_245_045 
+                        + m[A14]*Det3_245_025 - m[A15]*Det3_245_024;
+  G4double Det4_1245_1234 = m[A11]*Det3_245_234 - m[A12]*Det3_245_134 
+                        + m[A13]*Det3_245_124 - m[A14]*Det3_245_123;
+  G4double Det4_1245_1235 = m[A11]*Det3_245_235 - m[A12]*Det3_245_135 
+                        + m[A13]*Det3_245_125 - m[A15]*Det3_245_123;
+  G4double Det4_1245_1245 = m[A11]*Det3_245_245 - m[A12]*Det3_245_145 
+                        + m[A14]*Det3_245_125 - m[A15]*Det3_245_124;
+  G4double Det4_1345_0123 = m[A10]*Det3_345_123 - m[A11]*Det3_345_023 
+                        + m[A12]*Det3_345_013 - m[A13]*Det3_345_012;
+  G4double Det4_1345_0124 = m[A10]*Det3_345_124 - m[A11]*Det3_345_024 
+                        + m[A12]*Det3_345_014 - m[A14]*Det3_345_012;
+  G4double Det4_1345_0125 = m[A10]*Det3_345_125 - m[A11]*Det3_345_025 
+                        + m[A12]*Det3_345_015 - m[A15]*Det3_345_012;
+  G4double Det4_1345_0134 = m[A10]*Det3_345_134 - m[A11]*Det3_345_034 
+                        + m[A13]*Det3_345_014 - m[A14]*Det3_345_013;
+  G4double Det4_1345_0135 = m[A10]*Det3_345_135 - m[A11]*Det3_345_035 
+                        + m[A13]*Det3_345_015 - m[A15]*Det3_345_013;
+  G4double Det4_1345_0145 = m[A10]*Det3_345_145 - m[A11]*Det3_345_045 
+                        + m[A14]*Det3_345_015 - m[A15]*Det3_345_014;
+  G4double Det4_1345_0234 = m[A10]*Det3_345_234 - m[A12]*Det3_345_034 
+                        + m[A13]*Det3_345_024 - m[A14]*Det3_345_023;
+  G4double Det4_1345_0235 = m[A10]*Det3_345_235 - m[A12]*Det3_345_035 
+                        + m[A13]*Det3_345_025 - m[A15]*Det3_345_023;
+  G4double Det4_1345_0245 = m[A10]*Det3_345_245 - m[A12]*Det3_345_045 
+                        + m[A14]*Det3_345_025 - m[A15]*Det3_345_024;
+  G4double Det4_1345_0345 = m[A10]*Det3_345_345 - m[A13]*Det3_345_045 
+                        + m[A14]*Det3_345_035 - m[A15]*Det3_345_034;
+  G4double Det4_1345_1234 = m[A11]*Det3_345_234 - m[A12]*Det3_345_134 
+                        + m[A13]*Det3_345_124 - m[A14]*Det3_345_123;
+  G4double Det4_1345_1235 = m[A11]*Det3_345_235 - m[A12]*Det3_345_135 
+                        + m[A13]*Det3_345_125 - m[A15]*Det3_345_123;
+  G4double Det4_1345_1245 = m[A11]*Det3_345_245 - m[A12]*Det3_345_145 
+                        + m[A14]*Det3_345_125 - m[A15]*Det3_345_124;
+  G4double Det4_1345_1345 = m[A11]*Det3_345_345 - m[A13]*Det3_345_145 
+                        + m[A14]*Det3_345_135 - m[A15]*Det3_345_134;
+  G4double Det4_2345_0123 = m[A20]*Det3_345_123 - m[A21]*Det3_345_023 
+                        + m[A22]*Det3_345_013 - m[A23]*Det3_345_012;
+  G4double Det4_2345_0124 = m[A20]*Det3_345_124 - m[A21]*Det3_345_024 
+                        + m[A22]*Det3_345_014 - m[A24]*Det3_345_012;
+  G4double Det4_2345_0125 = m[A20]*Det3_345_125 - m[A21]*Det3_345_025 
+                        + m[A22]*Det3_345_015 - m[A25]*Det3_345_012;
+  G4double Det4_2345_0134 = m[A20]*Det3_345_134 - m[A21]*Det3_345_034 
+                        + m[A23]*Det3_345_014 - m[A24]*Det3_345_013;
+  G4double Det4_2345_0135 = m[A20]*Det3_345_135 - m[A21]*Det3_345_035 
+                        + m[A23]*Det3_345_015 - m[A25]*Det3_345_013;
+  G4double Det4_2345_0145 = m[A20]*Det3_345_145 - m[A21]*Det3_345_045 
+                        + m[A24]*Det3_345_015 - m[A25]*Det3_345_014;
+  G4double Det4_2345_0234 = m[A20]*Det3_345_234 - m[A22]*Det3_345_034 
+                        + m[A23]*Det3_345_024 - m[A24]*Det3_345_023;
+  G4double Det4_2345_0235 = m[A20]*Det3_345_235 - m[A22]*Det3_345_035 
+                        + m[A23]*Det3_345_025 - m[A25]*Det3_345_023;
+  G4double Det4_2345_0245 = m[A20]*Det3_345_245 - m[A22]*Det3_345_045 
+                        + m[A24]*Det3_345_025 - m[A25]*Det3_345_024;
+  G4double Det4_2345_0345 = m[A20]*Det3_345_345 - m[A23]*Det3_345_045 
+                        + m[A24]*Det3_345_035 - m[A25]*Det3_345_034;
+  G4double Det4_2345_1234 = m[A21]*Det3_345_234 - m[A22]*Det3_345_134 
+                        + m[A23]*Det3_345_124 - m[A24]*Det3_345_123;
+  G4double Det4_2345_1235 = m[A21]*Det3_345_235 - m[A22]*Det3_345_135 
+                        + m[A23]*Det3_345_125 - m[A25]*Det3_345_123;
+  G4double Det4_2345_1245 = m[A21]*Det3_345_245 - m[A22]*Det3_345_145 
+                        + m[A24]*Det3_345_125 - m[A25]*Det3_345_124;
+  G4double Det4_2345_1345 = m[A21]*Det3_345_345 - m[A23]*Det3_345_145 
+                        + m[A24]*Det3_345_135 - m[A25]*Det3_345_134;
+  G4double Det4_2345_2345 = m[A22]*Det3_345_345 - m[A23]*Det3_345_245 
+                        + m[A24]*Det3_345_235 - m[A25]*Det3_345_234;
+
+  // Find all NECESSARY 5x5 dets:  (19 of them)
+
+  G4double Det5_01234_01234 = m[A00]*Det4_1234_1234 - m[A01]*Det4_1234_0234 
+    + m[A02]*Det4_1234_0134 - m[A03]*Det4_1234_0124 + m[A04]*Det4_1234_0123;
+  G4double Det5_01235_01234 = m[A00]*Det4_1235_1234 - m[A01]*Det4_1235_0234 
+    + m[A02]*Det4_1235_0134 - m[A03]*Det4_1235_0124 + m[A04]*Det4_1235_0123;
+  G4double Det5_01235_01235 = m[A00]*Det4_1235_1235 - m[A01]*Det4_1235_0235 
+    + m[A02]*Det4_1235_0135 - m[A03]*Det4_1235_0125 + m[A05]*Det4_1235_0123;
+  G4double Det5_01245_01234 = m[A00]*Det4_1245_1234 - m[A01]*Det4_1245_0234 
+    + m[A02]*Det4_1245_0134 - m[A03]*Det4_1245_0124 + m[A04]*Det4_1245_0123;
+  G4double Det5_01245_01235 = m[A00]*Det4_1245_1235 - m[A01]*Det4_1245_0235 
+    + m[A02]*Det4_1245_0135 - m[A03]*Det4_1245_0125 + m[A05]*Det4_1245_0123;
+  G4double Det5_01245_01245 = m[A00]*Det4_1245_1245 - m[A01]*Det4_1245_0245 
+    + m[A02]*Det4_1245_0145 - m[A04]*Det4_1245_0125 + m[A05]*Det4_1245_0124;
+  G4double Det5_01345_01234 = m[A00]*Det4_1345_1234 - m[A01]*Det4_1345_0234 
+    + m[A02]*Det4_1345_0134 - m[A03]*Det4_1345_0124 + m[A04]*Det4_1345_0123;
+  G4double Det5_01345_01235 = m[A00]*Det4_1345_1235 - m[A01]*Det4_1345_0235 
+    + m[A02]*Det4_1345_0135 - m[A03]*Det4_1345_0125 + m[A05]*Det4_1345_0123;
+  G4double Det5_01345_01245 = m[A00]*Det4_1345_1245 - m[A01]*Det4_1345_0245 
+    + m[A02]*Det4_1345_0145 - m[A04]*Det4_1345_0125 + m[A05]*Det4_1345_0124;
+  G4double Det5_01345_01345 = m[A00]*Det4_1345_1345 - m[A01]*Det4_1345_0345 
+    + m[A03]*Det4_1345_0145 - m[A04]*Det4_1345_0135 + m[A05]*Det4_1345_0134;
+  G4double Det5_02345_01234 = m[A00]*Det4_2345_1234 - m[A01]*Det4_2345_0234 
+    + m[A02]*Det4_2345_0134 - m[A03]*Det4_2345_0124 + m[A04]*Det4_2345_0123;
+  G4double Det5_02345_01235 = m[A00]*Det4_2345_1235 - m[A01]*Det4_2345_0235 
+    + m[A02]*Det4_2345_0135 - m[A03]*Det4_2345_0125 + m[A05]*Det4_2345_0123;
+  G4double Det5_02345_01245 = m[A00]*Det4_2345_1245 - m[A01]*Det4_2345_0245 
+    + m[A02]*Det4_2345_0145 - m[A04]*Det4_2345_0125 + m[A05]*Det4_2345_0124;
+  G4double Det5_02345_01345 = m[A00]*Det4_2345_1345 - m[A01]*Det4_2345_0345 
+    + m[A03]*Det4_2345_0145 - m[A04]*Det4_2345_0135 + m[A05]*Det4_2345_0134;
+  G4double Det5_02345_02345 = m[A00]*Det4_2345_2345 - m[A02]*Det4_2345_0345 
+    + m[A03]*Det4_2345_0245 - m[A04]*Det4_2345_0235 + m[A05]*Det4_2345_0234;
+  G4double Det5_12345_01234 = m[A10]*Det4_2345_1234 - m[A11]*Det4_2345_0234 
+    + m[A12]*Det4_2345_0134 - m[A13]*Det4_2345_0124 + m[A14]*Det4_2345_0123;
+  G4double Det5_12345_01235 = m[A10]*Det4_2345_1235 - m[A11]*Det4_2345_0235 
+    + m[A12]*Det4_2345_0135 - m[A13]*Det4_2345_0125 + m[A15]*Det4_2345_0123;
+  G4double Det5_12345_01245 = m[A10]*Det4_2345_1245 - m[A11]*Det4_2345_0245 
+    + m[A12]*Det4_2345_0145 - m[A14]*Det4_2345_0125 + m[A15]*Det4_2345_0124;
+  G4double Det5_12345_01345 = m[A10]*Det4_2345_1345 - m[A11]*Det4_2345_0345 
+    + m[A13]*Det4_2345_0145 - m[A14]*Det4_2345_0135 + m[A15]*Det4_2345_0134;
+  G4double Det5_12345_02345 = m[A10]*Det4_2345_2345 - m[A12]*Det4_2345_0345 
+    + m[A13]*Det4_2345_0245 - m[A14]*Det4_2345_0235 + m[A15]*Det4_2345_0234;
+  G4double Det5_12345_12345 = m[A11]*Det4_2345_2345 - m[A12]*Det4_2345_1345 
+    + m[A13]*Det4_2345_1245 - m[A14]*Det4_2345_1235 + m[A15]*Det4_2345_1234;
+
+  // Find the determinant 
+
+  G4double det =  m[A00]*Det5_12345_12345 
+                - m[A01]*Det5_12345_02345 
+                + m[A02]*Det5_12345_01345 
+                - m[A03]*Det5_12345_01245 
+                + m[A04]*Det5_12345_01235 
+                - m[A05]*Det5_12345_01234;
+
+  if ( det == 0 )
+  {  
+    ifail = 1;
+    return;
+  } 
+
+  G4double oneOverDet = 1.0/det;
+  G4double mn1OverDet = - oneOverDet;
+
+  m[A00] =  Det5_12345_12345*oneOverDet;
+  m[A01] =  Det5_12345_02345*mn1OverDet;
+  m[A02] =  Det5_12345_01345*oneOverDet;
+  m[A03] =  Det5_12345_01245*mn1OverDet;
+  m[A04] =  Det5_12345_01235*oneOverDet;
+  m[A05] =  Det5_12345_01234*mn1OverDet;
+
+  m[A11] =  Det5_02345_02345*oneOverDet;
+  m[A12] =  Det5_02345_01345*mn1OverDet;
+  m[A13] =  Det5_02345_01245*oneOverDet;
+  m[A14] =  Det5_02345_01235*mn1OverDet;
+  m[A15] =  Det5_02345_01234*oneOverDet;
+
+  m[A22] =  Det5_01345_01345*oneOverDet;
+  m[A23] =  Det5_01345_01245*mn1OverDet;
+  m[A24] =  Det5_01345_01235*oneOverDet;
+  m[A25] =  Det5_01345_01234*mn1OverDet;
+
+  m[A33] =  Det5_01245_01245*oneOverDet;
+  m[A34] =  Det5_01245_01235*mn1OverDet;
+  m[A35] =  Det5_01245_01234*oneOverDet;
+
+  m[A44] =  Det5_01235_01235*oneOverDet;
+  m[A45] =  Det5_01235_01234*mn1OverDet;
+
+  m[A55] =  Det5_01234_01234*oneOverDet;
+
+  return;
+}
+
+void G4ErrorSymMatrix::invertCholesky5 (G4int & ifail)
+{
+
+  // Invert by 
+  //
+  // a) decomposing M = G*G^T with G lower triangular
+  //    (if M is not positive definite this will fail, leaving this unchanged)
+  // b) inverting G to form H
+  // c) multiplying H^T * H to get M^-1.
+  //
+  // If the matrix is pos. def. it is inverted and 1 is returned.
+  // If the matrix is not pos. def. it remains unaltered and 0 is returned.
+
+  G4double h10;                           // below-diagonal elements of H
+  G4double h20, h21;
+  G4double h30, h31, h32;
+  G4double h40, h41, h42, h43;
+
+  G4double h00, h11, h22, h33, h44;       // 1/diagonal elements of G = 
+                                          // diagonal elements of H
+
+  G4double g10;                           // below-diagonal elements of G
+  G4double g20, g21;
+  G4double g30, g31, g32;
+  G4double g40, g41, g42, g43;
+
+  ifail = 1;  // We start by assuing we won't succeed...
+
+  // Form G -- compute diagonal members of H directly rather than of G
+  //-------
+
+  // Scale first column by 1/sqrt(A00)
+
+  h00 = m[A00]; 
+  if (h00 <= 0) { return; }
+  h00 = 1.0 / std::sqrt(h00);
+
+  g10 = m[A10] * h00;
+  g20 = m[A20] * h00;
+  g30 = m[A30] * h00;
+  g40 = m[A40] * h00;
+
+  // Form G11 (actually, just h11)
+
+  h11 = m[A11] - (g10 * g10);
+  if (h11 <= 0) { return; }
+  h11 = 1.0 / std::sqrt(h11);
+
+  // Subtract inter-column column dot products from rest of column 1 and
+  // scale to get column 1 of G 
+
+  g21 = (m[A21] - (g10 * g20)) * h11;
+  g31 = (m[A31] - (g10 * g30)) * h11;
+  g41 = (m[A41] - (g10 * g40)) * h11;
+
+  // Form G22 (actually, just h22)
+
+  h22 = m[A22] - (g20 * g20) - (g21 * g21);
+  if (h22 <= 0) { return; }
+  h22 = 1.0 / std::sqrt(h22);
+
+  // Subtract inter-column column dot products from rest of column 2 and
+  // scale to get column 2 of G 
+
+  g32 = (m[A32] - (g20 * g30) - (g21 * g31)) * h22;
+  g42 = (m[A42] - (g20 * g40) - (g21 * g41)) * h22;
+
+  // Form G33 (actually, just h33)
+
+  h33 = m[A33] - (g30 * g30) - (g31 * g31) - (g32 * g32);
+  if (h33 <= 0) { return; }
+  h33 = 1.0 / std::sqrt(h33);
+
+  // Subtract inter-column column dot product from A43 and scale to get G43
+
+  g43 = (m[A43] - (g30 * g40) - (g31 * g41) - (g32 * g42)) * h33;
+
+  // Finally form h44 - if this is possible inversion succeeds
+
+  h44 = m[A44] - (g40 * g40) - (g41 * g41) - (g42 * g42) - (g43 * g43);
+  if (h44 <= 0) { return; }
+  h44 = 1.0 / std::sqrt(h44);
+
+  // Form H = 1/G -- diagonal members of H are already correct
+  //-------------
+
+  // The order here is dictated by speed considerations
+
+  h43 = -h33 *  g43 * h44;
+  h32 = -h22 *  g32 * h33;
+  h42 = -h22 * (g32 * h43 + g42 * h44);
+  h21 = -h11 *  g21 * h22;
+  h31 = -h11 * (g21 * h32 + g31 * h33);
+  h41 = -h11 * (g21 * h42 + g31 * h43 + g41 * h44);
+  h10 = -h00 *  g10 * h11;
+  h20 = -h00 * (g10 * h21 + g20 * h22);
+  h30 = -h00 * (g10 * h31 + g20 * h32 + g30 * h33);
+  h40 = -h00 * (g10 * h41 + g20 * h42 + g30 * h43 + g40 * h44);
+
+  // Change this to its inverse = H^T*H
+  //------------------------------------
+
+  m[A00] = h00 * h00 + h10 * h10 + h20 * h20 + h30 * h30 + h40 * h40;
+  m[A01] = h10 * h11 + h20 * h21 + h30 * h31 + h40 * h41;
+  m[A11] = h11 * h11 + h21 * h21 + h31 * h31 + h41 * h41;
+  m[A02] = h20 * h22 + h30 * h32 + h40 * h42;
+  m[A12] = h21 * h22 + h31 * h32 + h41 * h42;
+  m[A22] = h22 * h22 + h32 * h32 + h42 * h42;
+  m[A03] = h30 * h33 + h40 * h43;
+  m[A13] = h31 * h33 + h41 * h43;
+  m[A23] = h32 * h33 + h42 * h43;
+  m[A33] = h33 * h33 + h43 * h43;
+  m[A04] = h40 * h44;
+  m[A14] = h41 * h44;
+  m[A24] = h42 * h44;
+  m[A34] = h43 * h44;
+  m[A44] = h44 * h44;
+
+  ifail = 0;
+  return;
+}
+
+void G4ErrorSymMatrix::invertCholesky6 (G4int & ifail)
+{
+  // Invert by 
+  //
+  // a) decomposing M = G*G^T with G lower triangular
+  //    (if M is not positive definite this will fail, leaving this unchanged)
+  // b) inverting G to form H
+  // c) multiplying H^T * H to get M^-1.
+  //
+  // If the matrix is pos. def. it is inverted and 1 is returned.
+  // If the matrix is not pos. def. it remains unaltered and 0 is returned.
+
+  G4double h10;                           // below-diagonal elements of H
+  G4double h20, h21;
+  G4double h30, h31, h32;
+  G4double h40, h41, h42, h43;
+  G4double h50, h51, h52, h53, h54;
+
+  G4double h00, h11, h22, h33, h44, h55;  // 1/diagonal elements of G = 
+                                          // diagonal elements of H
+
+  G4double g10;                           // below-diagonal elements of G
+  G4double g20, g21;
+  G4double g30, g31, g32;
+  G4double g40, g41, g42, g43;
+  G4double g50, g51, g52, g53, g54;
+
+  ifail = 1;  // We start by assuing we won't succeed...
+
+  // Form G -- compute diagonal members of H directly rather than of G
+  //-------
+
+  // Scale first column by 1/sqrt(A00)
+
+  h00 = m[A00]; 
+  if (h00 <= 0) { return; }
+  h00 = 1.0 / std::sqrt(h00);
+
+  g10 = m[A10] * h00;
+  g20 = m[A20] * h00;
+  g30 = m[A30] * h00;
+  g40 = m[A40] * h00;
+  g50 = m[A50] * h00;
+
+  // Form G11 (actually, just h11)
+
+  h11 = m[A11] - (g10 * g10);
+  if (h11 <= 0) { return; }
+  h11 = 1.0 / std::sqrt(h11);
+
+  // Subtract inter-column column dot products from rest of column 1 and
+  // scale to get column 1 of G 
+
+  g21 = (m[A21] - (g10 * g20)) * h11;
+  g31 = (m[A31] - (g10 * g30)) * h11;
+  g41 = (m[A41] - (g10 * g40)) * h11;
+  g51 = (m[A51] - (g10 * g50)) * h11;
+
+  // Form G22 (actually, just h22)
+
+  h22 = m[A22] - (g20 * g20) - (g21 * g21);
+  if (h22 <= 0) { return; }
+  h22 = 1.0 / std::sqrt(h22);
+
+  // Subtract inter-column column dot products from rest of column 2 and
+  // scale to get column 2 of G 
+
+  g32 = (m[A32] - (g20 * g30) - (g21 * g31)) * h22;
+  g42 = (m[A42] - (g20 * g40) - (g21 * g41)) * h22;
+  g52 = (m[A52] - (g20 * g50) - (g21 * g51)) * h22;
+
+  // Form G33 (actually, just h33)
+
+  h33 = m[A33] - (g30 * g30) - (g31 * g31) - (g32 * g32);
+  if (h33 <= 0) { return; }
+  h33 = 1.0 / std::sqrt(h33);
+
+  // Subtract inter-column column dot products from rest of column 3 and
+  // scale to get column 3 of G 
+
+  g43 = (m[A43] - (g30 * g40) - (g31 * g41) - (g32 * g42)) * h33;
+  g53 = (m[A53] - (g30 * g50) - (g31 * g51) - (g32 * g52)) * h33;
+
+  // Form G44 (actually, just h44)
+
+  h44 = m[A44] - (g40 * g40) - (g41 * g41) - (g42 * g42) - (g43 * g43);
+  if (h44 <= 0) { return; }
+  h44 = 1.0 / std::sqrt(h44);
+
+  // Subtract inter-column column dot product from M54 and scale to get G54
+
+  g54 = (m[A54] - (g40 * g50) - (g41 * g51) - (g42 * g52) - (g43 * g53)) * h44;
+
+  // Finally form h55 - if this is possible inversion succeeds
+
+  h55 = m[A55] - (g50*g50) - (g51*g51) - (g52*g52) - (g53*g53) - (g54*g54);
+  if (h55 <= 0) { return; }
+  h55 = 1.0 / std::sqrt(h55);
+
+  // Form H = 1/G -- diagonal members of H are already correct
+  //-------------
+
+  // The order here is dictated by speed considerations
+
+  h54 = -h44 *  g54 * h55;
+  h43 = -h33 *  g43 * h44;
+  h53 = -h33 * (g43 * h54 + g53 * h55);
+  h32 = -h22 *  g32 * h33;
+  h42 = -h22 * (g32 * h43 + g42 * h44);
+  h52 = -h22 * (g32 * h53 + g42 * h54 + g52 * h55);
+  h21 = -h11 *  g21 * h22;
+  h31 = -h11 * (g21 * h32 + g31 * h33);
+  h41 = -h11 * (g21 * h42 + g31 * h43 + g41 * h44);
+  h51 = -h11 * (g21 * h52 + g31 * h53 + g41 * h54 + g51 * h55);
+  h10 = -h00 *  g10 * h11;
+  h20 = -h00 * (g10 * h21 + g20 * h22);
+  h30 = -h00 * (g10 * h31 + g20 * h32 + g30 * h33);
+  h40 = -h00 * (g10 * h41 + g20 * h42 + g30 * h43 + g40 * h44);
+  h50 = -h00 * (g10 * h51 + g20 * h52 + g30 * h53 + g40 * h54 + g50 * h55);
+
+  // Change this to its inverse = H^T*H
+  //------------------------------------
+
+  m[A00] = h00 * h00 + h10 * h10 + h20 * h20 + h30 * h30 + h40 * h40 + h50*h50;
+  m[A01] = h10 * h11 + h20 * h21 + h30 * h31 + h40 * h41 + h50 * h51;
+  m[A11] = h11 * h11 + h21 * h21 + h31 * h31 + h41 * h41 + h51 * h51;
+  m[A02] = h20 * h22 + h30 * h32 + h40 * h42 + h50 * h52;
+  m[A12] = h21 * h22 + h31 * h32 + h41 * h42 + h51 * h52;
+  m[A22] = h22 * h22 + h32 * h32 + h42 * h42 + h52 * h52;
+  m[A03] = h30 * h33 + h40 * h43 + h50 * h53;
+  m[A13] = h31 * h33 + h41 * h43 + h51 * h53;
+  m[A23] = h32 * h33 + h42 * h43 + h52 * h53;
+  m[A33] = h33 * h33 + h43 * h43 + h53 * h53;
+  m[A04] = h40 * h44 + h50 * h54;
+  m[A14] = h41 * h44 + h51 * h54;
+  m[A24] = h42 * h44 + h52 * h54;
+  m[A34] = h43 * h44 + h53 * h54;
+  m[A44] = h44 * h44 + h54 * h54;
+  m[A05] = h50 * h55;
+  m[A15] = h51 * h55;
+  m[A25] = h52 * h55;
+  m[A35] = h53 * h55;
+  m[A45] = h54 * h55;
+  m[A55] = h55 * h55;
+
+  ifail = 0;
+  return;
+}
+
+void G4ErrorSymMatrix::invert4  (G4int & ifail)
+{
+  ifail = 0;
+
+  // Find all NECESSARY 2x2 dets:  (14 of them)
+
+  G4double Det2_12_01 = m[A10]*m[A21] - m[A11]*m[A20];
+  G4double Det2_12_02 = m[A10]*m[A22] - m[A12]*m[A20];
+  G4double Det2_12_12 = m[A11]*m[A22] - m[A12]*m[A21];
+  G4double Det2_13_01 = m[A10]*m[A31] - m[A11]*m[A30];
+  G4double Det2_13_02 = m[A10]*m[A32] - m[A12]*m[A30];
+  G4double Det2_13_03 = m[A10]*m[A33] - m[A13]*m[A30];
+  G4double Det2_13_12 = m[A11]*m[A32] - m[A12]*m[A31];
+  G4double Det2_13_13 = m[A11]*m[A33] - m[A13]*m[A31];
+  G4double Det2_23_01 = m[A20]*m[A31] - m[A21]*m[A30];
+  G4double Det2_23_02 = m[A20]*m[A32] - m[A22]*m[A30];
+  G4double Det2_23_03 = m[A20]*m[A33] - m[A23]*m[A30];
+  G4double Det2_23_12 = m[A21]*m[A32] - m[A22]*m[A31];
+  G4double Det2_23_13 = m[A21]*m[A33] - m[A23]*m[A31];
+  G4double Det2_23_23 = m[A22]*m[A33] - m[A23]*m[A32];
+
+  // Find all NECESSARY 3x3 dets:   (10 of them)
+
+  G4double Det3_012_012 = m[A00]*Det2_12_12 - m[A01]*Det2_12_02 
+                                + m[A02]*Det2_12_01;
+  G4double Det3_013_012 = m[A00]*Det2_13_12 - m[A01]*Det2_13_02 
+                                + m[A02]*Det2_13_01;
+  G4double Det3_013_013 = m[A00]*Det2_13_13 - m[A01]*Det2_13_03
+                                + m[A03]*Det2_13_01;
+  G4double Det3_023_012 = m[A00]*Det2_23_12 - m[A01]*Det2_23_02 
+                                + m[A02]*Det2_23_01;
+  G4double Det3_023_013 = m[A00]*Det2_23_13 - m[A01]*Det2_23_03
+                                + m[A03]*Det2_23_01;
+  G4double Det3_023_023 = m[A00]*Det2_23_23 - m[A02]*Det2_23_03
+                                + m[A03]*Det2_23_02;
+  G4double Det3_123_012 = m[A10]*Det2_23_12 - m[A11]*Det2_23_02 
+                                + m[A12]*Det2_23_01;
+  G4double Det3_123_013 = m[A10]*Det2_23_13 - m[A11]*Det2_23_03 
+                                + m[A13]*Det2_23_01;
+  G4double Det3_123_023 = m[A10]*Det2_23_23 - m[A12]*Det2_23_03 
+                                + m[A13]*Det2_23_02;
+  G4double Det3_123_123 = m[A11]*Det2_23_23 - m[A12]*Det2_23_13 
+                                + m[A13]*Det2_23_12;
+
+  // Find the 4x4 det:
+
+  G4double det =  m[A00]*Det3_123_123 
+                - m[A01]*Det3_123_023 
+                + m[A02]*Det3_123_013 
+                - m[A03]*Det3_123_012;
+
+  if ( det == 0 )
+  {  
+    ifail = 1;
+    return;
+  } 
+
+  G4double oneOverDet = 1.0/det;
+  G4double mn1OverDet = - oneOverDet;
+
+  m[A00] =  Det3_123_123 * oneOverDet;
+  m[A01] =  Det3_123_023 * mn1OverDet;
+  m[A02] =  Det3_123_013 * oneOverDet;
+  m[A03] =  Det3_123_012 * mn1OverDet;
+
+
+  m[A11] =  Det3_023_023 * oneOverDet;
+  m[A12] =  Det3_023_013 * mn1OverDet;
+  m[A13] =  Det3_023_012 * oneOverDet;
+
+  m[A22] =  Det3_013_013 * oneOverDet;
+  m[A23] =  Det3_013_012 * mn1OverDet;
+
+  m[A33] =  Det3_012_012 * oneOverDet;
+
+  return;
+}
+
+void G4ErrorSymMatrix::invertHaywood4  (G4int & ifail)
+{
+  invert4(ifail); // For the 4x4 case, the method we use for invert is already
+                  // the Haywood method.
+}
+
Index: /trunk/source/error_propagation/src/G4ErrorTrackLengthTarget.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorTrackLengthTarget.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorTrackLengthTarget.cc	(revision 815)
@@ -0,0 +1,140 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorTrackLengthTarget.cc,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4ErrorTrackLengthTarget.hh"
+
+#include "G4ParticleTable.hh"
+#include "G4ParticleDefinition.hh"
+#include "G4VProcess.hh"
+#include "G4ProcessVector.hh"
+#include "G4ProcessManager.hh"
+
+#ifdef G4VERBOSE
+#include "G4ErrorPropagatorData.hh" //for verbosity checking
+#endif
+
+//----------------------------------------------------------------------------
+G4ErrorTrackLengthTarget::
+G4ErrorTrackLengthTarget(const G4double maxTrkLength )
+  : G4VDiscreteProcess ("G4ErrorTrackLengthTarget"),
+    theMaximumTrackLength( maxTrkLength )
+{
+  theType = G4ErrorTarget_TrkL;
+
+   G4ParticleTable::G4PTblDicIterator* theParticleIterator
+     = G4ParticleTable::GetParticleTable()->GetIterator();
+
+  // loop over all particles in G4ParticleTable
+
+  theParticleIterator->reset();
+  while( (*theParticleIterator)() )
+  {
+    G4ParticleDefinition* particle = theParticleIterator->value();
+    G4ProcessManager* pmanager = particle->GetProcessManager();
+    if (!particle->IsShortLived())
+    {
+      // Add transportation process for all particles other than  "shortlived"
+      if ( pmanager == 0)
+      {
+        // Error !! no process manager
+        G4String particleName = particle->GetParticleName();
+        G4Exception("G4ErrorTrackLengthTarget::G4ErrorTrackLengthTarget",
+                    "No process manager", RunMustBeAborted, particleName );
+      }
+      else
+      {
+        G4ProcessVector* procvec = pmanager->GetProcessList();
+        size_t isiz = procvec->size();
+        G4bool processAlreadyDefined = false;
+
+        for( size_t ii=0; ii < isiz; ii++ )
+        {
+          if( ((*procvec)[ii])->GetProcessName() == "G4ErrorTrackLengthTarget")
+          {
+            pmanager->RemoveProcess( (*procvec)[ii] );
+            processAlreadyDefined = true;
+          }
+        }
+        pmanager ->AddDiscreteProcess(this,4);
+        isiz = procvec->size();
+      }
+    }
+    else
+    {
+      // shortlived particle case
+    }
+  }
+}
+
+
+//-----------------------------------------------------------------------
+G4double G4ErrorTrackLengthTarget::
+PostStepGetPhysicalInteractionLength(const G4Track& track, G4double,
+                                     G4ForceCondition* condition )
+{
+  *condition = NotForced;
+  return GetMeanFreePath( track, 0., condition );
+}
+
+
+//-----------------------------------------------------------------------
+G4double G4ErrorTrackLengthTarget::
+GetMeanFreePath(const class G4Track & track, G4double, enum G4ForceCondition *)
+{
+#ifdef G4VERBOSE
+  if(G4ErrorPropagatorData::verbose() >= 3 )
+  { 
+    G4cout << " G4ErrorTrackLengthTarget::GetMeanFreePath "
+           << theMaximumTrackLength - track.GetTrackLength() << G4endl;
+  }
+#endif
+
+  return theMaximumTrackLength - track.GetTrackLength();
+}
+
+
+G4VParticleChange* G4ErrorTrackLengthTarget::
+PostStepDoIt(const G4Track& aTrack, const G4Step& )
+{
+  G4ParticleChange* aParticleChange = new G4ParticleChange;
+  aParticleChange->Initialize(aTrack);
+  return aParticleChange;
+}
+
+
+//-----------------------------------------------------------------------
+void G4ErrorTrackLengthTarget::Dump( const G4String& msg ) const
+{
+  G4cout << msg << "G4ErrorTrackLengthTarget: max track length = "
+         << theMaximumTrackLength << G4endl;
+}
Index: /trunk/source/error_propagation/src/G4ErrorTrajState.cc
===================================================================
--- /trunk/source/error_propagation/src/G4ErrorTrajState.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4ErrorTrajState.cc	(revision 815)
@@ -0,0 +1,123 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4ErrorTrajState.cc,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4ErrorTrajState.hh"
+#include "G4ParticleTable.hh"
+#include "G4ParticleDefinition.hh"
+#include "G4ErrorPropagatorData.hh"
+
+#include <iomanip>
+
+//--------------------------------------------------------------------------
+G4ErrorTrajState::G4ErrorTrajState( const G4String& partType,
+                                    const G4Point3D& pos,
+                                    const G4Vector3D& mom,
+                                    const G4ErrorTrajErr& errmat)
+  : fParticleType(partType), fPosition(pos), fMomentum(mom), fError(errmat)
+{
+  iverbose = G4ErrorPropagatorData::verbose();
+}
+
+
+//--------------------------------------------------------------------------
+G4int G4ErrorTrajState::PropagateError( const G4Track* )
+{ 
+  G4cerr << "ERROR - G4ErrorTrajState::PropagateError()" << G4endl
+         << "        Called for trajectory state type "
+         << G4int(GetTSType()) << G4endl;
+  G4Exception("G4ErrorTrajState::PropagateError", "GEANT4e-Error",
+              FatalException, "Wrong trajectory state type");
+   return -1; 
+}
+
+
+//--------------------------------------------------------------------------
+void G4ErrorTrajState::UpdatePosMom( const G4Point3D& pos,
+                                     const G4Vector3D& mom )
+{
+  fPosition = pos;
+  fMomentum = mom;
+}
+
+
+//--------------------------------------------------------------------------
+void G4ErrorTrajState::SetData( const G4String& partType,
+                                const G4Point3D& pos, const G4Vector3D& mom )
+{
+  fParticleType = partType;
+  BuildCharge();
+  fPosition = pos;
+  fMomentum = mom;
+}
+
+
+//--------------------------------------------------------------------------
+void G4ErrorTrajState::BuildCharge()
+{
+  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
+  G4ParticleDefinition* particle = particleTable->FindParticle(fParticleType); 
+  if( particle == 0)
+  {
+    G4cerr << "ERROR - G4ErrorTrajState::BuildCharge()" << G4endl
+           << "        Particle type not defined: " << fParticleType << G4endl;
+    G4Exception( "G4ErrorTrajState::BuildCharge()", "GEANT4e-error",
+                  FatalException, "Particle type not defined!");
+  }
+  else
+  {
+    fCharge = particle->GetPDGCharge();
+  }
+}
+
+
+//------------------------------------------------------------------------
+void G4ErrorTrajState::DumpPosMomError( std::ostream& out ) const
+{
+  out << *this;
+}
+
+
+//--------------------------------------------------------------------------
+std::ostream& operator<<(std::ostream& out, const G4ErrorTrajState& ts)
+{
+  //  long mode = out.setf(std::ios::fixed,std::ios::floatfield);
+  out  
+    << " G4ErrorTrajState of type " << ts.theTSType << " : partycle: "
+    << ts.fParticleType << "  position: " << std::setw(6) << ts.fPosition
+    << "              momentum: " << ts.fMomentum
+    << "   error matrix ";
+  G4cout << ts.fError << G4endl;
+
+  return out;
+}
+
Index: /trunk/source/error_propagation/src/G4VErrorLimitProcess.cc
===================================================================
--- /trunk/source/error_propagation/src/G4VErrorLimitProcess.cc	(revision 815)
+++ /trunk/source/error_propagation/src/G4VErrorLimitProcess.cc	(revision 815)
@@ -0,0 +1,67 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4VErrorLimitProcess.cc,v 1.2 2007/05/29 14:41:35 gcosmo Exp $
+// GEANT4 tag $Name:  $
+//
+// ------------------------------------------------------------
+//      GEANT 4 class implementation file 
+// ------------------------------------------------------------
+//
+
+#include "G4VErrorLimitProcess.hh"
+#include "G4ErrorMessenger.hh"
+
+//------------------------------------------------------------------------
+G4VErrorLimitProcess::G4VErrorLimitProcess(const G4String& processName)
+  : G4VDiscreteProcess (processName) 
+{
+  theStepLimit = kInfinity;
+  theStepLength = kInfinity;
+}
+
+
+//------------------------------------------------------------------------
+G4VErrorLimitProcess::~G4VErrorLimitProcess()
+{
+}
+
+
+//------------------------------------------------------------------------
+G4double G4VErrorLimitProcess::
+GetMeanFreePath(const class G4Track &, G4double, enum G4ForceCondition *)
+{
+  return theStepLength;
+}
+
+
+//------------------------------------------------------------------------
+G4VParticleChange* G4VErrorLimitProcess::
+PostStepDoIt(const G4Track& aTrack, const G4Step& )
+{
+  G4ParticleChange* aParticleChange = new G4ParticleChange;
+  aParticleChange->Initialize(aTrack);
+  return aParticleChange; 
+}
