Changeset 921 for trunk/source/geometry


Ignore:
Timestamp:
Feb 16, 2009, 10:14:30 AM (17 years ago)
Author:
garnier
Message:

en test de gl2ps. Problemes de libraries

Location:
trunk/source/geometry
Files:
164 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/geometry/magneticfield/History

    r850 r921  
    1 $Id: History,v 1.130 2008/04/24 12:40:50 gcosmo Exp $
     1$Id: History,v 1.135 2008/11/21 21:16:11 gum Exp $
    22-------------------------------------------------------------------
    33
     
    1717     * Reverse chronological order (last date on top), please *
    1818     ----------------------------------------------------------
     19
     20November, 19th, 2008  P.Gumplinger - field-V09-01-05
     21- renormalize the spin to ONE in G4EqEMFieldWithSpin.cc and G4Mag_SpinEqRhs.cc
     22
     23November, 7th, 2008   P.Gumplinger - field-V09-01-04
     24----------------------------------
     25- Added SetAnomaly() and GetAnomaly() accessors to G4EqEMFieldWithSpin.
     26
     27October, 28th, 2008   T.Nikitina - field-V09-01-03
     28--------------------------------
     29- Added 'ApproxCurveV' to method G4ChordFinder::ApproxCurvePointS() in
     30  order to better calculate the curve length.
     31- Some code cleanup.
     32
     33September, 18th, 2008   T.Nikitina
     34----------------------------------
     35- Added new stepper class G4ConstRK4, performing integration of one step
     36  with error calculation in constant magnetic field; implementation derived
     37  from G4ClassicalRK4.
     38
     39July, 15th, 2008   J.Apostolakis - field-V09-01-02
     40--------------------------------
     41- Revised signature of G4ChordFinder::FinderNextChord(), making 'FieldTrack'
     42  argument passed a reference.
     43
     44May, 28th, 2008   T.Nikitina
     45----------------------------
     46- G4ChordFinder: added new method ApproxCurvePointS() using Brent second order
     47  location mechanism.
    1948
    2049April 24th, 2008   T.Nikitina - field-V09-01-01
  • trunk/source/geometry/magneticfield/include/G4CashKarpRKF45.hh

    r850 r921  
    2626//
    2727// $Id: G4CashKarpRKF45.hh,v 1.11 2008/01/11 15:23:54 japost Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4ChordFinder.hh

    r850 r921  
    2525//
    2626//
    27 // $Id: G4ChordFinder.hh,v 1.19 2008/07/15 14:02:06 japost Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4ChordFinder.hh,v 1.21 2008/10/29 14:17:42 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
    31 // class G4ChordFinder
    32 //
    33 // Class description:
     31// Class G4ChordFinder
     32//
     33// class description:
    3434//
    3535// A class that provides RK integration of motion ODE  (as does g4magtr)
     
    3838
    3939// History:
    40 // - 25.02.97 John Apostolakis,  design and implementation
    41 // - 05.03.97 V. Grichine , makeup to G4 'standard'
     40// - 25.02.97 - John Apostolakis - Design and implementation
    4241// -------------------------------------------------------------------
    4342
     
    6261     
    6362      virtual ~G4ChordFinder();
    64 
    6563
    6664      G4double    AdvanceChordLimited( G4FieldTrack& yCurrent,
     
    7371        // -> Returns Length of Step taken.
    7472     
    75       G4FieldTrack ApproxCurvePointS(const  G4FieldTrack&  curveAPointVelocity,
    76                                       const  G4FieldTrack&  curveBPointVelocity,
    77                                       const  G4ThreeVector& currentEPoint,
    78                                       const  G4ThreeVector& currentFPoint,
    79                                       const  G4ThreeVector& PointG,
    80                                              G4bool first,G4double      epsStep);
     73      G4FieldTrack ApproxCurvePointS( const G4FieldTrack&  curveAPointVelocity,
     74                                      const G4FieldTrack&  curveBPointVelocity,
     75                                      const G4FieldTrack&  ApproxCurveV,
     76                                      const G4ThreeVector& currentEPoint,
     77                                      const G4ThreeVector& currentFPoint,
     78                                      const G4ThreeVector& PointG,
     79                                            G4bool first,  G4double epsStep);
    8180 
    82       G4FieldTrack ApproxCurvePointV(const G4FieldTrack&  curveAPointVelocity,
    83                                      const G4FieldTrack&  curveBPointVelocity,
    84                                      const G4ThreeVector& currentEPoint,
    85                                             G4double      epsStep);
     81      G4FieldTrack ApproxCurvePointV( const G4FieldTrack&  curveAPointVelocity,
     82                                      const G4FieldTrack&  curveBPointVelocity,
     83                                      const G4ThreeVector& currentEPoint,
     84                                            G4double       epsStep);
    8685
    8786      inline G4double InvParabolic( const G4double xa, const G4double ya,
    88                                     const G4double xb, const G4double yb,
    89                              const G4double xc, const G4double yc );
     87                                    const G4double xb, const G4double yb,
     88                                    const G4double xc, const G4double yc );
    9089
    9190      inline G4double  GetDeltaChord() const;
     
    112111        // A report with the above -- and possibly other stats
    113112      inline G4int SetVerbose( G4int newvalue=1);
    114        // Set verbosity and return old value
     113        // Set verbosity and return old value
     114
     115      void SetFractions_Last_Next( G4double fractLast= 0.90,
     116                                   G4double fractNext= 0.95 );
     117        // Parameters for  performance ... change with great care
     118
     119      inline void SetFirstFraction(G4double fractFirst);
     120        // Parameter for  performance ... change with great care
     121
     122   public:  // without description
     123
     124      void     TestChordPrint( G4int    noTrials,
     125                               G4int    lastStepTrial,
     126                               G4double dChordStep,
     127                               G4double nextStepTrial );
     128
     129        //   Printing for monitoring ...
     130 
     131      inline   G4double GetFirstFraction();         // Originally 0.999
     132      inline   G4double GetFractionLast();          // Originally 1.000
     133      inline   G4double GetFractionNextEstimate();  // Originally 0.980
     134      inline   G4double GetMultipleRadius();        // No original value
     135        //  Parameters for adapting performance ... use with great care
    115136
    116137   protected:   // .........................................................
     
    140161                                G4double  oldStepTrial,
    141162                                G4double  dChordStep);
    142   public:  // no description
    143       void     TestChordPrint( G4int    noTrials,
    144                                G4int    lastStepTrial,
    145                                G4double dChordStep,
    146                                G4double nextStepTrial );
    147         //   Printing for monitoring ...
    148  
    149       inline   G4double GetFirstFraction();         // Originally 0.999
    150       inline   G4double GetFractionLast();          // Originally 1.000
    151       inline   G4double GetFractionNextEstimate();  // Originally 0.980
    152       inline   G4double GetMultipleRadius();        // No original value
    153        //  Parameters for adapting performance ... use with great care
    154 
    155    public:  // with description
    156       void     SetFractions_Last_Next( G4double fractLast= 0.90,
    157                                        G4double fractNext= 0.95 );
    158       //  Parameters for  performance ... change with great care
    159 
    160       inline   void     SetFirstFraction(G4double fractFirst);
    161       //  Parameter for  performance ... change with great care
    162 
    163    protected:
     163
    164164      inline G4double GetLastStepEstimateUnc();
    165165      inline void     SetLastStepEstimateUnc( G4double stepEst );
     
    172172
    173173   private:  // ............................................................
    174                                             // G4int    nOK, nBAD;
     174                                          // G4int    nOK, nBAD;
    175175      G4MagInt_Driver* fIntgrDriver;
    176176
    177177      const G4double fDefaultDeltaChord;  // SET in G4ChordFinder.cc = 0.25 mm
    178178
    179       G4double fDeltaChord;                        //  Maximum miss distance
    180 
    181       G4double    fLastStepEstimate_Unconstrained; //  State information for efficiency
     179      G4double fDeltaChord;               //  Maximum miss distance
     180
     181      G4double    fLastStepEstimate_Unconstrained;
     182        //  State information for efficiency
     183
    182184      //  Variables used in construction/destruction
     185
    183186      G4bool fAllocatedStepper;
    184187      G4EquationOfMotion* fEquation;
  • trunk/source/geometry/magneticfield/include/G4ChordFinder.icc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4ChordFinder.icc,v 1.13 2008/05/28 09:20:03 tnikitin Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4ChordFinder.icc,v 1.14 2008/10/29 14:34:35 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// G4ChordFinder inline implementations
     
    134134                       T = ya/yc;
    135135        const G4double Q = (T-1)*(R-1)*(S-1);
    136         if (fabs(Q) <DBL_MIN ) return  DBL_MAX;
     136        if (std::fabs(Q) <DBL_MIN ) return  DBL_MAX;
    137137       
    138138        const G4double P = S*(T*(R-T)*(xc-xb) - (1-R)*(xb-xa));
  • trunk/source/geometry/magneticfield/include/G4ChordFinderSaf.hh

    r850 r921  
    2424// ********************************************************************
    2525//
    26 // $Id: G4ChordFinderSaf.hh,v 1.3 2006/06/29 18:21:52 gunter Exp $
    27 // GEANT4 tag $Name: HEAD $
     26// $Id: G4ChordFinderSaf.hh,v 1.4 2008/09/12 16:12:18 gcosmo Exp $
     27// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2828//
    2929//
     
    5353  ~G4ChordFinderSaf();
    5454
    55   G4double FindNextChord( const  G4FieldTrack  yStart,
     55  G4double FindNextChord( const  G4FieldTrack&  yStart,
    5656                          G4double     stepMax,
    5757                          G4FieldTrack&   yEnd,  // Endpoint
  • trunk/source/geometry/magneticfield/include/G4ClassicalRK4.hh

    r850 r921  
    2626//
    2727// $Id: G4ClassicalRK4.hh,v 1.10 2006/06/29 18:21:55 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4DELPHIMagField.hh

    r850 r921  
    2626//
    2727// $Id: G4DELPHIMagField.hh,v 1.4 2006/06/29 18:21:57 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4ElectricField.hh

    r850 r921  
    2626//
    2727// $Id: G4ElectricField.hh,v 1.2 2006/06/29 18:21:59 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4ElectroMagneticField.hh

    r850 r921  
    2626//
    2727// $Id: G4ElectroMagneticField.hh,v 1.11 2006/06/29 18:22:01 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4EqEMFieldWithSpin.hh

    r850 r921  
    2525//
    2626//
    27 // $Id: G4EqEMFieldWithSpin.hh,v 1.1 2007/08/30 23:34:01 gum Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4EqEMFieldWithSpin.hh,v 1.3 2008/11/14 13:37:09 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    4444
    4545#include "G4EquationOfMotion.hh"
    46 #include "G4ElectroMagneticField.hh"
     46
     47class G4ElectroMagneticField;
    4748
    4849class G4EqEMFieldWithSpin : public G4EquationOfMotion
     
    5253    G4EqEMFieldWithSpin(G4ElectroMagneticField *emField );
    5354
    54     ~G4EqEMFieldWithSpin() {;}
     55    ~G4EqEMFieldWithSpin();
    5556
    5657    void  SetChargeMomentumMass(G4double particleCharge, // in e+ units
     
    6465      // calculates the value of the derivative dydx.
    6566
     67    inline void SetAnomaly(G4double a) { anomaly = a; }
     68    inline G4double GetAnomaly() const { return anomaly; }
     69      // set/get magnetic anomaly
     70
    6671  private:
    6772
    68     G4double        fElectroMagCof ;
    69     G4double        fMassCof;
     73    G4double fElectroMagCof ;
     74    G4double fMassCof;
    7075
    7176    G4double omegac;
     
    7883};
    7984
    80 #endif
     85#endif /* G4EQEMFIELDWITHSPIN */
  • trunk/source/geometry/magneticfield/include/G4EqMagElectricField.hh

    r850 r921  
    2626//
    2727// $Id: G4EqMagElectricField.hh,v 1.9 2006/06/29 18:22:03 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4EquationOfMotion.hh

    r850 r921  
    2626//
    2727// $Id: G4EquationOfMotion.hh,v 1.10 2006/06/29 18:22:05 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4EquationOfMotion.icc

    r850 r921  
    2626//
    2727// $Id: G4EquationOfMotion.icc,v 1.9 2006/06/29 18:22:07 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4ErrorMag_UsualEqRhs.hh

    r850 r921  
    2626//
    2727// $Id: G4ErrorMag_UsualEqRhs.hh,v 1.1 2007/05/16 12:54:02 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4ExactHelixStepper.hh

    r850 r921  
    2525//
    2626// $Id: G4ExactHelixStepper.hh,v 1.5 2007/05/18 12:50:31 tnikitin Exp $
    27 // GEANT4 tag $Name: HEAD $
     27// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2828//
    2929//
  • trunk/source/geometry/magneticfield/include/G4ExplicitEuler.hh

    r850 r921  
    2626//
    2727// $Id: G4ExplicitEuler.hh,v 1.9 2006/06/29 18:22:11 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4Field.hh

    r850 r921  
    2626//
    2727// $Id: G4Field.hh,v 1.10 2006/06/29 18:22:13 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4FieldManager.hh

    r850 r921  
    2626//
    2727// $Id: G4FieldManager.hh,v 1.16 2006/06/29 18:22:15 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// 
  • trunk/source/geometry/magneticfield/include/G4FieldManager.icc

    r850 r921  
    2626//
    2727// $Id: G4FieldManager.icc,v 1.12 2006/06/29 18:22:18 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4FieldManagerStore.hh

    r850 r921  
    2626//
    2727// $Id: G4FieldManagerStore.hh,v 1.3 2008/01/17 09:39:08 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// class G4FieldManagerStore
  • trunk/source/geometry/magneticfield/include/G4FieldTrack.hh

    r850 r921  
    2626//
    2727// $Id: G4FieldTrack.hh,v 1.21 2006/11/13 18:24:35 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4FieldTrack.icc

    r850 r921  
    2626//
    2727// $Id: G4FieldTrack.icc,v 1.21 2006/11/13 18:24:35 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// -------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/include/G4HarmonicPolMagField.hh

    r850 r921  
    2626//
    2727// $Id: G4HarmonicPolMagField.hh,v 1.4 2006/06/29 18:22:24 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// class G4HarmonicPolMagField
  • trunk/source/geometry/magneticfield/include/G4HelixExplicitEuler.hh

    r850 r921  
    2626//
    2727// $Id: G4HelixExplicitEuler.hh,v 1.9 2007/08/21 08:52:00 tnikitin Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4HelixHeum.hh

    r850 r921  
    2626//
    2727// $Id: G4HelixHeum.hh,v 1.8 2006/06/29 18:22:36 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4HelixImplicitEuler.hh

    r850 r921  
    2626//
    2727// $Id: G4HelixImplicitEuler.hh,v 1.8 2006/06/29 18:22:38 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4HelixSimpleRunge.hh

    r850 r921  
    2626//
    2727// $Id: G4HelixSimpleRunge.hh,v 1.7 2006/06/29 18:22:41 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4ImplicitEuler.hh

    r850 r921  
    2626//
    2727// $Id: G4ImplicitEuler.hh,v 1.8 2006/06/29 18:22:44 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4LineCurrentMagField.hh

    r850 r921  
    2626//
    2727// $Id: G4LineCurrentMagField.hh,v 1.4 2006/06/29 18:22:46 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4LineSection.hh

    r850 r921  
    2626//
    2727// $Id: G4LineSection.hh,v 1.9 2006/06/29 18:22:48 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4MagErrorStepper.hh

    r850 r921  
    2626//
    2727// $Id: G4MagErrorStepper.hh,v 1.11 2006/06/29 18:22:50 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4MagErrorStepper.icc

    r850 r921  
    2626//
    2727// $Id: G4MagErrorStepper.icc,v 1.13 2006/06/29 18:22:52 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/include/G4MagHelicalStepper.hh

    r850 r921  
    2727//
    2828// $Id: G4MagHelicalStepper.hh,v 1.15 2007/08/21 08:48:28 tnikitin Exp $
    29 // GEANT4 tag $Name: HEAD $
     29// GEANT4 tag $Name: geant4-09-02-cand-01 $
    3030//
    3131//
  • trunk/source/geometry/magneticfield/include/G4MagHelicalStepper.icc

    r850 r921  
    2626//
    2727// $Id: G4MagHelicalStepper.icc,v 1.13 2007/05/18 15:45:15 tnikitin Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// Linear Step in regions of no field
  • trunk/source/geometry/magneticfield/include/G4MagIntegratorDriver.hh

    r850 r921  
    2626//
    2727// $Id: G4MagIntegratorDriver.hh,v 1.20 2007/05/10 10:10:05 japost Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4MagIntegratorDriver.icc

    r850 r921  
    2626//
    2727// $Id: G4MagIntegratorDriver.icc,v 1.13 2007/05/10 10:10:48 japost Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/include/G4MagIntegratorStepper.hh

    r850 r921  
    2525//
    2626// $Id: G4MagIntegratorStepper.hh,v 1.12 2006/09/20 09:31:01 japost Exp $
    27 // GEANT4 tag $Name: HEAD $
     27// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2828//
    2929//
  • trunk/source/geometry/magneticfield/include/G4MagIntegratorStepper.icc

    r850 r921  
    2525//
    2626// $Id: G4MagIntegratorStepper.icc,v 1.10 2006/09/20 09:31:46 japost Exp $
    27 // GEANT4 tag $Name: HEAD $
     27// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2828//
    2929
  • trunk/source/geometry/magneticfield/include/G4Mag_EqRhs.hh

    r850 r921  
    2626//
    2727// $Id: G4Mag_EqRhs.hh,v 1.9 2006/06/29 18:23:07 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4Mag_SpinEqRhs.hh

    r850 r921  
    2626//
    2727// $Id: G4Mag_SpinEqRhs.hh,v 1.11 2006/06/29 18:23:09 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4Mag_UsualEqRhs.hh

    r850 r921  
    2626//
    2727// $Id: G4Mag_UsualEqRhs.hh,v 1.7 2006/06/29 18:23:12 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4MagneticField.hh

    r850 r921  
    2626//
    2727// $Id: G4MagneticField.hh,v 1.14 2006/06/29 18:23:14 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4QuadrupoleMagField.hh

    r850 r921  
    2626//
    2727// $Id: G4QuadrupoleMagField.hh,v 1.4 2006/06/29 18:23:16 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4RKG3_Stepper.hh

    r850 r921  
    2727//
    2828// $Id: G4RKG3_Stepper.hh,v 1.13 2007/05/18 12:44:02 tnikitin Exp $
    29 // GEANT4 tag $Name: HEAD $
     29// GEANT4 tag $Name: geant4-09-02-cand-01 $
    3030//
    3131//
  • trunk/source/geometry/magneticfield/include/G4SimpleHeum.hh

    r850 r921  
    2626//
    2727// $Id: G4SimpleHeum.hh,v 1.8 2006/06/29 18:23:20 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4SimpleRunge.hh

    r850 r921  
    2626//
    2727// $Id: G4SimpleRunge.hh,v 1.8 2006/06/29 18:23:23 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4UniformElectricField.hh

    r850 r921  
    2626//
    2727// $Id: G4UniformElectricField.hh,v 1.9 2006/06/29 18:23:25 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/include/G4UniformMagField.hh

    r850 r921  
    2626//
    2727// $Id: G4UniformMagField.hh,v 1.9 2006/06/29 18:23:27 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4CashKarpRKF45.cc

    r850 r921  
    2626//
    2727// $Id: G4CashKarpRKF45.cc,v 1.15 2008/01/11 18:11:44 japost Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// The Cash-Karp Runge-Kutta-Fehlberg 4/5 method is an embedded fourth
  • trunk/source/geometry/magneticfield/src/G4ChordFinder.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4ChordFinder.cc,v 1.49 2008/07/15 14:02:06 japost Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4ChordFinder.cc,v 1.51 2008/10/29 14:17:42 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
    31 // 25.02.97 John Apostolakis,  design and implimentation
    32 // 05.03.97 V. Grichine , style modification
     31// 25.02.97 - John Apostolakis - Design and implementation
    3332// -------------------------------------------------------------------
     33
     34#include <iomanip>
    3435
    3536#include "G4ChordFinder.hh"
     
    3839#include "G4ClassicalRK4.hh"
    3940
    40 #include <iomanip>
    4141
    4242// ..........................................................................
     
    5454{
    5555  // Simple constructor which does not create equation, ..
    56       // fDeltaChord= fDefaultDeltaChord;
     56
    5757  fIntgrDriver= pIntegrationDriver;
    5858  fAllocatedStepper= false;
     
    6262    // check the values and set the other parameters
    6363}
     64
    6465
    6566// ..........................................................................
     
    8081  //  Construct the Chord Finder
    8182  //  by creating in inverse order the  Driver, the Stepper and EqRhs ...
     83
    8284  G4Mag_EqRhs *pEquation = new G4Mag_UsualEqRhs(theMagField);
    8385  fEquation = pEquation;                           
     
    103105                                     pItsStepper->GetNumberOfVariables() );
    104106}
     107
     108
     109// ......................................................................
     110
     111G4ChordFinder::~G4ChordFinder()
     112{
     113  delete   fEquation; // fIntgrDriver->pIntStepper->theEquation_Rhs;
     114  if( fAllocatedStepper)
     115  {
     116     delete fDriversStepper;
     117  }
     118  delete   fIntgrDriver;
     119
     120  if( fStatsVerbose ) { PrintStatistics(); }
     121}
     122
    105123
    106124// ......................................................................
     
    113131  if( fractNext == -1.0 )   fractNext = 0.98;  // 0.9;
    114132
    115   // fFirstFraction  = 0.999;  // Orig 0.999 A safe value,  range: ~ 0.95 - 0.999
    116   // fMultipleRadius = 15.0;   // For later use, range: ~  2 - 20
    117 
    118   if( fStatsVerbose ) {
     133  // fFirstFraction  = 0.999; // Orig 0.999 A safe value, range: ~ 0.95 - 0.999
     134  // fMultipleRadius = 15.0;  // For later use, range: ~  2 - 20
     135
     136  if( fStatsVerbose )
     137  {
    119138    G4cout << " ChordFnd> Trying to set fractions: "
    120            << " first " << fFirstFraction
    121            << " last " <<  fractLast
    122            << " next " <<  fractNext
    123            << " and multiple " << fMultipleRadius
    124            << G4endl;
     139           << " first " << fFirstFraction
     140           << " last " <<  fractLast
     141           << " next " <<  fractNext
     142           << " and multiple " << fMultipleRadius
     143           << G4endl;
    125144  }
    126145
    127146  if( (fractLast > 0.0) && (fractLast <=1.0) )
    128     { fFractionLast= fractLast; }
    129   else
     147  {
     148    fFractionLast= fractLast;
     149  }
     150  else
     151  {
     152    G4cerr << "G4ChordFinder::SetFractions_Last_Next: Invalid "
     153           << " fraction Last = " << fractLast
     154           << " must be  0 <  fractionLast <= 1 " << G4endl;
     155  }
     156  if( (fractNext > 0.0) && (fractNext <1.0) )
     157  {
     158    fFractionNextEstimate = fractNext;
     159  }
     160  else
     161  {
    130162    G4cerr << "G4ChordFinder:: SetFractions_Last_Next: Invalid "
    131            << " fraction Last = " << fractLast
    132            << " must be  0 <  fractionLast <= 1 " << G4endl;
    133   if( (fractNext > 0.0) && (fractNext <1.0) )
    134     { fFractionNextEstimate = fractNext; }
    135   else
    136     G4cerr << "G4ChordFinder:: SetFractions_Last_Next: Invalid "
    137            << " fraction Next = " << fractNext
    138            << " must be  0 <  fractionNext < 1 " << G4endl;
    139 }
     163           << " fraction Next = " << fractNext
     164           << " must be  0 <  fractionNext < 1 " << G4endl;
     165  }
     166}
     167
    140168
    141169// ......................................................................
    142170
    143 G4ChordFinder::~G4ChordFinder()
    144 {
    145   delete   fEquation; // fIntgrDriver->pIntStepper->theEquation_Rhs;
    146   if( fAllocatedStepper)
     171G4double
     172G4ChordFinder::AdvanceChordLimited( G4FieldTrack& yCurrent,
     173                                    G4double      stepMax,
     174                                    G4double      epsStep,
     175                                    const G4ThreeVector latestSafetyOrigin,
     176                                    G4double       latestSafetyRadius )
     177{
     178  G4double stepPossible;
     179  G4double dyErr;
     180  G4FieldTrack yEnd( yCurrent);
     181  G4double  startCurveLen= yCurrent.GetCurveLength();
     182  G4double nextStep;
     183  //            *************
     184  stepPossible= FindNextChord(yCurrent, stepMax, yEnd, dyErr, epsStep,
     185                              &nextStep, latestSafetyOrigin, latestSafetyRadius
     186                             );
     187  //            *************
     188
     189  G4bool good_advance;
     190
     191  if ( dyErr < epsStep * stepPossible )
     192  {
     193     // Accept this accuracy.
     194
     195     yCurrent = yEnd;
     196     good_advance = true;
     197  }
     198  else
     199  { 
     200     // Advance more accurately to "end of chord"
     201     //                           ***************
     202     good_advance = fIntgrDriver->AccurateAdvance(yCurrent, stepPossible,
     203                                                  epsStep, nextStep);
     204     if ( ! good_advance )
     205     {
     206       // In this case the driver could not do the full distance
     207       stepPossible= yCurrent.GetCurveLength()-startCurveLen;
     208     }
     209  }
     210  return stepPossible;
     211}
     212
     213
     214// ............................................................................
     215
     216G4double
     217G4ChordFinder::FindNextChord( const  G4FieldTrack& yStart,
     218                                     G4double     stepMax,
     219                                     G4FieldTrack&   yEnd, // Endpoint
     220                                     G4double&   dyErrPos, // Error of endpoint
     221                                     G4double    epsStep,
     222                                     G4double*  pStepForAccuracy,
     223                              const  G4ThreeVector, //  latestSafetyOrigin,
     224                                     G4double       //  latestSafetyRadius
     225                                        )
     226{
     227  // Returns Length of Step taken
     228
     229  G4FieldTrack yCurrent=  yStart; 
     230  G4double    stepTrial, stepForAccuracy;
     231  G4double    dydx[G4FieldTrack::ncompSVEC];
     232
     233  //  1.)  Try to "leap" to end of interval
     234  //  2.)  Evaluate if resulting chord gives d_chord that is good enough.
     235  // 2a.)  If d_chord is not good enough, find one that is.
     236 
     237  G4bool    validEndPoint= false;
     238  G4double  dChordStep, lastStepLength; //  stepOfLastGoodChord;
     239
     240  fIntgrDriver-> GetDerivatives( yCurrent, dydx );
     241
     242  G4int     noTrials=0;
     243  const G4double safetyFactor= fFirstFraction; //  0.975 or 0.99 ? was 0.999
     244
     245  stepTrial = std::min( stepMax, safetyFactor*fLastStepEstimate_Unconstrained );
     246
     247  G4double newStepEst_Uncons= 0.0;
     248  do
    147249  {
    148      delete fDriversStepper;
    149   }                                //  fIntgrDriver->pIntStepper;}
    150   delete   fIntgrDriver;
    151 
    152   if( fStatsVerbose ) { PrintStatistics();  }
    153 }
     250     G4double stepForChord; 
     251     yCurrent = yStart;    // Always start from initial point
     252   
     253     //            ************
     254     fIntgrDriver->QuickAdvance( yCurrent, dydx, stepTrial,
     255                                 dChordStep, dyErrPos);
     256     //            ************
     257     
     258     //  We check whether the criterion is met here.
     259     validEndPoint = AcceptableMissDist(dChordStep);
     260
     261     lastStepLength = stepTrial;
     262
     263     // This method estimates to step size for a good chord.
     264     stepForChord = NewStep(stepTrial, dChordStep, newStepEst_Uncons );
     265
     266     if( ! validEndPoint )
     267     {
     268        if( stepTrial<=0.0 )
     269        {
     270          stepTrial = stepForChord;
     271        }
     272        else if (stepForChord <= stepTrial)
     273        {
     274          // Reduce by a fraction, possibly up to 20%
     275          stepTrial = std::min( stepForChord, fFractionLast * stepTrial);
     276        }
     277        else
     278        {
     279          stepTrial *= 0.1;
     280        }
     281     }
     282     noTrials++;
     283  }
     284  while( ! validEndPoint );   // End of do-while  RKD
     285
     286  if( newStepEst_Uncons > 0.0  )
     287  {
     288     fLastStepEstimate_Unconstrained= newStepEst_Uncons;
     289  }
     290
     291  AccumulateStatistics( noTrials );
     292
     293  if( pStepForAccuracy )
     294  {
     295     // Calculate the step size required for accuracy, if it is needed
     296     //
     297     G4double dyErr_relative = dyErrPos/(epsStep*lastStepLength);
     298     if( dyErr_relative > 1.0 )
     299     {
     300        stepForAccuracy = fIntgrDriver->ComputeNewStepSize( dyErr_relative,
     301                                                            lastStepLength );
     302     }
     303     else
     304     {
     305        stepForAccuracy = 0.0;   // Convention to show step was ok
     306     }
     307     *pStepForAccuracy = stepForAccuracy;
     308  }
     309
     310#ifdef  TEST_CHORD_PRINT
     311  static int dbg=0;
     312  if( dbg )
     313  {
     314    G4cout << "ChordF/FindNextChord:  NoTrials= " << noTrials
     315           << " StepForGoodChord=" << std::setw(10) << stepTrial << G4endl;
     316  }
     317#endif
     318  yEnd=  yCurrent; 
     319  return stepTrial;
     320}
     321
     322
     323// ...........................................................................
     324
     325G4double G4ChordFinder::NewStep(G4double  stepTrialOld,
     326                                G4double  dChordStep, // Curr. dchord achieved
     327                                G4double& stepEstimate_Unconstrained ) 
     328{
     329  // Is called to estimate the next step size, even for successful steps,
     330  // in order to predict an accurate 'chord-sensitive' first step
     331  // which is likely to assist in more performant 'stepping'.
     332
     333  G4double stepTrial;
     334  static G4double lastStepTrial = 1.,  lastDchordStep= 1.;
     335
     336#if 1
     337
     338  if (dChordStep > 0.0)
     339  {
     340    stepEstimate_Unconstrained =
     341                 stepTrialOld*std::sqrt( fDeltaChord / dChordStep );
     342    stepTrial =  fFractionNextEstimate * stepEstimate_Unconstrained;
     343  }
     344  else
     345  {
     346    // Should not update the Unconstrained Step estimate: incorrect!
     347    stepTrial =  stepTrialOld * 2.;
     348  }
     349
     350  if( stepTrial <= 0.001 * stepTrialOld)
     351  {
     352     if ( dChordStep > 1000.0 * fDeltaChord )
     353     {
     354        stepTrial= stepTrialOld * 0.03;   
     355     }
     356     else
     357     {
     358        if ( dChordStep > 100. * fDeltaChord )
     359        {
     360          stepTrial= stepTrialOld * 0.1;   
     361        }
     362        else   // Try halving the length until dChordStep OK
     363        {
     364          stepTrial= stepTrialOld * 0.5;   
     365        }
     366     }
     367  }
     368  else if (stepTrial > 1000.0 * stepTrialOld)
     369  {
     370     stepTrial= 1000.0 * stepTrialOld;
     371  }
     372
     373  if( stepTrial == 0.0 )
     374  {
     375     stepTrial= 0.000001;
     376  }
     377
     378  lastStepTrial = stepTrialOld;
     379  lastDchordStep= dChordStep;
     380
     381#else
     382
     383  if ( dChordStep > 1000. * fDeltaChord )
     384  {
     385        stepTrial= stepTrialOld * 0.03;   
     386  }
     387  else
     388  {
     389     if ( dChordStep > 100. * fDeltaChord )
     390     {
     391        stepTrial= stepTrialOld * 0.1;   
     392     }
     393     else  // Keep halving the length until dChordStep OK
     394     {
     395        stepTrial= stepTrialOld * 0.5;   
     396     }
     397  }
     398
     399#endif
     400
     401  // A more sophisticated chord-finder could figure out a better
     402  // stepTrial, from dChordStep and the required d_geometry
     403  //   e.g.
     404  //      Calculate R, r_helix (eg at orig point)
     405  //      if( stepTrial < 2 pi  R )
     406  //          stepTrial = R arc_cos( 1 - fDeltaChord / r_helix )
     407  //      else   
     408  //          ??
     409
     410  return stepTrial;
     411}
     412
     413
     414// ...........................................................................
     415
     416G4FieldTrack
     417G4ChordFinder::ApproxCurvePointS( const G4FieldTrack&  CurveA_PointVelocity,
     418                                  const G4FieldTrack&  CurveB_PointVelocity,
     419                                  const G4FieldTrack&  ApproxCurveV,
     420                                  const G4ThreeVector& CurrentE_Point,
     421                                  const G4ThreeVector& CurrentF_Point,
     422                                  const G4ThreeVector& PointG,
     423                                       G4bool first, G4double eps_step)
     424{
     425  // ApproxCurvePointS is 2nd implementation of ApproxCurvePoint.
     426  // Use Brent Algorithm (or InvParabolic) when possible.
     427  // Given a starting curve point A (CurveA_PointVelocity), curve point B
     428  // (CurveB_PointVelocity), a point E which is (generally) not on the curve
     429  // and  a point F which is on the curve (first approximation), find new
     430  // point S on the curve closer to point E.
     431  // While advancing towards S utilise 'eps_step' as a measure of the
     432  // relative accuracy of each Step.
     433
     434  G4FieldTrack EndPoint( CurveA_PointVelocity);
     435  G4ThreeVector Point_A=CurveA_PointVelocity.GetPosition();
     436  G4ThreeVector Point_B=CurveB_PointVelocity.GetPosition();
     437  G4double xa,xb,xc,ya,yb,yc;
     438 
     439  // InverseParabolic. AF Intersects (First Part of Curve)
     440
     441  if(first)
     442  {
     443      xa=0.;
     444      ya=(PointG-Point_A).mag();
     445      xb=(Point_A-CurrentF_Point).mag();
     446      yb=-(PointG-CurrentF_Point).mag();
     447      xc=(Point_A-Point_B).mag();
     448      yc=-(CurrentE_Point-Point_B).mag();
     449  }   
     450  else
     451  {
     452     xa=0.;
     453     ya=(Point_A-PointG).mag();
     454     xb=(Point_B-Point_A).mag();
     455     yb=-(PointG-Point_B).mag();
     456     xc=-(Point_A-CurrentF_Point).mag();
     457     yc=-(Point_A-CurrentE_Point).mag();
     458   
     459  }
     460  const G4double tolerance= 1.e-12;
     461  if(ya<=tolerance||std::abs(yc)<=tolerance)
     462  {
     463    ; // What to do for the moment: return the same point as at start
     464      // then PropagatorInField will take care
     465  }
     466  else
     467  {
     468    G4double test_step = InvParabolic(xa,ya,xb,yb,xc,yc);
     469    G4double curve;
     470    if(first)
     471    {
     472      curve=std::abs(EndPoint.GetCurveLength()
     473                    -ApproxCurveV.GetCurveLength());
     474    }
     475    else
     476    {
     477      curve=std::abs(EndPoint.GetCurveLength()
     478                    -CurveB_PointVelocity.GetCurveLength());
     479    }
     480     
     481    if(test_step<=0)    { test_step=0.1*xb; }
     482    if(test_step>=xb)   { test_step=0.5*xb; }
     483    if(test_step>=curve){ test_step=0.5*curve; }
     484
     485    if(curve*(1.+eps_step)<xb) // Similar to ReEstimate Step from
     486    {                          // G4VIntersectionLocator
     487      test_step=0.5*curve;
     488    }
     489
     490    G4bool goodAdvance;
     491    goodAdvance = fIntgrDriver->AccurateAdvance(EndPoint,test_step, eps_step);
     492     
     493#ifdef G4DEBUG_FIELD
     494    // Printing Brent and Linear Approximation
     495    //
     496    G4cout << "G4ChordFinder::ApproxCurvePointS() - test-step ShF = "
     497           << test_step << "  EndPoint = " << EndPoint << G4endl;
     498
     499    //  Test Track
     500    //
     501    G4FieldTrack TestTrack( CurveA_PointVelocity);
     502    TestTrack = ApproxCurvePointV( CurveA_PointVelocity,
     503                                   CurveB_PointVelocity,
     504                                   CurrentE_Point, eps_step );
     505    G4cout.precision(14);
     506    G4cout << "G4ChordFinder::BrentApprox = " << EndPoint  << G4endl;
     507    G4cout << "G4ChordFinder::LinearApprox= " << TestTrack << G4endl;
     508#endif
     509  }
     510  return EndPoint;
     511}
     512
     513
     514// ...........................................................................
     515
     516G4FieldTrack G4ChordFinder::
     517ApproxCurvePointV( const G4FieldTrack& CurveA_PointVelocity,
     518                   const G4FieldTrack& CurveB_PointVelocity,
     519                   const G4ThreeVector& CurrentE_Point,
     520                         G4double eps_step)
     521{
     522  // If r=|AE|/|AB|, and s=true path lenght (AB)
     523  // return the point that is r*s along the curve!
     524 
     525  G4FieldTrack   Current_PointVelocity = CurveA_PointVelocity;
     526
     527  G4ThreeVector  CurveA_Point= CurveA_PointVelocity.GetPosition();
     528  G4ThreeVector  CurveB_Point= CurveB_PointVelocity.GetPosition();
     529
     530  G4ThreeVector  ChordAB_Vector= CurveB_Point   - CurveA_Point;
     531  G4ThreeVector  ChordAE_Vector= CurrentE_Point - CurveA_Point;
     532
     533  G4double       ABdist= ChordAB_Vector.mag();
     534  G4double  curve_length;  //  A curve length  of AB
     535  G4double  AE_fraction;
     536 
     537  curve_length= CurveB_PointVelocity.GetCurveLength()
     538              - CurveA_PointVelocity.GetCurveLength(); 
     539 
     540  G4double  integrationInaccuracyLimit= std::max( perMillion, 0.5*eps_step );
     541  if( curve_length < ABdist * (1. - integrationInaccuracyLimit) )
     542  {
     543#ifdef G4DEBUG_FIELD
     544    G4cerr << " Warning in G4ChordFinder::ApproxCurvePoint: "
     545           << G4endl
     546           << " The two points are further apart than the curve length "
     547           << G4endl
     548           << " Dist = "         << ABdist
     549           << " curve length = " << curve_length
     550           << " relativeDiff = " << (curve_length-ABdist)/ABdist
     551           << G4endl;
     552    if( curve_length < ABdist * (1. - 10*eps_step) )
     553    {
     554      G4cerr << " ERROR: the size of the above difference"
     555             << " exceeds allowed limits.  Aborting." << G4endl;
     556      G4Exception("G4ChordFinder::ApproxCurvePointV()", "PrecisionError",
     557                  FatalException, "Unphysical curve length.");
     558    }
     559#endif
     560    // Take default corrective action: adjust the maximum curve length.
     561    // NOTE: this case only happens for relatively straight paths.
     562    // curve_length = ABdist;
     563  }
     564
     565  G4double  new_st_length;
     566
     567  if ( ABdist > 0.0 )
     568  {
     569     AE_fraction = ChordAE_Vector.mag() / ABdist;
     570  }
     571  else
     572  {
     573     AE_fraction = 0.5;                         // Guess .. ?;
     574#ifdef G4DEBUG_FIELD
     575     G4cout << "Warning in G4ChordFinder::ApproxCurvePointV():"
     576            << " A and B are the same point!" << G4endl
     577            << " Chord AB length = " << ChordAE_Vector.mag() << G4endl
     578            << G4endl;
     579#endif
     580  }
     581 
     582  if( (AE_fraction> 1.0 + perMillion) || (AE_fraction< 0.) )
     583  {
     584#ifdef G4DEBUG_FIELD
     585    G4cerr << " G4ChordFinder::ApproxCurvePointV() - Warning:"
     586           << " Anomalous condition:AE > AB or AE/AB <= 0 " << G4endl
     587           << "   AE_fraction = " <<  AE_fraction << G4endl
     588           << "   Chord AE length = " << ChordAE_Vector.mag() << G4endl
     589           << "   Chord AB length = " << ABdist << G4endl << G4endl;
     590    G4cerr << " OK if this condition occurs after a recalculation of 'B'"
     591           << G4endl << " Otherwise it is an error. " << G4endl ;
     592#endif
     593     // This course can now result if B has been re-evaluated,
     594     // without E being recomputed (1 July 99).
     595     // In this case this is not a "real error" - but it is undesired
     596     // and we cope with it by a default corrective action ...
     597     //
     598     AE_fraction = 0.5;                         // Default value
     599  }
     600
     601  new_st_length= AE_fraction * curve_length;
     602
     603  G4bool good_advance;
     604  if ( AE_fraction > 0.0 )
     605  {
     606     good_advance = fIntgrDriver->AccurateAdvance(Current_PointVelocity,
     607                                                  new_st_length, eps_step );
     608     //
     609     // In this case it does not matter if it cannot advance the full distance
     610  }
     611
     612  // If there was a memory of the step_length actually required at the start
     613  // of the integration Step, this could be re-used ...
     614
     615  G4cout.precision(14);
     616
     617  return Current_PointVelocity;
     618}
     619
     620
     621// ......................................................................
    154622
    155623void
     
    157625{
    158626  // Print Statistics
     627
    159628  G4cout << "G4ChordFinder statistics report: " << G4endl;
    160629  G4cout
     
    171640}
    172641
    173 // ......................................................................
    174 
    175 G4double
    176 G4ChordFinder::AdvanceChordLimited( G4FieldTrack& yCurrent,
    177                                     G4double      stepMax,
    178                                     G4double      epsStep,
    179                                     const G4ThreeVector latestSafetyOrigin,
    180                                     G4double       latestSafetyRadius
    181                                     )
    182 {
    183   G4double stepPossible;
    184   G4double dyErr;
    185   G4FieldTrack yEnd( yCurrent);
    186   G4double  startCurveLen= yCurrent.GetCurveLength();
    187   G4double nextStep;
    188   //            *************
    189   stepPossible= FindNextChord(yCurrent, stepMax, yEnd, dyErr, epsStep, &nextStep
    190                               , latestSafetyOrigin, latestSafetyRadius
    191                              );
    192   //            *************
    193   //  G4cout<<"Exit Find Next Chord Err= "<<dyErr<<" eps=  "<<epsStep<<"stepPos=  "<<stepPossible<<G4endl;
    194   G4bool good_advance;
    195 
    196   if ( dyErr < epsStep * stepPossible )
    197  
    198       {   //G4cout<<"err comparison = "<<dyErr<<" eps=  "<<epsStep<<G4endl;
    199      // Accept this accuracy.
    200      yCurrent = yEnd;
    201      good_advance = true;
    202   }
    203   else
    204   { 
    205     // G4cout<<"Entering Accurate Advance"<<G4endl;
    206      // Advance more accurately to "end of chord"
    207      //                           ***************
    208      good_advance = fIntgrDriver->AccurateAdvance(yCurrent, stepPossible, epsStep, nextStep);
    209      //                           ***************
    210      if ( ! good_advance ){
    211        // In this case the driver could not do the full distance
    212        stepPossible= yCurrent.GetCurveLength()-startCurveLen;
    213      }
    214   }
    215 
    216 #ifdef G4DEBUG_FIELD
    217   //G4cout << "Exiting FindNextChord Limited with:" << G4endl
    218   //       << "   yCurrent: " << yCurrent<< G4endl;
    219 #endif
    220 
    221   return stepPossible;
    222 }
    223 
    224 // #define  TEST_CHORD_PRINT  1
    225 
    226 // ............................................................................
    227 
    228 G4double
    229 G4ChordFinder::FindNextChord( const  G4FieldTrack& yStart,
    230                                      G4double     stepMax,
    231                                      G4FieldTrack&   yEnd, // Endpoint
    232                                      G4double&   dyErrPos, // Error of endpoint
    233                                      G4double    epsStep,
    234                                      G4double*  pStepForAccuracy,
    235                               const  G4ThreeVector, //  latestSafetyOrigin,
    236                                      G4double       //  latestSafetyRadius
    237                                         )
    238   // Returns Length of Step taken
    239 {
    240   //G4cout<<"Inter Find Next Chord with step="<<stepMax<<G4endl; 
    241   // G4int       stepRKnumber=0;
    242   G4FieldTrack yCurrent=  yStart; 
    243   G4double    stepTrial, stepForAccuracy;
    244   G4double    dydx[G4FieldTrack::ncompSVEC];
    245 
    246   //  1.)  Try to "leap" to end of interval
    247   //  2.)  Evaluate if resulting chord gives d_chord that is good enough.
    248   //     2a.)  If d_chord is not good enough, find one that is.
    249  
    250   G4bool    validEndPoint= false;
    251   G4double  dChordStep, lastStepLength; //  stepOfLastGoodChord;
    252 
    253   fIntgrDriver-> GetDerivatives( yCurrent, dydx )  ;
    254   //for (G4int i=0;i<G4FieldTrack::ncompSVEC;i++){
    255   //  dydx[i]=0.;
    256   //}
    257   G4int     noTrials=0;
    258   const G4double safetyFactor= fFirstFraction; //  0.975 or 0.99 ? was 0.999
    259 
    260   stepTrial = std::min( stepMax,
    261                           safetyFactor * fLastStepEstimate_Unconstrained );
    262 
    263   G4double newStepEst_Uncons= 0.0;
    264   do
    265   {
    266      G4double stepForChord; 
    267      yCurrent = yStart;    // Always start from initial point
    268    
    269      //            ************
    270      fIntgrDriver->QuickAdvance( yCurrent, dydx, stepTrial,
    271                                  dChordStep, dyErrPos);
    272      //            ************
    273 
    274      // G4cout<<"AfterQuickAdv step="<<stepTrial<<"  dC="<<dChordStep<<" yErr="<<dyErrPos<<G4endl;
    275      
    276       //  We check whether the criterion is met here.
    277      validEndPoint = AcceptableMissDist(dChordStep);
    278      // if(validEndPoint){G4cout<<"validEndPoint"<<fDeltaChord<<G4endl;}
    279      // else{G4cout<<"No__validEndPoint"<<G4endl;}
    280 
    281 
    282      //&& (dyErrPos < eps) ;
    283      //   validEndPoint = AcceptableMissDist(dChordStep) && (dyErrPos < epsStep) ;
    284 
    285      lastStepLength = stepTrial;
    286 
    287      // This method estimates to step size for a good chord.
    288      stepForChord = NewStep(stepTrial, dChordStep, newStepEst_Uncons );
    289 
    290      if( ! validEndPoint ) {
    291         if( stepTrial<=0.0 )
    292           stepTrial = stepForChord;
    293         else if (stepForChord <= stepTrial)
    294           // Reduce by a fraction, possibly up to 20%
    295           stepTrial = std::min( stepForChord,
    296                                 fFractionLast * stepTrial);
    297         else
    298           stepTrial *= 0.1;
    299 
    300         // if(dbg) G4cerr<<"Dchord too big. Try new hstep="<<stepTrial<<G4endl;
    301      }
    302      // #ifdef  TEST_CHORD_PRINT
    303      // TestChordPrint( noTrials, lastStepLength, dChordStep, stepTrial );
    304      // #endif
    305 
    306      noTrials++;
    307   }
    308   while( ! validEndPoint );   // End of do-while  RKD
    309 
    310   if( newStepEst_Uncons > 0.0  ){
    311     fLastStepEstimate_Unconstrained= newStepEst_Uncons;
    312   }
    313 
    314   AccumulateStatistics( noTrials );
    315 
    316   // stepOfLastGoodChord = stepTrial;
    317 
    318   if( pStepForAccuracy ){
    319      // Calculate the step size required for accuracy, if it is needed
    320      G4double dyErr_relative = dyErrPos/(epsStep*lastStepLength);
    321      if( dyErr_relative > 1.0 ) {
    322         stepForAccuracy =
    323            fIntgrDriver->ComputeNewStepSize( dyErr_relative,
    324                                              lastStepLength );
    325      }else{
    326         stepForAccuracy = 0.0;   // Convention to show step was ok
    327      }
    328      *pStepForAccuracy = stepForAccuracy;
    329   }
    330 
    331 #ifdef  TEST_CHORD_PRINT
    332   static int dbg=0;
    333   if( dbg )
    334     G4cout << "ChordF/FindNextChord:  NoTrials= " << noTrials
    335            << " StepForGoodChord=" << std::setw(10) << stepTrial << G4endl;
    336 #endif
    337   //G4cout << "ChordF/FindNextChord:  NoTrials= " << noTrials
    338   //         << " StepForGoodChord=" << std::setw(10) << stepTrial << G4endl;
    339   yEnd=  yCurrent; 
    340   return stepTrial;
    341 }
    342 
    343 // ----------------------------------------------------------------------------
    344 #if 0         
    345 //   #ifdef G4VERBOSE
    346 if( dbg ) {
    347    G4cerr << "Returned from QuickAdvance with: yCur=" << yCurrent <<G4endl;
    348    G4cerr << " dChordStep= "<< dChordStep <<" dyErr=" << dyErr << G4endl;
    349 }
    350 #endif
    351 // ----------------------------------------------------------------------------
    352642
    353643// ...........................................................................
    354644
    355 G4double G4ChordFinder::NewStep(G4double  stepTrialOld,
    356                                 G4double  dChordStep, // Curr. dchord achieved
    357                                 G4double& stepEstimate_Unconstrained ) 
    358 //
    359 // Is called to estimate the next step size, even for successful steps,
    360 // in order to predict an accurate 'chord-sensitive' first step
    361 // which is likely to assist in more performant 'stepping'.
    362 //
    363        
    364 {
    365   G4double stepTrial;
    366   static G4double lastStepTrial = 1.,  lastDchordStep= 1.;
    367 
    368 #if 1
    369   // const G4double  threshold = 1.21, multiplier = 0.9;
    370   //  0.9 < 1 / std::sqrt(1.21)
    371 
    372   if (dChordStep > 0.0)
    373   {
    374     stepEstimate_Unconstrained = stepTrialOld*std::sqrt( fDeltaChord / dChordStep );
    375     // stepTrial =  0.98 * stepEstimate_Unconstrained;
    376     stepTrial =  fFractionNextEstimate * stepEstimate_Unconstrained;
    377   }
    378   else
    379   {
    380     // Should not update the Unconstrained Step estimate: incorrect!
    381     stepTrial =  stepTrialOld * 2.;
    382   }
    383 
    384   // if ( dChordStep < threshold * fDeltaChord ){
    385   //    stepTrial= stepTrialOld *  multiplier;   
    386   // }
    387   if( stepTrial <= 0.001 * stepTrialOld)
    388   {
    389      if ( dChordStep > 1000.0 * fDeltaChord ){
    390         stepTrial= stepTrialOld * 0.03;   
    391      }else{
    392         if ( dChordStep > 100. * fDeltaChord ){
    393           stepTrial= stepTrialOld * 0.1;   
    394         }else{
    395     // Try halving the length until dChordStep OK
    396           stepTrial= stepTrialOld * 0.5;   
    397         }
    398      }
    399   }else if (stepTrial > 1000.0 * stepTrialOld)
    400   {
    401      stepTrial= 1000.0 * stepTrialOld;
    402   }
    403 
    404   if( stepTrial == 0.0 ){
    405      stepTrial= 0.000001;
    406   }
    407 
    408   lastStepTrial = stepTrialOld;
    409   lastDchordStep= dChordStep;
    410 #else
    411   if ( dChordStep > 1000. * fDeltaChord ){
    412         stepTrial= stepTrialOld * 0.03;   
    413   }else{
    414      if ( dChordStep > 100. * fDeltaChord ){
    415         stepTrial= stepTrialOld * 0.1;   
    416      }else{
    417         // Keep halving the length until dChordStep OK
    418         stepTrial= stepTrialOld * 0.5;   
    419      }
    420   }
    421 #endif
    422 
    423   // A more sophisticated chord-finder could figure out a better
    424   //   stepTrial, from dChordStep and the required d_geometry
    425   //   eg
    426   //      Calculate R, r_helix (eg at orig point)
    427   //      if( stepTrial < 2 pi  R )
    428   //          stepTrial = R arc_cos( 1 - fDeltaChord / r_helix )
    429   //      else   
    430   //          ??
    431 
    432   return stepTrial;
    433 }
    434 
    435 //  ApproxCurvePointS is 2nd implementation of ApproxCurvePoint.
    436 //  Use Brent Algorithm(or InvParabolic) when it possible.
    437 //  Given a starting curve point A (CurveA_PointVelocity), 
    438 //  curve point B (CurveB_PointVelocity), a point E which is (generally)
    439 //  not on the curve  and  a point F which is on the curve(first approximation)
    440 //  From this information find new point S on the curve closer to point E.
    441 //  While advancing towards S utilise eps_step
    442 //  as a measure of the relative accuracy of each Step.
    443 G4FieldTrack
    444 G4ChordFinder::ApproxCurvePointS( const G4FieldTrack& CurveA_PointVelocity,
    445                                   const G4FieldTrack& CurveB_PointVelocity,
    446                                   const G4ThreeVector& CurrentE_Point,
    447                                   const G4ThreeVector& CurrentF_Point,
    448                                   const G4ThreeVector& PointG,
    449                                        G4bool first, G4double eps_step)
    450 {
    451 
    452  
    453   G4FieldTrack EndPoint( CurveA_PointVelocity);
    454   G4ThreeVector Point_A=CurveA_PointVelocity.GetPosition();
    455   G4ThreeVector Point_B=CurveB_PointVelocity.GetPosition();
    456   G4double xa,xb,xc,ya,yb,yc;
    457  
    458 //InverseParabolic
    459 //AF Intersects (First Part of Curve)
    460   if(first){
    461       xa=0.;
    462       ya=(PointG-Point_A).mag();
    463       xb=(Point_A-CurrentF_Point).mag();
    464       yb=-(PointG-CurrentF_Point).mag();
    465       xc=(Point_A-Point_B).mag();
    466       yc=-(CurrentE_Point-Point_B).mag();
    467   }   
    468   else{
    469      xa=0.;
    470      ya=(Point_A-PointG).mag();
    471      xb=(Point_B-Point_A).mag();
    472      yb=-(PointG-Point_B).mag();
    473      xc=-(Point_A-CurrentF_Point).mag();
    474      yc=-(Point_A-CurrentE_Point).mag();
    475    
    476   }
    477   const G4double tolerance= 1.e-12;
    478   if(ya<=tolerance||std::abs(yc)<=tolerance){
    479     ; //What to do for the moment return the same point as in begin
    480      //Then PropagatorInField will take care
    481    }
    482    else{
    483          
    484       G4double test_step  =InvParabolic(xa,ya,xb,yb,xc,yc);
    485       G4double curve=std::abs(EndPoint.GetCurveLength()-CurveB_PointVelocity.GetCurveLength());
    486       G4double dist= (EndPoint.GetPosition()-Point_B).mag();
    487       if(test_step<=0) { test_step=0.1*xb;}
    488       if(test_step>=xb){ test_step=0.5*xb;}
    489        
    490 
    491       if(curve*(1.+eps_step)<dist){
    492         test_step=0.5*dist;
    493        }
    494 
    495        G4bool goodAdvance;
    496        goodAdvance=
    497              fIntgrDriver->AccurateAdvance(EndPoint,test_step, eps_step);
    498             //            ***************
    499      
    500        #ifdef G4DEBUG_FIELD
    501         G4cout<<"G4ChordFinder:: test-step ShF="<<test_step<<"  EndPoint="<<EndPoint<<G4endl;
    502       //    Test Track
    503        G4FieldTrack TestTrack( CurveA_PointVelocity);
    504        TestTrack = ApproxCurvePointV( CurveA_PointVelocity,
    505                                                   CurveB_PointVelocity,
    506                                                   CurrentE_Point,
    507                                                   eps_step );
    508        G4cout.precision(14);
    509        G4cout<<"G4ChordFinder:: BrentApprox="<<EndPoint<<G4endl;
    510        G4cout<<"G4ChordFinder::LinearApprox="<<TestTrack<<G4endl;
    511        #endif
    512   }
    513 return EndPoint;
    514 
    515 
    516 G4FieldTrack
    517 G4ChordFinder::ApproxCurvePointV( const G4FieldTrack& CurveA_PointVelocity,
    518                                   const G4FieldTrack& CurveB_PointVelocity,
    519                                   const G4ThreeVector& CurrentE_Point,
    520                                         G4double eps_step)
    521 {
    522   // 1st implementation:
    523   //    if r=|AE|/|AB|, and s=true path lenght (AB)
    524   //    return the point that is r*s along the curve!
    525   /////////////////////////////
    526   //
    527   //2st implementation : Inverse Parabolic Extrapolation by D.C.Williams
    528   //
    529   //    Uses InvParabolic (xa,ya,xb,yb,xc,yc)
    530 
    531   G4FieldTrack    Current_PointVelocity = CurveA_PointVelocity;
    532 
    533   G4ThreeVector  CurveA_Point= CurveA_PointVelocity.GetPosition();
    534   G4ThreeVector  CurveB_Point= CurveB_PointVelocity.GetPosition();
    535 
    536   G4ThreeVector  ChordAB_Vector= CurveB_Point   - CurveA_Point;
    537   G4ThreeVector  ChordAE_Vector= CurrentE_Point - CurveA_Point;
    538 
    539   G4double       ABdist= ChordAB_Vector.mag();
    540   G4double  curve_length;  //  A curve length  of AB
    541   G4double  AE_fraction;
    542  
    543   curve_length= CurveB_PointVelocity.GetCurveLength()
    544               - CurveA_PointVelocity.GetCurveLength(); 
    545 
    546   // const
    547   G4double  integrationInaccuracyLimit= std::max( perMillion, 0.5*eps_step );
    548   if( curve_length < ABdist * (1. - integrationInaccuracyLimit) ){
    549 #ifdef G4DEBUG_FIELD
    550     G4cerr << " Warning in G4ChordFinder::ApproxCurvePoint: "
    551            << G4endl
    552            << " The two points are further apart than the curve length "
    553            << G4endl
    554            << " Dist = "         << ABdist
    555            << " curve length = " << curve_length
    556            << " relativeDiff = " << (curve_length-ABdist)/ABdist
    557            << G4endl;
    558     if( curve_length < ABdist * (1. - 10*eps_step) ) {
    559       G4cerr << " ERROR: the size of the above difference"
    560              << " exceeds allowed limits.  Aborting." << G4endl;
    561       G4Exception("G4ChordFinder::ApproxCurvePointV()", "PrecisionError",
    562                   FatalException, "Unphysical curve length.");
    563     }
    564 #endif
    565     // Take default corrective action:
    566     //    -->  adjust the maximum curve length.
    567     //  NOTE: this case only happens for relatively straight paths.
    568     curve_length = ABdist;
    569   }
    570 
    571   G4double  new_st_length;
    572 
    573   if ( ABdist > 0.0 ){
    574      AE_fraction = ChordAE_Vector.mag() / ABdist;
    575   }else{
    576      AE_fraction = 0.5;                         // Guess .. ?;
    577 #ifdef G4DEBUG_FIELD
    578      G4cout << "Warning in G4ChordFinder::ApproxCurvePoint:"
    579             << " A and B are the same point!" << G4endl
    580             << " Chord AB length = " << ChordAE_Vector.mag() << G4endl
    581             << G4endl;
    582 #endif
    583   }
    584  
    585   if( (AE_fraction> 1.0 + perMillion) || (AE_fraction< 0.) ){
    586 #ifdef G4DEBUG_FIELD
    587     G4cerr << " G4ChordFinder::ApproxCurvePointV - Warning:"
    588            << " Anomalous condition:AE > AB or AE/AB <= 0 " << G4endl
    589            << "   AE_fraction = " <<  AE_fraction << G4endl
    590            << "   Chord AE length = " << ChordAE_Vector.mag() << G4endl
    591            << "   Chord AB length = " << ABdist << G4endl << G4endl;
    592     G4cerr << " OK if this condition occurs after a recalculation of 'B'"
    593            << G4endl << " Otherwise it is an error. " << G4endl ;
    594 #endif
    595      // This course can now result if B has been re-evaluated,
    596      //   without E being recomputed   (1 July 99)
    597      //  In this case this is not a "real error" - but it undesired
    598      //   and we cope with it by a default corrective action ...
    599      AE_fraction = 0.5;                         // Default value
    600   }
    601 
    602   new_st_length= AE_fraction * curve_length;
    603 
    604   G4bool good_advance;
    605   if ( AE_fraction > 0.0 ) {
    606      good_advance =
    607       fIntgrDriver->AccurateAdvance(Current_PointVelocity,
    608                                     new_st_length,
    609                                     eps_step ); // Relative accuracy
    610      // In this case it does not matter if it cannot advance the full distance
    611   }
    612 
    613   // If there was a memory of the step_length actually require at the start
    614   // of the integration Step, this could be re-used ...
    615    G4cout.precision(14);
    616      
    617    //     G4cout<<"G4ChordFinder::LinearApprox="<<Current_PointVelocity<<G4endl;
    618   return Current_PointVelocity;
    619 }
    620 
    621 void
    622 G4ChordFinder::TestChordPrint( G4int    noTrials,
    623                                G4int    lastStepTrial,
    624                                G4double dChordStep,
    625                                G4double nextStepTrial )
     645void G4ChordFinder::TestChordPrint( G4int    noTrials,
     646                                    G4int    lastStepTrial,
     647                                    G4double dChordStep,
     648                                    G4double nextStepTrial )
    626649{
    627650     G4int oldprec= G4cout.precision(5);
    628651     G4cout << " ChF/fnc: notrial " << std::setw( 3) << noTrials
    629652            << " this_step= "       << std::setw(10) << lastStepTrial;
    630      if( std::fabs( (dChordStep / fDeltaChord) - 1.0 ) < 0.001 ){
    631              G4cout.precision(8);
    632      }else{  G4cout.precision(6); }
    633      G4cout << " dChordStep=  "     << std::setw(12) << dChordStep;
     653     if( std::fabs( (dChordStep / fDeltaChord) - 1.0 ) < 0.001 )
     654     {
     655       G4cout.precision(8);
     656     }
     657     else
     658     {
     659       G4cout.precision(6);
     660     }
     661     G4cout << " dChordStep=  " << std::setw(12) << dChordStep;
    634662     if( dChordStep > fDeltaChord ) { G4cout << " d+"; }
    635663     else                           { G4cout << " d-"; }
  • trunk/source/geometry/magneticfield/src/G4ChordFinderSaf.cc

    r831 r921  
    116116
    117117G4double
    118 G4ChordFinderSaf::FindNextChord( const  G4FieldTrack  yStart,
     118G4ChordFinderSaf::FindNextChord( const  G4FieldTrack&  yStart,
    119119                                     G4double     stepMax,
    120120                                     G4FieldTrack&   yEnd, // Endpoint
  • trunk/source/geometry/magneticfield/src/G4ClassicalRK4.cc

    r850 r921  
    2626//
    2727// $Id: G4ClassicalRK4.cc,v 1.12 2006/06/29 18:23:37 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// -------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4DELPHIMagField.cc

    r850 r921  
    2626//
    2727// $Id: G4DELPHIMagField.cc,v 1.6 2006/06/29 18:23:39 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929// -------------------------------------------------------------------
    3030
  • trunk/source/geometry/magneticfield/src/G4ElectricField.cc

    r850 r921  
    2626//
    2727// $Id: G4ElectricField.cc,v 1.2 2006/06/29 18:23:42 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4ElectroMagneticField.cc

    r850 r921  
    2626//
    2727// $Id: G4ElectroMagneticField.cc,v 1.3 2006/06/29 18:23:44 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4EqEMFieldWithSpin.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4EqEMFieldWithSpin.cc,v 1.2 2008/04/24 12:33:08 tnikitin Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4EqEMFieldWithSpin.cc,v 1.4 2008/11/21 21:17:03 gum Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    4040
    4141#include "G4EqEMFieldWithSpin.hh"
     42#include "G4ElectroMagneticField.hh"
    4243#include "G4ThreeVector.hh"
    4344#include "globals.hh"
    4445
    4546G4EqEMFieldWithSpin::G4EqEMFieldWithSpin(G4ElectroMagneticField *emField )
    46       : G4EquationOfMotion( emField ) { anomaly = 1.165923e-3; }
     47      : G4EquationOfMotion( emField )
     48{
     49  anomaly = 0.0011659208;
     50}
     51
     52G4EqEMFieldWithSpin::~G4EqEMFieldWithSpin()
     53{
     54}
    4755
    4856void 
    4957G4EqEMFieldWithSpin::SetChargeMomentumMass(G4double particleCharge, // e+ units
    50                                             G4double MomentumXc,
     58                                            G4double MomentumXc,
    5159                                            G4double particleMass)
    5260{
     
    6169   beta  = MomentumXc/E;
    6270   gamma = E/particleMass;
     71
    6372}
    64 
    65 
    6673
    6774void
    6875G4EqEMFieldWithSpin::EvaluateRhsGivenB(const G4double y[],
    69                                         const G4double Field[],
    70                                               G4double dydx[] ) const
     76                                       const G4double Field[],
     77                                             G4double dydx[] ) const
    7178{
    7279
     
    114121
    115122   G4ThreeVector Spin(y[9],y[10],y[11]);
     123
     124   if (Spin.mag() > 0.) Spin = Spin.unit();
     125
    116126   G4ThreeVector dSpin;
    117127
  • trunk/source/geometry/magneticfield/src/G4EqMagElectricField.cc

    r850 r921  
    2626//
    2727// $Id: G4EqMagElectricField.cc,v 1.14 2008/04/24 12:33:35 tnikitin Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4EquationOfMotion.cc

    r850 r921  
    2626//
    2727// $Id: G4EquationOfMotion.cc,v 1.9 2006/06/29 18:23:48 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// -------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4ErrorMag_UsualEqRhs.cc

    r850 r921  
    2626//
    2727// $Id: G4ErrorMag_UsualEqRhs.cc,v 1.1 2007/05/16 12:54:02 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4ExactHelixStepper.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4ExactHelixStepper.cc,v 1.8 2007/12/10 16:29:47 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4ExactHelixStepper.cc,v 1.9 2008/10/29 14:34:35 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//  Helix a-la-Explicity Euler: x_1 = x_0 + helix(h)
     
    112112{
    113113  // Implementation : must check whether h/R >  pi  !!
    114   //   If( h/R <  pi)   DistChord=h/2*tan(Ang_curve/4)
     114  //   If( h/R <  pi)   DistChord=h/2*std::tan(Ang_curve/4)
    115115  //   Else             DistChord=R_helix
    116116  //
  • trunk/source/geometry/magneticfield/src/G4ExplicitEuler.cc

    r850 r921  
    2626//
    2727// $Id: G4ExplicitEuler.cc,v 1.8 2006/06/29 18:23:53 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4FieldManager.cc

    r850 r921  
    2626//
    2727// $Id: G4FieldManager.cc,v 1.15 2007/12/07 15:34:10 japost Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// -------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4FieldManagerStore.cc

    r850 r921  
    2626//
    2727// $Id: G4FieldManagerStore.cc,v 1.4 2008/01/17 10:56:23 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// G4FieldManagerStore
  • trunk/source/geometry/magneticfield/src/G4FieldTrack.cc

    r850 r921  
    2626//
    2727// $Id: G4FieldTrack.cc,v 1.14 2007/10/03 15:34:42 japost Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// -------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4HarmonicPolMagField.cc

    r850 r921  
    2626//
    2727// $Id: G4HarmonicPolMagField.cc,v 1.6 2006/06/29 18:24:00 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// -------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4HelixExplicitEuler.cc

    r850 r921  
    2626//
    2727// $Id: G4HelixExplicitEuler.cc,v 1.8 2007/12/10 16:29:49 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4HelixHeum.cc

    r850 r921  
    2626//
    2727// $Id: G4HelixHeum.cc,v 1.6 2006/06/29 18:24:04 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4HelixImplicitEuler.cc

    r850 r921  
    2626//
    2727// $Id: G4HelixImplicitEuler.cc,v 1.6 2006/06/29 18:24:06 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4HelixSimpleRunge.cc

    r850 r921  
    2626//
    2727// $Id: G4HelixSimpleRunge.cc,v 1.7 2006/06/29 18:24:08 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4ImplicitEuler.cc

    r850 r921  
    2626//
    2727// $Id: G4ImplicitEuler.cc,v 1.9 2006/06/29 18:24:11 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4LineCurrentMagField.cc

    r850 r921  
    2525//
    2626// $Id: G4LineCurrentMagField.cc,v 1.6 2006/06/29 18:24:13 gunter Exp $
    27 // GEANT4 tag $Name: HEAD $
     27// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2828// -------------------------------------------------------------------
    2929
  • trunk/source/geometry/magneticfield/src/G4LineSection.cc

    r850 r921  
    2626//
    2727// $Id: G4LineSection.cc,v 1.10 2006/06/29 18:24:16 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4MagErrorStepper.cc

    r850 r921  
    2626//
    2727// $Id: G4MagErrorStepper.cc,v 1.13 2006/06/29 18:24:18 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4MagHelicalStepper.cc

    r850 r921  
    2626//
    2727// $Id: G4MagHelicalStepper.cc,v 1.23 2007/09/05 12:20:17 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4MagIntegratorDriver.cc

    r850 r921  
    2626//
    2727// $Id: G4MagIntegratorDriver.cc,v 1.49 2007/08/17 12:30:33 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4MagIntegratorStepper.cc

    r850 r921  
    2626//
    2727// $Id: G4MagIntegratorStepper.cc,v 1.11 2006/06/29 18:24:34 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4Mag_EqRhs.cc

    r850 r921  
    2626//
    2727// $Id: G4Mag_EqRhs.cc,v 1.11 2006/06/29 18:24:36 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//  This is the standard right-hand side for equation of motion 
  • trunk/source/geometry/magneticfield/src/G4Mag_SpinEqRhs.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4Mag_SpinEqRhs.cc,v 1.12 2006/06/29 18:24:39 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4Mag_SpinEqRhs.cc,v 1.13 2008/11/21 21:18:26 gum Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// This is the standard right-hand side for equation of motion.
     
    4545  : G4Mag_EqRhs( MagField )
    4646{
    47    anomaly = 1.165923e-3;
     47   anomaly = 0.0011659208;
    4848}
    4949
     
    5353G4Mag_SpinEqRhs::SetChargeMomentumMass(G4double particleCharge, // in e+ units
    5454                                       G4double MomentumXc,
    55                                        G4double mass)
     55                                       G4double particleMass)
    5656{
    5757   //  To set fCof_val
    58    G4Mag_EqRhs::SetChargeMomentumMass(particleCharge, MomentumXc, mass);
     58   G4Mag_EqRhs::SetChargeMomentumMass(particleCharge, MomentumXc, particleMass);
    5959
    60    omegac = 0.105658387*GeV/mass * 2.837374841e-3*(rad/cm/kilogauss);
     60   omegac = 0.105658387*GeV/particleMass * 2.837374841e-3*(rad/cm/kilogauss);
    6161
    6262   ParticleCharge = particleCharge;
    6363
    64    E = std::sqrt(sqr(MomentumXc)+sqr(mass));
     64   E = std::sqrt(sqr(MomentumXc)+sqr(particleMass));
    6565   beta  = MomentumXc/E;
    66    gamma = E/mass;
     66   gamma = E/particleMass;
    6767
    6868}
     
    9696
    9797   G4ThreeVector Spin(y[9],y[10],y[11]);
     98
     99   if (Spin.mag() > 0.) Spin = Spin.unit();
     100
    98101   G4ThreeVector dSpin;
    99102
  • trunk/source/geometry/magneticfield/src/G4Mag_UsualEqRhs.cc

    r850 r921  
    2626//
    2727// $Id: G4Mag_UsualEqRhs.cc,v 1.12 2006/06/29 18:24:42 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4MagneticField.cc

    r850 r921  
    2626//
    2727// $Id: G4MagneticField.cc,v 1.3 2006/06/29 18:24:44 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4QuadrupoleMagField.cc

    r850 r921  
    2626//
    2727// $Id: G4QuadrupoleMagField.cc,v 1.4 2006/06/29 18:24:46 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// -------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4RKG3_Stepper.cc

    r850 r921  
    2626//
    2727// $Id: G4RKG3_Stepper.cc,v 1.15 2007/08/21 10:17:41 tnikitin Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// -------------------------------------------------------------------
  • trunk/source/geometry/magneticfield/src/G4SimpleHeum.cc

    r850 r921  
    2626//
    2727// $Id: G4SimpleHeum.cc,v 1.8 2006/06/29 18:24:51 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//  Simple Heum:
  • trunk/source/geometry/magneticfield/src/G4SimpleRunge.cc

    r850 r921  
    2626//
    2727// $Id: G4SimpleRunge.cc,v 1.10 2006/06/29 18:24:53 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//  Simple Runge:
  • trunk/source/geometry/magneticfield/src/G4UniformElectricField.cc

    r850 r921  
    2626//
    2727// $Id: G4UniformElectricField.cc,v 1.12 2006/06/29 18:24:56 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/magneticfield/src/G4UniformMagField.cc

    r850 r921  
    2626//
    2727// $Id: G4UniformMagField.cc,v 1.11 2006/06/29 18:24:58 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/management/History

    r850 r921  
    1 $Id: History,v 1.128 2008/07/15 10:27:55 gcosmo Exp $
     1$Id: History,v 1.131 2008/09/23 13:10:55 gcosmo Exp $
    22-------------------------------------------------------------------
    33
     
    1717     * Reverse chronological order (last date on top), please *
    1818     ----------------------------------------------------------
     19
     20September 23, 2008  G. Cosmo               geommng-V09-01-08
     21- G4VSolid: explicitely reserve memory for polygon vectors in clipping
     22  algorithm to help reducing memory footprint. Courtesy of P.Elmer, CMS.
     23
     24September 10, 2008  G. Cosmo               geommng-V09-01-07
     25- G4VSolid: promote copy-constructor and assignment operator to public
     26  to cope with specific use-case in ATLAS (see problem report #1023).
    1927
    2028July 15, 2008  G.Cosmo                     geommng-V09-01-06
  • trunk/source/geometry/management/include/G4VSolid.hh

    r850 r921  
    2525//
    2626//
    27 // $Id: G4VSolid.hh,v 1.28 2008/02/20 15:24:25 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4VSolid.hh,v 1.29 2008/09/10 13:18:42 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    230230      // persistifiable objects.
    231231
     232    G4VSolid(const G4VSolid& rhs);
     233    G4VSolid& operator=(const G4VSolid& rhs);
     234      // Copy constructor and assignment operator.
     235
    232236  protected:  // with description
    233237
     
    294298      // expressed by the first argument.
    295299
    296   protected:  // without description
    297 
    298     G4VSolid(const G4VSolid& rhs);
    299     G4VSolid& operator=(const G4VSolid& rhs);
    300       // Protected copy constructor and assignment operator.
    301 
    302300  protected:
    303301
  • trunk/source/geometry/management/src/G4VSolid.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4VSolid.cc,v 1.37 2008/02/20 15:24:26 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4VSolid.cc,v 1.39 2008/09/23 13:07:41 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// class G4VSolid
     
    7171//////////////////////////////////////////////////////////////////////////
    7272//
    73 // Protected copy constructor
     73// Copy constructor
    7474//
    7575
     
    181181
    182182  G4ThreeVectorList polygon;
     183  polygon.reserve(4);
    183184  polygon.push_back((*pVertices)[pSectionIndex]);
    184185  polygon.push_back((*pVertices)[pSectionIndex+1]);
     
    210211{
    211212  G4ThreeVectorList polygon;
     213  polygon.reserve(4);
    212214  polygon.push_back((*pVertices)[pSectionIndex]);
    213215  polygon.push_back((*pVertices)[pSectionIndex+4]);
  • trunk/source/geometry/navigation/History

    r850 r921  
    1 $Id: History,v 1.119 2008/04/29 15:33:05 gcosmo Exp $
     1$Id: History,v 1.125 2008/11/14 18:26:53 gcosmo Exp $
    22-------------------------------------------------------------------
    33
     
    1717     * Reverse chronological order (last date on top), please *
    1818     ----------------------------------------------------------
     19
     20November 14th, 2008 - T.Nikitina, J.Apostolakis (geomnav-V09-01-09)
     21-----------------------------------------------
     22- Introduced first implementation of new optional method in locator classes
     23  AdjustementOfFoundIntersection() using surface-normal of the intersecting
     24  solid to boost accuracy. Added the optional call to the new method in each
     25  concrete locator.
     26- Removed unnecessary accessors for Brent locator in G4PropagatorInField.
     27- G4VoxelNavigation: implemented additional check when running in "check"
     28  mode; if it is on the surface, ensure that it can move on next step;
     29  either DistanceToIn(p,v) or DistanceToOut(p,v) should return a finite
     30  value greater than the tolerance.
     31
     32November 10th, 2008 - G.Cosmo (geomnav-V09-01-08)
     33-----------------------------
     34- G4PathFinder: cleared unecessary calls to ComputeSafety() in ReLocate().
     35
     36October 28th, 2008 - T.Nikitina (geomnav-V09-01-07)
     37-------------------------------
     38- Moved method LocateIntersectionPoint() in G4PropagatorInField to a separate
     39  class G4VIntersectionLocator, now allowing to use different location
     40  algorithms: Brent, MultiLevel, Simple.
     41- New classes: G4VIntersectionLocator, G4SimpleLocator, G4BrentLocator and
     42  G4MultiLevelLocator. 
     43- Coworks with tag "field-V09-01-03".
     44
     45October 10th, 2008 - G.Cosmo (geomnav-V09-01-06)
     46----------------------------
     47- Introduced optional Boolean argument in G4Navigator::ComputeSafety() to
     48  allow for computation of safety without modifying the state restoring of
     49  the navigator.
     50- Modified accordingly the following classes, for calls to ComputeSafety():
     51  G4SafetyHelper, G4PathFinder (now calling ComputeSafety() with TRUE
     52  argument to preserve navigator's state), G4MultiNavigator and
     53  G4ErrorPropagationNavigator.
     54
     55May 5th, 2008 - T.Nikitina (geomnav-V09-01-05)
     56--------------------------
     57- Added Brent method for LocateIntersectionPoint() in G4PropagatorInField.
     58  The Brent method is now used as default and can be switched off through
     59  call to the proper accessor function SetBrentMethod().
     60- Requires related update to G4ChordFinder in geometry/magneticfield module
     61  included in tag "field-V09-01-02".
    1962
    2063April 29th, 2008 - M.Asai (geomnav-V09-01-04)
  • trunk/source/geometry/navigation/include/G4AuxiliaryNavServices.hh

    r850 r921  
    2626//
    2727// $Id: G4AuxiliaryNavServices.hh,v 1.4 2007/05/22 07:48:08 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4AuxiliaryNavServices.icc

    r850 r921  
    2626//
    2727// $Id: G4AuxiliaryNavServices.icc,v 1.4 2007/05/22 07:48:08 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4DrawVoxels.hh

    r850 r921  
    2626//
    2727// $Id: G4DrawVoxels.hh,v 1.3 2006/06/29 18:35:36 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4ErrorPropagationNavigator.hh

    r850 r921  
    2525//
    2626//
    27 // $Id: G4ErrorPropagationNavigator.hh,v 1.1 2007/05/16 12:49:18 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4ErrorPropagationNavigator.hh,v 1.2 2008/10/24 14:00:03 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    6464
    6565    G4double ComputeSafety(const G4ThreeVector &globalpoint,
    66                            const G4double pProposedMaxLength = DBL_MAX);
     66                           const G4double pProposedMaxLength = DBL_MAX,
     67                           const G4bool keepState = false);
    6768      // Calls the navigation in the detector geometry and then checks
    6869      // if the distance to surface is smaller than the proposed safety
  • trunk/source/geometry/navigation/include/G4GeomTestErrorList.hh

    r850 r921  
    2626//
    2727// $Id: G4GeomTestErrorList.hh,v 1.3 2006/06/29 18:35:38 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/include/G4GeomTestLogger.hh

    r850 r921  
    2626//
    2727// $Id: G4GeomTestLogger.hh,v 1.3 2006/06/29 18:35:40 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/include/G4GeomTestOverlapList.hh

    r850 r921  
    2626//
    2727// $Id: G4GeomTestOverlapList.hh,v 1.3 2006/06/29 18:35:43 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/include/G4GeomTestOvershootList.hh

    r850 r921  
    2626//
    2727// $Id: G4GeomTestOvershootList.hh,v 1.3 2006/06/29 18:35:45 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/include/G4GeomTestPoint.hh

    r850 r921  
    2626//
    2727// $Id: G4GeomTestPoint.hh,v 1.3 2006/06/29 18:35:48 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/include/G4GeomTestSegment.hh

    r850 r921  
    2626//
    2727// $Id: G4GeomTestSegment.hh,v 1.4 2007/05/11 13:43:59 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/include/G4GeomTestStreamLogger.hh

    r850 r921  
    2626//
    2727// $Id: G4GeomTestStreamLogger.hh,v 1.3 2006/06/29 18:35:52 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/include/G4GeomTestVolPoint.hh

    r850 r921  
    2626//
    2727// $Id: G4GeomTestVolPoint.hh,v 1.3 2006/06/29 18:35:55 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/include/G4GeomTestVolume.hh

    r850 r921  
    2626//
    2727// $Id: G4GeomTestVolume.hh,v 1.3 2006/06/29 18:35:57 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/include/G4GeometryMessenger.hh

    r850 r921  
    2626//
    2727// $Id: G4GeometryMessenger.hh,v 1.4 2006/06/29 18:35:59 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/include/G4MultiNavigator.hh

    r850 r921  
    2525//
    2626//
    27 // $Id: G4MultiNavigator.hh,v 1.4 2007/05/21 15:36:25 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4MultiNavigator.hh,v 1.5 2008/10/24 14:00:03 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    113113
    114114  G4double ComputeSafety(const G4ThreeVector &globalpoint,
    115                          const G4double pProposedMaxLength = DBL_MAX);
     115                         const G4double pProposedMaxLength = DBL_MAX,
     116                         const G4bool keepState = false);
    116117    // Calculate the isotropic distance to the nearest boundary
    117118    // in any geometry from the specified point in the global coordinate
  • trunk/source/geometry/navigation/include/G4Navigator.hh

    r850 r921  
    2525//
    2626//
    27 // $Id: G4Navigator.hh,v 1.26 2007/10/18 14:18:36 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4Navigator.hh,v 1.27 2008/10/24 14:00:03 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    181181
    182182  virtual G4double ComputeSafety(const G4ThreeVector &globalpoint,
    183                                  const G4double pProposedMaxLength = DBL_MAX);
     183                                 const G4double pProposedMaxLength = DBL_MAX,
     184                                 const G4bool keepState = false);
    184185    // Calculate the isotropic distance to the nearest boundary from the
    185186    // specified point in the global coordinate system.
  • trunk/source/geometry/navigation/include/G4Navigator.icc

    r850 r921  
    2626//
    2727// $Id: G4Navigator.icc,v 1.15 2007/10/18 14:18:36 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4NormalNavigation.hh

    r850 r921  
    2626//
    2727// $Id: G4NormalNavigation.hh,v 1.4 2006/06/29 18:36:06 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4NormalNavigation.icc

    r850 r921  
    2626//
    2727// $Id: G4NormalNavigation.icc,v 1.4 2006/06/29 18:36:08 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4ParameterisedNavigation.hh

    r850 r921  
    2626//
    2727// $Id: G4ParameterisedNavigation.hh,v 1.6 2007/11/09 16:06:02 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4ParameterisedNavigation.icc

    r850 r921  
    2626//
    2727// $Id: G4ParameterisedNavigation.icc,v 1.7 2007/11/09 16:06:02 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4PathFinder.hh

    r850 r921  
    2525//
    2626// $Id: G4PathFinder.hh,v 1.34 2007/11/02 12:28:31 japost Exp $
    27 // GEANT4 tag $Name: HEAD $
     27// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2828//
    2929// class G4PathFinder
  • trunk/source/geometry/navigation/include/G4PhantomParameterisation.hh

    r850 r921  
    2626//
    2727// $Id: G4PhantomParameterisation.hh,v 1.4 2008/01/22 15:02:36 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4PhantomParameterisation.icc

    r850 r921  
    2626//
    2727// $Id: G4PhantomParameterisation.icc,v 1.1 2007/10/17 19:13:58 arce Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//--------------------------------------------------------------------
  • trunk/source/geometry/navigation/include/G4PropagatorInField.hh

    r850 r921  
    2424// ********************************************************************
    2525//
    26 //
    27 // $Id: G4PropagatorInField.hh,v 1.14 2008/05/28 09:11:59 tnikitin Exp $
    28 // GEANT4 tag $Name: HEAD $
    2926//
    30 // class G4PropagatorInField
    31 //
    32 // Class description:
     27// $Id: G4PropagatorInField.hh,v 1.17 2008/11/13 14:28:56 tnikitin Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
     29//
     30//
     31// Class G4PropagatorInField
     32//
     33// class description:
    3334//
    3435// This class performs the navigation/propagation of a particle/track
     
    3637// For the calculation of the path, it relies on the class G4ChordFinder.
    3738//
    38 // Key Method:
    39 //              ComputeStep(..)
     39// Key Method: ComputeStep(..)
     40
    4041// History:
    4142// -------
     
    5455#include "G4FieldTrack.hh"
    5556#include "G4FieldManager.hh"
     57#include "G4VIntersectionLocator.hh"
     58
    5659class G4ChordFinder;
    5760
     
    6669
    6770   G4PropagatorInField( G4Navigator    *theNavigator,
    68                         G4FieldManager *detectorFieldMgr );
     71                        G4FieldManager *detectorFieldMgr,
     72                        G4VIntersectionLocator *vLocator=0 );
    6973  ~G4PropagatorInField();
    7074
     
    116120   inline G4FieldTrack GetEndState() const;
    117121
    118    // The following methods are now obsolescent but *for now* will work
    119    //   They are being replaced by same-name methods in G4FieldManager,
    120    //   allowing the specialisation in different volumes.
    121    //   Their new behaviour is to change the values for the global field manager.
    122    inline G4double  GetMinimumEpsilonStep() const;
    123    inline void      SetMinimumEpsilonStep( G4double newEpsMin );
    124      // Minimum for Relative accuracy of any Step
    125 
     122   inline G4double  GetMinimumEpsilonStep() const;  // Min for relative accuracy
     123   inline void      SetMinimumEpsilonStep( G4double newEpsMin ); //  of any step
    126124   inline G4double  GetMaximumEpsilonStep() const;
    127125   inline void      SetMaximumEpsilonStep( G4double newEpsMax );
    128 
    129126   inline void      SetLargestAcceptableStep( G4double newBigDist );
    130127   inline G4double  GetLargestAcceptableStep();
     128     // The 6 above methods are now obsolescent but *for now* will work
     129     // They are being replaced by same-name methods in G4FieldManager,
     130     // allowing the specialisation in different volumes.
     131     // Their new behaviour is to change the values for the global field
     132     // manager
     133
     134   void SetTrajectoryFilter(G4VCurvedTrajectoryFilter* filter);
     135     // Set the filter that examines & stores 'intermediate'
     136     //  curved trajectory points.  Currently only position is stored.
     137
     138   std::vector<G4ThreeVector>* GimmeTrajectoryVectorAndForgetIt() const;
     139     // Access the points which have passed by the filter.
     140     // Responsibility for deleting the points lies with the client.
     141     // This method MUST BE called exactly ONCE per step.
     142
     143   void ClearPropagatorState();
     144     // Clear all the State of this class and its current associates
     145     //   --> the current field manager & chord finder will also be called
     146
     147   inline void SetDetectorFieldManager( G4FieldManager* newGlobalFieldManager );
     148     // Update this (dangerous) state -- for the time being
    131149 
    132      // Use alternative Locator(based on Brent Method,second order Intersection)
    133   inline void      SetBrentMethod(G4bool newLocator);
    134   inline G4bool    GetBrentMethod();
    135 
    136  public:  // with description
    137 
    138    // The following methods are obsolete and will not work --
    139    //   as they have been replaced by the same methods in G4FieldManager
    140    //   since Geant4 4.0
     150   inline void   SetUseSafetyForOptimization( G4bool );
     151   inline G4bool GetUseSafetyForOptimization();
     152     // Toggle & view parameter for using safety to discard
     153     //   unneccesary calls to navigator (thus 'optimising' performance)
     154   inline G4bool IntersectChord( G4ThreeVector  StartPointA,
     155                                 G4ThreeVector  EndPointB,
     156                                 G4double      &NewSafety,
     157                                 G4double      &LinearStepLength,
     158                                 G4ThreeVector &IntersectionPoint);
     159     // Intersect the chord from StartPointA to EndPointB
     160     // and return whether an intersection occurred
     161     // NOTE : SAFETY IS CHANGED
     162
     163   inline G4VIntersectionLocator* GetIntersectionLocator();
     164   inline void SetIntersectionLocator(G4VIntersectionLocator *pLocator );
     165 
     166 public:  // without description
     167
    141168   inline G4double  GetDeltaIntersection() const;
    142169   inline G4double  GetDeltaOneStep() const;
     
    144171   inline void    SetDeltaIntersection( G4double deltaIntersection );
    145172   inline void    SetDeltaOneStep( G4double deltaOneStep ); 
    146 
    147  public:  // without description
     173     // The above 5 methods are obsolete and will not work, as they have been
     174     // replaced by the same methods in G4FieldManager since Geant4 4.0 ...
    148175
    149176   inline G4FieldManager*  GetCurrentFieldManager();
    150177   inline void             SetNavigatorForPropagating( G4Navigator *SimpleOrMultiNavigator );
    151178   inline G4Navigator*     GetNavigatorForPropagating();
    152 
    153  public:  // no description
    154179
    155180   inline void SetThresholdNoZeroStep( G4int noAct,
     
    158183   inline G4int GetThresholdNoZeroSteps( G4int i );
    159184
    160  public:  // with description
    161   //
    162   void SetTrajectoryFilter(G4VCurvedTrajectoryFilter* filter);
    163   // Set the filter that examines & stores 'intermediate'
    164   //  curved trajectory points.  Currently only position is stored.
    165 
    166   std::vector<G4ThreeVector>* GimmeTrajectoryVectorAndForgetIt() const;
    167   // Access the points which have passed by the filter.
    168   // Responsibility for deleting the points lies with the client.
    169   // This method MUST BE called exactly ONCE per step.
    170 
    171   void ClearPropagatorState();
    172   // Clear all the State of this class and its current associates
    173   //   --> the current field manager & chord finder will also be called
    174 
    175   inline void SetDetectorFieldManager( G4FieldManager* newGlobalFieldManager );
    176       // Update this (dangerous) state -- for the time being
    177  
    178   inline void   SetUseSafetyForOptimization( G4bool );
    179   inline G4bool GetUseSafetyForOptimization();
    180       // Toggle & view parameter for using safety to discard
    181       //   unneccesary calls to navigator (thus 'optimising' performance)
    182 
    183185 protected:  // with description
    184 
    185    G4bool LocateIntersectionPoint(
    186         const  G4FieldTrack&       curveStartPointTangent,  //  A
    187         const  G4FieldTrack&       curveEndPointTangent,    //  B
    188         const  G4ThreeVector&      trialPoint,              //  E
    189                G4FieldTrack&       intersectPointTangent,   // Output
    190                G4bool&             recalculatedEndPoint);   // Out:
    191 
    192      // If such an intersection exists, this function
    193      // calculate the intersection point of the true path of the particle
    194      // with the surface of the current volume (or of one of its daughters).
    195      // (Should use lateral displacement as measure of convergence).
    196 
    197    G4bool IntersectChord( G4ThreeVector  StartPointA,
    198                           G4ThreeVector  EndPointB,
    199                           G4double      &NewSafety,
    200                           G4double      &LinearStepLength,
    201                           G4ThreeVector &IntersectionPoint);
    202      // Intersect the chord from StartPointA to EndPointB
    203      // and return whether an intersection occurred
    204 
    205    G4FieldTrack ReEstimateEndpoint( const G4FieldTrack &CurrentStateA, 
    206                                     const G4FieldTrack &EstimtdEndStateB,
    207                                           G4double      linearDistSq,
    208                                           G4double      curveDist);
    209      // Return new estimate for state after curveDist
    210      // starting from CurrentStateA,  to replace EstimtdEndStateB,
    211      // (and report displacement -- if field is compiled verbose.)
    212186
    213187   void PrintStepLengthDiagnostic( G4double      currentProposedStepLength,
     
    217191 private:
    218192
    219   // ----------------------------------------------------------------------
    220   //  DATA Members
    221   // ----------------------------------------------------------------------
     193   // ----------------------------------------------------------------------
     194   //  DATA Members
     195   // ----------------------------------------------------------------------
    222196
    223197   G4FieldManager *fDetectorFieldMgr;
     
    228202
    229203   G4Navigator   *fNavigator;
    230 
     204 
    231205   //  STATE information
    232206   //  -----------------
     
    270244     // Geometrical tolerance defining surface thickness
    271245
    272   G4int maxNumberOfStepsForIntersection;
    273   G4int maxNumberOfCallsToReIntegration;
    274   G4int maxNumberOfCallsToReIntegration_depth;
    275     //  Counters for Statistics about Location and ReIntegrations
    276 private:
    277 
    278    static const G4int max_depth=4;
    279    G4FieldTrack* ptrInterMedFT[max_depth+1];
    280      // Used to store intermediate values of tracks in case of
    281      // too slow progress
    282 private:
    283    G4bool fUseBrentLocator;
    284    
    285 private:
    286 
    287   G4VCurvedTrajectoryFilter* fpTrajectoryFilter;
    288     // The filter encapsulates the algorithm which selects which
    289     // intermediate points should be stored in a trajectory.
    290     // When it is NULL, no intermediate points will be stored.
    291     // Else PIF::ComputeStep must submit (all) intermediate
    292     // points it calculates, to this filter.  (jacek 04/11/2002)
     246   G4VIntersectionLocator *fIntersectionLocator;
     247   G4bool fAllocatedLocator;
     248     // Used to Intersection Locator
     249
     250 private:
     251
     252   G4VCurvedTrajectoryFilter* fpTrajectoryFilter;
     253     // The filter encapsulates the algorithm which selects which
     254     // intermediate points should be stored in a trajectory.
     255     // When it is NULL, no intermediate points will be stored.
     256     // Else PIF::ComputeStep must submit (all) intermediate
     257     // points it calculates, to this filter.  (jacek 04/11/2002)
    293258};
    294259
  • trunk/source/geometry/navigation/include/G4PropagatorInField.icc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4PropagatorInField.icc,v 1.11 2008/05/28 09:12:05 tnikitin Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4PropagatorInField.icc,v 1.13 2008/10/29 14:31:55 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    268268}
    269269
    270 inline
    271 void G4PropagatorInField::SetBrentMethod(G4bool newLocator)
    272 {
    273   fUseBrentLocator=newLocator;
    274 }
    275 inline
    276 G4bool G4PropagatorInField::GetBrentMethod()
    277 {
    278   return fUseBrentLocator;
    279 }
     270inline
     271void G4PropagatorInField::
     272SetIntersectionLocator( G4VIntersectionLocator *pIntLoc )
     273{
     274  if(pIntLoc)  { fIntersectionLocator= pIntLoc; }
     275}
     276
     277inline
     278G4VIntersectionLocator* G4PropagatorInField::GetIntersectionLocator()
     279{
     280  return fIntersectionLocator;
     281}
     282
     283inline
     284G4bool G4PropagatorInField::IntersectChord( G4ThreeVector  StartPointA,
     285                                            G4ThreeVector  EndPointB,
     286                                            G4double      &NewSafety,
     287                                            G4double      &LinearStepLength,
     288                                            G4ThreeVector &IntersectionPoint )
     289{
     290  // Calculate the direction and length of the chord AB
     291  //
     292  return fIntersectionLocator
     293         ->IntersectChord(StartPointA,EndPointB,NewSafety,
     294                          fPreviousSafety,fPreviousSftOrigin,
     295                          LinearStepLength,IntersectionPoint);
     296}
  • trunk/source/geometry/navigation/include/G4RegularNavigation.hh

    r850 r921  
    2626//
    2727// $Id: G4RegularNavigation.hh,v 1.2 2007/10/18 14:18:36 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4ReplicaNavigation.hh

    r850 r921  
    2626//
    2727// $Id: G4ReplicaNavigation.hh,v 1.6 2007/05/18 07:31:09 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4ReplicaNavigation.icc

    r850 r921  
    2626//
    2727// $Id: G4ReplicaNavigation.icc,v 1.5 2006/06/29 18:36:22 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4SafetyHelper.hh

    r850 r921  
    2626//
    2727// $Id: G4SafetyHelper.hh,v 1.7 2007/05/02 15:32:13 japost Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4TransportationManager.hh

    r850 r921  
    2626//
    2727// $Id: G4TransportationManager.hh,v 1.12 2007/04/20 15:28:37 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// class G4TransportationManager
  • trunk/source/geometry/navigation/include/G4TransportationManager.icc

    r850 r921  
    2626//
    2727// $Id: G4TransportationManager.icc,v 1.10 2007/04/20 15:28:37 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929// ------------------------------------------------------------
    3030//  GEANT 4  inlined function members implementation
  • trunk/source/geometry/navigation/include/G4VoxelNavigation.hh

    r850 r921  
    2626//
    2727// $Id: G4VoxelNavigation.hh,v 1.5 2007/05/11 13:43:59 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/include/G4VoxelNavigation.icc

    r850 r921  
    2626//
    2727// $Id: G4VoxelNavigation.icc,v 1.4 2006/06/29 18:36:30 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/src/G4AuxiliaryNavServices.cc

    r850 r921  
    2525//
    2626// $Id: G4AuxiliaryNavServices.cc,v 1.3 2006/06/29 18:36:32 gunter Exp $
    27 // GEANT4 tag $Name: HEAD $
     27// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2828//
    2929// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/src/G4DrawVoxels.cc

    r850 r921  
    2626//
    2727// $Id: G4DrawVoxels.cc,v 1.4 2006/06/29 18:36:34 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/src/G4ErrorPropagationNavigator.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4ErrorPropagationNavigator.cc,v 1.1 2007/05/16 12:49:18 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4ErrorPropagationNavigator.cc,v 1.2 2008/10/24 14:00:03 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    126126G4double G4ErrorPropagationNavigator::
    127127ComputeSafety( const G4ThreeVector &pGlobalpoint,
    128                const G4double pMaxLength )
     128               const G4double pMaxLength,
     129               const G4bool keepState )
    129130{
    130   G4double newSafety = G4Navigator::ComputeSafety(pGlobalpoint, pMaxLength);
     131  G4double newSafety = G4Navigator::ComputeSafety(pGlobalpoint,
     132                                                  pMaxLength, keepState);
    131133
    132134  G4ErrorPropagatorData *g4edata
  • trunk/source/geometry/navigation/src/G4GeomTestErrorList.cc

    r850 r921  
    2626//
    2727// $Id: G4GeomTestErrorList.cc,v 1.3 2006/06/29 18:36:36 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/src/G4GeomTestOverlapList.cc

    r850 r921  
    2626//
    2727// $Id: G4GeomTestOverlapList.cc,v 1.3 2006/06/29 18:36:39 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/src/G4GeomTestOvershootList.cc

    r850 r921  
    2626//
    2727// $Id: G4GeomTestOvershootList.cc,v 1.3 2006/06/29 18:36:41 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/src/G4GeomTestPoint.cc

    r850 r921  
    2626//
    2727// $Id: G4GeomTestPoint.cc,v 1.3 2006/06/29 18:36:44 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/src/G4GeomTestSegment.cc

    r850 r921  
    2626//
    2727// $Id: G4GeomTestSegment.cc,v 1.11 2007/11/16 09:39:14 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/src/G4GeomTestStreamLogger.cc

    r850 r921  
    2626//
    2727// $Id: G4GeomTestStreamLogger.cc,v 1.3 2006/06/29 18:36:49 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/src/G4GeomTestVolPoint.cc

    r850 r921  
    2626//
    2727// $Id: G4GeomTestVolPoint.cc,v 1.3 2006/06/29 18:36:52 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/src/G4GeomTestVolume.cc

    r850 r921  
    2626//
    2727// $Id: G4GeomTestVolume.cc,v 1.6 2007/11/16 09:39:14 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/src/G4GeometryMessenger.cc

    r850 r921  
    2626//
    2727// $Id: G4GeometryMessenger.cc,v 1.5 2006/06/29 18:36:57 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
  • trunk/source/geometry/navigation/src/G4MultiNavigator.cc

    r831 r921  
    2525//
    2626//
    27 // $Id: G4MultiNavigator.cc,v 1.7 2007/11/02 13:48:43 japost Exp $
     27// $Id: G4MultiNavigator.cc,v 1.8 2008/10/24 14:00:03 gcosmo Exp $
    2828// GEANT4 tag $ Name:  $
    2929//
     
    423423
    424424G4double G4MultiNavigator::ComputeSafety( const G4ThreeVector& position,
    425                                                 G4double       maxDistance)
     425                                          const G4double       maxDistance,
     426                                          const G4bool         state)
    426427{
    427428    // Recompute safety for the relevant point
     
    434435    for( register int num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
    435436    {
    436        safety = (*pNavigatorIter)->ComputeSafety( position, maxDistance );
     437       safety = (*pNavigatorIter)->ComputeSafety( position, maxDistance, state);
    437438       if( safety < minSafety ) { minSafety = safety; }
    438439    }
  • trunk/source/geometry/navigation/src/G4Navigator.cc

    r831 r921  
    2525//
    2626//
    27 // $Id: G4Navigator.cc,v 1.37 2007/10/18 14:18:36 gcosmo Exp $
     27// $Id: G4Navigator.cc,v 1.38 2008/10/24 14:00:03 gcosmo Exp $
    2828// GEANT4 tag $ Name:  $
    2929//
     
    12141214//
    12151215G4double G4Navigator::ComputeSafety( const G4ThreeVector &pGlobalpoint,
    1216                                      const G4double pMaxLength)
     1216                                     const G4double pMaxLength,
     1217                                     const G4bool keepState)
    12171218{
    12181219  G4double newSafety = 0.0;
     
    12351236  }
    12361237#endif
     1238
     1239  if (keepState)  { SetSavedState(); }
    12371240
    12381241  G4double distEndpointSq = (pGlobalpoint-fStepEndPoint).mag2();
     
    13221325  fPreviousSafety = newSafety;
    13231326
     1327  if (keepState)  { RestoreSavedState(); }
     1328
    13241329#ifdef G4DEBUG_NAVIGATION
    13251330  if( fVerbose > 1 )
  • trunk/source/geometry/navigation/src/G4NormalNavigation.cc

    r850 r921  
    2626//
    2727// $Id: G4NormalNavigation.cc,v 1.9 2007/05/11 13:43:59 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/src/G4ParameterisedNavigation.cc

    r850 r921  
    2626//
    2727// $Id: G4ParameterisedNavigation.cc,v 1.12 2007/11/09 16:06:02 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/src/G4PathFinder.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4PathFinder.cc,v 1.59 2008/04/29 15:32:54 gcosmo Exp $
     27// $Id: G4PathFinder.cc,v 1.61 2008/11/13 12:59:26 gcosmo Exp $
    2828// GEANT4 tag $ Name:  $
    2929//
     
    581581  if( (!fNewTrack) && ( longMoveEnd && longMoveSaf ) )
    582582  { 
    583      G4ThreeVector  LastSafetyLocation;
    584        // Copy to keep last value - and restore
    585 
    586      LastSafetyLocation= fSafetyLocation;
    587 
    588583     // Recompute ComputeSafety for end position
    589584     //
    590585     revisedSafety= ComputeSafety(lastEndPosition);
    591 
    592      // Reset the state of last call to ComputeSafety
    593      //
    594      ComputeSafety( LastSafetyLocation );
    595586
    596587#ifdef G4DEBUG_PATHFINDER
     
    757748 
    758749   std::vector<G4Navigator*>::iterator pNavigatorIter;
    759    pNavigatorIter= fpTransportManager-> GetActiveNavigatorsIterator();
     750   pNavigatorIter= fpTransportManager->GetActiveNavigatorsIterator();
    760751
    761752   for( register G4int num=0; num<fNoActiveNavigators; ++pNavigatorIter,++num )
    762753   {
    763       G4double safety = (*pNavigatorIter)->ComputeSafety( position );
     754      G4double safety = (*pNavigatorIter)->ComputeSafety( position,true );
    764755      if( safety < minSafety ) { minSafety = safety; }
    765756      fNewSafetyComputed[num]= safety;
     
    11831174     for( numNav=0; numNav < fNoActiveNavigators; ++numNav )
    11841175     {
    1185         safety= fpNavigator[numNav]->ComputeSafety( startPoint );
     1176        safety= fpNavigator[numNav]->ComputeSafety( startPoint, false );
    11861177        fPreSafetyValues[numNav]= safety;
    11871178        fCurrentPreStepSafety[numNav]= safety;
  • trunk/source/geometry/navigation/src/G4PropagatorInField.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4PropagatorInField.cc,v 1.43 2008/05/28 09:12:23 tnikitin Exp $
    28 // GEANT4 tag $Name: HEAD $
    2927//
    3028//
     
    5048#include "G4VCurvedTrajectoryFilter.hh"
    5149#include "G4ChordFinder.hh"
     50#include "G4BrentLocator.hh"
    5251
    5352///////////////////////////////////////////////////////////////////////////
     
    5655
    5756G4PropagatorInField::G4PropagatorInField( G4Navigator    *theNavigator,
    58                                           G4FieldManager *detectorFieldMgr )
     57                                          G4FieldManager *detectorFieldMgr,
     58                                          G4VIntersectionLocator *vLocator  )
    5959  : fDetectorFieldMgr(detectorFieldMgr),
    6060    fCurrentFieldMgr(detectorFieldMgr),
     
    8383  fPreviousSafety= 0.0;
    8484  kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
    85   //
    86   fUseBrentLocator=true;
    87   // In case of too slow progress in finding Intersection Point
    88   // intermediates Points on the Track must be stored.
    89   // Initialise the array of Pointers [max_depth+1] to do this 
    90   G4ThreeVector zeroV(0.0,0.0,0.0);
    91   for (G4int idepth=0; idepth<max_depth+1; idepth++ )
    92   {
    93     ptrInterMedFT[ idepth ] = new G4FieldTrack( zeroV, zeroV, 0., 0., 0., 0.);
    94   }
    95   // Counter for Maximum Number Of Trial before Intersection Found
    96     maxNumberOfStepsForIntersection=0;
    97  // Counter for Number Of Calls to ReIntegrationEndPoint Method
    98     maxNumberOfCallsToReIntegration=0;
    99     maxNumberOfCallsToReIntegration_depth=0;
     85
     86  // Definding Intersection Locator and his parameters
     87  if(vLocator==0){
     88    fIntersectionLocator= new G4BrentLocator(theNavigator);
     89    fAllocatedLocator=true;
     90  }else{
     91    fIntersectionLocator=vLocator;
     92    fAllocatedLocator=false;
     93  }
     94  fIntersectionLocator->SetEpsilonStepFor(fEpsilonStep);
     95  fIntersectionLocator->SetDeltaIntersectionFor(GetDeltaIntersection());
     96  fIntersectionLocator->SetChordFinderFor(GetChordFinder());
     97  fIntersectionLocator->SetSafetyParametersFor( fUseSafetyForOptimisation);
    10098}
    10199
    102100G4PropagatorInField::~G4PropagatorInField()
    103101{
    104   for ( G4int idepth=0; idepth<max_depth+1; idepth++)
    105   {
    106     delete ptrInterMedFT[idepth];
    107   }
    108   if(fVerboseLevel>0){
    109   G4cout<<"G4PropagatorInField::Location with Max Number of Steps="
    110        << maxNumberOfStepsForIntersection<<G4endl;
    111   G4cout<<"G4PropagatorInField::ReIntegrateEndPoint was called "<<
    112     maxNumberOfCallsToReIntegration<<" times and for depth algorithm "<<
    113     maxNumberOfCallsToReIntegration_depth<<" times"<<G4endl;
    114   }
     102  if(fAllocatedLocator)delete  fIntersectionLocator;
    115103}
    116104
     
    162150  fSetFieldMgr= false;
    163151
    164   GetChordFinder()->SetChargeMomentumMass(fCharge, fInitialMomentumModulus, fMass); 
    165  
     152  GetChordFinder()->SetChargeMomentumMass(fCharge, fInitialMomentumModulus, fMass);
     153
     154 // Values for Intersection Locator has to be updated on each call
     155 // because the CurrentFieldManager changes
     156    fIntersectionLocator->SetChordFinderFor(GetChordFinder());
     157    fIntersectionLocator->SetSafetyParametersFor( fUseSafetyForOptimisation);
     158    fIntersectionLocator->SetEpsilonStepFor(fEpsilonStep);
     159    fIntersectionLocator->SetDeltaIntersectionFor(GetDeltaIntersection());
     160
    166161  G4FieldTrack  CurrentState(pFieldTrack);
    167162  G4FieldTrack  OriginalState = CurrentState;
     
    300295       //   of vol(A), if it exists. Start with point E as first "estimate".
    301296       G4bool recalculatedEndPt= false;
    302        G4bool found_intersection =
    303          LocateIntersectionPoint( SubStepStartState, CurrentState,
     297       
     298         G4bool found_intersection = fIntersectionLocator->
     299         EstimateIntersectionPoint( SubStepStartState, CurrentState,
    304300                                  InterSectionPointE, IntersectPointVelct_G,
    305                                   recalculatedEndPt);
    306        // G4cout<<"In Locate"<<recalculatedEndPt<<"  and V"<<IntersectPointVelct_G.GetPosition()<<G4endl;
     301                                  recalculatedEndPt,fPreviousSafety,fPreviousSftOrigin);
    307302       intersects = intersects && found_intersection;
    308303       if( found_intersection ) {       
     
    432427 
    433428  return TruePathLength;
    434 }
    435 
    436 // --------------------------------------------------------------------------
    437 // G4bool
    438 // G4PropagatorInField::LocateIntersectionPoint(
    439 //   const G4FieldTrack&       CurveStartPointVelocity,   //  A
    440 //   const G4FieldTrack&       CurveEndPointVelocity,     //  B
    441 //   const G4ThreeVector&      TrialPoint,                //  E
    442 //         G4FieldTrack&       IntersectedOrRecalculated  // Output
    443 //         G4bool&             recalculated)              // Out
    444 // --------------------------------------------------------------------------
    445 //
    446 // Function that returns the intersection of the true path with the surface
    447 // of the current volume (either the external one or the inner one with one
    448 // of the daughters
    449 //
    450 //     A = Initial point
    451 //     B = another point
    452 //
    453 // Both A and B are assumed to be on the true path.
    454 //
    455 //     E is the first point of intersection of the chord AB with
    456 //     a volume other than A  (on the surface of A or of a daughter)
    457 //
    458 // Convention of Use :
    459 //     i) If it returns "true", then IntersectionPointVelocity is set
    460 //       to the approximate intersection point.
    461 //    ii) If it returns "false", no intersection was found.
    462 //          The validity of IntersectedOrRecalculated depends on 'recalculated'
    463 //        a) if latter is false, then IntersectedOrRecalculated is invalid.
    464 //        b) if latter is true,  then IntersectedOrRecalculated is
    465 //             the new endpoint, due to a re-integration.
    466 // --------------------------------------------------------------------------
    467 
    468 G4bool
    469 G4PropagatorInField::LocateIntersectionPoint(
    470   const   G4FieldTrack&       CurveStartPointVelocity,   //  A
    471   const   G4FieldTrack&       CurveEndPointVelocity,     //  B
    472   const   G4ThreeVector&      TrialPoint,                //  E
    473           G4FieldTrack&       IntersectedOrRecalculatedFT, // Out: point found
    474           G4bool&             recalculatedEndPoint)        // Out:
    475 {
    476   // Find Intersection Point ( A, B, E )  of true path AB - start at E.
    477 
    478   G4bool found_approximate_intersection = false;
    479   G4bool there_is_no_intersection       = false;
    480  
    481   G4FieldTrack  CurrentA_PointVelocity = CurveStartPointVelocity;
    482   G4FieldTrack  CurrentB_PointVelocity = CurveEndPointVelocity;
    483   G4ThreeVector CurrentE_Point = TrialPoint;
    484   G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity); // FT-Def-Construct
    485   G4double    NewSafety= -0.0;
    486  
    487   G4bool final_section= true;  // Shows whether current section is last
    488                                // (i.e. B=full end)
    489   G4bool first_section=true;
    490   recalculatedEndPoint= false;
    491  
    492   G4bool restoredFullEndpoint= false;
    493 
    494   G4int substep_no = 0;
    495    
    496   // Limits for substep number
    497   //
    498   const G4int max_substeps=   10000;  // Test 120  (old value 100 )
    499   const G4int warn_substeps=   1000;  //      100 
    500 
    501   // Statistics for substeps
    502   //
    503   static G4int max_no_seen= -1;
    504   static G4int trigger_substepno_print= warn_substeps - 20 ;
    505  
    506   //-------------------------------------------------------------------------- 
    507   //  Algoritm for the case if progress in founding intersection is too slow.
    508   //  Process is defined too slow if after N=param_substeps advances on the
    509   //  path, it will be only 'fraction_done' of the total length.
    510   //  In this case the remaining length is divided in two half and
    511   //  the loop is restarted for each half. 
    512   //  If progress is still too slow, the division in two halfs continue
    513   //  until 'max_depth'.
    514   //--------------------------------------------------------------------------
    515   G4double count_did_len=0.;
    516   G4double count_all_len=0;
    517   G4int param_substeps=100;//Test value for the maximum number of substeps
    518   if(!fUseBrentLocator)  param_substeps=10;// Reduced value for the maximum number
    519 
    520   const G4double fraction_done=0.3;
    521 
    522   G4bool Second_half=false;      // First half or second half of divided step
    523 
    524   // We need to know this for the 'final_section':
    525   // real 'final_section' or first half 'final_section'
    526   // In algorithm it is considered that the 'Second_half' is true
    527   // and it becomes false only if we are in the first-half of level
    528   // depthness or if we are in the first section
    529 
    530   G4int depth=0; // Depth counts how many subdivisions of initial step made
    531 
    532 #ifdef G4DEBUG_FIELD
    533   static G4double tolerance= 1.0e-8;
    534   G4ThreeVector  StartPosition= CurveStartPointVelocity.GetPosition();
    535   if( (TrialPoint - StartPosition).mag() < tolerance * mm )
    536   {
    537      G4cerr << "WARNING - G4PropagatorInField::LocateIntersectionPoint()"
    538             << G4endl
    539             << "          Intermediate F point is on top of starting point A."
    540             << G4endl;
    541      G4Exception("G4PropagatorInField::LocateIntersectionPoint()",
    542                  "IntersectionPointIsAtStart", JustWarning,
    543                  "Intersection point F is exactly at start point A." );
    544   }
    545 #endif
    546 
    547   // Intermediates Points on the Track = Subdivided Points must be stored.
    548   // Give the initial values to 'InterMedFt'
    549   // Important is 'ptrInterMedFT[0]', it saves the 'EndCurvePoint'
    550   //
    551   *ptrInterMedFT[0] = CurveEndPointVelocity;
    552   for (G4int idepth=1; idepth<max_depth+1; idepth++ )
    553   {
    554     *ptrInterMedFT[idepth]=CurveStartPointVelocity;
    555   }
    556 
    557   // 'SubStartPoint' is needed to calculate the length of the divided step
    558   //
    559   G4FieldTrack SubStart_PointVelocity = CurveStartPointVelocity;
    560    
    561   do
    562   {
    563     G4int substep_no_p = 0;
    564     G4bool sub_final_section = false; // the same as final_section,
    565                                       // but for 'sub_section'
    566     do // REPEAT param
    567     {
    568       G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition(); 
    569       G4ThreeVector Point_B = CurrentB_PointVelocity.GetPosition();
    570        
    571       // F = a point on true AB path close to point E
    572       // (the closest if possible)
    573       //
    574       if((!fUseBrentLocator)||(substep_no_p==0)){
    575        ApproxIntersecPointV = GetChordFinder()
    576                              ->ApproxCurvePointV( CurrentA_PointVelocity,
    577                                                   CurrentB_PointVelocity,
    578                                                   CurrentE_Point,
    579                                                   fEpsilonStep );
    580       //  The above method is the key & most intuitive part ...
    581       }
    582 #ifdef G4DEBUG_FIELD
    583       if( ApproxIntersecPointV.GetCurveLength() >
    584           CurrentB_PointVelocity.GetCurveLength() * (1.0 + tolerance) )
    585       {
    586         G4cerr << "ERROR - G4PropagatorInField::LocateIntersectionPoint()"
    587                << G4endl
    588                << "        Intermediate F point is more advanced than"
    589                << " endpoint B." << G4endl;
    590         G4Exception("G4PropagatorInField::LocateIntersectionPoint()",
    591                     "IntermediatePointConfusion", FatalException,
    592                     "Intermediate F point is past end B point" );
    593       }
    594 #endif
    595 
    596       G4ThreeVector CurrentF_Point= ApproxIntersecPointV.GetPosition();
    597       if(substep_no> maxNumberOfStepsForIntersection)maxNumberOfStepsForIntersection=substep_no; 
    598       // First check whether EF is small - then F is a good approx. point
    599       // Calculate the length and direction of the chord AF
    600       //
    601       G4ThreeVector  ChordEF_Vector = CurrentF_Point - CurrentE_Point;
    602 
    603       if ( ChordEF_Vector.mag2() <= sqr(GetDeltaIntersection()) )
    604       {
    605         found_approximate_intersection = true;
    606         // Create the "point" return value
    607         //
    608         IntersectedOrRecalculatedFT = ApproxIntersecPointV;
    609         IntersectedOrRecalculatedFT.SetPosition( CurrentE_Point );
    610        
    611         // Note: in order to return a point on the boundary,
    612         //       we must return E. But it is F on the curve.
    613         //       So we must "cheat": we are using the position at point E
    614         //       and the velocity at point F !!!
    615         //
    616         // This must limit the length we can allow for displacement!
    617       }
    618       else  // E is NOT close enough to the curve (ie point F)
    619       {
    620         // Check whether any volumes are encountered by the chord AF
    621         // ---------------------------------------------------------
    622         // First relocate to restore any Voxel etc information
    623         // in the Navigator before calling ComputeStep()
    624         //
    625         fNavigator->LocateGlobalPointWithinVolume( Point_A );
    626 
    627         G4ThreeVector PointG;   // Candidate intersection point
    628         G4double stepLengthAF;
    629         G4bool Intersects_AF = IntersectChord( Point_A,   CurrentF_Point,
    630                                                NewSafety, stepLengthAF,
    631                                                PointG );
    632         if( Intersects_AF )
    633         {
    634           if(fUseBrentLocator){
    635            
    636             G4FieldTrack EndPoint=ApproxIntersecPointV;
    637             ApproxIntersecPointV= GetChordFinder()->ApproxCurvePointS(
    638                    CurrentA_PointVelocity,CurrentB_PointVelocity,
    639                    CurrentE_Point,CurrentF_Point,PointG,true,fEpsilonStep);
    640             CurrentB_PointVelocity =  EndPoint;
    641             CurrentE_Point = PointG;
    642           // By moving point B, must take care if current
    643           // AF has no intersection to try current FB!!
    644           //
    645           final_section= false;
    646 
    647           }
    648           else{
    649           // G is our new Candidate for the intersection point.
    650           // It replaces  "E" and we will repeat the test to see if
    651           // it is a good enough approximate point for us.
    652           //       B    <- F
    653           //       E    <- G
    654 
    655           CurrentB_PointVelocity = ApproxIntersecPointV;
    656           CurrentE_Point = PointG; 
    657      
    658           // By moving point B, must take care if current
    659           // AF has no intersection to try current FB!!
    660           //
    661           final_section= false;
    662           }
    663 #ifdef G4VERBOSE
    664           if( fVerboseLevel > 3 )
    665           {
    666             G4cout << "G4PiF::LI> Investigating intermediate point"
    667                    << " at s=" << ApproxIntersecPointV.GetCurveLength()
    668                    << " on way to full s="
    669                    << CurveEndPointVelocity.GetCurveLength() << G4endl;
    670           }
    671 #endif
    672         }
    673         else  // not Intersects_AF
    674         { 
    675           // In this case:
    676           // There is NO intersection of AF with a volume boundary.
    677           // We must continue the search in the segment FB!
    678           //
    679           fNavigator->LocateGlobalPointWithinVolume( CurrentF_Point );
    680 
    681           G4double stepLengthFB;
    682           G4ThreeVector PointH;
    683 
    684           // Check whether any volumes are encountered by the chord FB
    685           // ---------------------------------------------------------
    686 
    687           G4bool Intersects_FB = IntersectChord( CurrentF_Point, Point_B,
    688                                                  NewSafety, stepLengthFB,
    689                                                  PointH );
    690           if( Intersects_FB )
    691           {
    692             if(fUseBrentLocator){
    693                CurrentA_PointVelocity = ApproxIntersecPointV;
    694                ApproxIntersecPointV= GetChordFinder()->ApproxCurvePointS(
    695                    CurrentA_PointVelocity,CurrentB_PointVelocity,
    696                    CurrentE_Point,Point_A,PointH,false,fEpsilonStep);
    697                CurrentE_Point = PointH;
    698            }
    699            else{
    700  
    701             // There is an intersection of FB with a volume boundary
    702             // H <- First Intersection of Chord FB
    703 
    704             // H is our new Candidate for the intersection point.
    705             // It replaces  "E" and we will repeat the test to see if
    706             // it is a good enough approximate point for us.
    707 
    708             // Note that F must be in volume volA  (the same as A)
    709             // (otherwise AF would meet a volume boundary!)
    710             //   A    <- F
    711             //   E    <- H
    712 
    713             CurrentA_PointVelocity = ApproxIntersecPointV;
    714             CurrentE_Point = PointH;
    715            }
    716           }
    717           else  // not Intersects_FB
    718           {
    719             // There is NO intersection of FB with a volume boundary
    720 
    721             if( final_section  )
    722             {
    723               // If B is the original endpoint, this means that whatever
    724               // volume(s) intersected the original chord, none touch the
    725               // smaller chords we have used.
    726               // The value of 'IntersectedOrRecalculatedFT' returned is
    727               // likely not valid
    728 
    729               // Check on real final_section or SubEndSection
    730               //
    731               if( ((Second_half)&&(depth==0)) || (first_section) )
    732               {
    733                 there_is_no_intersection = true;   // real final_section
    734               }
    735               else
    736               {
    737                 // end of subsection, not real final section
    738                 // exit from the and go to the depth-1 level
    739 
    740                 substep_no_p = param_substeps+2;  // exit from the loop
    741 
    742                 // but 'Second_half' is still true because we need to find
    743                 // the 'CurrentE_point' for the next loop
    744                 //
    745                 Second_half = true;
    746                 sub_final_section = true;
    747            
    748               }
    749             }
    750             else
    751             {
    752               // We must restore the original endpoint
    753 
    754               CurrentA_PointVelocity = CurrentB_PointVelocity;  // Got to B
    755               CurrentB_PointVelocity = CurveEndPointVelocity;
    756               restoredFullEndpoint = true;
    757             }
    758           } // Endif (Intersects_FB)
    759         } // Endif (Intersects_AF)
    760 
    761         // Ensure that the new endpoints are not further apart in space
    762         // than on the curve due to different errors in the integration
    763         //
    764         G4double linDistSq, curveDist;
    765         linDistSq = ( CurrentB_PointVelocity.GetPosition()
    766                     - CurrentA_PointVelocity.GetPosition() ).mag2();
    767         curveDist = CurrentB_PointVelocity.GetCurveLength()
    768                     - CurrentA_PointVelocity.GetCurveLength();
    769          if( curveDist*curveDist*(1+2*fEpsilonStep ) < linDistSq )
    770         {
    771           // Re-integrate to obtain a new B
    772           //
    773           G4FieldTrack newEndPointFT=
    774                   ReEstimateEndpoint( CurrentA_PointVelocity,
    775                                       CurrentB_PointVelocity,
    776                                       linDistSq,    // to avoid recalculation
    777                                       curveDist );
    778           G4FieldTrack oldPointVelB = CurrentB_PointVelocity;
    779           CurrentB_PointVelocity = newEndPointFT;
    780           maxNumberOfCallsToReIntegration= maxNumberOfCallsToReIntegration+1;
    781           #ifdef G4DEBUG_FIELD
    782           G4cout<<"G4PIF::Call ReIntEnd1 linD="<<std::sqrt(linDistSq)<<" curve="<<curveDist<<" n="<<substep_no<<G4endl;
    783           G4cout<<"G4PIF::Call ReIntEnd2 IntersectAF="<< Intersects_AF<<" final_section="<<final_section<<G4endl;
    784           #endif
    785           if( (final_section)&&(Second_half)&&(depth==0) ) // real final section
    786           {
    787             recalculatedEndPoint = true;
    788             IntersectedOrRecalculatedFT = newEndPointFT;
    789               // So that we can return it, if it is the endpoint!
    790           }
    791          
    792         }
    793    
    794         if( curveDist < 0.0 )
    795         {
    796           G4cerr << "ERROR - G4PropagatorInField::LocateIntersectionPoint()"
    797                  << G4endl
    798                  << "        Error in advancing propagation." << G4endl;
    799           fVerboseLevel = 5; // Print out a maximum of information
    800           printStatus( CurrentA_PointVelocity,  CurrentB_PointVelocity,
    801                        -1.0, NewSafety,  substep_no, 0 );
    802           G4cerr << "        Point A (start) is " << CurrentA_PointVelocity
    803                  << G4endl;
    804           G4cerr << "        Point B (end)   is " << CurrentB_PointVelocity
    805                  << G4endl;
    806           G4cerr << "        Curve distance is " << curveDist << G4endl;
    807           G4cerr << G4endl
    808                  << "The final curve point is not further along"
    809                  << " than the original!" << G4endl;
    810           if( recalculatedEndPoint )
    811           {
    812             G4cerr << "Recalculation of EndPoint was called with fEpsStep= "
    813                    << fEpsilonStep << G4endl;
    814           }
    815           G4cerr.precision(20);
    816           G4cerr << " Point A (Curve start)   is " << CurveStartPointVelocity
    817                  << G4endl;
    818           G4cerr << " Point B (Curve   end)   is " << CurveEndPointVelocity
    819                  << G4endl;
    820           G4cerr << " Point A (Current start) is " << CurrentA_PointVelocity
    821                  << G4endl;
    822           G4cerr << " Point B (Current end)   is " << CurrentB_PointVelocity
    823                  << G4endl;
    824           G4cerr << " Point S (Sub start)     is " << SubStart_PointVelocity
    825                  << G4endl;
    826           G4cerr << " Point E (Trial Point)   is " << CurrentE_Point
    827                  << G4endl;
    828           G4cerr << " Point F (Intersection)  is " << ApproxIntersecPointV
    829                  << G4endl;
    830           G4cerr << "        LocateIntersection parameters are : Substep no= "
    831                  << substep_no << G4endl;
    832           G4cerr << "        Substep depth no= "<< substep_no_p  << " Depth= "
    833                  << depth << G4endl;
    834           G4cerr << "        did_len= "<< count_did_len  << " all_len= "
    835                  << count_all_len << G4endl;
    836           G4Exception("G4PropagatorInField::LocateIntersectionPoint()",
    837                       "FatalError", FatalException,
    838                       "Error in advancing propagation.");
    839         }
    840        
    841         if(restoredFullEndpoint)
    842         {
    843           final_section = restoredFullEndpoint;
    844           restoredFullEndpoint = false;
    845         }
    846       } // EndIf ( E is close enough to the curve, ie point F. )
    847         // tests ChordAF_Vector.mag() <= maximum_lateral_displacement
    848 
    849 #ifdef G4DEBUG_LOCATE_INTERSECTION 
    850       if( substep_no >= trigger_substepno_print )
    851       {
    852         G4cout << "Difficulty in converging in "
    853                << "G4PropagatorInField::LocateIntersectionPoint():"
    854                << G4endl
    855                << "    Substep no = " << substep_no << G4endl;
    856         if( substep_no == trigger_substepno_print )
    857         {
    858           printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
    859                        -1.0, NewSafety, 0, 0);
    860         }
    861         G4cout << " State of point A: ";
    862         printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
    863                      -1.0, NewSafety, substep_no-1, 0);
    864         G4cout << " State of point B: ";
    865         printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
    866                      -1.0, NewSafety, substep_no, 0);
    867       }
    868 #endif
    869 
    870       substep_no++;
    871       substep_no_p++;
    872 
    873     } while (  ( ! found_approximate_intersection )
    874             && ( ! there_is_no_intersection )     
    875             && ( substep_no_p <= param_substeps) );  // UNTIL found or
    876                                                      // failed param substep
    877     first_section = false;
    878 
    879     if( (!found_approximate_intersection) && (!there_is_no_intersection) )
    880     {
    881       G4double did_len = std::abs( CurrentA_PointVelocity.GetCurveLength()
    882                        - SubStart_PointVelocity.GetCurveLength());
    883       G4double all_len = std::abs( CurrentB_PointVelocity.GetCurveLength()
    884                        - SubStart_PointVelocity.GetCurveLength());
    885       count_did_len=did_len;
    886       count_all_len=all_len;   
    887       G4double stepLengthAB;
    888       G4ThreeVector PointGe;
    889 
    890       // Check if progress is too slow and if it possible to go deeper,
    891       // then halve the step if so
    892       //
    893       if( ( ( did_len )<fraction_done*all_len)
    894          && (depth<max_depth) && (!sub_final_section) )
    895       {
    896 
    897         Second_half=false;
    898         depth++;
    899 
    900         G4double Sub_len = (all_len-did_len)/(2.);
    901         G4FieldTrack start = CurrentA_PointVelocity;
    902         G4MagInt_Driver* integrDriver=GetChordFinder()->GetIntegrationDriver();
    903         integrDriver->AccurateAdvance(start, Sub_len, fEpsilonStep);
    904         *ptrInterMedFT[depth] = start;
    905         CurrentB_PointVelocity = *ptrInterMedFT[depth];
    906  
    907         // Adjust 'SubStartPoint' to calculate the 'did_length' in next loop
    908         //
    909         SubStart_PointVelocity = CurrentA_PointVelocity;
    910 
    911         // Find new trial intersection point needed at start of the loop
    912         //
    913         G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();
    914         G4ThreeVector SubE_point = CurrentB_PointVelocity.GetPosition();   
    915      
    916         fNavigator->LocateGlobalPointWithinVolume(Point_A);
    917         G4bool Intersects_AB = IntersectChord(Point_A, SubE_point,
    918                                               NewSafety, stepLengthAB, PointGe);
    919         if(Intersects_AB)
    920         {
    921           CurrentE_Point = PointGe;
    922         }
    923         else
    924         {
    925           // No intersection found for first part of curve
    926           // (CurrentA,InterMedPoint[depth]). Go to the second part
    927           //
    928           Second_half = true;
    929         }
    930       } // if did_len
    931 
    932       if( (Second_half)&&(depth!=0) )
    933       {
    934         // Second part of curve (InterMed[depth],Intermed[depth-1])                       )
    935         // On the depth-1 level normally we are on the 'second_half'
    936 
    937         Second_half = true;
    938 
    939         //  Find new trial intersection point needed at start of the loop
    940         //
    941         SubStart_PointVelocity = *ptrInterMedFT[depth];
    942         CurrentA_PointVelocity = *ptrInterMedFT[depth];
    943         CurrentB_PointVelocity = *ptrInterMedFT[depth-1];
    944         // Ensure that the new endpoints are not further apart in space
    945         // than on the curve due to different errors in the integration
    946         //
    947         G4double linDistSq, curveDist;
    948         linDistSq = ( CurrentB_PointVelocity.GetPosition()
    949                     - CurrentA_PointVelocity.GetPosition() ).mag2();
    950         curveDist = CurrentB_PointVelocity.GetCurveLength()
    951                     - CurrentA_PointVelocity.GetCurveLength();
    952         if( curveDist*curveDist*(1+2*fEpsilonStep ) < linDistSq )
    953         {
    954           // Re-integrate to obtain a new B
    955           //
    956           G4FieldTrack newEndPointFT=
    957                   ReEstimateEndpoint( CurrentA_PointVelocity,
    958                                       CurrentB_PointVelocity,
    959                                       linDistSq,    // to avoid recalculation
    960                                       curveDist );
    961           G4FieldTrack oldPointVelB = CurrentB_PointVelocity;
    962           CurrentB_PointVelocity = newEndPointFT;
    963           maxNumberOfCallsToReIntegration_depth= maxNumberOfCallsToReIntegration_depth+1;
    964         }
    965 
    966         G4ThreeVector Point_A    = CurrentA_PointVelocity.GetPosition();
    967         G4ThreeVector SubE_point = CurrentB_PointVelocity.GetPosition();   
    968         fNavigator->LocateGlobalPointWithinVolume(Point_A);
    969         G4bool Intersects_AB = IntersectChord(Point_A, SubE_point, NewSafety,
    970                                               stepLengthAB, PointGe);
    971         if(Intersects_AB)
    972         {
    973           CurrentE_Point = PointGe;
    974         }
    975         else
    976         {
    977           final_section = true;
    978         }
    979         depth--;
    980       }
    981     }  // if(!found_aproximate_intersection)
    982 
    983   } while ( ( ! found_approximate_intersection )
    984             && ( ! there_is_no_intersection )     
    985             && ( substep_no <= max_substeps) ); // UNTIL found or failed
    986 
    987   if( substep_no > max_no_seen )
    988   {
    989     max_no_seen = substep_no;
    990     if( max_no_seen > warn_substeps )
    991     {
    992       trigger_substepno_print = max_no_seen-20; // Want to see last 20 steps
    993     }
    994   }
    995 
    996   if(  ( substep_no >= max_substeps)
    997       && !there_is_no_intersection
    998       && !found_approximate_intersection )
    999   {
    1000     G4cerr << "WARNING - G4PropagatorInField::LocateIntersectionPoint()"
    1001            << G4endl
    1002            << "          Convergence is requiring too many substeps: "
    1003            << substep_no << G4endl;
    1004     G4cerr << "          Abandoning effort to intersect. " << G4endl;
    1005     G4cerr << "          Information on start & current step follows in cout."
    1006            << G4endl;
    1007     G4cout << "WARNING - G4PropagatorInField::LocateIntersectionPoint()"
    1008            << G4endl
    1009            << "          Convergence is requiring too many substeps: "
    1010            << substep_no << G4endl;
    1011     G4cout << "          Found intersection = "
    1012            << found_approximate_intersection << G4endl
    1013            << "          Intersection exists = "
    1014            << !there_is_no_intersection << G4endl;
    1015     G4cout << "          Start and Endpoint of Requested Step:" << G4endl;
    1016     printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
    1017                  -1.0, NewSafety, 0, 0);
    1018     G4cout << G4endl;
    1019     G4cout << "          'Bracketing' starting and endpoint of current Sub-Step"
    1020            << G4endl;
    1021     printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
    1022                  -1.0, NewSafety, substep_no-1, 0);
    1023     printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
    1024                  -1.0, NewSafety, substep_no, 0);
    1025     G4cout << G4endl;
    1026  
    1027 #ifdef FUTURE_CORRECTION
    1028     // Attempt to correct the results of the method // FIX - TODO
    1029 
    1030     if ( ! found_approximate_intersection )
    1031     {
    1032       recalculatedEndPoint = true;
    1033       // Return the further valid intersection point -- potentially A ??
    1034       // JA/19 Jan 2006
    1035       IntersectedOrRecalculatedFT = CurrentA_PointVelocity;
    1036 
    1037       G4cout << "WARNING - G4PropagatorInField::LocateIntersectionPoint()"
    1038              << G4endl
    1039              << "          Did not convergence after " << substep_no
    1040              << " substeps." << G4endl;
    1041       G4cout << "          The endpoint was adjused to pointA resulting"
    1042              << G4endl
    1043              << "          from the last substep: " << CurrentA_PointVelocity
    1044              << G4endl;
    1045     }
    1046 #endif
    1047 
    1048     G4cout.precision( 10 );
    1049     G4double done_len = CurrentA_PointVelocity.GetCurveLength();
    1050     G4double full_len = CurveEndPointVelocity.GetCurveLength();
    1051     G4cout << "ERROR - G4PropagatorInField::LocateIntersectionPoint()"
    1052            << G4endl
    1053            << "        Undertaken only length: " << done_len
    1054            << " out of " << full_len << " required." << G4endl;
    1055     G4cout << "        Remaining length = " << full_len - done_len << G4endl;
    1056 
    1057     G4Exception("G4PropagatorInField::LocateIntersectionPoint()",
    1058                 "UnableToLocateIntersection", FatalException,
    1059                 "Too many substeps while trying to locate intersection.");
    1060   }
    1061   else if( substep_no >= warn_substeps )
    1062   { 
    1063     int oldprc= G4cout.precision( 10 );
    1064     G4cout << "WARNING - G4PropagatorInField::LocateIntersectionPoint()"
    1065            << G4endl
    1066            << "          Undertaken length: " 
    1067            << CurrentB_PointVelocity.GetCurveLength();
    1068     G4cout << " - Needed: "  << substep_no << " substeps." << G4endl
    1069            << "          Warning level = " << warn_substeps
    1070            << " and maximum substeps = " << max_substeps << G4endl;
    1071     G4Exception("G4PropagatorInField::LocateIntersectionPoint()",
    1072                 "DifficultyToLocateIntersection", JustWarning,
    1073                 "Many substeps while trying to locate intersection.");
    1074     G4cout.precision( oldprc );
    1075   }
    1076  
    1077   return  !there_is_no_intersection; //  Success or failure
    1078429}
    1079430
     
    1210561}
    1211562
    1212 G4bool
    1213 G4PropagatorInField::IntersectChord( G4ThreeVector  StartPointA,
    1214                                      G4ThreeVector  EndPointB,
    1215                                      G4double      &NewSafety,
    1216                                      G4double      &LinearStepLength,
    1217                                      G4ThreeVector &IntersectionPoint
    1218                                    )
    1219 {
    1220     // Calculate the direction and length of the chord AB
    1221     G4ThreeVector  ChordAB_Vector = EndPointB - StartPointA;
    1222     G4double       ChordAB_Length = ChordAB_Vector.mag();  // Magnitude (norm)
    1223     G4ThreeVector  ChordAB_Dir =    ChordAB_Vector.unit();
    1224     G4bool intersects;
    1225 
    1226     G4ThreeVector OriginShift = StartPointA - fPreviousSftOrigin ;
    1227     G4double      MagSqShift  = OriginShift.mag2() ;
    1228     G4double      currentSafety;
    1229     G4bool        doCallNav= false;
    1230 
    1231     if( MagSqShift >= sqr(fPreviousSafety) )
    1232     {
    1233         currentSafety = 0.0 ;
    1234     }else{
    1235         currentSafety = fPreviousSafety - std::sqrt(MagSqShift) ;
    1236     }
    1237 
    1238     if( fUseSafetyForOptimisation && (ChordAB_Length <= currentSafety) )
    1239     {
    1240        // The Step is guaranteed to be taken
    1241 
    1242        LinearStepLength = ChordAB_Length;
    1243        intersects = false;
    1244 
    1245        NewSafety= currentSafety;
    1246 
    1247 #if 0
    1248        G4cout << " G4PropagatorInField does not call Navigator::ComputeStep " << G4endl ;
    1249        G4cout << "    step= " << LinearStepLength << " safety= " << NewSafety << G4endl;
    1250        G4cout << "    safety: Origin = " << fPreviousSftOrigin << " val= " << fPreviousSafety << G4endl;
    1251 #endif
    1252     }
    1253     else
    1254     {
    1255        doCallNav= true;
    1256        // Check whether any volumes are encountered by the chord AB
    1257 
    1258        // G4cout << " G4PropagatorInField calling Navigator::ComputeStep " << G4endl ;
    1259 
    1260        LinearStepLength =
    1261         fNavigator->ComputeStep( StartPointA, ChordAB_Dir,
    1262                                  ChordAB_Length, NewSafety );
    1263        intersects = (LinearStepLength <= ChordAB_Length);
    1264        // G4Navigator contracts to return k_infinity if len==asked
    1265        // and it did not find a surface boundary at that length
    1266        LinearStepLength = std::min( LinearStepLength, ChordAB_Length);
    1267 
    1268        // G4cout << " G4PiF got step= " << LinearStepLength << " safety= " << NewSafety << G4endl;
    1269 
    1270        // Save the last calculated safety!
    1271        fPreviousSftOrigin = StartPointA;
    1272        fPreviousSafety= NewSafety;
    1273 
    1274        if( intersects ){
    1275           // Intersection Point of chord AB and either volume A's surface
    1276           //                                or a daughter volume's surface ..
    1277           IntersectionPoint = StartPointA + LinearStepLength * ChordAB_Dir;
    1278        }
    1279     }
    1280 
    1281 #ifdef DEBUG_INTERSECTS_CHORD
    1282     // printIntersection(
    1283     // StartPointA, EndPointB, LinearStepLength, IntersectionPoint, NewSafety
    1284 
    1285     G4cout << " G4PropagatorInField::IntersectChord reports " << G4endl;
    1286     G4cout << " PiF-IC> "
    1287            << "Start="  << std::setw(12) << StartPointA       << " "
    1288            << "End= "   << std::setw(8) << EndPointB         << " "
    1289            << "StepIn=" << std::setw(8) << LinearStepLength  << " "
    1290            << "NewSft=" << std::setw(8) << NewSafety << " "
    1291            << "CallNav=" << doCallNav      << "  "
    1292            << "Intersects " << intersects     << "  ";
    1293     if( intersects )
    1294       G4cout << "IntrPt=" << std::setw(8) << IntersectionPoint << " " ;
    1295     G4cout << G4endl;
    1296 #endif
    1297 
    1298     return intersects;
    1299 }
    1300 
    1301 // --------------------- oooo000000000000oooo ----------------------------
    1302 
    1303 G4FieldTrack G4PropagatorInField::
    1304 ReEstimateEndpoint( const G4FieldTrack &CurrentStateA, 
    1305                     const G4FieldTrack &EstimatedEndStateB,
    1306                           G4double      linearDistSq,
    1307                           G4double      curveDist
    1308                   )
    1309 {
    1310   // G4double checkCurveDist= EstimatedEndStateB.GetCurveLength()
    1311   //   - CurrentStateA.GetCurveLength();
    1312   // G4double checkLinDistSq= (EstimatedEndStateB.GetPosition()
    1313   //                    - CurrentStateA.GetPosition() ).mag2();
    1314 
    1315   G4FieldTrack newEndPoint( CurrentStateA );
    1316   G4MagInt_Driver* integrDriver= GetChordFinder()->GetIntegrationDriver();
    1317 
    1318   G4FieldTrack retEndPoint( CurrentStateA );
    1319   G4bool goodAdvance;
    1320   G4int  itrial=0;
    1321   const G4int no_trials= 20;
    1322 
    1323   G4double endCurveLen= EstimatedEndStateB.GetCurveLength();
    1324   do
    1325   {
    1326      G4double currentCurveLen= newEndPoint.GetCurveLength();
    1327      G4double advanceLength= endCurveLen - currentCurveLen ;
    1328      if (std::abs(advanceLength)<kCarTolerance)
    1329      {
    1330        advanceLength=(EstimatedEndStateB.GetPosition()
    1331                      -newEndPoint.GetPosition()).mag();
    1332      }
    1333      goodAdvance=
    1334        integrDriver->AccurateAdvance(newEndPoint, advanceLength, fEpsilonStep);
    1335      //              ***************
    1336   }
    1337   while( !goodAdvance && (++itrial < no_trials) );
    1338 
    1339   if( goodAdvance )
    1340   {
    1341     retEndPoint= newEndPoint;
    1342   }
    1343   else
    1344   {
    1345     retEndPoint= EstimatedEndStateB; // Could not improve without major work !!
    1346   }
    1347 
    1348   //  All the work is done
    1349   //   below are some diagnostics only -- before the return!
    1350   //
    1351   static const G4String MethodName("G4PropagatorInField::ReEstimateEndpoint");
    1352 
    1353 #ifdef G4VERBOSE
    1354   G4int  latest_good_trials=0;
    1355   if( itrial > 1)
    1356   {
    1357     if( fVerboseLevel > 0 )
    1358     {
    1359       G4cout << MethodName << " called - goodAdv= " << goodAdvance
    1360              << " trials = " << itrial
    1361              << " previous good= " << latest_good_trials
    1362              << G4endl;
    1363     }
    1364     latest_good_trials=0;
    1365   }
    1366   else
    1367   {   
    1368     latest_good_trials++;
    1369   }
    1370 #endif
    1371 
    1372 #ifdef G4DEBUG_FIELD
    1373   G4double lengthDone = newEndPoint.GetCurveLength()
    1374                       - CurrentStateA.GetCurveLength();
    1375   if( !goodAdvance )
    1376   {
    1377     if( fVerboseLevel >= 3 )
    1378     {
    1379       G4cout << MethodName << "> AccurateAdvance failed " ;
    1380       G4cout << " in " << itrial << " integration trials/steps. " << G4endl;
    1381       G4cout << " It went only " << lengthDone << " instead of " << curveDist
    1382              << " -- a difference of " << curveDist - lengthDone  << G4endl;
    1383       G4cout << " ReEstimateEndpoint> Reset endPoint to original value!"
    1384              << G4endl;
    1385     }
    1386   }
    1387 
    1388   static G4int noInaccuracyWarnings = 0;
    1389   G4int maxNoWarnings = 10;
    1390   if (  (noInaccuracyWarnings < maxNoWarnings )
    1391        || (fVerboseLevel > 1) )
    1392     {
    1393       G4cerr << "G4PropagatorInField::LocateIntersectionPoint():"
    1394              << G4endl
    1395              << " Warning: Integration inaccuracy requires"
    1396              <<   " an adjustment in the step's endpoint."  << G4endl
    1397              << "   Two mid-points are further apart than their"
    1398              <<   " curve length difference"                << G4endl
    1399              << "   Dist = "       << std::sqrt(linearDistSq)
    1400              << " curve length = " << curveDist             << G4endl;
    1401       G4cerr << " Correction applied is "
    1402              << (newEndPoint.GetPosition()-EstimatedEndStateB.GetPosition()).mag()
    1403              << G4endl;
    1404     }
    1405 #else
    1406   // Statistics on the RMS value of the corrections
    1407 
    1408   static G4int    noCorrections=0;
    1409   static G4double sumCorrectionsSq = 0;
    1410   noCorrections++;
    1411   if( goodAdvance )
    1412   {
    1413     sumCorrectionsSq += (EstimatedEndStateB.GetPosition() -
    1414                          newEndPoint.GetPosition()).mag2();
    1415   }
    1416   linearDistSq -= curveDist; // To use linearDistSq ... !
    1417 #endif
    1418 
    1419   return retEndPoint;
    1420 }
    1421 
    1422563// Access the points which have passed through the filter. The
    1423564// points are stored as ThreeVectors for the initial impelmentation
  • trunk/source/geometry/navigation/src/G4ReplicaNavigation.cc

    r850 r921  
    2626//
    2727// $Id: G4ReplicaNavigation.cc,v 1.19 2008/04/28 15:39:55 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/src/G4SafetyHelper.cc

    r831 r921  
    2424// ********************************************************************
    2525//
    26 // $Id: G4SafetyHelper.cc,v 1.15 2007/11/14 10:04:21 gcosmo Exp $
     26// $Id: G4SafetyHelper.cc,v 1.16 2008/10/24 14:00:03 gcosmo Exp $
    2727// GEANT4 tag $ Name:  $
    2828//
     
    128128    {
    129129      // Safety for mass geometry
    130       fLastSafety = fpMassNavigator->ComputeSafety(position);
     130      fLastSafety = fpMassNavigator->ComputeSafety(position,true);
    131131    }
    132132    else
    133133    {
    134134      // Safety for all geometries
    135       fLastSafety = fpPathFinder->ComputeSafety( position );
     135      fLastSafety = fpPathFinder->ComputeSafety(position);
    136136    }
    137137    newSafety = fLastSafety;
  • trunk/source/geometry/navigation/src/G4TransportationManager.cc

    r850 r921  
    2626//
    2727// $Id: G4TransportationManager.cc,v 1.15 2007/04/12 11:51:48 vnivanch Exp $
    28 // GEANT4 tag $Name: HEAD $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
  • trunk/source/geometry/navigation/src/G4VoxelNavigation.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4VoxelNavigation.cc,v 1.7 2007/05/11 13:43:59 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4VoxelNavigation.cc,v 1.9 2008/11/14 18:26:35 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    254254                G4String solidResponse = "-kInside-";
    255255                if (insideIntPt == kOutside)
    256                   solidResponse = "-kOutside-";
     256                  { solidResponse = "-kOutside-"; }
    257257                else if (insideIntPt == kSurface)
    258                   solidResponse = "-kSurface-";
     258                  { solidResponse = "-kSurface-"; }
    259259                if( fVerbose == 1 )
    260260                {
     
    265265                         << "    For point p: " << intersectionPoint
    266266                         << ", considered as 'intersection' point." << G4endl;
     267                }
     268                G4double safetyIn= -1, safetyOut= -1;  //  Set to invalid values
     269                G4double newDistIn= -1,  newDistOut= -1;
     270                if( insideIntPt != kInside )
     271                {
     272                  safetyIn= sampleSolid->DistanceToIn(intersectionPoint);
     273                  newDistIn= sampleSolid->DistanceToIn(intersectionPoint,
     274                                                       sampleDirection);
     275                }
     276                if( insideIntPt != kOutside )
     277                {
     278                  safetyOut= sampleSolid->DistanceToOut(intersectionPoint);
     279                  newDistOut= sampleSolid->DistanceToOut(intersectionPoint,
     280                                                         sampleDirection);
    267281                }
    268282                if( insideIntPt != kSurface )
     
    277291                         << " for this point !" << G4endl;
    278292                  G4cout << "          Point = " << intersectionPoint << G4endl;
     293                  G4cout << "          Safety values: " << G4endl;
    279294                  if ( insideIntPt != kInside )
    280                     G4cout << "        DistanceToIn(p) = "
    281                            << sampleSolid->DistanceToIn(intersectionPoint)
     295                  {
     296                    G4cout << "          DistanceToIn(p)  = " << safetyIn
    282297                           << G4endl;
    283                   if ( insideIntPt != kOutside )
    284                     G4cout << "        DistanceToOut(p) = "
    285                            << sampleSolid->DistanceToOut(intersectionPoint)
     298                  }
     299                  if ( insideIntPt != kOutside )
     300                  {
     301                    G4cout << "          DistanceToOut(p) = " << safetyOut
    286302                           << G4endl;
     303                  }
    287304                  G4Exception("G4VoxelNavigation::ComputeStep()",
    288305                              "InaccurateDistanceToIn", JustWarning,
    289                               "Navigator gets conflicting response from Solid.");
     306                              "Conflicting response from Solid.");
    290307                  G4cout.precision(oldcoutPrec);
     308                }
     309                else
     310                { 
     311                  // If it is on the surface, *ensure* that either DistanceToIn
     312                  // or DistanceToOut returns a finite value ( >= Tolerance).
     313                  //
     314                  if( std::max( newDistIn, newDistOut ) <= kCarTolerance )
     315                  {
     316                    G4cout << "ERROR - G4VoxelNavigation::ComputeStep()"
     317                       << G4endl
     318                       << "  Identified point for which the solid "
     319                       << sampleSolid->GetName() << G4endl
     320                       << "  has MAJOR problem:  " << G4endl
     321                       << "  --> Both DistanceToIn(p,v) and DistanceToOut(p,v) "
     322                       << "return Zero, an equivalent value or negative value."
     323                       << G4endl;
     324                    G4cout << "    Solid: " << sampleSolid << G4endl;
     325                    G4cout << "    Point p= " << intersectionPoint << G4endl;
     326                    G4cout << "    Direction v= " << sampleDirection << G4endl;
     327                    G4cout << "    DistanceToIn(p,v)     = " << newDistIn
     328                           << G4endl;
     329                    G4cout << "    DistanceToOut(p,v,..) = " << newDistOut
     330                           << G4endl;
     331                    G4cout << "    Safety values: " << G4endl;
     332                    G4cout << "      DistanceToIn(p)  = " << safetyIn
     333                           << G4endl;
     334                    G4cout << "      DistanceToOut(p) = " << safetyOut
     335                           << G4endl;
     336                    G4Exception("G4VoxelNavigation::ComputeStep()",
     337                              "DistanceToInAndOutAreZero", FatalException,
     338                              "Zero from both Solid DistanceIn and Out(p,v).");
     339                  }
    291340                }
    292341              }
  • trunk/source/geometry/solids/CSG/History

    r850 r921  
    1 $Id: History,v 1.105 2008/07/07 10:43:04 gcosmo Exp $
     1$Id: History,v 1.109 2008/11/21 09:50:20 gcosmo Exp $
    22-------------------------------------------------------------------
    33
     
    1717     * Reverse chronological order (last date on top), please *
    1818     ----------------------------------------------------------
     19
     20Nov 21, 2008  G.Cosmo                    geom-csg-V09-01-08
     21- G4Sphere: defined Get/SetInnerRadius() accessors to be compliant with
     22  other CSG solids and allow consistent treatment in persistency code...
     23
     24Nov 06, 2008  G.Cosmo                    geom-csg-V09-01-07
     25- G4Tubs, G4Cons: implemented caching of trigonometric values, now directly
     26  computed inside modifiers for Phi angles and required for parametrised
     27  cases. Improvement bringing up to 20% speedup in normal tracking for
     28  tube/cone-sections placements.
     29
     30Nov 05, 2008  G.Cosmo                    geom-csg-V09-01-06
     31- G4Cons: implemented first speed improvements and corrections from joint
     32  code review of G4Cons class. Cached computation for half-tolerance and
     33  use of Boolean flag for identifying if full-cone or section.
     34- G4Tubs: more refinements to previous review; corrected implementation
     35  of constructor to conform to implementation as in G4Cons. Fixed issue in
     36  SetDeltaPhi() method after changes introduced in the previous tag.
     37
     38Sep 18, 2008  T.Nikitina                 geom-csg-V09-01-05
     39- G4Tubs: implemented first speed improvements and corrections from joint
     40  code review of G4Tubs class. Cached computation for half-tolerance and
     41  use of Boolean flag for identifying if full-tube or section.
    1942
    2043Jul 07, 2008  V.Grichine                 geom-csg-V09-01-04
  • trunk/source/geometry/solids/CSG/include/G4Cons.hh

    r850 r921  
    2525//
    2626//
    27 // $Id: G4Cons.hh,v 1.18 2007/05/18 07:38:00 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4Cons.hh,v 1.21 2008/11/06 11:04:00 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    5454//  fDPhi  delta angle of the segment in radians
    5555//
     56//  fPhiFullCone   Boolean variable used for indicate the Phi Section
     57//
    5658//   Note:
    5759//      Internally fSPhi & fDPhi are adjusted so that fDPhi<=2PI,
     
    7375  public:  // with description
    7476
    75         G4Cons(const G4String& pName,
    76                      G4double pRmin1, G4double pRmax1,
    77                      G4double pRmin2, G4double pRmax2,
    78                      G4double pDz,
    79                      G4double pSPhi, G4double pDPhi);
     77    G4Cons(const G4String& pName,
     78                 G4double pRmin1, G4double pRmax1,
     79                 G4double pRmin2, G4double pRmax2,
     80                 G4double pDz,
     81                 G4double pSPhi, G4double pDPhi);
    8082         
    81         virtual ~G4Cons() ;
    82 
    83   // Accessors
    84 
    85         inline G4double    GetInnerRadiusMinusZ() const;
    86         inline G4double    GetOuterRadiusMinusZ() const;
    87         inline G4double    GetInnerRadiusPlusZ()  const;
    88         inline G4double    GetOuterRadiusPlusZ()  const;
    89  
    90         inline G4double    GetZHalfLength()       const;
    91  
    92         inline G4double    GetStartPhiAngle () const;
    93         inline G4double    GetDeltaPhiAngle () const;
    94  
    95   // Modifiers
    96 
    97         inline void    SetInnerRadiusMinusZ( G4double Rmin1 );
    98         inline void    SetOuterRadiusMinusZ( G4double Rmax1 );
    99         inline void    SetInnerRadiusPlusZ ( G4double Rmin2 );
    100         inline void    SetOuterRadiusPlusZ ( G4double Rmax2 );
     83    virtual ~G4Cons() ;
     84
     85    // Accessors
     86
     87    inline G4double    GetInnerRadiusMinusZ() const;
     88    inline G4double    GetOuterRadiusMinusZ() const;
     89    inline G4double    GetInnerRadiusPlusZ()  const;
     90    inline G4double    GetOuterRadiusPlusZ()  const;
     91 
     92    inline G4double    GetZHalfLength()       const;
     93 
     94    inline G4double    GetStartPhiAngle () const;
     95    inline G4double    GetDeltaPhiAngle () const;
     96 
     97    // Modifiers
     98
     99    inline void    SetInnerRadiusMinusZ( G4double Rmin1 );
     100    inline void    SetOuterRadiusMinusZ( G4double Rmax1 );
     101    inline void    SetInnerRadiusPlusZ ( G4double Rmin2 );
     102    inline void    SetOuterRadiusPlusZ ( G4double Rmax2 );
    101103         
    102         inline void    SetZHalfLength      ( G4double newDz );
    103         inline void    SetStartPhiAngle    ( G4double newSPhi);
    104         inline void    SetDeltaPhiAngle    ( G4double newDPhi);
    105 
    106   // Other methods for solid
    107 
    108         inline G4double    GetCubicVolume();
    109         inline G4double    GetSurfaceArea();
    110 
    111         void ComputeDimensions(G4VPVParameterisation* p,
    112                                const G4int n,
    113                                const G4VPhysicalVolume* pRep);
    114 
    115         G4bool CalculateExtent(const EAxis pAxis,
    116                                const G4VoxelLimits& pVoxelLimit,
    117                                const G4AffineTransform& pTransform,
    118                                      G4double& pmin, G4double& pmax) const;         
    119 
    120         EInside Inside(const G4ThreeVector& p) const;
    121 
    122         G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const;
    123 
    124         G4double DistanceToIn(const G4ThreeVector& p,
    125                                const G4ThreeVector& v) const;
    126         G4double DistanceToIn(const G4ThreeVector& p) const;
    127         G4double DistanceToOut(const G4ThreeVector& p,
    128                                const G4ThreeVector& v,
    129                                const G4bool calcNorm=G4bool(false),
    130                                      G4bool *validNorm=0,
    131                                      G4ThreeVector *n=0) const;             
    132         G4double DistanceToOut(const G4ThreeVector& p) const;
    133 
    134         G4GeometryType  GetEntityType() const;
     104    inline void    SetZHalfLength      ( G4double newDz );
     105    inline void    SetStartPhiAngle    ( G4double newSPhi);
     106    inline void    SetDeltaPhiAngle    ( G4double newDPhi);
     107
     108    // Other methods for solid
     109
     110    inline G4double    GetCubicVolume();
     111    inline G4double    GetSurfaceArea();
     112
     113    void ComputeDimensions(G4VPVParameterisation* p,
     114                           const G4int n,
     115                           const G4VPhysicalVolume* pRep);
     116
     117    G4bool CalculateExtent(const EAxis pAxis,
     118                           const G4VoxelLimits& pVoxelLimit,
     119                           const G4AffineTransform& pTransform,
     120                                 G4double& pmin, G4double& pmax) const;         
     121
     122    EInside Inside(const G4ThreeVector& p) const;
     123
     124    G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const;
     125
     126    G4double DistanceToIn (const G4ThreeVector& p,
     127                           const G4ThreeVector& v) const;
     128    G4double DistanceToIn (const G4ThreeVector& p) const;
     129    G4double DistanceToOut(const G4ThreeVector& p,
     130                           const G4ThreeVector& v,
     131                           const G4bool calcNorm=G4bool(false),
     132                                 G4bool *validNorm=0,
     133                                 G4ThreeVector *n=0) const;             
     134    G4double DistanceToOut(const G4ThreeVector& p) const;
     135
     136    G4GeometryType  GetEntityType() const;
    135137       
    136         G4ThreeVector GetPointOnSurface() const;
     138    G4ThreeVector GetPointOnSurface() const;
    137139       
    138         std::ostream& StreamInfo(std::ostream& os) const;
    139 
    140   // Visualisation functions
    141 
    142         void          DescribeYourselfTo( G4VGraphicsScene& scene ) const;
    143         G4Polyhedron* CreatePolyhedron() const;
    144         G4NURBS*      CreateNURBS() const;
     140    std::ostream& StreamInfo(std::ostream& os) const;
     141
     142    // Visualisation functions
     143
     144    void          DescribeYourselfTo( G4VGraphicsScene& scene ) const;
     145    G4Polyhedron* CreatePolyhedron() const;
     146    G4NURBS*      CreateNURBS() const;
    145147
    146148  public:  // without description
    147149       
    148         G4Cons(__void__&);
    149           // Fake default constructor for usage restricted to direct object
    150           // persistency for clients requiring preallocation of memory for
    151           // persistifiable objects.
    152 
    153         //  Old access functions
    154 
    155         inline G4double    GetRmin1() const;
    156         inline G4double    GetRmax1() const;
    157         inline G4double    GetRmin2() const;
    158         inline G4double    GetRmax2() const;
    159  
    160         inline G4double    GetDz()    const;
    161  
    162         inline G4double    GetSPhi() const;
    163         inline G4double    GetDPhi() const;
     150    G4Cons(__void__&);
     151      //
     152      // Fake default constructor for usage restricted to direct object
     153      // persistency for clients requiring preallocation of memory for
     154      // persistifiable objects.
     155
     156    //  Old access functions
     157
     158    inline G4double    GetRmin1() const;
     159    inline G4double    GetRmax1() const;
     160    inline G4double    GetRmin2() const;
     161    inline G4double    GetRmax2() const;
     162 
     163    inline G4double    GetDz()    const;
     164 
     165    inline G4double    GetSPhi() const;
     166    inline G4double    GetDPhi() const;
    164167
    165168  protected:
    166169 
    167         G4ThreeVectorList*
    168         CreateRotatedVertices(const G4AffineTransform& pTransform) const;
    169  
    170         // Used by distanceToOut
    171  
    172         enum ESide {kNull,kRMin,kRMax,kSPhi,kEPhi,kPZ,kMZ};
    173  
    174         // used by normal
    175  
    176         enum ENorm {kNRMin,kNRMax,kNSPhi,kNEPhi,kNZ};
     170    G4ThreeVectorList*
     171    CreateRotatedVertices(const G4AffineTransform& pTransform) const;
     172 
     173    G4double fRmin1, fRmin2, fRmax1, fRmax2, fDz, fSPhi, fDPhi;
     174    G4bool fPhiFullCone;
     175
     176    // Used by distanceToOut
     177 
     178    enum ESide {kNull,kRMin,kRMax,kSPhi,kEPhi,kPZ,kMZ};
     179 
     180    // used by normal
     181 
     182    enum ENorm {kNRMin,kNRMax,kNSPhi,kNEPhi,kNZ};
    177183
    178184  private:
    179185
    180         G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
    181           // Algorithm for SurfaceNormal() following the original
    182           // specification for points not on the surface
     186    inline void Initialise();
     187      // Reset relevant values to zero
     188
     189    inline void InitializeTrigonometry();
     190      //
     191      // Recompute relevant trigonometric values and cache them
     192
     193    G4ThreeVector ApproxSurfaceNormal(const G4ThreeVector& p) const;
     194      //
     195      // Algorithm for SurfaceNormal() following the original
     196      // specification for points not on the surface
    183197
    184198  private:
    185199
    186         G4double kRadTolerance, kAngTolerance;
    187 
    188         G4double fRmin1,fRmin2,
    189                  fRmax1,fRmax2,
    190                  fDz,
    191                  fSPhi,fDPhi;
     200    G4double kRadTolerance, kAngTolerance;
     201      //
     202      // Radial and angular tolerances
     203
     204    G4double sinCPhi, cosCPhi, cosHDPhiOT, cosHDPhiIT,
     205             sinSPhi, cosSPhi, sinEPhi, cosEPhi;
     206      //
     207      // Cached trigonometric values
    192208};
    193209
  • trunk/source/geometry/solids/CSG/include/G4Cons.icc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4Cons.icc,v 1.6 2006/10/19 15:33:37 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4Cons.icc,v 1.8 2008/11/06 10:55:40 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
     
    3737
    3838inline
    39 G4double G4Cons::GetInnerRadiusMinusZ() const
    40 {
    41   return fRmin1 ;
    42 }
    43 
    44 inline
    45 G4double G4Cons::GetOuterRadiusMinusZ() const
    46 {
    47   return fRmax1 ;
    48 }
    49 
    50 inline
    51 G4double G4Cons::GetInnerRadiusPlusZ() const
    52 {
    53   return fRmin2 ;
    54 }
    55 
    56 inline
    57 G4double G4Cons::GetOuterRadiusPlusZ() const
    58 {
    59   return fRmax2 ;
    60 }
    61 
    62 inline
    63 G4double G4Cons::GetZHalfLength() const
    64 {
    65   return fDz ;
    66 }
    67 
    68 inline 
    69 G4double G4Cons::GetStartPhiAngle() const
    70 {
    71   return fSPhi ;
    72 }
    73 
    74 inline
    75 G4double G4Cons::GetDeltaPhiAngle() const
    76 {
    77   return fDPhi;
    78 }
    79 
    80 inline
    81 void G4Cons::SetInnerRadiusMinusZ( G4double Rmin1 )
    82 {
    83   fRmin1= Rmin1 ;
     39void G4Cons::Initialise()
     40{
    8441  fCubicVolume= 0.;
    8542  fSurfaceArea= 0.;
     
    8744}
    8845
     46inline
     47void G4Cons::InitializeTrigonometry()
     48{
     49  G4double hDPhi = 0.5*fDPhi;                       // half delta phi
     50  G4double cPhi  = fSPhi + hDPhi;
     51  G4double ePhi  = fSPhi + fDPhi;
     52
     53  sinCPhi    = std::sin(cPhi);
     54  cosCPhi    = std::cos(cPhi);
     55  cosHDPhiIT = std::cos(hDPhi - 0.5*kAngTolerance); // inner/outer tol half dphi
     56  cosHDPhiOT = std::cos(hDPhi + 0.5*kAngTolerance);
     57  sinSPhi = std::sin(fSPhi);
     58  cosSPhi = std::cos(fSPhi);
     59  sinEPhi = std::sin(ePhi);
     60  cosEPhi = std::cos(ePhi);
     61}
     62
     63inline
     64G4double G4Cons::GetInnerRadiusMinusZ() const
     65{
     66  return fRmin1 ;
     67}
     68
     69inline
     70G4double G4Cons::GetOuterRadiusMinusZ() const
     71{
     72  return fRmax1 ;
     73}
     74
     75inline
     76G4double G4Cons::GetInnerRadiusPlusZ() const
     77{
     78  return fRmin2 ;
     79}
     80
     81inline
     82G4double G4Cons::GetOuterRadiusPlusZ() const
     83{
     84  return fRmax2 ;
     85}
     86
     87inline
     88G4double G4Cons::GetZHalfLength() const
     89{
     90  return fDz ;
     91}
     92
     93inline 
     94G4double G4Cons::GetStartPhiAngle() const
     95{
     96  return fSPhi ;
     97}
     98
     99inline
     100G4double G4Cons::GetDeltaPhiAngle() const
     101{
     102  return fDPhi;
     103}
     104
     105inline
     106void G4Cons::SetInnerRadiusMinusZ( G4double Rmin1 )
     107{
     108  fRmin1= Rmin1 ;
     109  Initialise();
     110}
     111
    89112inline
    90113void G4Cons::SetOuterRadiusMinusZ( G4double Rmax1 )
    91114{
    92115  fRmax1= Rmax1 ;
    93   fCubicVolume= 0.;
    94   fSurfaceArea= 0.;
    95   fpPolyhedron = 0;
     116  Initialise();
    96117}
    97118
     
    100121{
    101122  fRmin2= Rmin2 ;
    102   fCubicVolume= 0.;
    103   fSurfaceArea= 0.;
    104   fpPolyhedron = 0;
     123  Initialise();
    105124}
    106125
     
    109128{
    110129  fRmax2= Rmax2 ;
    111   fCubicVolume= 0.;
    112   fSurfaceArea= 0.;
    113   fpPolyhedron = 0;
     130  Initialise();
    114131}
    115132
     
    118135{
    119136  fDz= newDz ;
    120   fCubicVolume= 0.;
    121   fSurfaceArea= 0.;
    122   fpPolyhedron = 0;
     137  Initialise();
    123138}
    124139
     
    127142{
    128143  fSPhi= newSPhi;
    129   fCubicVolume= 0.;
    130   fSurfaceArea= 0.;
    131   fpPolyhedron = 0;
     144  Initialise();
     145  InitializeTrigonometry();
    132146}
    133147
    134148void G4Cons::SetDeltaPhiAngle ( G4double newDPhi )
    135149{
     150  if ( newDPhi >= twopi-kAngTolerance*0.5 )
     151  {
     152    fPhiFullCone = true;
     153  }
     154  else if ( newDPhi > 0 )
     155  {
     156    fPhiFullCone = false;
     157  }
     158  else
     159  {
     160     G4cerr << "ERROR - G4Cons()::SetDeltaPhiAngle() : " << GetName() << G4endl
     161            << "        Negative delta-Phi ! - " << newDPhi << G4endl;
     162     G4Exception("G4Cons::SetDeltaPhiAngle()", "InvalidSetup",
     163                  FatalException, "Invalid dphi.");
     164  }
    136165  fDPhi=  newDPhi;
    137   fCubicVolume= 0.;
    138   fSurfaceArea= 0.;
    139   fpPolyhedron = 0;
     166  Initialise();
     167  InitializeTrigonometry();
    140168}
    141169
     
    220248                         + 0.5*(fRmax1*fRmax1-fRmin1*fRmin1
    221249                               +fRmax2*fRmax2-fRmin2*fRmin2 ));
    222     if(fDPhi < twopi )
     250    if(!fPhiFullCone)
    223251    {
    224252      fSurfaceArea = fSurfaceArea+4*fDz*(mmax-mmin);
  • trunk/source/geometry/solids/CSG/include/G4Sphere.hh

    r850 r921  
    2525//
    2626//
    27 // $Id: G4Sphere.hh,v 1.20 2007/05/18 07:38:00 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4Sphere.hh,v 1.21 2008/11/21 09:50:05 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    8888    // Accessors
    8989       
    90     inline G4double GetInsideRadius   () const;
     90    inline G4double GetInnerRadius    () const;
    9191    inline G4double GetOuterRadius    () const;
    9292    inline G4double GetStartPhiAngle  () const;
     
    9797    // Modifiers
    9898
    99     inline void SetInsideRadius   (G4double newRmin);
     99    inline void SetInnerRadius    (G4double newRMin);
    100100    inline void SetOuterRadius    (G4double newRmax);
    101101    inline void SetStartPhiAngle  (G4double newSphi);
     
    162162    inline G4double  GetSTheta() const;
    163163    inline G4double  GetDTheta() const;
     164    inline G4double  GetInsideRadius() const;
     165    inline void SetInsideRadius(G4double newRmin);
    164166
    165167  protected:
  • trunk/source/geometry/solids/CSG/include/G4Sphere.icc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4Sphere.icc,v 1.7 2006/10/19 15:33:37 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4Sphere.icc,v 1.8 2008/11/21 09:50:05 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
     
    4343
    4444inline
     45G4double G4Sphere::GetInnerRadius() const
     46{
     47  return fRmin;
     48}
     49
     50inline
    4551G4double G4Sphere::GetOuterRadius() const
    4652{
     
    7379inline
    7480void G4Sphere::SetInsideRadius(G4double newRmin)
     81{
     82  fRmin= newRmin;
     83  fCubicVolume= 0.;
     84  fSurfaceArea= 0.;
     85  fpPolyhedron = 0;
     86}
     87
     88inline
     89void G4Sphere::SetInnerRadius(G4double newRmin)
    7590{
    7691  fRmin= newRmin;
  • trunk/source/geometry/solids/CSG/include/G4Tubs.hh

    r850 r921  
    2525//
    2626//
    27 // $Id: G4Tubs.hh,v 1.17 2007/05/18 07:38:00 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4Tubs.hh,v 1.21 2008/11/06 10:55:40 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    3939//   A tube or tube segment with curved sides parallel to
    4040//   the z-axis. The tube has a specified half-length along
    41 //   the z axis, about which it is centred, and a given
     41//   the z-axis, about which it is centered, and a given
    4242//   minimum and maximum radius. A minimum radius of 0
    43 //   signifies a filled tube /cylinder. The tube segment is
     43//   corresponds to filled tube /cylinder. The tube segment is
    4444//   specified by starting and delta angles for phi, with 0
    4545//   being the +x axis, PI/2 the +y axis.
     
    5757//
    5858//   fDPhi  Delta angle of the segment.
     59//
     60//   fPhiFullTube   Boolean variable used for indicate the Phi Section
    5961
    6062// History:
     
    103105    inline void SetStartPhiAngle (G4double newSPhi);
    104106    inline void SetDeltaPhiAngle (G4double newDPhi);
    105 
     107   
    106108    // Methods for solid
    107109
     
    144146
    145147    G4Tubs(__void__&);
     148      //
    146149      // Fake default constructor for usage restricted to direct object
    147150      // persistency for clients requiring preallocation of memory for
     
    164167      // for G4VSolid:: ClipCrossSection and ClipBetweenSections
    165168
    166     G4double fRMin,fRMax,fDz,fSPhi,fDPhi;
    167 
    168     // Used by distanceToOut
     169    G4double fRMin, fRMax, fDz, fSPhi, fDPhi;
     170    G4bool fPhiFullTube;
     171   
     172      // Used by distanceToOut
    169173
    170174    enum ESide {kNull,kRMin,kRMax,kSPhi,kEPhi,kPZ,kMZ};
    171175
    172     // used by normal
     176      // Used by normal
    173177
    174178    enum ENorm {kNRMin,kNRMax,kNSPhi,kNEPhi,kNZ};
     
    176180  private:
    177181
     182    inline void Initialize();
     183      //
     184      // Reset relevant values to zero
     185
     186    inline void InitializeTrigonometry();
     187      //
     188      // Recompute relevant trigonometric values and cache them
     189
    178190    G4ThreeVector ApproxSurfaceNormal( const G4ThreeVector& p ) const;
     191      //
    179192      // Algorithm for SurfaceNormal() following the original
    180193      // specification for points not on the surface
     
    183196
    184197    G4double kRadTolerance, kAngTolerance;
     198      //
    185199      // Radial and angular tolerances
     200
     201    G4double sinCPhi, cosCPhi, cosHDPhiOT, cosHDPhiIT,
     202             sinSPhi, cosSPhi, sinEPhi, cosEPhi;
     203      //
     204      // Cached trigonometric values
    186205};
    187206
  • trunk/source/geometry/solids/CSG/include/G4Tubs.icc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4Tubs.icc,v 1.7 2006/10/19 15:33:37 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4Tubs.icc,v 1.11 2008/11/06 10:55:40 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// --------------------------------------------------------------------
     
    6666}
    6767
     68inline
     69void G4Tubs::Initialize()
     70{
     71  fCubicVolume = 0.;
     72  fSurfaceArea = 0.;
     73  fpPolyhedron = 0;
     74}
     75
     76inline
     77void G4Tubs::InitializeTrigonometry()
     78{
     79  G4double hDPhi = 0.5*fDPhi;                       // half delta phi
     80  G4double cPhi  = fSPhi + hDPhi;
     81  G4double ePhi  = fSPhi + fDPhi;
     82
     83  sinCPhi    = std::sin(cPhi);
     84  cosCPhi    = std::cos(cPhi);
     85  cosHDPhiIT = std::cos(hDPhi - 0.5*kAngTolerance); // inner/outer tol half dphi
     86  cosHDPhiOT = std::cos(hDPhi + 0.5*kAngTolerance);
     87  sinSPhi = std::sin(fSPhi);
     88  cosSPhi = std::cos(fSPhi);
     89  sinEPhi = std::sin(ePhi);
     90  cosEPhi = std::cos(ePhi);
     91}
     92
    6893inline
    6994void G4Tubs::SetInnerRadius (G4double newRMin)
    7095{
    7196  fRMin= newRMin;
    72   fCubicVolume= 0.;
    73   fSurfaceArea= 0.;
    74   fpPolyhedron = 0;
     97  Initialize();
    7598}
    7699
     
    79102{
    80103  fRMax= newRMax;
    81   fCubicVolume= 0.;
    82   fSurfaceArea= 0.;
    83   fpPolyhedron = 0;
     104  Initialize();
    84105}
    85106
     
    88109{
    89110  fDz= newDz;
    90   fCubicVolume= 0.;
    91   fSurfaceArea= 0.;
    92   fpPolyhedron = 0;
     111  Initialize();
    93112}
    94113
     
    97116{
    98117  fSPhi= newSPhi;
    99   fCubicVolume= 0.;
    100   fSurfaceArea= 0.;
    101   fpPolyhedron = 0;
     118  Initialize();
     119  InitializeTrigonometry();
    102120}
    103121
     
    105123void G4Tubs::SetDeltaPhiAngle (G4double newDPhi)
    106124{
     125  if ( newDPhi >= twopi-kAngTolerance*0.5 )
     126  {
     127    fPhiFullTube = true;
     128  }
     129  else if ( newDPhi > 0 )
     130  {
     131    fPhiFullTube = false;
     132  }
     133  else
     134  {
     135     G4cerr << "ERROR - G4Tubs()::SetDeltaPhiAngle() : " << GetName() << G4endl
     136            << "        Negative delta-Phi ! - " << newDPhi << G4endl;
     137     G4Exception("G4Tubs::SetDeltaPhiAngle()", "InvalidSetup",
     138                  FatalException, "Invalid dphi.");
     139  }
    107140  fDPhi= newDPhi;
    108   fCubicVolume= 0.;
    109   fSurfaceArea= 0.;
    110   fpPolyhedron = 0;
     141  Initialize();
     142  InitializeTrigonometry();
    111143}
    112144
     
    158190  {
    159191    fSurfaceArea = fDPhi*(fRMin+fRMax)*(2*fDz+fRMax-fRMin);
    160     if (fDPhi < twopi)
     192    if (!fPhiFullTube)
    161193    {
    162194      fSurfaceArea = fSurfaceArea + 4*fDz*(fRMax-fRMin);
  • trunk/source/geometry/solids/CSG/src/G4Cons.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4Cons.cc,v 1.56 2008/02/20 08:56:16 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4Cons.cc,v 1.60 2008/11/06 15:26:53 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    8787
    8888  if ( pDz > 0 )
    89     fDz = pDz ;
     89  {
     90    fDz = pDz;
     91  }
    9092  else
    9193  {
     
    99101  // Check radii
    100102
    101   if ( pRmin1 < pRmax1 && pRmin2 < pRmax2 && pRmin1 >= 0 && pRmin2 >= 0 )
     103  if ( (pRmin1<pRmax1) && (pRmin2<pRmax2) && (pRmin1>=0) && (pRmin2>=0) )
    102104  {
    103105
     
    106108    fRmin2 = pRmin2 ;
    107109    fRmax2 = pRmax2 ;
    108     if( (pRmin1 == 0.0 && pRmin2 > 0.0) ) fRmin1 = 1e3*kRadTolerance ;
    109     if( (pRmin2 == 0.0 && pRmin1 > 0.0) ) fRmin2 = 1e3*kRadTolerance ;
     110    if( (pRmin1 == 0.0) && (pRmin2 > 0.0) ) { fRmin1 = 1e3*kRadTolerance ; }
     111    if( (pRmin2 == 0.0) && (pRmin1 > 0.0) ) { fRmin2 = 1e3*kRadTolerance ; }
    110112  }
    111113  else
     
    119121  }
    120122
    121   // Check angles
    122 
    123   if ( pDPhi >= twopi )
     123  fPhiFullCone = true;
     124  if ( pDPhi >= twopi-kAngTolerance*0.5 ) // Check angles
    124125  {
    125126    fDPhi=twopi;
     
    128129  else
    129130  {
    130     if ( pDPhi > 0 ) fDPhi = pDPhi ;
     131    fPhiFullCone = false;
     132    if ( pDPhi > 0 )
     133    {
     134      fDPhi = pDPhi;
     135    }
    131136    else
    132137    {
     
    135140             << pDPhi << G4endl;
    136141      G4Exception("G4Cons::G4Cons()", "InvalidSetup",
    137                   FatalException, "Invalid pDPhi.") ;
    138     }
    139 
    140     // Ensure pSPhi in 0-2PI or -2PI-0 range if shape crosses 0
    141 
    142     if ( pSPhi < 0 ) fSPhi = twopi - std::fmod(std::fabs(pSPhi),twopi) ;
    143     else             fSPhi = std::fmod(pSPhi,twopi) ;
    144      
    145     if (fSPhi + fDPhi > twopi) fSPhi -= twopi ;
    146   }
     142                  FatalException, "Invalid dphi.");
     143    }
     144
     145    // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
     146
     147    if ( pSPhi < 0 )
     148    {
     149      fSPhi = twopi - std::fmod(std::fabs(pSPhi),twopi);
     150    }
     151    else
     152    {
     153      fSPhi = std::fmod(pSPhi,twopi) ;
     154    }
     155    if ( fSPhi+fDPhi > twopi )
     156    {
     157      fSPhi -= twopi ;
     158    }
     159  }
     160  InitializeTrigonometry();
    147161}
    148162
     
    173187  G4double r2, rl, rh, pPhi, tolRMin, tolRMax; // rh2, rl2 ;
    174188  EInside in;
    175 
    176   if (std::fabs(p.z()) > fDz + kCarTolerance*0.5 ) return in = kOutside;
    177   else if(std::fabs(p.z()) >= fDz - kCarTolerance*0.5 )   in = kSurface;
    178   else                                                    in = kInside;
     189  static const G4double halfCarTolerance=kCarTolerance*0.5;
     190  static const G4double halfRadTolerance=kRadTolerance*0.5;
     191  static const G4double halfAngTolerance=kAngTolerance*0.5;
     192
     193  if (std::fabs(p.z()) > fDz + halfCarTolerance )  { return in = kOutside; }
     194  else if(std::fabs(p.z()) >= fDz - halfCarTolerance )    { in = kSurface; }
     195  else                                                    { in = kInside;  }
    179196
    180197  r2 = p.x()*p.x() + p.y()*p.y() ;
     
    184201  // rh2 = rh*rh;
    185202
    186   tolRMin = rl - kRadTolerance*0.5 ;
    187   if ( tolRMin < 0 ) tolRMin = 0 ;
    188   tolRMax = rh + kRadTolerance*0.5 ;
    189 
    190   if ( r2 < tolRMin*tolRMin || r2 > tolRMax*tolRMax ) return in = kOutside;
    191 
    192   if (rl) tolRMin = rl + kRadTolerance*0.5 ;
    193   else    tolRMin = 0.0 ;
    194   tolRMax         = rh - kRadTolerance*0.5 ;
     203  tolRMin = rl - halfRadTolerance;
     204  if ( tolRMin < 0 )  { tolRMin = 0; }
     205  tolRMax = rh + halfRadTolerance;
     206
     207  if ( (r2<tolRMin*tolRMin) || (r2>tolRMax*tolRMax) ) { return in = kOutside; }
     208
     209  if (rl) { tolRMin = rl + halfRadTolerance; }
     210  else    { tolRMin = 0.0; }
     211  tolRMax = rh - halfRadTolerance;
    195212     
    196213  if (in == kInside) // else it's kSurface already
    197214  {
    198      if (r2 < tolRMin*tolRMin || r2 >= tolRMax*tolRMax) in = kSurface;
    199     //  if (r2 <= tolRMin*tolRMin || r2-rh2 >= -rh*kRadTolerance) in = kSurface;
    200   }
    201   if ( ( fDPhi < twopi - kAngTolerance ) &&
    202        ( (p.x() != 0.0 ) || (p.y() != 0.0) ) )
     215     if ( (r2 < tolRMin*tolRMin) || (r2 >= tolRMax*tolRMax) ) { in = kSurface; }
     216  }
     217  if ( !fPhiFullCone && ((p.x() != 0.0) || (p.y() != 0.0)) )
    203218  {
    204219    pPhi = std::atan2(p.y(),p.x()) ;
    205220
    206     if ( pPhi < fSPhi - kAngTolerance*0.5  )             pPhi += twopi ;
    207     else if ( pPhi > fSPhi + fDPhi + kAngTolerance*0.5 ) pPhi -= twopi;
     221    if ( pPhi < fSPhi - halfAngTolerance  )             { pPhi += twopi; }
     222    else if ( pPhi > fSPhi + fDPhi + halfAngTolerance ) { pPhi -= twopi; }
    208223   
    209     if ( (pPhi < fSPhi - kAngTolerance*0.5) ||         
    210          (pPhi > fSPhi + fDPhi + kAngTolerance*0.5) )   return in = kOutside;
     224    if ( (pPhi < fSPhi - halfAngTolerance) ||         
     225         (pPhi > fSPhi + fDPhi + halfAngTolerance) )  { return in = kOutside; }
    211226     
    212227    else if (in == kInside)  // else it's kSurface anyway already
    213228    {
    214         if ( (pPhi < fSPhi + kAngTolerance*0.5) ||
    215              (pPhi > fSPhi + fDPhi - kAngTolerance*0.5) )  in = kSurface ;
    216     }
    217   }
    218   else if( fDPhi < twopi - kAngTolerance )  in = kSurface ;
     229       if ( (pPhi < fSPhi + halfAngTolerance) ||
     230            (pPhi > fSPhi + fDPhi - halfAngTolerance) )  { in = kSurface; }
     231    }
     232  }
     233  else if ( !fPhiFullCone )  { in = kSurface; }
    219234
    220235  return in ;
     
    244259                    G4double&          pMax  ) const
    245260{
    246   if ( !pTransform.IsRotated() &&
    247         fDPhi == twopi && fRmin1 == 0 && fRmin2 == 0 )
     261  if ( !pTransform.IsRotated() && (fDPhi == twopi)
     262    && (fRmin1 == 0) && (fRmin2 == 0) )
    248263  {
    249264    // Special case handling for unrotated solid cones
     
    265280    if (pVoxelLimit.IsZLimited())
    266281    {
    267       if( zMin > pVoxelLimit.GetMaxZExtent() + kCarTolerance ||
    268           zMax < pVoxelLimit.GetMinZExtent() - kCarTolerance   )
     282      if( (zMin > pVoxelLimit.GetMaxZExtent() + kCarTolerance) ||
     283          (zMax < pVoxelLimit.GetMinZExtent() - kCarTolerance)  )
    269284      {
    270285        return false ;
     
    290305    if (pVoxelLimit.IsXLimited())
    291306    {
    292       if ( xMin > pVoxelLimit.GetMaxXExtent() + kCarTolerance ||
    293            xMax < pVoxelLimit.GetMinXExtent() - kCarTolerance    )
     307      if ( (xMin > pVoxelLimit.GetMaxXExtent() + kCarTolerance) ||
     308           (xMax < pVoxelLimit.GetMinXExtent() - kCarTolerance)  )
    294309      {
    295310        return false ;
     
    315330    if (pVoxelLimit.IsYLimited())
    316331    {
    317       if ( yMin > pVoxelLimit.GetMaxYExtent() + kCarTolerance ||
    318            yMax < pVoxelLimit.GetMinYExtent() - kCarTolerance     )
     332      if ( (yMin > pVoxelLimit.GetMaxYExtent() + kCarTolerance) ||
     333           (yMax < pVoxelLimit.GetMinYExtent() - kCarTolerance)  )
    319334      {
    320335        return false ;
     
    338353        yoff2 = yMax - yoffset ;
    339354
    340         if (yoff1 >= 0 && yoff2 >= 0) // Y limits cross max/min x => no change
    341         {
     355        if ((yoff1 >= 0) && (yoff2 >= 0)) // Y limits cross max/min x
     356        {                                 // => no change
    342357          pMin = xMin ;
    343358          pMax = xMax ;
     
    362377        xoff2 = xMax - xoffset ;
    363378
    364         if (xoff1 >= 0 && xoff2 >= 0 ) // X limits cross max/min y => no change
    365         {
     379        if ((xoff1 >= 0) && (xoff2 >= 0) ) // X limits cross max/min y
     380        {                                  // => no change
    366381          pMin = yMin ;
    367382          pMax = yMax ;
     
    409424    for ( i = 0 ; i < noEntries ; i += 4 )
    410425    {
    411       ClipCrossSection(vertices,i,pVoxelLimit,pAxis,pMin,pMax) ;
     426      ClipCrossSection(vertices, i, pVoxelLimit, pAxis, pMin, pMax) ;
    412427    }
    413428    for ( i = 0 ; i < noBetweenSections4 ; i += 4 )
    414429    {
    415       ClipBetweenSections(vertices,i,pVoxelLimit,pAxis,pMin,pMax) ;
     430      ClipBetweenSections(vertices, i, pVoxelLimit, pAxis, pMin, pMax) ;
    416431    }   
    417     if ( pMin != kInfinity || pMax != -kInfinity )
     432    if ( (pMin != kInfinity) || (pMax != -kInfinity) )
    418433    {
    419434      existsAfterClip = true ;
     
    462477  G4double tanRMin, secRMin, pRMin, widRMin;
    463478  G4double tanRMax, secRMax, pRMax, widRMax;
    464   G4double delta = 0.5*kCarTolerance, dAngle = 0.5*kAngTolerance;
     479
     480  static const G4double delta  = 0.5*kCarTolerance;
     481  static const G4double dAngle = 0.5*kAngTolerance;
    465482 
    466   G4ThreeVector norm, sumnorm(0.,0.,0.), nZ = G4ThreeVector(0.,0.,1.0);
     483  G4ThreeVector norm, sumnorm(0.,0.,0.), nZ = G4ThreeVector(0.,0.,1.);
    467484  G4ThreeVector nR, nr(0.,0.,0.), nPs, nPe;
    468485
     
    482499  distRMax = std::fabs(pRMax - widRMax)/secRMax;
    483500
    484   if (fDPhi < twopi)   //  &&  rho ) // Protected against (0,0,z)
     501  if (!fPhiFullCone)  // Protected against (0,0,z)
    485502  {
    486503    if ( rho )
     
    488505      pPhi = std::atan2(p.y(),p.x());
    489506
    490       if(pPhi  < fSPhi-delta)           pPhi     += twopi;
    491       else if(pPhi > fSPhi+fDPhi+delta) pPhi     -= twopi;
     507      if (pPhi  < fSPhi-delta)            { pPhi += twopi; }
     508      else if (pPhi > fSPhi+fDPhi+delta)  { pPhi -= twopi; }
    492509
    493510      distSPhi = std::fabs( pPhi - fSPhi );
    494       distEPhi = std::fabs(pPhi - fSPhi - fDPhi);
     511      distEPhi = std::fabs( pPhi - fSPhi - fDPhi );
    495512    }
    496513    else if( !(fRmin1) || !(fRmin2) )
     
    499516      distEPhi = 0.;
    500517    }
    501     nPs = G4ThreeVector(std::sin(fSPhi),-std::cos(fSPhi),0);
    502     nPe = G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0);
     518    nPs = G4ThreeVector(std::sin(fSPhi), -std::cos(fSPhi), 0);
     519    nPe = G4ThreeVector(-std::sin(fSPhi+fDPhi), std::cos(fSPhi+fDPhi), 0);
    503520  }
    504521  if ( rho > delta )   
    505522  {
    506     nR = G4ThreeVector(p.x()/rho/secRMax,p.y()/rho/secRMax,-tanRMax/secRMax);
    507     if (fRmin1 || fRmin2) nr = G4ThreeVector(-p.x()/rho/secRMin,-p.y()/rho/secRMin,tanRMin/secRMin);
     523    nR = G4ThreeVector(p.x()/rho/secRMax, p.y()/rho/secRMax, -tanRMax/secRMax);
     524    if (fRmin1 || fRmin2)
     525    {
     526      nr = G4ThreeVector(-p.x()/rho/secRMin,-p.y()/rho/secRMin,tanRMin/secRMin);
     527    }
    508528  }
    509529
     
    513533    sumnorm += nR;
    514534  }
    515   if( (fRmin1 || fRmin2) && distRMin <= delta )
     535  if( (fRmin1 || fRmin2) && (distRMin <= delta) )
    516536  {
    517537    noSurfaces ++;
    518538    sumnorm += nr;
    519539  }
    520   if( fDPhi < twopi )   
     540  if( !fPhiFullCone )   
    521541  {
    522542    if (distSPhi <= dAngle)
     
    534554  {
    535555    noSurfaces ++;
    536     if ( p.z() >= 0.)  sumnorm += nZ;
    537     else               sumnorm -= nZ;
     556    if ( p.z() >= 0.)  { sumnorm += nZ; }
     557    else               { sumnorm -= nZ; }
    538558  }
    539559  if ( noSurfaces == 0 )
     
    545565     norm = ApproxSurfaceNormal(p);
    546566  }
    547   else if ( noSurfaces == 1 ) norm = sumnorm;
    548   else                        norm = sumnorm.unit();
     567  else if ( noSurfaces == 1 )  { norm = sumnorm; }
     568  else                         { norm = sumnorm.unit(); }
     569
    549570  return norm ;
    550571}
    551572
    552 //////////////////////////////////////////////////////////////////////////////////
     573////////////////////////////////////////////////////////////////////////////
    553574//
    554575// Algorithm for SurfaceNormal() following the original specification
     
    605626    }
    606627  }
    607   if ( fDPhi < twopi && rho )  // Protected against (0,0,z)
     628  if ( !fPhiFullCone && rho )  // Protected against (0,0,z)
    608629  {
    609630    phi = std::atan2(p.y(),p.x()) ;
    610631
    611     if (phi < 0) phi += twopi ;
    612 
    613     if (fSPhi < 0) distSPhi = std::fabs(phi - (fSPhi + twopi))*rho ;
    614     else           distSPhi = std::fabs(phi - fSPhi)*rho ;
     632    if (phi < 0)  { phi += twopi; }
     633
     634    if (fSPhi < 0)  { distSPhi = std::fabs(phi - (fSPhi + twopi))*rho; }
     635    else            { distSPhi = std::fabs(phi - fSPhi)*rho; }
    615636
    616637    distEPhi = std::fabs(phi - fSPhi - fDPhi)*rho ;
     
    620641    if (distSPhi < distEPhi)
    621642    {
    622       if (distSPhi < distMin) side = kNSPhi ;
     643      if (distSPhi < distMin)  { side = kNSPhi; }
    623644    }
    624645    else
    625646    {
    626       if (distEPhi < distMin) side = kNEPhi ;
     647      if (distEPhi < distMin)  { side = kNEPhi; }
    627648    }
    628649  }   
     
    631652    case kNRMin:      // Inner radius
    632653      rho *= secRMin ;
    633       norm = G4ThreeVector(-p.x()/rho,-p.y()/rho,tanRMin/secRMin) ;
     654      norm = G4ThreeVector(-p.x()/rho, -p.y()/rho, tanRMin/secRMin) ;
    634655      break ;
    635656    case kNRMax:      // Outer radius
    636657      rho *= secRMax ;
    637       norm = G4ThreeVector(p.x()/rho,p.y()/rho,-tanRMax/secRMax) ;
     658      norm = G4ThreeVector(p.x()/rho, p.y()/rho, -tanRMax/secRMax) ;
    638659      break ;
    639660    case kNZ:      // +/- dz
    640       if (p.z() > 0) norm = G4ThreeVector(0,0,1) ;
    641       else           norm = G4ThreeVector(0,0,-1) ;
     661      if (p.z() > 0)  { norm = G4ThreeVector(0,0,1);  }
     662      else            { norm = G4ThreeVector(0,0,-1); }
    642663      break ;
    643664    case kNSPhi:
    644       norm = G4ThreeVector(std::sin(fSPhi),-std::cos(fSPhi),0) ;
     665      norm = G4ThreeVector(std::sin(fSPhi), -std::cos(fSPhi), 0) ;
    645666      break ;
    646667    case kNEPhi:
    647       norm=G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0) ;
     668      norm=G4ThreeVector(-std::sin(fSPhi+fDPhi), std::cos(fSPhi+fDPhi), 0) ;
    648669      break ;
    649670    default:
     
    677698//
    678699// NOTE:
    679 // - Precalculations for phi trigonometry are Done `just in time'
    680700// - `if valid' implies tolerant checking of intersection points
    681701// - z, phi intersection from Tubs
     
    686706  G4double snxt = kInfinity ;      // snxt = default return value
    687707
    688   G4bool seg ;        // true if segmented in phi
    689   G4double hDPhi,hDPhiOT,hDPhiIT,cosHDPhiOT=0.,cosHDPhiIT=0. ;
    690           // half dphi + outer tolerance
    691   G4double cPhi,sinCPhi=0.,cosCPhi=0. ;  // central phi
     708  static const G4double halfCarTolerance=kCarTolerance*0.5;
     709  static const G4double halfRadTolerance=kRadTolerance*0.5;
    692710
    693711  G4double tanRMax,secRMax,rMaxAv,rMaxOAv ;  // Data for cones
     
    704722  G4double nt1,nt2,nt3 ;
    705723  G4double Comp ;
    706   G4double cosSPhi,sinSPhi ;    // Trig for phi start intersect
    707   G4double ePhi,cosEPhi,sinEPhi ;  // for phi end intersect
    708 
    709   //
    710   // Set phi divided flag and precalcs
    711   //
    712   if (fDPhi < twopi)
    713   {
    714     seg        = true ;
    715     hDPhi      = 0.5*fDPhi ;    // half delta phi
    716     cPhi       = fSPhi + hDPhi ; ;
    717     hDPhiOT    = hDPhi + 0.5*kAngTolerance ;  // outers tol' half delta phi
    718     hDPhiIT    = hDPhi - 0.5*kAngTolerance ;
    719     sinCPhi    = std::sin(cPhi) ;
    720     cosCPhi    = std::cos(cPhi) ;
    721     cosHDPhiOT = std::cos(hDPhiOT) ;
    722     cosHDPhiIT = std::cos(hDPhiIT) ;
    723   }
    724   else     seg = false ;
    725724
    726725  // Cone Precalcs
     
    730729  rMinAv  = (fRmin1 + fRmin2)*0.5 ;
    731730
    732   if (rMinAv > kRadTolerance*0.5)
    733   {
    734     rMinOAv = rMinAv - kRadTolerance*0.5 ;
    735     rMinIAv = rMinAv + kRadTolerance*0.5 ;
     731  if (rMinAv > halfRadTolerance)
     732  {
     733    rMinOAv = rMinAv - halfRadTolerance ;
     734    rMinIAv = rMinAv + halfRadTolerance ;
    736735  }
    737736  else
     
    743742  secRMax = std::sqrt(1.0 + tanRMax*tanRMax) ;
    744743  rMaxAv  = (fRmax1 + fRmax2)*0.5 ;
    745   rMaxOAv = rMaxAv + kRadTolerance*0.5 ;
     744  rMaxOAv = rMaxAv + halfRadTolerance ;
    746745   
    747746  // Intersection with z-surfaces
    748747
    749   tolIDz = fDz - kCarTolerance*0.5 ;
    750   tolODz = fDz + kCarTolerance*0.5 ;
     748  tolIDz = fDz - halfCarTolerance ;
     749  tolODz = fDz + halfCarTolerance ;
    751750
    752751  if (std::fabs(p.z()) >= tolIDz)
     
    756755      s = (std::fabs(p.z()) - fDz)/std::fabs(v.z()) ;  // Z intersect distance
    757756
    758       if( s < 0.0 ) s = 0.0 ;                  // negative dist -> zero
     757      if( s < 0.0 )  { s = 0.0; }                      // negative dist -> zero
    759758
    760759      xi   = p.x() + s*v.x() ;  // Intersection coords
    761760      yi   = p.y() + s*v.y() ;
    762       rhoi2 = xi*xi + yi*yi   ;
     761      rhoi2 = xi*xi + yi*yi  ;
    763762
    764763      // Check validity of intersection
     
    767766      if (v.z() > 0)
    768767      {
    769         tolORMin  = fRmin1 - 0.5*kRadTolerance*secRMin ;
    770         tolIRMin  = fRmin1 + 0.5*kRadTolerance*secRMin ;
    771         tolIRMax  = fRmax1 - 0.5*kRadTolerance*secRMin ;
    772         tolORMax2 = (fRmax1 + 0.5*kRadTolerance*secRMax)*
    773                     (fRmax1 + 0.5*kRadTolerance*secRMax) ;
     768        tolORMin  = fRmin1 - halfRadTolerance*secRMin ;
     769        tolIRMin  = fRmin1 + halfRadTolerance*secRMin ;
     770        tolIRMax  = fRmax1 - halfRadTolerance*secRMin ;
     771        tolORMax2 = (fRmax1 + halfRadTolerance*secRMax)*
     772                    (fRmax1 + halfRadTolerance*secRMax) ;
    774773      }
    775774      else
    776775      {
    777         tolORMin  = fRmin2 - 0.5*kRadTolerance*secRMin ;
    778         tolIRMin  = fRmin2 + 0.5*kRadTolerance*secRMin ;
    779         tolIRMax  = fRmax2 - 0.5*kRadTolerance*secRMin ;
    780         tolORMax2 = (fRmax2 + 0.5*kRadTolerance*secRMax)*
    781                     (fRmax2 + 0.5*kRadTolerance*secRMax) ;
     776        tolORMin  = fRmin2 - halfRadTolerance*secRMin ;
     777        tolIRMin  = fRmin2 + halfRadTolerance*secRMin ;
     778        tolIRMax  = fRmax2 - halfRadTolerance*secRMin ;
     779        tolORMax2 = (fRmax2 + halfRadTolerance*secRMax)*
     780                    (fRmax2 + halfRadTolerance*secRMax) ;
    782781      }
    783782      if ( tolORMin > 0 )
     
    791790        tolIRMin2 = 0.0 ;
    792791      }
    793       if ( tolIRMax > 0 )   tolIRMax2 = tolIRMax*tolIRMax ;      
    794       else                  tolIRMax2 = 0.0 ;
     792      if ( tolIRMax > 0 )  { tolIRMax2 = tolIRMax*tolIRMax; }     
     793      else                 { tolIRMax2 = 0.0; }
    795794     
    796       if (tolIRMin2 <= rhoi2 && rhoi2 <= tolIRMax2)
    797       {
    798   if ( seg && rhoi2 )
    799   {
    800     // Psi = angle made with central (average) phi of shape
    801 
    802     cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
    803 
    804     if (cosPsi >= cosHDPhiIT) return s ;
    805   }
    806   else return s ;
    807       }
    808       /*
    809       else if (tolORMin2 <= rhoi2 && rhoi2 <= tolORMax2)
    810       {
    811   if ( seg && rhoi2 )
    812   {
    813     // Psi = angle made with central (average) phi of shape
    814 
    815     cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
    816 
    817     if (cosPsi >= cosHDPhiIT) return s ;
    818   }
    819   else return s ;
    820       }
    821       */
     795      if ( (tolIRMin2 <= rhoi2) && (rhoi2 <= tolIRMax2) )
     796      {
     797        if ( !fPhiFullCone && rhoi2 )
     798        {
     799          // Psi = angle made with central (average) phi of shape
     800
     801          cosPsi = (xi*cosCPhi + yi*sinCPhi)/std::sqrt(rhoi2) ;
     802
     803          if (cosPsi >= cosHDPhiIT)  { return s; }
     804        }
     805        else
     806        {
     807          return s;
     808        }
     809      }
    822810    }
    823811    else  // On/outside extent, and heading away  -> cannot intersect
     
    861849  if (std::fabs(nt1) > kRadTolerance)  // Equation quadratic => 2 roots
    862850  {
    863       b = nt2/nt1 ;
    864       c = nt3/nt1 ;
    865       d = b*b-c   ;
    866     if ( nt3 > rout*kRadTolerance*secRMax || rout < 0 )
     851    b = nt2/nt1;
     852    c = nt3/nt1;
     853    d = b*b-c  ;
     854    if ( (nt3 > rout*kRadTolerance*secRMax) || (rout < 0) )
    867855    {
    868856      // If outside real cone (should be rho-rout>kRadTolerance*0.5
    869857      // NOT rho^2 etc) saves a std::sqrt() at expense of accuracy
    870858
    871 
    872859      if (d >= 0)
    873860      {
    874861         
    875         if (rout < 0 && nt3 <= 0 )
     862        if ((rout < 0) && (nt3 <= 0))
    876863        {
    877864          // Inside `shadow cone' with -ve radius
     
    882869        else
    883870        {
    884           if ( b <= 0 && c >= 0 ) // both >=0, try smaller root
     871          if ((b <= 0) && (c >= 0)) // both >=0, try smaller root
    885872          {
    886873            s = -b - std::sqrt(d) ;
     
    906893            // Z ok. Check phi intersection if reqd
    907894
    908             if ( ! seg )  return s ;
     895            if ( fPhiFullCone )  { return s; }
    909896            else
    910897            {
     
    914901              cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
    915902
    916               if ( cosPsi >= cosHDPhiIT ) return s ;
     903              if ( cosPsi >= cosHDPhiIT )  { return s; }
    917904            }
    918905          }
     
    925912      // check not inside, and heading through G4Cons (-> 0 to in)
    926913
    927       if ( t3  > (rin + kRadTolerance*0.5*secRMin)*
    928                  (rin + kRadTolerance*0.5*secRMin) &&
    929            nt2 < 0                                 &&
    930            d >= 0                                  &&
    931            //  nt2 < -kCarTolerance*secRMax/2/fDz                  &&
    932            // t2 < std::sqrt(t3)*v.z()*tanRMax                          &&
    933            // d > kCarTolerance*secRMax*(rout-b*tanRMax*v.z())/nt1 &&
    934            std::fabs(p.z()) <= tolIDz )
     914      if ( ( t3  > (rin + halfRadTolerance*secRMin)*
     915                   (rin + halfRadTolerance*secRMin) )
     916        && (nt2 < 0) && (d >= 0) && (std::fabs(p.z()) <= tolIDz) )
    935917      {
    936918        // Inside cones, delta r -ve, inside z extent
    937919
    938         if (seg)
     920        if ( !fPhiFullCone )
    939921        {
    940922          cosPsi = (p.x()*cosCPhi + p.y()*sinCPhi)/std::sqrt(t3) ;
    941923
    942           if (cosPsi >= cosHDPhiIT) return 0.0 ;
    943         }
    944         else  return 0.0 ;
     924          if (cosPsi >= cosHDPhiIT)  { return 0.0; }
     925        }
     926        else  { return 0.0; }
    945927      }
    946928    }
     
    952934      s = -0.5*nt3/nt2 ;
    953935
    954       if ( s < 0 )   return kInfinity ;   // travel away
     936      if ( s < 0 )  { return kInfinity; }   // travel away
    955937      else  // s >= 0,  If 'forwards'. Check z intersection
    956938      {
    957939        zi = p.z() + s*v.z() ;
    958940
    959         if (std::fabs(zi) <= tolODz && nt2 < 0)
     941        if ((std::fabs(zi) <= tolODz) && (nt2 < 0))
    960942        {
    961943          // Z ok. Check phi intersection if reqd
    962944
    963           if ( ! seg ) return s ;
     945          if ( fPhiFullCone )  { return s; }
    964946          else
    965947          {
     
    969951            cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
    970952
    971             if (cosPsi >= cosHDPhiIT) return s ;
     953            if (cosPsi >= cosHDPhiIT)  { return s; }
    972954          }
    973955        }
     
    1015997            if ( std::fabs(zi) <= tolODz )
    1016998            {
    1017               if ( seg )
     999              if ( !fPhiFullCone )
    10181000              {
    10191001                xi     = p.x() + s*v.x() ;
     
    10221004                cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
    10231005
    1024                 if (cosPsi >= cosHDPhiIT) snxt = s ;
     1006                if (cosPsi >= cosHDPhiIT)  { snxt = s; }
    10251007              }
    1026               else return s ;
     1008              else  { return s; }
    10271009            }
    10281010          }
     
    10461028          ri = rMinAv + zi*tanRMin ;
    10471029
    1048           if ( ri >= 0 )
     1030          if ( ri > 0 )
    10491031          {
    1050             if ( s >= 0 && std::fabs(zi) <= tolODz )  // s > 0
     1032            if ( (s >= 0) && (std::fabs(zi) <= tolODz) )  // s > 0
    10511033            {
    1052               if ( seg )
     1034              if ( !fPhiFullCone )
    10531035              {
    10541036                xi     = p.x() + s*v.x() ;
     
    10561038                cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
    10571039
    1058                 if (cosPsi >= cosHDPhiOT) snxt = s ;
     1040                if (cosPsi >= cosHDPhiOT)  { snxt = s; }
    10591041              }
    1060               else  return s ;
     1042              else  { return s; }
    10611043            }
    10621044          }
     
    10671049            ri = rMinAv + zi*tanRMin ;
    10681050
    1069             if ( s >= 0 && ri >= 0 && std::fabs(zi) <= tolODz ) // s>0
     1051            if ( (s >= 0) && (ri > 0) && (std::fabs(zi) <= tolODz) ) // s>0
    10701052            {
    1071               if ( seg )
     1053              if ( !fPhiFullCone )
    10721054              {
    10731055                xi     = p.x() + s*v.x() ;
     
    10751057                cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
    10761058
    1077                 if (cosPsi >= cosHDPhiIT) snxt = s ;
     1059                if (cosPsi >= cosHDPhiIT)  { snxt = s; }
    10781060              }
    1079               else  return s ;
     1061              else  { return s; }
    10801062            }
    10811063          }
     
    10951077            // Inside inner real cone, heading outwards, inside z range
    10961078
    1097             if ( seg )
     1079            if ( !fPhiFullCone )
    10981080            {
    10991081              cosPsi = (p.x()*cosCPhi + p.y()*sinCPhi)/std::sqrt(t3) ;
    11001082
    1101               if (cosPsi >= cosHDPhiIT)  return 0.0 ;
     1083              if (cosPsi >= cosHDPhiIT)  { return 0.0; }
    11021084            }
    1103             else  return 0.0 ;
     1085            else  { return 0.0; }
    11041086          }
    11051087          else
     
    11231105                zi = p.z() + s*v.z() ;
    11241106
    1125                 if ( s >= 0 && std::fabs(zi) <= tolODz )  // s>0
     1107                if ( (s >= 0) && (std::fabs(zi) <= tolODz) )  // s>0
    11261108                {
    1127                   if ( seg )
     1109                  if ( !fPhiFullCone )
    11281110                  {
    11291111                    xi     = p.x() + s*v.x() ;
     
    11321114                    cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri ;
    11331115
    1134                     if ( cosPsi >= cosHDPhiIT )  snxt = s ;
     1116                    if ( cosPsi >= cosHDPhiIT )  { snxt = s; }
    11351117                  }
    1136                   else return s ;
     1118                  else  { return s; }
    11371119                }
    11381120              }
    1139               else  return kInfinity ;
     1121              else  { return kInfinity; }
    11401122            }
    11411123          }
     
    11521134            zi = p.z() + s*v.z() ;
    11531135
    1154             if ( s >= 0 && std::fabs(zi) <= tolODz )  // s>0
     1136            if ( (s >= 0) && (std::fabs(zi) <= tolODz) )  // s>0
    11551137            {
    1156               if ( seg )
     1138              if ( !fPhiFullCone )
    11571139              {
    11581140                xi     = p.x() + s*v.x();
     
    11611143                cosPsi = (xi*cosCPhi + yi*sinCPhi)/ri;
    11621144
    1163                 if (cosPsi >= cosHDPhiIT) snxt = s ;
     1145                if (cosPsi >= cosHDPhiIT)  { snxt = s; }
    11641146              }
    1165               else  return s ;
     1147              else  { return s; }
    11661148            }
    11671149          }
     
    11801162  //         -> Should use some form of loop Construct
    11811163
    1182   if ( seg )
    1183   {
    1184     // First phi surface (`S'tarting phi)
    1185 
    1186     sinSPhi = std::sin(fSPhi) ;
    1187     cosSPhi = std::cos(fSPhi) ;
     1164  if ( !fPhiFullCone )
     1165  {
     1166    // First phi surface (starting phi)
     1167
    11881168    Comp    = v.x()*sinSPhi - v.y()*cosSPhi ;
    11891169                   
     
    11921172      Dist = (p.y()*cosSPhi - p.x()*sinSPhi) ;
    11931173
    1194       if (Dist < kCarTolerance*0.5)
     1174      if (Dist < halfCarTolerance)
    11951175      {
    11961176        s = Dist/Comp ;
     
    11981178        if ( s < snxt )
    11991179        {
    1200           if ( s < 0 ) s = 0.0 ;
     1180          if ( s < 0 )  { s = 0.0; }
    12011181
    12021182          zi = p.z() + s*v.z() ;
     
    12101190            tolORMax2 = (rMaxOAv + zi*tanRMax)*(rMaxOAv + zi*tanRMax) ;
    12111191
    1212             if ( rhoi2 >= tolORMin2 && rhoi2 <= tolORMax2 )
     1192            if ( (rhoi2 >= tolORMin2) && (rhoi2 <= tolORMax2) )
    12131193            {
    12141194              // z and r intersections good - check intersecting with
    12151195              // correct half-plane
    12161196
    1217               if ((yi*cosCPhi - xi*sinCPhi) <= 0 ) snxt = s ;
    1218             }   
     1197              if ((yi*cosCPhi - xi*sinCPhi) <= 0 )  { snxt = s; }
     1198            }
    12191199          }
    12201200        }
    12211201      }
    1222     }   
    1223     // Second phi surface (`E'nding phi)
    1224 
    1225     ePhi    = fSPhi + fDPhi ;
    1226     sinEPhi = std::sin(ePhi) ;
    1227     cosEPhi = std::cos(ePhi) ;
     1202    }
     1203
     1204    // Second phi surface (Ending phi)
     1205
    12281206    Comp    = -(v.x()*sinEPhi - v.y()*cosEPhi) ;
    12291207       
     
    12311209    {
    12321210      Dist = -(p.y()*cosEPhi - p.x()*sinEPhi) ;
    1233       if (Dist < kCarTolerance*0.5)
     1211      if (Dist < halfCarTolerance)
    12341212      {
    12351213        s = Dist/Comp ;
     
    12371215        if ( s < snxt )
    12381216        {
    1239           if ( s < 0 )  s = 0.0 ;
     1217          if ( s < 0 )  { s = 0.0; }
    12401218
    12411219          zi = p.z() + s*v.z() ;
     
    12491227            tolORMax2 = (rMaxOAv + zi*tanRMax)*(rMaxOAv + zi*tanRMax) ;
    12501228
    1251             if ( rhoi2 >= tolORMin2 && rhoi2 <= tolORMax2 )
     1229            if ( (rhoi2 >= tolORMin2) && (rhoi2 <= tolORMax2) )
    12521230            {
    12531231              // z and r intersections good - check intersecting with
    12541232              // correct half-plane
    12551233
    1256               if ( (yi*cosCPhi - xi*sinCPhi) >= 0.0 )  snxt = s ;
    1257             }   
     1234              if ( (yi*cosCPhi - xi*sinCPhi) >= 0.0 )  { snxt = s; }
     1235            }
    12581236          }
    12591237        }
     
    12611239    }
    12621240  }
    1263   if (snxt < kCarTolerance*0.5) snxt = 0.;
    1264 
    1265 #ifdef consdebug
    1266   G4cout.precision(24);
    1267   G4cout<<"G4Cons::DistanceToIn(p,v) "<<G4endl;
    1268   G4cout<<"position = "<<p<<G4endl;
    1269   G4cout<<"direction = "<<v<<G4endl;
    1270   G4cout<<"distance = "<<snxt<<G4endl;
    1271 #endif
     1241  if (snxt < halfCarTolerance)  { snxt = 0.; }
    12721242
    12731243  return snxt ;
     
    12831253G4double G4Cons::DistanceToIn(const G4ThreeVector& p) const
    12841254{
    1285   G4double safe=0.0, rho, safeR1, safeR2, safeZ ;
     1255  G4double safe=0.0, rho, safeR1, safeR2, safeZ, safePhi, cosPsi ;
    12861256  G4double tanRMin, secRMin, pRMin ;
    12871257  G4double tanRMax, secRMax, pRMax ;
    1288   G4double phiC, cosPhiC, sinPhiC, safePhi, ePhi ;
    1289   G4double cosPsi ;
    12901258
    12911259  rho   = std::sqrt(p.x()*p.x() + p.y()*p.y()) ;
     
    13041272    safeR2  = (rho - pRMax)/secRMax ;
    13051273
    1306     if ( safeR1 > safeR2) safe = safeR1 ;
    1307     else                  safe = safeR2 ;
     1274    if ( safeR1 > safeR2) { safe = safeR1; }
     1275    else                  { safe = safeR2; }
    13081276  }
    13091277  else
     
    13141282    safe    = (rho - pRMax)/secRMax ;
    13151283  }
    1316   if ( safeZ > safe ) safe = safeZ ;
    1317 
    1318   if ( fDPhi < twopi && rho )
    1319   {
    1320     phiC    = fSPhi + fDPhi*0.5 ;
    1321     cosPhiC = std::cos(phiC) ;
    1322     sinPhiC = std::sin(phiC) ;
    1323 
     1284  if ( safeZ > safe )  { safe = safeZ; }
     1285
     1286  if ( !fPhiFullCone && rho )
     1287  {
    13241288    // Psi=angle from central phi to point
    13251289
    1326     cosPsi = (p.x()*cosPhiC + p.y()*sinPhiC)/rho ;
     1290    cosPsi = (p.x()*cosCPhi + p.y()*sinCPhi)/rho ;
    13271291
    13281292    if ( cosPsi < std::cos(fDPhi*0.5) ) // Point lies outside phi range
    13291293    {
    1330       if ( (p.y()*cosPhiC - p.x()*sinPhiC) <= 0.0 )
    1331       {
    1332         safePhi = std::fabs(p.x()*std::sin(fSPhi) - p.y()*std::cos(fSPhi)) ;
     1294      if ( (p.y()*cosCPhi - p.x()*sinCPhi) <= 0.0 )
     1295      {
     1296        safePhi = std::fabs(p.x()*std::sin(fSPhi)-p.y()*std::cos(fSPhi));
    13331297      }
    13341298      else
    13351299      {
    1336         ePhi    = fSPhi + fDPhi ;
    1337         safePhi = std::fabs(p.x()*std::sin(ePhi) - p.y()*std::cos(ePhi)) ;
    1338       }
    1339       if ( safePhi > safe ) safe = safePhi ;
    1340     }
    1341   }
    1342   if ( safe < 0.0 ) safe = 0.0 ;
     1300        safePhi = std::fabs(p.x()*sinEPhi-p.y()*cosEPhi);
     1301      }
     1302      if ( safePhi > safe )  { safe = safePhi; }
     1303    }
     1304  }
     1305  if ( safe < 0.0 )  { safe = 0.0; }
    13431306
    13441307  return safe ;
     
    13471310///////////////////////////////////////////////////////////////
    13481311//
    1349 // Calculate distance to surface of shape from `inside', allowing for tolerance
     1312// Calculate distance to surface of shape from 'inside', allowing for tolerance
    13501313// - Only Calc rmax intersection if no valid rmin intersection
    13511314
    13521315G4double G4Cons::DistanceToOut( const G4ThreeVector& p,
    1353               const G4ThreeVector& v,
    1354               const G4bool calcNorm,
    1355                     G4bool *validNorm,
    1356                     G4ThreeVector *n) const
     1316                                const G4ThreeVector& v,
     1317                                const G4bool calcNorm,
     1318                                      G4bool *validNorm,
     1319                                      G4ThreeVector *n) const
    13571320{
    13581321  ESide side = kNull, sider = kNull, sidephi = kNull;
    13591322
     1323  static const G4double halfCarTolerance=kCarTolerance*0.5;
     1324  static const G4double halfRadTolerance=kRadTolerance*0.5;
     1325  static const G4double halfAngTolerance=kAngTolerance*0.5;
     1326
    13601327  G4double snxt,sr,sphi,pdist ;
    13611328
     
    13731340  // Vars for phi intersection:
    13741341
    1375   G4double sinSPhi, cosSPhi, ePhi, sinEPhi, cosEPhi ;
    1376   G4double cPhi, sinCPhi, cosCPhi ;
    13771342  G4double pDistS, compS, pDistE, compE, sphi2, xi, yi, risec, vphi ;
    13781343  G4double zi, ri, deltaRoi2 ;
     
    13841349    pdist = fDz - p.z() ;
    13851350
    1386     if (pdist > kCarTolerance*0.5)
     1351    if (pdist > halfCarTolerance)
    13871352    {
    13881353      snxt = pdist/v.z() ;
     
    13961361        *validNorm = true ;
    13971362      }
    1398       return snxt = 0.0 ;
     1363      return  snxt = 0.0;
    13991364    }
    14001365  }
     
    14031368    pdist = fDz + p.z() ;
    14041369
    1405     if ( pdist > kCarTolerance*0.5)
     1370    if ( pdist > halfCarTolerance)
    14061371    {
    14071372      snxt = -pdist/v.z() ;
     
    14651430                - fRmax1*(fRmax1 + kRadTolerance*secRMax);
    14661431  }
    1467   else deltaRoi2 = 1.0 ;
    1468 
    1469   if ( nt1 && deltaRoi2 > 0.0 ) 
     1432  else
     1433  {
     1434    deltaRoi2 = 1.0;
     1435  }
     1436
     1437  if ( nt1 && (deltaRoi2 > 0.0) ) 
    14701438  {
    14711439    // Equation quadratic => 2 roots : second root must be leaving
     
    14781446    {
    14791447      // Check if on outer cone & heading outwards
    1480       // NOTE: Should use rho-rout>-kRadtolerance*0.5
     1448      // NOTE: Should use rho-rout>-kRadTolerance*0.5
    14811449       
    1482       if (nt3 > -kRadTolerance*0.5 && nt2 >= 0 )
     1450      if (nt3 > -halfRadTolerance && nt2 >= 0 )
    14831451      {
    14841452        if (calcNorm)
     
    14861454          risec      = std::sqrt(t3)*secRMax ;
    14871455          *validNorm = true ;
    1488           *n         = G4ThreeVector(p.x()/risec,p.y()/risec,-tanRMax/secRMax) ;
     1456          *n         = G4ThreeVector(p.x()/risec,p.y()/risec,-tanRMax/secRMax);
    14891457        }
    14901458        return snxt=0 ;
     
    14971465        ri    = tanRMax*zi + rMaxAv ;
    14981466         
    1499         if ( (ri >= 0) && (-kRadTolerance*0.5 <= sr) &&
    1500                           ( sr <= kRadTolerance*0.5)     )
     1467        if ((ri >= 0) && (-halfRadTolerance <= sr) && (sr <= halfRadTolerance))
    15011468        {
    15021469          // An intersection within the tolerance
     
    15061473          sidetol = kRMax ;
    15071474        }           
    1508         if ( (ri < 0) || (sr < kRadTolerance*0.5) )
     1475        if ( (ri < 0) || (sr < halfRadTolerance) )
    15091476        {
    15101477          // Safety: if both roots -ve ensure that sr cannot `win'
     
    15151482          ri  = tanRMax*zi + rMaxAv ;
    15161483
    1517           if (ri >= 0 && sr2 > kRadTolerance*0.5)  sr = sr2 ;
     1484          if ((ri >= 0) && (sr2 > halfRadTolerance))
     1485          {
     1486            sr = sr2;
     1487          }
    15181488          else
    15191489          {
    15201490            sr = kInfinity ;
    15211491
    1522             if(    (-kRadTolerance*0.5 <= sr2)
    1523                 && ( sr2 <= kRadTolerance*0.5)  )
     1492            if( (-halfRadTolerance <= sr2) && ( sr2 <= halfRadTolerance) )
    15241493            {
    15251494              // An intersection within the tolerance.
     
    15401509      if ( calcNorm )
    15411510      {
    1542         risec      = std::sqrt(t3)*secRMax ;
    1543         *validNorm = true ;
    1544         *n         = G4ThreeVector(p.x()/risec,p.y()/risec,-tanRMax/secRMax) ;
     1511        risec      = std::sqrt(t3)*secRMax;
     1512        *validNorm = true;
     1513        *n         = G4ThreeVector(p.x()/risec,p.y()/risec,-tanRMax/secRMax);
    15451514      }
    15461515      return snxt = 0.0 ;
    15471516    }
    15481517  }
    1549   else if ( nt2 && deltaRoi2 > 0.0 )
     1518  else if ( nt2 && (deltaRoi2 > 0.0) )
    15501519  {
    15511520    // Linear case (only one intersection) => point outside outer cone
     
    15531522    if ( calcNorm )
    15541523    {
    1555       risec      = std::sqrt(t3)*secRMax ;
    1556       *validNorm = true ;
    1557       *n         = G4ThreeVector(p.x()/risec,p.y()/risec,-tanRMax/secRMax) ;
     1524      risec      = std::sqrt(t3)*secRMax;
     1525      *validNorm = true;
     1526      *n         = G4ThreeVector(p.x()/risec,p.y()/risec,-tanRMax/secRMax);
    15581527    }
    15591528    return snxt = 0.0 ;
     
    15691538  // Check possible intersection within tolerance
    15701539
    1571   if ( slentol <= kCarTolerance*0.5 )
     1540  if ( slentol <= halfCarTolerance )
    15721541  {
    15731542    // An intersection within the tolerance was found. 
     
    15801549    // Calculate a normal vector,  as below
    15811550
    1582     xi    = p.x() + slentol*v.x() ;
    1583     yi    = p.y() + slentol*v.y() ;
    1584     risec = std::sqrt(xi*xi + yi*yi)*secRMax ;
    1585     G4ThreeVector Normal = G4ThreeVector(xi/risec,yi/risec,-tanRMax/secRMax) ;
     1551    xi    = p.x() + slentol*v.x();
     1552    yi    = p.y() + slentol*v.y();
     1553    risec = std::sqrt(xi*xi + yi*yi)*secRMax;
     1554    G4ThreeVector Normal = G4ThreeVector(xi/risec,yi/risec,-tanRMax/secRMax);
    15861555
    15871556    if ( Normal.dot(v) > 0 )    // We will leave the Cone immediatelly
     
    15951564    }
    15961565    else // On the surface, but not heading out so we ignore this intersection
    1597     {    //                                    (as it is within tolerance). 
     1566    {    //                                        (as it is within tolerance).
    15981567      slentol = kInfinity ;
    15991568    }
     
    16211590      d = b*b - c ;
    16221591
    1623       if (d >= 0.0 )
     1592      if ( d >= 0.0 )
    16241593      {
    16251594        // NOTE: should be rho-rin<kRadTolerance*0.5,
     
    16301599          if ( nt2 < 0.0 )
    16311600          {
    1632             if (calcNorm)  *validNorm = false ;
    1633             return          snxt      = 0.0 ;
     1601            if (calcNorm)  { *validNorm = false; }
     1602            return          snxt      = 0.0;
    16341603          }
    16351604        }
     
    16401609          ri  = tanRMin*zi + rMinAv ;
    16411610
    1642           if( (ri >= 0.0) && (-kRadTolerance*0.5 <= sr2) &&
    1643                              ( sr2 <= kRadTolerance*0.5)      )
     1611          if( (ri>=0.0)&&(-halfRadTolerance<=sr2)&&(sr2<=halfRadTolerance) )
    16441612          {
    16451613            // An intersection within the tolerance
     
    16491617            sidetol = kRMax ;
    16501618          }
    1651           if( (ri<0) || (sr2 < kRadTolerance*0.5) )
     1619          if( (ri<0) || (sr2 < halfRadTolerance) )
    16521620          {
    16531621            sr3 = -b + std::sqrt(d) ;
     
    16561624            //         distancetoout
    16571625
    1658             if  ( sr3 > kCarTolerance*0.5 )
     1626            if  ( sr3 > halfRadTolerance )
    16591627            {
    16601628              if( sr3 < sr )
     
    16701638              }
    16711639            }
    1672             else if ( sr3 > -kCarTolerance*0.5 )
     1640            else if ( sr3 > -halfRadTolerance )
    16731641            {
    16741642              // Intersection in tolerance. Store to check if it's good
     
    16781646            }
    16791647          }
    1680           else if ( sr2 < sr && sr2 > kCarTolerance*0.5 )
     1648          else if ( (sr2 < sr) && (sr2 > halfCarTolerance) )
    16811649          {
    16821650            sr    = sr2 ;
    16831651            sider = kRMin ;
    16841652          }
    1685           else if (sr2 > -kCarTolerance*0.5)
     1653          else if (sr2 > -halfCarTolerance)
    16861654          {
    16871655            // Intersection in tolerance. Store to check if it's good
     
    16901658            sidetol = kRMin ;
    16911659          }   
    1692           if( slentol <= kCarTolerance*0.5  )
     1660          if( slentol <= halfCarTolerance  )
    16931661          {
    16941662            // An intersection within the tolerance was found.
     
    17061674            if( Normal.dot(v) > 0 )
    17071675            {
    1708               // We will leave the Cone immediatelly
     1676              // We will leave the cone immediately
     1677
    17091678              if( calcNorm )
    17101679              {
     
    17311700  // Phi Intersection
    17321701 
    1733   if ( fDPhi < twopi )
    1734   {
    1735     sinSPhi = std::sin(fSPhi) ;
    1736     cosSPhi = std::cos(fSPhi) ;
    1737     ePhi    = fSPhi + fDPhi ;
    1738     sinEPhi = std::sin(ePhi) ;
    1739     cosEPhi = std::cos(ePhi) ;
    1740     cPhi    = fSPhi + fDPhi*0.5 ;
    1741     sinCPhi = std::sin(cPhi) ;
    1742     cosCPhi = std::cos(cPhi) ;
     1702  if ( !fPhiFullCone )
     1703  {
    17431704    // add angle calculation with correction
    1744       // of the  difference in domain of atan2 and Sphi
    1745         vphi = std::atan2(v.y(),v.x()) ;
    1746 
    1747          if ( vphi < fSPhi - kAngTolerance*0.5  )             vphi += twopi ;
    1748          else if ( vphi > fSPhi + fDPhi + kAngTolerance*0.5 ) vphi -= twopi;
     1705    // of the difference in domain of atan2 and Sphi
     1706
     1707    vphi = std::atan2(v.y(),v.x()) ;
     1708
     1709    if ( vphi < fSPhi - halfAngTolerance  )              { vphi += twopi; }
     1710    else if ( vphi > fSPhi + fDPhi + halfAngTolerance )  { vphi -= twopi; }
     1711
    17491712    if ( p.x() || p.y() )   // Check if on z axis (rho not needed later)
    17501713    {
     
    17611724      sidephi = kNull ;
    17621725
    1763       if( ( (fDPhi <= pi) && ( (pDistS <= 0.5*kCarTolerance)
    1764                               && (pDistE <= 0.5*kCarTolerance) ) )
    1765          || ( (fDPhi >  pi) && !((pDistS >  0.5*kCarTolerance)
    1766                               && (pDistE >  0.5*kCarTolerance) ) )  )
    1767         {
    1768           // Inside both phi *full* planes
    1769           if ( compS < 0 )
     1726      if( ( (fDPhi <= pi) && ( (pDistS <= halfCarTolerance)
     1727                            && (pDistE <= halfCarTolerance) ) )
     1728         || ( (fDPhi >  pi) && !((pDistS >  halfCarTolerance)
     1729                              && (pDistE >  halfCarTolerance) ) )  )
     1730      {
     1731        // Inside both phi *full* planes
     1732        if ( compS < 0 )
     1733        {
     1734          sphi = pDistS/compS ;
     1735          if (sphi >= -halfCarTolerance)
    17701736          {
    1771             sphi = pDistS/compS ;
    1772             if (sphi >= -0.5*kCarTolerance)
     1737            xi = p.x() + sphi*v.x() ;
     1738            yi = p.y() + sphi*v.y() ;
     1739
     1740            // Check intersecting with correct half-plane
     1741            // (if not -> no intersect)
     1742            //
     1743            if ( (std::abs(xi)<=kCarTolerance)
     1744              && (std::abs(yi)<=kCarTolerance) )
    17731745            {
    1774               xi = p.x() + sphi*v.x() ;
    1775               yi = p.y() + sphi*v.y() ;
    1776 
    1777               // Check intersecting with correct half-plane
    1778               // (if not -> no intersect)
    1779               //
    1780                if((std::abs(xi)<=kCarTolerance)&&(std::abs(yi)<=kCarTolerance)){
    1781                  sidephi= kSPhi;
    1782                 if(((fSPhi-0.5*kAngTolerance)<=vphi)&&((ePhi+0.5*kAngTolerance)>=vphi))
    1783                     { sphi = kInfinity; }
    1784                                        
     1746              sidephi= kSPhi;
     1747              if ( ( fSPhi-halfAngTolerance <= vphi )
     1748                && ( fSPhi+fDPhi+halfAngTolerance >=vphi ) )
     1749              {
     1750                sphi = kInfinity;
    17851751              }
    1786               else
    1787               if ((yi*cosCPhi-xi*sinCPhi)>=0)
    1788               {
    1789                 sphi = kInfinity ;
    1790               }
    1791               else
    1792               {
    1793                 sidephi = kSPhi ;
    1794                 if ( pDistS > -kCarTolerance*0.5 )
    1795                 {
    1796                   sphi = 0.0 ; // Leave by sphi immediately
    1797                 }   
    1798               }       
     1752            }
     1753            else
     1754            if ( (yi*cosCPhi-xi*sinCPhi)>=0 )
     1755            {
     1756              sphi = kInfinity ;
    17991757            }
    18001758            else
    18011759            {
    1802               sphi = kInfinity ;
    1803             }
     1760              sidephi = kSPhi ;
     1761              if ( pDistS > -halfCarTolerance )
     1762              {
     1763                sphi = 0.0 ; // Leave by sphi immediately
     1764              }   
     1765            }       
    18041766          }
    18051767          else
     
    18071769            sphi = kInfinity ;
    18081770          }
    1809 
    1810           if ( compE < 0 )
     1771        }
     1772        else
     1773        {
     1774          sphi = kInfinity ;
     1775        }
     1776
     1777        if ( compE < 0 )
     1778        {
     1779          sphi2 = pDistE/compE ;
     1780
     1781          // Only check further if < starting phi intersection
     1782          //
     1783          if ( (sphi2 > -halfCarTolerance) && (sphi2 < sphi) )
    18111784          {
    1812             sphi2 = pDistE/compE ;
    1813 
    1814             // Only check further if < starting phi intersection
    1815             //
    1816             if ( (sphi2 > -0.5*kCarTolerance) && (sphi2 < sphi) )
     1785            xi = p.x() + sphi2*v.x() ;
     1786            yi = p.y() + sphi2*v.y() ;
     1787
     1788            // Check intersecting with correct half-plane
     1789
     1790            if ( (std::abs(xi)<=kCarTolerance)
     1791              && (std::abs(yi)<=kCarTolerance) )
    18171792            {
    1818               xi = p.x() + sphi2*v.x() ;
    1819               yi = p.y() + sphi2*v.y() ;
    1820 
    1821               // Check intersecting with correct half-plane
    1822                if((std::abs(xi)<=kCarTolerance)&&(std::abs(yi)<=kCarTolerance)){
    1823                // Leaving via ending phi
    1824                 if(!(((fSPhi-0.5*kAngTolerance)<=vphi)&&((ePhi+0.5*kAngTolerance)>=vphi))){
    1825                   sidephi = kEPhi ;
    1826                   if ( pDistE <= -kCarTolerance*0.5 ) sphi = sphi2 ;
    1827                   else                                sphi = 0.0 ;
    1828                   }
    1829                 }
    1830              else // Check intersecting with correct half-plane
    1831               if ( (yi*cosCPhi-xi*sinCPhi) >= 0)
     1793              // Leaving via ending phi
     1794
     1795              if(!( (fSPhi-halfAngTolerance <= vphi)
     1796                 && (fSPhi+fDPhi+halfAngTolerance >= vphi) ) )
    18321797              {
    1833                 // Leaving via ending phi
    1834 
    18351798                sidephi = kEPhi ;
    1836                 if ( pDistE <= -kCarTolerance*0.5 ) sphi = sphi2 ;
    1837                 else                                sphi = 0.0 ;
     1799                if ( pDistE <= -halfCarTolerance )  { sphi = sphi2; }
     1800                else                                { sphi = 0.0; }
    18381801              }
    18391802            }
     1803            else // Check intersecting with correct half-plane
     1804            if ( yi*cosCPhi-xi*sinCPhi >= 0 )
     1805            {
     1806              // Leaving via ending phi
     1807
     1808              sidephi = kEPhi ;
     1809              if ( pDistE <= -halfCarTolerance )  { sphi = sphi2; }
     1810              else                                { sphi = 0.0; }
     1811            }
    18401812          }
    18411813        }
    1842         else
    1843         {
    1844           sphi = kInfinity ;
    1845         }
    1846 
    1847 
     1814      }
     1815      else
     1816      {
     1817        sphi = kInfinity ;
     1818      }
    18481819    }
    18491820    else
     
    18521823      // within phi of shape, Step limited by rmax, else Step =0
    18531824
    1854       // vphi = std::atan2(v.y(),v.x()) ;
    1855 
    1856       // if ( fSPhi < vphi && vphi < fSPhi + fDPhi ) sphi = kInfinity ;
    1857 
    1858        if ( ((fSPhi-0.5*kAngTolerance) <= vphi) && (vphi <=( fSPhi + fDPhi)+0.5*kAngTolerance) )
    1859          {
    1860           sphi = kInfinity ;
    1861         }
     1825      if ( (fSPhi-halfAngTolerance <= vphi)
     1826        && (vphi <= fSPhi+fDPhi+halfAngTolerance) )
     1827      {
     1828        sphi = kInfinity ;
     1829      }
    18621830      else
    18631831      {
     
    18681836    if ( sphi < snxt )  // Order intersecttions
    18691837    {
    1870         snxt=sphi ;
    1871         side=sidephi ;
     1838      snxt=sphi ;
     1839      side=sidephi ;
    18721840    }
    18731841  }
     
    18801848  {
    18811849    switch(side)
    1882     {
    1883       case kRMax:
    1884           // Note: returned vector not normalised
    1885           // (divide by frmax for unit vector)
     1850    {                     // Note: returned vector not normalised
     1851      case kRMax:         // (divide by frmax for unit vector)
    18861852        xi         = p.x() + snxt*v.x() ;
    18871853        yi         = p.y() + snxt*v.y() ;
     
    18911857        break ;
    18921858      case kRMin:
    1893         *validNorm=false ;  // Rmin is inconvex
     1859        *validNorm = false ;  // Rmin is inconvex
    18941860        break ;
    18951861      case kSPhi:
    18961862        if ( fDPhi <= pi )
    18971863        {
    1898           *n         = G4ThreeVector(std::sin(fSPhi),-std::cos(fSPhi),0) ;
     1864          *n         = G4ThreeVector(sinSPhi, -cosSPhi, 0);
    18991865          *validNorm = true ;
    19001866        }
    1901         else   *validNorm = false ;
     1867        else
     1868        {
     1869          *validNorm = false ;
     1870        }
    19021871        break ;
    19031872      case kEPhi:
    19041873        if ( fDPhi <= pi )
    19051874        {
    1906           *n         = G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0) ;
     1875          *n = G4ThreeVector(-sinEPhi, cosEPhi, 0);
    19071876          *validNorm = true ;
    19081877        }
    1909         else  *validNorm = false ;
     1878        else
     1879        {
     1880          *validNorm = false ;
     1881        }
    19101882        break ;
    19111883      case kPZ:
     
    19251897        G4cout << "p.y() = "   << p.y()/mm << " mm" << G4endl ;
    19261898        G4cout << "p.z() = "   << p.z()/mm << " mm" << G4endl << G4endl ;
    1927         G4cout << "pho at z = "   << std::sqrt( p.x()*p.x()+p.y()*p.y() )/mm << " mm"
    1928                << G4endl << G4endl ;
     1899        G4cout << "pho at z = "   << std::sqrt( p.x()*p.x()+p.y()*p.y() )/mm
     1900               << " mm" << G4endl << G4endl ;
    19291901        if( p.x() != 0. || p.x() != 0.)
    19301902        {
    1931            G4cout << "point phi = "   << std::atan2(p.y(),p.x())/degree << " degree"
    1932                   << G4endl << G4endl ;
     1903           G4cout << "point phi = "   << std::atan2(p.y(),p.x())/degree
     1904                  << " degree" << G4endl << G4endl ;
    19331905        }
    19341906        G4cout << "Direction:" << G4endl << G4endl ;
     
    19431915    }
    19441916  }
    1945   if (snxt < kCarTolerance*0.5) snxt = 0.;
    1946 #ifdef consdebug
    1947   G4cout.precision(24);
    1948   G4cout<<"G4Cons::DistanceToOut(p,v,...) "<<G4endl;
    1949   G4cout<<"position = "<<p<<G4endl;
    1950   G4cout<<"direction = "<<v<<G4endl;
    1951   G4cout<<"distance = "<<snxt<<G4endl;
    1952 #endif
     1917  if (snxt < halfCarTolerance)  { snxt = 0.; }
     1918
    19531919  return snxt ;
    19541920}
     
    19601926G4double G4Cons::DistanceToOut(const G4ThreeVector& p) const
    19611927{
    1962   G4double safe=0.0,rho,safeR1,safeR2,safeZ ;
    1963   G4double tanRMin,secRMin,pRMin ;
    1964   G4double tanRMax,secRMax,pRMax ;
    1965   G4double safePhi,phiC,cosPhiC,sinPhiC,ePhi ;
     1928  G4double safe=0.0, rho, safeR1, safeR2, safeZ, safePhi;
     1929  G4double tanRMin, secRMin, pRMin;
     1930  G4double tanRMax, secRMax, pRMax;
    19661931
    19671932#ifdef G4CSGDEBUG
     
    19751940    G4cout << "p.y() = "   << p.y()/mm << " mm" << G4endl ;
    19761941    G4cout << "p.z() = "   << p.z()/mm << " mm" << G4endl << G4endl ;
    1977     G4cout << "pho at z = "   << std::sqrt( p.x()*p.x()+p.y()*p.y() )/mm << " mm"
    1978            << G4endl << G4endl ;
    1979     if( p.x() != 0. || p.x() != 0.)
    1980     {
    1981       G4cout << "point phi = "   << std::atan2(p.y(),p.x())/degree << " degree"
    1982              << G4endl << G4endl ;
    1983     }
    1984     G4Exception("G4Cons::DistanceToOut(p)", "Notification", JustWarning,
    1985                 "Point p is outside !?" );
     1942    G4cout << "pho at z = "   << std::sqrt( p.x()*p.x()+p.y()*p.y() )/mm
     1943           << " mm" << G4endl << G4endl ;
     1944    if( (p.x() != 0.) || (p.x() != 0.) )
     1945    {
     1946      G4cout << "point phi = "   << std::atan2(p.y(),p.x())/degree
     1947             << " degree" << G4endl << G4endl ;
     1948    }
     1949    G4Exception("G4Cons::DistanceToOut(p)", "Notification",
     1950                JustWarning, "Point p is outside !?" );
    19861951  }
    19871952#endif
     
    19971962    safeR1  = (rho - pRMin)/secRMin ;
    19981963  }
    1999   else safeR1 = kInfinity ;
     1964  else
     1965  {
     1966    safeR1 = kInfinity ;
     1967  }
    20001968
    20011969  tanRMax = (fRmax2 - fRmax1)*0.5/fDz ;
     
    20041972  safeR2  = (pRMax - rho)/secRMax ;
    20051973
    2006   if (safeR1 < safeR2) safe = safeR1 ;
    2007   else                 safe = safeR2 ;
    2008   if (safeZ < safe)    safe = safeZ  ;
     1974  if (safeR1 < safeR2)  { safe = safeR1; }
     1975  else                  { safe = safeR2; }
     1976  if (safeZ < safe)     { safe = safeZ ; }
    20091977
    20101978  // Check if phi divided, Calc distances closest phi plane
    20111979
    2012   if (fDPhi < twopi)
     1980  if (!fPhiFullCone)
    20131981  {
    20141982    // Above/below central phi of G4Cons?
    20151983
    2016     phiC    = fSPhi + fDPhi*0.5 ;
    2017     cosPhiC = std::cos(phiC) ;
    2018     sinPhiC = std::sin(phiC) ;
    2019 
    2020     if ( (p.y()*cosPhiC - p.x()*sinPhiC) <= 0 )
    2021     {
    2022       safePhi = -(p.x()*std::sin(fSPhi) - p.y()*std::cos(fSPhi)) ;
     1984    if ( (p.y()*cosCPhi - p.x()*sinCPhi) <= 0 )
     1985    {
     1986      safePhi = -(p.x()*sinSPhi - p.y()*cosSPhi) ;
    20231987    }
    20241988    else
    20251989    {
    2026       ePhi    = fSPhi + fDPhi ;
    2027       safePhi = (p.x()*std::sin(ePhi) - p.y()*std::cos(ePhi)) ;
    2028     }
    2029     if (safePhi < safe) safe = safePhi ;
    2030   }
    2031   if ( safe < 0 ) safe = 0 ;
    2032   return safe ; 
     1990      safePhi = (p.x()*sinEPhi - p.y()*cosEPhi) ;
     1991    }
     1992    if (safePhi < safe)  { safe = safePhi; }
     1993  }
     1994  if ( safe < 0 )  { safe = 0; }
     1995
     1996  return safe ;
    20331997}
    20341998
     
    20682032  meshAngle = fDPhi/(noCrossSections - 1) ;
    20692033
    2070   // G4double RMax = (fRmax2 >= fRmax1) ? fRmax2 : fRmax1  ;
    2071 
    20722034  meshRMax1 = fRmax1/std::cos(meshAngle*0.5) ;
    20732035  meshRMax2 = fRmax2/std::cos(meshAngle*0.5) ;
     
    20762038  // on the x axis. Will give better extent calculations when not rotated.
    20772039
    2078   if (fDPhi == twopi && fSPhi == 0.0 )
     2040  if ( fPhiFullCone && (fSPhi == 0.0) )
    20792041  {
    20802042    sAngle = -meshAngle*0.5 ;
     
    21022064      rMaxY2 = meshRMax2*sinCrossAngle ;
    21032065       
    2104       // G4double RMin = (fRmin2 <= fRmin1) ? fRmin2 : fRmin1  ;
    2105 
    21062066      rMinX1 = fRmin1*cosCrossAngle ;
    21072067      rMinY1 = fRmin1*sinCrossAngle ;
     
    21272087                "Error in allocation of vertices. Out of memory !");
    21282088  }
     2089
    21292090  return vertices ;
    21302091}
     
    21922153  rRand2 = RandFlat::shoot(fRmin2,fRmax2);
    21932154 
    2194   if(fSPhi == 0. && fDPhi == twopi){ Afive = 0.; }
     2155  if ( (fSPhi == 0.) && fPhiFullCone )  { Afive = 0.; }
    21952156  chose  = RandFlat::shoot(0.,Aone+Atwo+Athree+Afour+2.*Afive);
    21962157 
     
    22252186  else if( (chose >= Aone + Atwo) && (chose < Aone + Atwo + Athree) )
    22262187  {
    2227     return G4ThreeVector (rRand1*cosu,rRand1*sinu,-1*fDz);
     2188    return G4ThreeVector (rRand1*cosu, rRand1*sinu, -1*fDz);
    22282189  }
    22292190  else if( (chose >= Aone + Atwo + Athree)
  • trunk/source/geometry/solids/CSG/src/G4Tubs.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4Tubs.cc,v 1.68 2008/06/23 13:37:39 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4Tubs.cc,v 1.74 2008/11/06 15:26:53 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    108108                "Invalid Z half-length");
    109109  }
    110   if ( pRMin < pRMax && pRMin >= 0 ) // Check radii
     110  if ( (pRMin < pRMax) && (pRMin >= 0) ) // Check radii
    111111  {
    112112    fRMin = pRMin ;
     
    121121                "Invalid radii.");
    122122  }
    123   if ( pDPhi >= twopi ) // Check angles
     123
     124  fPhiFullTube = true;
     125  if ( pDPhi >= twopi-kAngTolerance*0.5 ) // Check angles
    124126  {
    125127    fDPhi=twopi;
     128    fSPhi=0;
    126129  }
    127130  else
    128131  {
     132    fPhiFullTube = false;
    129133    if ( pDPhi > 0 )
    130134    {
     
    136140             << "        Negative delta-Phi ! - "
    137141             << pDPhi << G4endl;
    138       G4Exception("G4Tubs::G4Tubs()", "InvalidSetup", FatalException,
    139                   "Invalid dphi.");
    140     }
    141   }
    142  
    143   // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
    144 
    145   fSPhi = pSPhi;
    146 
    147   if ( fSPhi < 0 )
    148   {
    149     fSPhi = twopi - std::fmod(std::fabs(fSPhi),twopi) ;
    150   }
    151   else
    152   {
    153     fSPhi = std::fmod(fSPhi,twopi) ;
    154   }
    155   if (fSPhi + fDPhi > twopi )
    156   {
    157     fSPhi -= twopi ;
    158   }
     142      G4Exception("G4Tubs::G4Tubs()", "InvalidSetup",
     143                  FatalException, "Invalid dphi.");
     144    }
     145
     146    // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
     147
     148    if ( pSPhi < 0 )
     149    {
     150      fSPhi = twopi - std::fmod(std::fabs(pSPhi),twopi);
     151    }
     152    else
     153    {
     154      fSPhi = std::fmod(pSPhi,twopi) ;
     155    }
     156    if ( fSPhi+fDPhi > twopi )
     157    {
     158      fSPhi -= twopi ;
     159    }
     160  }
     161  InitializeTrigonometry();
    159162}
    160163
     
    290293        yoff2 = yMax    - yoffset ;
    291294
    292         if ( yoff1 >= 0 && yoff2 >= 0 ) // Y limits cross max/min x => no change
    293         {
     295        if ( (yoff1 >= 0) && (yoff2 >= 0) ) // Y limits cross max/min x
     296        {                                   // => no change
    294297          pMin = xMin ;
    295298          pMax = xMax ;
     
    317320        xoff2 = xMax - xoffset ;
    318321
    319         if ( xoff1 >= 0 && xoff2 >= 0 ) // X limits cross max/min y => no change
    320         {
     322        if ( (xoff1 >= 0) && (xoff2 >= 0) ) // X limits cross max/min y
     323        {                                   // => no change
    321324          pMin = yMin ;
    322325          pMax = yMax ;
     
    363366    noEntries = vertices->size() ;
    364367    noBetweenSections4 = noEntries - 4 ;
    365     /*
    366     G4cout << "vertices = " << noEntries << "\t"
    367            << "v-4 = " << noBetweenSections4 << G4endl;
    368     G4cout << G4endl;
    369     for(i = 0 ; i < noEntries ; i++ )
    370     {
    371       G4cout << i << "\t" << "v.x = " << ((*vertices)[i]).x() << "\t"
    372                           << "v.y = " << ((*vertices)[i]).y() << "\t"
    373                           << "v.z = " << ((*vertices)[i]).z() << "\t" << G4endl;
    374     }     
    375     G4cout << G4endl;
    376     G4cout << "ClipCrossSection" << G4endl;
    377     */
     368   
    378369    for (i = 0 ; i < noEntries ; i += 4 )
    379370    {
    380       // G4cout << "section = " << i << G4endl;
    381       ClipCrossSection(vertices,i,pVoxelLimit,pAxis,pMin,pMax) ;
    382     }
    383     // G4cout << "ClipBetweenSections" << G4endl;
     371      ClipCrossSection(vertices, i, pVoxelLimit, pAxis, pMin, pMax) ;
     372    }
    384373    for (i = 0 ; i < noBetweenSections4 ; i += 4 )
    385374    {
    386       // G4cout << "between sections = " << i << G4endl;
    387       ClipBetweenSections(vertices,i,pVoxelLimit,pAxis,pMin,pMax) ;
    388     }
    389     if (pMin != kInfinity || pMax != -kInfinity )
     375      ClipBetweenSections(vertices, i, pVoxelLimit, pAxis, pMin, pMax) ;
     376    }
     377    if ((pMin != kInfinity) || (pMax != -kInfinity) )
    390378    {
    391379      existsAfterClip = true ;
     
    426414  G4double r2,pPhi,tolRMin,tolRMax;
    427415  EInside in = kOutside ;
    428  
    429   if (std::fabs(p.z()) <= fDz - kCarTolerance*0.5)
     416  static const G4double halfCarTolerance=kCarTolerance*0.5;
     417  static const G4double halfRadTolerance=kRadTolerance*0.5;
     418  static const G4double halfAngTolerance=kAngTolerance*0.5;
     419
     420  if (std::fabs(p.z()) <= fDz - halfCarTolerance)
    430421  {
    431422    r2 = p.x()*p.x() + p.y()*p.y() ;
    432423
    433     if (fRMin) { tolRMin = fRMin + kRadTolerance*0.5 ; }
     424    if (fRMin) { tolRMin = fRMin + halfRadTolerance ; }
    434425    else       { tolRMin = 0 ; }
    435426
    436     tolRMax = fRMax - kRadTolerance*0.5 ;
     427    tolRMax = fRMax - halfRadTolerance ;
    437428     
    438     if (r2 >= tolRMin*tolRMin && r2 <= tolRMax*tolRMax)
    439     {
    440       if ( fDPhi == twopi )
     429    if ((r2 >= tolRMin*tolRMin) && (r2 <= tolRMax*tolRMax))
     430    {
     431      if ( fPhiFullTube )
    441432      {
    442433        in = kInside ;
     
    447438        // if not inside, try outer tolerant phi boundaries
    448439
    449         pPhi = std::atan2(p.y(),p.x()) ;
    450         if ((tolRMin==0)&&(p.x()==0)&&(p.y()==0))
     440        if ((tolRMin==0)&&(p.x()<=halfCarTolerance)&&(p.y()<=halfCarTolerance))
    451441        {
    452442          in=kSurface;
     
    454444        else
    455445        {
    456           if ( pPhi < -kAngTolerance*0.5 )  { pPhi += twopi; } // 0<=pPhi<2pi
     446          pPhi = std::atan2(p.y(),p.x()) ;
     447          if ( pPhi < -halfAngTolerance )  { pPhi += twopi; } // 0<=pPhi<2pi
    457448
    458449          if ( fSPhi >= 0 )
    459450          {
    460             if ( (std::abs(pPhi) < kAngTolerance*0.5)
    461               && (std::abs(fSPhi + fDPhi - twopi) < kAngTolerance*0.5) )
     451            if ( (std::abs(pPhi) < halfAngTolerance)
     452              && (std::abs(fSPhi + fDPhi - twopi) < halfAngTolerance) )
    462453            {
    463454              pPhi += twopi ; // 0 <= pPhi < 2pi
    464455            }
    465             if ( (pPhi >= fSPhi + kAngTolerance*0.5)
    466               && (pPhi <= fSPhi + fDPhi - kAngTolerance*0.5) )
     456            if ( (pPhi >= fSPhi + halfAngTolerance)
     457              && (pPhi <= fSPhi + fDPhi - halfAngTolerance) )
    467458            {
    468459              in = kInside ;
    469460            }
    470             else if ( (pPhi >= fSPhi - kAngTolerance*0.5)
    471                    && (pPhi <= fSPhi + fDPhi + kAngTolerance*0.5) )
     461            else if ( (pPhi >= fSPhi - halfAngTolerance)
     462                   && (pPhi <= fSPhi + fDPhi + halfAngTolerance) )
    472463            {
    473464              in = kSurface ;
     
    476467          else  // fSPhi < 0
    477468          {
    478             if ( (pPhi <= fSPhi + twopi - kAngTolerance*0.5)
    479               && (pPhi >= fSPhi + fDPhi  + kAngTolerance*0.5) ) {;}
    480             else if ( (pPhi <= fSPhi + twopi + kAngTolerance*0.5)
    481                    && (pPhi >= fSPhi + fDPhi  - kAngTolerance*0.5) )
     469            if ( (pPhi <= fSPhi + twopi - halfAngTolerance)
     470              && (pPhi >= fSPhi + fDPhi  + halfAngTolerance) ) {;} //kOutside
     471            else if ( (pPhi <= fSPhi + twopi + halfAngTolerance)
     472                   && (pPhi >= fSPhi + fDPhi  - halfAngTolerance) )
    482473            {
    483474              in = kSurface ;
     
    493484    else  // Try generous boundaries
    494485    {
    495       tolRMin = fRMin - kRadTolerance*0.5 ;
    496       tolRMax = fRMax + kRadTolerance*0.5 ;
     486      tolRMin = fRMin - halfRadTolerance ;
     487      tolRMax = fRMax + halfRadTolerance ;
    497488
    498489      if ( tolRMin < 0 )  { tolRMin = 0; }
     
    500491      if ( (r2 >= tolRMin*tolRMin) && (r2 <= tolRMax*tolRMax) )
    501492      {
    502         if ( fDPhi == twopi || r2 == 0 ) // Continuous in phi or on z-axis
    503         {
     493        if (fPhiFullTube || (r2 <=halfRadTolerance*halfRadTolerance) )
     494        {                        // Continuous in phi or on z-axis
    504495          in = kSurface ;
    505496        }
     
    508499          pPhi = std::atan2(p.y(),p.x()) ;
    509500
    510           if ( pPhi < -kAngTolerance*0.5 )  { pPhi += twopi; } // 0<=pPhi<2pi
     501          if ( pPhi < -halfAngTolerance)  { pPhi += twopi; } // 0<=pPhi<2pi
    511502          if ( fSPhi >= 0 )
    512503          {
    513             if ( (std::abs(pPhi) < kAngTolerance*0.5)
    514               && (std::abs(fSPhi + fDPhi - twopi) < kAngTolerance*0.5) )
     504            if ( (std::abs(pPhi) < halfAngTolerance)
     505              && (std::abs(fSPhi + fDPhi - twopi) < halfAngTolerance) )
    515506            {
    516507              pPhi += twopi ; // 0 <= pPhi < 2pi
    517508            }
    518             if ( (pPhi >= fSPhi - kAngTolerance*0.5)
    519               && (pPhi <= fSPhi + fDPhi + kAngTolerance*0.5) )
     509            if ( (pPhi >= fSPhi - halfAngTolerance)
     510              && (pPhi <= fSPhi + fDPhi + halfAngTolerance) )
    520511            {
    521512              in = kSurface ;
     
    524515          else  // fSPhi < 0
    525516          {
    526             if ( (pPhi <= fSPhi + twopi - kAngTolerance*0.5)
    527               && (pPhi >= fSPhi + fDPhi  + kAngTolerance*0.5) ) {;}
     517            if ( (pPhi <= fSPhi + twopi - halfAngTolerance)
     518              && (pPhi >= fSPhi + fDPhi + halfAngTolerance) ) {;} // kOutside
    528519            else
    529520            {
     
    535526    }
    536527  }
    537   else if (std::fabs(p.z()) <= fDz + kCarTolerance*0.5)
     528  else if (std::fabs(p.z()) <= fDz + halfCarTolerance)
    538529  {                                          // Check within tolerant r limits
    539530    r2      = p.x()*p.x() + p.y()*p.y() ;
    540     tolRMin = fRMin - kRadTolerance*0.5 ;
    541     tolRMax = fRMax + kRadTolerance*0.5 ;
     531    tolRMin = fRMin - halfRadTolerance ;
     532    tolRMax = fRMax + halfRadTolerance ;
    542533
    543534    if ( tolRMin < 0 )  { tolRMin = 0; }
     
    545536    if ( (r2 >= tolRMin*tolRMin) && (r2 <= tolRMax*tolRMax) )
    546537    {
    547       if (fDPhi == twopi || r2 == 0 ) // Continuous in phi or on z-axis
    548       {
     538      if (fPhiFullTube || (r2 <=halfRadTolerance*halfRadTolerance))
     539      {                        // Continuous in phi or on z-axis
    549540        in = kSurface ;
    550541      }
     
    553544        pPhi = std::atan2(p.y(),p.x()) ;
    554545
    555         if ( pPhi < -kAngTolerance*0.5 )  { pPhi += twopi; }  // 0<=pPhi<2pi
     546        if ( pPhi < -halfAngTolerance )  { pPhi += twopi; }  // 0<=pPhi<2pi
    556547        if ( fSPhi >= 0 )
    557548        {
    558           if ( (std::abs(pPhi) < kAngTolerance*0.5)
    559             && (std::abs(fSPhi + fDPhi - twopi) < kAngTolerance*0.5) )
     549          if ( (std::abs(pPhi) < halfAngTolerance)
     550            && (std::abs(fSPhi + fDPhi - twopi) < halfAngTolerance) )
    560551          {
    561552            pPhi += twopi ; // 0 <= pPhi < 2pi
    562553          }
    563           if ( (pPhi >= fSPhi - kAngTolerance*0.5)
    564             && (pPhi <= fSPhi + fDPhi + kAngTolerance*0.5) )
     554          if ( (pPhi >= fSPhi - halfAngTolerance)
     555            && (pPhi <= fSPhi + fDPhi + halfAngTolerance) )
    565556          {
    566557            in = kSurface;
     
    569560        else  // fSPhi < 0
    570561        {
    571           if ( (pPhi <= fSPhi + twopi - kAngTolerance*0.5)
    572             && (pPhi >= fSPhi + fDPhi  + kAngTolerance*0.5) ) {;}
     562          if ( (pPhi <= fSPhi + twopi - halfAngTolerance)
     563            && (pPhi >= fSPhi + fDPhi  + halfAngTolerance) ) {;}
    573564          else
    574565          {
     
    589580
    590581G4ThreeVector G4Tubs::SurfaceNormal( const G4ThreeVector& p ) const
    591 { G4int noSurfaces = 0;
     582{
     583  G4int noSurfaces = 0;
    592584  G4double rho, pPhi;
    593   G4double delta   = 0.5*kCarTolerance, dAngle = 0.5*kAngTolerance;
    594585  G4double distZ, distRMin, distRMax;
    595586  G4double distSPhi = kInfinity, distEPhi = kInfinity;
     587
     588  static const G4double halfCarTolerance = 0.5*kCarTolerance;
     589  static const G4double halfAngTolerance = 0.5*kAngTolerance;
     590
    596591  G4ThreeVector norm, sumnorm(0.,0.,0.);
    597592  G4ThreeVector nZ = G4ThreeVector(0, 0, 1.0);
     
    604599  distZ    = std::fabs(std::fabs(p.z()) - fDz);
    605600
    606   if (fDPhi < twopi)   //  &&  rho ) // Protected against (0,0,z)
    607   {
    608     if ( rho )
     601  if (!fPhiFullTube)    // Protected against (0,0,z)
     602  {
     603    if ( rho > halfCarTolerance )
    609604    {
    610605      pPhi = std::atan2(p.y(),p.x());
    611606   
    612       if(pPhi  < fSPhi-delta)           { pPhi += twopi; }
    613       else if(pPhi > fSPhi+fDPhi+delta) { pPhi -= twopi; }
    614 
    615       distSPhi = std::fabs( pPhi - fSPhi );       
     607      if(pPhi  < fSPhi- halfCarTolerance)           { pPhi += twopi; }
     608      else if(pPhi > fSPhi+fDPhi+ halfCarTolerance) { pPhi -= twopi; }
     609
     610      distSPhi = std::fabs(pPhi - fSPhi);       
    616611      distEPhi = std::fabs(pPhi - fSPhi - fDPhi);
    617612    }
     
    624619    nPe = G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0);
    625620  }
    626   if ( rho > delta )  { nR = G4ThreeVector(p.x()/rho,p.y()/rho,0); }
    627 
    628   if( distRMax <= delta )
     621  if ( rho > halfCarTolerance ) { nR = G4ThreeVector(p.x()/rho,p.y()/rho,0); }
     622
     623  if( distRMax <= halfCarTolerance )
    629624  {
    630625    noSurfaces ++;
    631626    sumnorm += nR;
    632627  }
    633   if( fRMin && distRMin <= delta )
     628  if( fRMin && (distRMin <= halfCarTolerance) )
    634629  {
    635630    noSurfaces ++;
     
    638633  if( fDPhi < twopi )   
    639634  {
    640     if (distSPhi <= dAngle)  // delta)
     635    if (distSPhi <= halfAngTolerance) 
    641636    {
    642637      noSurfaces ++;
    643638      sumnorm += nPs;
    644639    }
    645     if (distEPhi <= dAngle) // delta)
     640    if (distEPhi <= halfAngTolerance)
    646641    {
    647642      noSurfaces ++;
     
    649644    }
    650645  }
    651   if (distZ <= delta
     646  if (distZ <= halfCarTolerance
    652647  {
    653648    noSurfaces ++;
     
    668663  else if ( noSurfaces == 1 )  { norm = sumnorm; }
    669664  else                         { norm = sumnorm.unit(); }
     665
    670666  return norm;
    671667}
     
    714710    }
    715711  }   
    716   if (fDPhi < twopi  &&  rho ) // Protected against (0,0,z)
     712  if (!fPhiFullTube  &&  rho ) // Protected against (0,0,z)
    717713  {
    718714    phi = std::atan2(p.y(),p.x()) ;
     
    749745    case kNRMin : // Inner radius
    750746    {                     
    751       norm = G4ThreeVector(-p.x()/rho,-p.y()/rho,0) ;
     747      norm = G4ThreeVector(-p.x()/rho, -p.y()/rho, 0) ;
    752748      break ;
    753749    }
    754750    case kNRMax : // Outer radius
    755751    {                 
    756       norm = G4ThreeVector(p.x()/rho,p.y()/rho,0) ;
     752      norm = G4ThreeVector(p.x()/rho, p.y()/rho, 0) ;
    757753      break ;
    758754    }
    759755    case kNZ : //    + or - dz
    760756    {                             
    761       if ( p.z() > 0 ) norm = G4ThreeVector(0,0,1)  ;
    762       else             norm = G4ThreeVector(0,0,-1) ;
     757      if ( p.z() > 0 )  { norm = G4ThreeVector(0,0,1) ; }
     758      else              { norm = G4ThreeVector(0,0,-1); }
    763759      break ;
    764760    }
    765761    case kNSPhi:
    766762    {
    767       norm = G4ThreeVector(std::sin(fSPhi),-std::cos(fSPhi),0) ;
     763      norm = G4ThreeVector(std::sin(fSPhi), -std::cos(fSPhi), 0) ;
    768764      break ;
    769765    }
    770766    case kNEPhi:
    771767    {
    772       norm = G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0) ;
     768      norm = G4ThreeVector(-std::sin(fSPhi+fDPhi), std::cos(fSPhi+fDPhi), 0) ;
    773769      break;
    774770    }
     
    804800//
    805801// NOTE:
    806 // - Precalculations for phi trigonometry are Done `just in time'
    807 // - `if valid' implies tolerant checking of intersection points
     802// - 'if valid' implies tolerant checking of intersection points
    808803
    809804G4double G4Tubs::DistanceToIn( const G4ThreeVector& p,
    810805                               const G4ThreeVector& v  ) const
    811806{
    812   G4double snxt = kInfinity ;  // snxt = default return value
    813 
    814   // Precalculated trig for phi intersections - used by r,z intersections to
    815   //                                            check validity
    816 
    817   G4bool seg ;        // true if segmented
    818 
    819   G4double hDPhi, hDPhiOT, hDPhiIT, cosHDPhiOT=0., cosHDPhiIT=0. ;
    820           // half dphi + outer tolerance
    821 
    822   G4double cPhi, sinCPhi=0., cosCPhi=0. ;  // central phi
    823 
    824   G4double tolORMin2, tolIRMax2 ;  // `generous' radii squared
    825 
     807  G4double snxt = kInfinity ;      // snxt = default return value
     808  G4double tolORMin2, tolIRMax2 ;  // 'generous' radii squared
    826809  G4double tolORMax2, tolIRMin2, tolODz, tolIDz ;
     810
     811  static const G4double halfCarTolerance = 0.5*kCarTolerance;
     812  static const G4double halfRadTolerance = 0.5*kRadTolerance;
    827813
    828814  // Intersection point variables
    829815  //
    830   G4double Dist, s, xi, yi, zi, rho2, inum, iden, cosPsi ;
    831 
    832   G4double t1, t2, t3, b, c, d ;   // Quadratic solver variables
    833 
    834   G4double Comp ;
    835   G4double cosSPhi, sinSPhi ;    // Trig for phi start intersect
    836 
    837   G4double ePhi, cosEPhi, sinEPhi ;  // for phi end intersect
    838 
    839   // Set phi divided flag and precalcs
    840 
    841   if ( fDPhi < twopi )
    842   {
    843     seg        = true ;
    844     hDPhi      = 0.5*fDPhi ;    // half delta phi
    845     cPhi       = fSPhi + hDPhi ;
    846     hDPhiOT    = hDPhi + 0.5*kAngTolerance ;  // outers tol' half delta phi
    847     hDPhiIT    = hDPhi - 0.5*kAngTolerance ;
    848     sinCPhi    = std::sin(cPhi) ;
    849     cosCPhi    = std::cos(cPhi) ;
    850     cosHDPhiOT = std::cos(hDPhiOT) ;
    851     cosHDPhiIT = std::cos(hDPhiIT) ;
    852   }
    853   else
    854   {
    855     seg = false  ;
    856   }
    857 
     816  G4double Dist, s, xi, yi, zi, rho2, inum, iden, cosPsi, Comp ;
     817  G4double t1, t2, t3, b, c, d ;     // Quadratic solver variables
     818 
    858819  // Calculate tolerant rmin and rmax
    859820
    860821  if (fRMin > kRadTolerance)
    861822  {
    862     tolORMin2 = (fRMin - 0.5*kRadTolerance)*(fRMin - 0.5*kRadTolerance) ;
    863     tolIRMin2 = (fRMin + 0.5*kRadTolerance)*(fRMin + 0.5*kRadTolerance) ;
     823    tolORMin2 = (fRMin - halfRadTolerance)*(fRMin - halfRadTolerance) ;
     824    tolIRMin2 = (fRMin + halfRadTolerance)*(fRMin + halfRadTolerance) ;
    864825  }
    865826  else
     
    868829    tolIRMin2 = 0.0 ;
    869830  }
    870   tolORMax2 = (fRMax + 0.5*kRadTolerance)*(fRMax + 0.5*kRadTolerance) ;
    871   tolIRMax2 = (fRMax - 0.5*kRadTolerance)*(fRMax - 0.5*kRadTolerance) ;
     831  tolORMax2 = (fRMax + halfRadTolerance)*(fRMax + halfRadTolerance) ;
     832  tolIRMax2 = (fRMax - halfRadTolerance)*(fRMax - halfRadTolerance) ;
    872833
    873834  // Intersection with Z surfaces
    874835
    875   tolIDz = fDz - kCarTolerance*0.5 ;
    876   tolODz = fDz + kCarTolerance*0.5 ;
     836  tolIDz = fDz - halfCarTolerance ;
     837  tolODz = fDz + halfCarTolerance ;
    877838
    878839  if (std::fabs(p.z()) >= tolIDz)
     
    880841    if ( p.z()*v.z() < 0 )    // at +Z going in -Z or visa versa
    881842    {
    882       s = (std::fabs(p.z()) - fDz)/std::fabs(v.z()) ;     // Z intersect distance
     843      s = (std::fabs(p.z()) - fDz)/std::fabs(v.z()) ;   // Z intersect distance
    883844
    884845      if(s < 0.0)  { s = 0.0; }
     
    890851      // Check validity of intersection
    891852
    892       if (tolIRMin2 <= rho2 && rho2 <= tolIRMax2)
    893       {
    894         if (seg && rho2)
     853      if ((tolIRMin2 <= rho2) && (rho2 <= tolIRMax2))
     854      {
     855        if (!fPhiFullTube && rho2)
    895856        {
    896857          // Psi = angle made with central (average) phi of shape
     
    899860          iden   = std::sqrt(rho2) ;
    900861          cosPsi = inum/iden ;
    901           if (cosPsi >= cosHDPhiIT) return s ;
     862          if (cosPsi >= cosHDPhiIT)  { return s ; }
    902863        }
    903864        else
     
    909870    else
    910871    {
    911       if ( snxt<kCarTolerance*0.5 )  { snxt=0; }
     872      if ( snxt<halfCarTolerance )  { snxt=0; }
    912873      return snxt ;  // On/outside extent, and heading away
    913874                     // -> cannot intersect
     
    934895    b = t2/t1 ;
    935896    c = t3 - fRMax*fRMax ;
    936     if (t3 >= tolORMax2 && t2<0)   // This also handles the tangent case
     897    if ((t3 >= tolORMax2) && (t2<0))   // This also handles the tangent case
    937898    {
    938899      // Try outer cylinder intersection
     
    954915            // Z ok. Check phi intersection if reqd
    955916            //
    956             if (!seg)
     917            if (fPhiFullTube)
    957918            {
    958919              return s ;
     
    963924              yi     = p.y() + s*v.y() ;
    964925              cosPsi = (xi*cosCPhi + yi*sinCPhi)/fRMax ;
    965               if (cosPsi >= cosHDPhiIT) return s ;
     926              if (cosPsi >= cosHDPhiIT)  { return s ; }
    966927            }
    967928          }  //  end if std::fabs(zi)
     
    974935      // check not inside, and heading through tubs (-> 0 to in)
    975936
    976       if (t3 > tolIRMin2 && t2 < 0 && std::fabs(p.z()) <= tolIDz)
     937      if ((t3 > tolIRMin2) && (t2 < 0) && (std::fabs(p.z()) <= tolIDz))
    977938      {
    978939        // Inside both radii, delta r -ve, inside z extent
    979940
    980         if (seg)
     941        if (!fPhiFullTube)
    981942        {
    982943          inum   = p.x()*cosCPhi + p.y()*sinCPhi ;
     
    1004965                snxt = c/(-b+std::sqrt(d)); // using safe solution
    1005966                                            // for quadratic equation
    1006                 if ( snxt<kCarTolerance*0.5 ) { snxt=0; }
     967                if ( snxt < halfCarTolerance ) { snxt=0; }
    1007968                return snxt ;
    1008969              }     
     
    1035996              snxt= c/(-b+std::sqrt(d)); // using safe solution
    1036997                                         // for quadratic equation
    1037               if ( snxt<kCarTolerance*0.5 ) { snxt=0; }
     998              if ( snxt < halfCarTolerance ) { snxt=0; }
    1038999              return snxt ;
    10391000            }     
     
    10431004            }
    10441005          }
    1045         } // end if   (seg)
     1006        } // end if   (!fPhiFullTube)
    10461007      }   // end if   (t3>tolIRMin2)
    10471008    }     // end if   (Inside Outer Radius)
     
    10561017
    10571018        s = -b + std::sqrt(d) ;
    1058         if (s >= -0.5*kCarTolerance)  // check forwards
     1019        if (s >= -halfCarTolerance)  // check forwards
    10591020        {
    10601021          // Check z intersection
     
    10661027            // Z ok. Check phi
    10671028            //
    1068             if ( !seg )
     1029            if ( fPhiFullTube )
    10691030            {
    10701031              return s ;
     
    10981059  //         -> use some form of loop Construct ?
    10991060  //
    1100   if ( seg )
     1061  if ( !fPhiFullTube )
    11011062  {
    11021063    // First phi surface (Starting phi)
    1103 
    1104     sinSPhi = std::sin(fSPhi) ;
    1105     cosSPhi = std::cos(fSPhi) ;
     1064    //
    11061065    Comp    = v.x()*sinSPhi - v.y()*cosSPhi ;
    11071066                   
     
    11101069      Dist = (p.y()*cosSPhi - p.x()*sinSPhi) ;
    11111070
    1112       if ( Dist < kCarTolerance*0.5 )
     1071      if ( Dist < halfCarTolerance )
    11131072      {
    11141073        s = Dist/Comp ;
     
    11351094              // - check intersecting with correct half-plane
    11361095              //
    1137               if ((yi*cosCPhi-xi*sinCPhi) <= 0) snxt = s ;
    1138             }   
     1096              if ((yi*cosCPhi-xi*sinCPhi) <= halfCarTolerance) { snxt = s; }
     1097            }
    11391098          }
    11401099        }
     
    11421101    }
    11431102     
    1144     // Second phi surface (`E'nding phi)
    1145 
    1146     ePhi    = fSPhi + fDPhi ;
    1147     sinEPhi = std::sin(ePhi) ;
    1148     cosEPhi = std::cos(ePhi) ;
     1103    // Second phi surface (Ending phi)
     1104
    11491105    Comp    = -(v.x()*sinEPhi - v.y()*cosEPhi) ;
    11501106       
     
    11531109      Dist = -(p.y()*cosEPhi - p.x()*sinEPhi) ;
    11541110
    1155       if ( Dist < kCarTolerance*0.5 )
     1111      if ( Dist < halfCarTolerance )
    11561112      {
    11571113        s = Dist/Comp ;
     
    11771133              // - check intersecting with correct half-plane
    11781134              //
    1179               if ( (yi*cosCPhi-xi*sinCPhi) >= 0 )  { snxt = s; }
    1180             }   
     1135              if ( (yi*cosCPhi-xi*sinCPhi) >= 0 ) { snxt = s; }
     1136            }                         //?? >=-halfCarTolerance
    11811137          }
    11821138        }
    11831139      }
    11841140    }         //  Comp < 0
    1185   }           //  seg != 0
    1186   if ( snxt<kCarTolerance*0.5 )  { snxt=0; }
     1141  }           //  !fPhiFullTube
     1142  if ( snxt<halfCarTolerance )  { snxt=0; }
    11871143  return snxt ;
    11881144}
     
    12171173{
    12181174  G4double safe=0.0, rho, safe1, safe2, safe3 ;
    1219   G4double phiC, cosPhiC, sinPhiC, safePhi, ePhi, cosPsi ;
     1175  G4double safePhi, cosPsi ;
    12201176
    12211177  rho   = std::sqrt(p.x()*p.x() + p.y()*p.y()) ;
     
    12281184  if ( safe3 > safe )  { safe = safe3; }
    12291185
    1230   if (fDPhi < twopi && rho)
    1231   {
    1232     phiC    = fSPhi + fDPhi*0.5 ;
    1233     cosPhiC = std::cos(phiC) ;
    1234     sinPhiC = std::sin(phiC) ;
    1235 
     1186  if ( (!fPhiFullTube) && (rho) )
     1187  {
    12361188    // Psi=angle from central phi to point
    12371189    //
    1238     cosPsi = (p.x()*cosPhiC + p.y()*sinPhiC)/rho ;
    1239 
     1190    cosPsi = (p.x()*cosCPhi + p.y()*sinCPhi)/rho ;
     1191   
    12401192    if ( cosPsi < std::cos(fDPhi*0.5) )
    12411193    {
    12421194      // Point lies outside phi range
    12431195
    1244       if ( (p.y()*cosPhiC - p.x()*sinPhiC) <= 0 )
    1245       {
    1246         safePhi = std::fabs(p.x()*std::sin(fSPhi) - p.y()*std::cos(fSPhi)) ;
     1196      if ( (p.y()*cosCPhi - p.x()*sinCPhi) <= 0 )
     1197      {
     1198        safePhi = std::fabs(p.x()*sinSPhi - p.y()*cosSPhi) ;
    12471199      }
    12481200      else
    12491201      {
    1250         ePhi    = fSPhi + fDPhi ;
    1251         safePhi = std::fabs(p.x()*std::sin(ePhi) - p.y()*std::cos(ePhi)) ;
     1202        safePhi = std::fabs(p.x()*sinEPhi - p.y()*cosEPhi) ;
    12521203      }
    12531204      if ( safePhi > safe )  { safe = safePhi; }
     
    12691220                                      G4ThreeVector *n    ) const
    12701221
    1271   ESide side = kNull , sider = kNull, sidephi = kNull ;
    1272   G4double snxt, sr = kInfinity, sphi = kInfinity, pdist ;
     1222  ESide side=kNull , sider=kNull, sidephi=kNull ;
     1223  G4double snxt, sr=kInfinity, sphi=kInfinity, pdist ;
    12731224  G4double deltaR, t1, t2, t3, b, c, d2, roMin2 ;
    12741225
     1226  static const G4double halfCarTolerance = kCarTolerance*0.5;
     1227  static const G4double halfAngTolerance = kAngTolerance*0.5;
     1228 
    12751229  // Vars for phi intersection:
    12761230
    1277   G4double sinSPhi, cosSPhi, ePhi, sinEPhi, cosEPhi ;
    1278   G4double cPhi, sinCPhi, cosCPhi ;
    12791231  G4double pDistS, compS, pDistE, compE, sphi2, xi, yi, vphi, roi2 ;
    12801232 
     
    12841236  {
    12851237    pdist = fDz - p.z() ;
    1286     if ( pdist > kCarTolerance*0.5 )
     1238    if ( pdist > halfCarTolerance )
    12871239    {
    12881240      snxt = pdist/v.z() ;
     
    13031255    pdist = fDz + p.z() ;
    13041256
    1305     if ( pdist > kCarTolerance*0.5 )
     1257    if ( pdist > halfCarTolerance )
    13061258    {
    13071259      snxt = -pdist/v.z() ;
     
    13261278  // Radial Intersections
    13271279  //
    1328   // Find intersction with cylinders at rmax/rmin
     1280  // Find intersection with cylinders at rmax/rmin
    13291281  // Intersection point (xi,yi,zi) on line x=p.x+t*v.x etc.
    13301282  //
     
    13591311        b     = t2/t1 ;
    13601312        c     = deltaR/t1 ;
    1361         d2= b*b-c;
    1362         if(d2>=0.){sr    = -b + std::sqrt(d2);}
    1363         else{sr=0.;};
     1313        d2    = b*b-c;
     1314        if( d2 >= 0 ) { sr = -b + std::sqrt(d2); }
     1315        else          { sr = 0.; }
    13641316        sider = kRMax ;
    13651317      }
     
    13711323        if ( calcNorm )
    13721324        {
    1373           // if ( p.x() || p.y() )
    1374           // {
    1375           //  *n=G4ThreeVector(p.x(),p.y(),0);
    1376           // }
    1377           // else
    1378           // {
    1379           //  *n=v;
    1380           // }
    13811325          *n         = G4ThreeVector(p.x()/fRMax,p.y()/fRMax,0) ;
    13821326          *validNorm = true ;
     
    14171361          c     = deltaR/t1 ;
    14181362          d2    = b*b-c;
    1419           if(d2>=0.)
     1363          if( d2 >=0. )
    14201364          {
    14211365            sr     = -b + std::sqrt(d2) ;
     
    14231367          }
    14241368          else // Case: On the border+t2<kRadTolerance
    1425                //       (v is perpendiculair to the surface)
     1369               //       (v is perpendicular to the surface)
    14261370          {
    14271371            if (calcNorm)
     
    14411385        c      = deltaR/t1;
    14421386        d2     = b*b-c;
    1443         if(d2>=0.)
     1387        if( d2 >= 0 )
    14441388        {
    14451389          sr     = -b + std::sqrt(d2) ;
     
    14471391        }
    14481392        else // Case: On the border+t2<kRadTolerance
    1449              //       (v is perpendiculair to the surface)
     1393             //       (v is perpendicular to the surface)
    14501394        {
    14511395          if (calcNorm)
     
    14611405    // Phi Intersection
    14621406
    1463     if ( fDPhi < twopi )
    1464     {
    1465       sinSPhi = std::sin(fSPhi) ;
    1466       cosSPhi = std::cos(fSPhi) ;
    1467       ePhi    = fSPhi + fDPhi ;
    1468       sinEPhi = std::sin(ePhi) ;
    1469       cosEPhi = std::cos(ePhi) ;
    1470       cPhi    = fSPhi + fDPhi*0.5 ;
    1471       sinCPhi = std::sin(cPhi) ;
    1472       cosCPhi = std::cos(cPhi) ;
    1473 
     1407    if ( !fPhiFullTube )
     1408    {
    14741409      // add angle calculation with correction
    14751410      // of the difference in domain of atan2 and Sphi
    14761411      //
    14771412      vphi = std::atan2(v.y(),v.x()) ;
    1478 
    1479       if ( vphi < fSPhi - kAngTolerance*0.5  )             { vphi += twopi; }
    1480       else if ( vphi > fSPhi + fDPhi + kAngTolerance*0.5 ) { vphi -= twopi; }
     1413     
     1414      if ( vphi < fSPhi - halfAngTolerance  )             { vphi += twopi; }
     1415      else if ( vphi > fSPhi + fDPhi + halfAngTolerance ) { vphi -= twopi; }
    14811416
    14821417
     
    14921427        compS   = -sinSPhi*v.x() + cosSPhi*v.y() ;
    14931428        compE   =  sinEPhi*v.x() - cosEPhi*v.y() ;
     1429       
    14941430        sidephi = kNull;
    14951431       
    1496         if( ( (fDPhi <= pi) && ( (pDistS <= 0.5*kCarTolerance)
    1497                               && (pDistE <= 0.5*kCarTolerance) ) )
    1498          || ( (fDPhi >  pi) && !((pDistS >  0.5*kCarTolerance)
    1499                               && (pDistE >  0.5*kCarTolerance) ) )  )
     1432        if( ( (fDPhi <= pi) && ( (pDistS <= halfCarTolerance)
     1433                              && (pDistE <= halfCarTolerance) ) )
     1434         || ( (fDPhi >  pi) && !((pDistS >  halfCarTolerance)
     1435                              && (pDistE >  halfCarTolerance) ) )  )
    15001436        {
    15011437          // Inside both phi *full* planes
     
    15051441            sphi = pDistS/compS ;
    15061442           
    1507             if (sphi >= -0.5*kCarTolerance)
     1443            if (sphi >= -halfCarTolerance)
    15081444            {
    15091445              xi = p.x() + sphi*v.x() ;
     
    15131449              // (if not -> no intersect)
    15141450              //
    1515               if((std::abs(xi)<=kCarTolerance)&&(std::abs(yi)<=kCarTolerance))
    1516                 { sidephi = kSPhi;
    1517                 if (((fSPhi-0.5*kAngTolerance)<=vphi)
    1518                    &&((ePhi+0.5*kAngTolerance)>=vphi))
     1451              if( (std::abs(xi)<=kCarTolerance)&&(std::abs(yi)<=kCarTolerance) )
     1452              {
     1453                sidephi = kSPhi;
     1454                if (((fSPhi-halfAngTolerance)<=vphi)
     1455                   &&((fSPhi+fDPhi+halfAngTolerance)>=vphi))
    15191456                {
    15201457                  sphi = kInfinity;
    15211458                }
    15221459              }
    1523               else if ((yi*cosCPhi-xi*sinCPhi)>=0)
     1460              else if ( yi*cosCPhi-xi*sinCPhi >=0 )
    15241461              {
    15251462                sphi = kInfinity ;
     
    15281465              {
    15291466                sidephi = kSPhi ;
    1530                 if ( pDistS > -kCarTolerance*0.5 )
     1467                if ( pDistS > -halfCarTolerance )
    15311468                {
    15321469                  sphi = 0.0 ; // Leave by sphi immediately
     
    15501487            // Only check further if < starting phi intersection
    15511488            //
    1552             if ( (sphi2 > -0.5*kCarTolerance) && (sphi2 < sphi) )
     1489            if ( (sphi2 > -halfCarTolerance) && (sphi2 < sphi) )
    15531490            {
    15541491              xi = p.x() + sphi2*v.x() ;
     
    15591496                // Leaving via ending phi
    15601497                //
    1561                 if(!(((fSPhi-0.5*kAngTolerance)<=vphi)
    1562                     &&((ePhi+0.5*kAngTolerance)>=vphi)))
     1498                if( !((fSPhi-halfAngTolerance <= vphi)
     1499                     &&(fSPhi+fDPhi+halfAngTolerance >= vphi)) )
    15631500                {
    15641501                  sidephi = kEPhi ;
    1565                   if ( pDistE <= -kCarTolerance*0.5 )  { sphi = sphi2 ; }
    1566                   else                                 { sphi = 0.0 ; }
     1502                  if ( pDistE <= -halfCarTolerance )  { sphi = sphi2 ; }
     1503                  else                                { sphi = 0.0 ;  }
    15671504                }
    15681505              }
     
    15741511                //
    15751512                sidephi = kEPhi ;
    1576                 if ( pDistE <= -kCarTolerance*0.5 ) { sphi = sphi2 ; }
    1577                 else                                { sphi = 0.0 ; }
     1513                if ( pDistE <= -halfCarTolerance ) { sphi = sphi2 ; }
     1514                else                               { sphi = 0.0 ;  }
    15781515              }
    15791516            }
     
    15891526        // On z axis + travel not || to z axis -> if phi of vector direction
    15901527        // within phi of shape, Step limited by rmax, else Step =0
    1591 
    1592         // vphi = std::atan2(v.y(),v.x()) ;//defined previosly
    1593         // G4cout<<"In axis vphi="<<vphi
    1594         //       <<" Sphi="<<fSPhi<<" Ephi="<<ePhi<<G4endl;
    1595         // old  if ( (fSPhi < vphi) && (vphi < fSPhi + fDPhi) )
    1596         // new : correction for if statement, must be '<=' 
    15971528               
    1598         if ( ((fSPhi-0.5*kAngTolerance) <= vphi)
    1599            && (vphi <=( ePhi+0.5*kAngTolerance) ))
     1529        if ( (fSPhi - halfAngTolerance <= vphi)
     1530           && (vphi <= fSPhi + fDPhi + halfAngTolerance ) )
    16001531        {
    16011532          sphi = kInfinity ;
     
    16401571        if ( fDPhi <= pi )
    16411572        {
    1642           *n         = G4ThreeVector(std::sin(fSPhi),-std::cos(fSPhi),0) ;
     1573          *n         = G4ThreeVector(sinSPhi,-cosSPhi,0) ;
    16431574          *validNorm = true ;
    16441575        }
     
    16521583        if (fDPhi <= pi)
    16531584        {
    1654           *n = G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0) ;
     1585          *n = G4ThreeVector(-sinEPhi,cosEPhi,0) ;
    16551586          *validNorm = true ;
    16561587        }
     
    16621593
    16631594      case kPZ:
    1664         *n=G4ThreeVector(0,0,1) ;
    1665         *validNorm=true ;
     1595        *n         = G4ThreeVector(0,0,1) ;
     1596        *validNorm = true ;
    16661597        break ;
    16671598
     
    16901621    }
    16911622  }
    1692   if ( snxt<kCarTolerance*0.5 )  { snxt=0 ; }
     1623  if ( snxt<halfCarTolerance )  { snxt=0 ; }
    16931624
    16941625  return snxt ;
     
    17011632G4double G4Tubs::DistanceToOut( const G4ThreeVector& p ) const
    17021633{
    1703   G4double safe=0.0, rho, safeR1, safeR2, safeZ ;
    1704   G4double safePhi, phiC, cosPhiC, sinPhiC, ePhi ;
     1634  G4double safe=0.0, rho, safeR1, safeR2, safeZ, safePhi ;
    17051635  rho = std::sqrt(p.x()*p.x() + p.y()*p.y()) ;
    17061636
     
    17381668  // Check if phi divided, Calc distances closest phi plane
    17391669  //
    1740   if ( fDPhi < twopi )
    1741   {
    1742     // Above/below central phi of Tubs?
    1743 
    1744     phiC    = fSPhi + fDPhi*0.5 ;
    1745     cosPhiC = std::cos(phiC) ;
    1746     sinPhiC = std::sin(phiC) ;
    1747 
    1748     if ( (p.y()*cosPhiC - p.x()*sinPhiC) <= 0 )
    1749     {
    1750       safePhi = -(p.x()*std::sin(fSPhi) - p.y()*std::cos(fSPhi)) ;
     1670  if ( !fPhiFullTube )
     1671  {
     1672    if ( p.y()*cosCPhi-p.x()*sinCPhi <= 0 )
     1673    {
     1674      safePhi = -(p.x()*sinSPhi - p.y()*cosSPhi) ;
    17511675    }
    17521676    else
    17531677    {
    1754       ePhi    = fSPhi + fDPhi ;
    1755       safePhi = (p.x()*std::sin(ePhi) - p.y()*std::cos(ePhi)) ;
     1678      safePhi = (p.x()*sinEPhi - p.y()*cosEPhi) ;
    17561679    }
    17571680    if (safePhi < safe)  { safe = safePhi ; }
     
    18061729  // on the x axis. Will give better extent calculations when not rotated.
    18071730
    1808   if (fDPhi == pi*2.0 && fSPhi == 0 )  { sAngle = -meshAngle*0.5 ; }
    1809   else                                 { sAngle =  fSPhi ; }
     1731  if (fPhiFullTube && (fSPhi == 0) )  { sAngle = -meshAngle*0.5 ; }
     1732  else                                { sAngle =  fSPhi ; }
    18101733   
    18111734  vertices = new G4ThreeVectorList();
     
    19751898  if (fRMin != 0)
    19761899  {
    1977     if (fDPhi >= twopi)
     1900    if (fPhiFullTube)
    19781901    {
    19791902      pNURBS = new G4NURBStube (fRMin,fRMax,fDz) ;
     
    19861909  else
    19871910  {
    1988     if (fDPhi >= twopi)
     1911    if (fPhiFullTube)
    19891912    {
    19901913      pNURBS = new G4NURBScylinder (fRMax,fDz) ;
  • trunk/source/geometry/solids/specific/History

    r850 r921  
    1 $Id: History,v 1.145 2008/08/12 08:57:31 gcosmo Exp $
     1$Id: History,v 1.150 2008/11/21 09:26:53 gcosmo Exp $
    22-------------------------------------------------------------------
    33
     
    1717     * Reverse chronological order (last date on top), please *
    1818     ----------------------------------------------------------
     19
     2021-Nov-2008, G.Cosmo (geom-specific-V09-01-19)
     21- Added missing accessors to G4EllipticalCone, required for detector
     22  persistency.
     23
     2413-Nov-2008, G.Cosmo (geom-specific-V09-01-18)
     25- Corrected initialisation of algorithm in G4TriangularFacet constructor.
     26
     2730-Oct-2008, I.Hrivnacova (geom-specific-V09-01-17)
     28- G4ExtrudedSolid: fixed bug in the decomposition of polygonal sides for
     29  quadrangular facets in MakeFacets(). Addresses problem report #1029.
     30
     3123-Sep-2008, T.Nikitina (geom-specific-V09-01-16)
     32- Corrected algorithm in G4TriangularFacet::GetPointOnFace() according to
     33  suggestion advanced in problem report #1025. Fixes a problem of false
     34  overlaps detection related to G4ExtrudedSolid and G4TessellatedSolid.
     35
     3612-Sep-2008, G.Cosmo (geom-specific-V09-01-15)
     37- G4VFacet: corrected increment of indeces in operator==(), following
     38  problem report #1024.
    1939
    204025-Jul-2008, I.Hrivnacova (geom-specific-V09-01-14)
  • trunk/source/geometry/solids/specific/include/G4EllipticalCone.hh

    r850 r921  
    2525//
    2626//
    27 // $Id: G4EllipticalCone.hh,v 1.11 2007/08/20 15:21:40 tnikitin Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4EllipticalCone.hh,v 1.12 2008/11/21 09:26:22 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    9696    //
    9797    inline G4double GetSemiAxisMax () const;
     98    inline G4double GetSemiAxisX () const;
     99    inline G4double GetSemiAxisY () const;
     100    inline G4double GetZMax() const;
    98101    inline G4double GetZTopCut() const;
    99102    inline void SetSemiAxis (G4double x, G4double y, G4double z);
  • trunk/source/geometry/solids/specific/include/G4EllipticalCone.icc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4EllipticalCone.icc,v 1.6 2006/10/20 13:45:20 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4EllipticalCone.icc,v 1.7 2008/11/21 09:26:22 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    4343{
    4444  return ySemiAxis > xSemiAxis ? ySemiAxis : xSemiAxis;
     45}
     46
     47inline
     48G4double G4EllipticalCone::GetSemiAxisX () const
     49{
     50  return xSemiAxis;
     51}
     52
     53inline
     54G4double G4EllipticalCone::GetSemiAxisY () const
     55{
     56  return ySemiAxis;
     57}
     58
     59inline
     60G4double G4EllipticalCone::GetZMax() const
     61{
     62  return zheight;
    4563}
    4664
  • trunk/source/geometry/solids/specific/src/G4ExtrudedSolid.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4ExtrudedSolid.cc,v 1.17 2008/08/12 08:54:57 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4ExtrudedSolid.cc,v 1.18 2008/10/30 11:47:45 ivana Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    562562
    563563    good = AddFacet( new G4QuadrangularFacet( GetVertex(fNz-1, 3), GetVertex(fNz-1, 2),
    564                                               GetVertex(fNz-1, 1), GetVertex(1, 0),
     564                                              GetVertex(fNz-1, 1), GetVertex(fNz-1, 0),
    565565                                              ABSOLUTE) );
    566566    if ( ! good ) { return false; }
  • trunk/source/geometry/solids/specific/src/G4TriangularFacet.cc

    r850 r921  
    2525// ********************************************************************
    2626//
    27 // $Id: G4TriangularFacet.cc,v 1.10 2007/12/10 16:30:35 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4TriangularFacet.cc,v 1.12 2008/11/13 08:25:07 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    7575  : G4VFacet()
    7676{
    77   if (!tGeomAlg) { tGeomAlg = G4TessellatedGeometryAlgorithms::GetInstance(); }
     77  tGeomAlg  = G4TessellatedGeometryAlgorithms::GetInstance();
    7878  P0        = Pt0;
    7979  nVertices = 3;
     
    710710G4ThreeVector G4TriangularFacet::GetPointOnFace() const
    711711{
    712   G4double lambda0 = CLHEP::RandFlat::shoot(0.,1.);
    713   G4double lambda1 = CLHEP::RandFlat::shoot(0.,lambda0);
    714 
     712  G4double alpha = CLHEP::RandFlat::shoot(0.,1.);
     713  G4double beta = CLHEP::RandFlat::shoot(0.,1);
     714  G4double lambda1=alpha*beta;
     715  G4double lambda0=alpha-lambda1;
     716 
    715717  return (P0 + lambda0*E[0] + lambda1*E[1]);
    716718}
  • trunk/source/geometry/solids/specific/src/G4VFacet.cc

    r850 r921  
    2525// ********************************************************************
    2626//
    27 // $Id: G4VFacet.cc,v 1.6 2007/08/23 14:45:03 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4VFacet.cc,v 1.7 2008/09/12 07:16:22 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    9696    {
    9797      coincident = (GetVertex(i)-right.GetVertex(j)).mag2() < tolerance;
    98     } while (!coincident && j++ < nVertices);
    99   } while (coincident && i++ < nVertices);
     98    } while (!coincident && ++j < nVertices);
     99  } while (coincident && ++i < nVertices);
    100100 
    101101  return coincident;
     
    117117std::ostream &G4VFacet::StreamInfo(std::ostream &os) const
    118118{
    119   os <<G4endl;
    120   os <<"***********************************************************************"
    121      <<G4endl;
    122   os <<"FACET TYPE       = " <<geometryType <<G4endl;
    123   os <<"ABSOLUTE VECTORS = " <<G4endl;
    124   os <<"P0               = " <<P0 <<G4endl;
     119  os << G4endl;
     120  os << "*********************************************************************"
     121     << G4endl;
     122  os << "FACET TYPE       = " << geometryType << G4endl;
     123  os << "ABSOLUTE VECTORS = " << G4endl;
     124  os << "P0               = " << P0 << G4endl;
    125125  for (G4ThreeVectorList::const_iterator it=P.begin(); it!=P.end(); it++)
    126     os <<"P[" <<it-P.begin()+1 <<"]      = " <<*it <<G4endl;
    127    
    128   os <<"RELATIVE VECTORS = " <<G4endl;
     126    { os << "P[" << it-P.begin()+1 << "]      = " << *it << G4endl; }
     127
     128  os << "RELATIVE VECTORS = " << G4endl;
    129129  for (G4ThreeVectorList::const_iterator it=E.begin(); it!=E.end(); it++)
    130     os <<"E[" <<it-E.begin()+1 <<"]      = " <<*it <<G4endl;
    131  
    132   os <<"***********************************************************************"
    133      <<G4endl;
     130    { os << "E[" << it-E.begin()+1 << "]      = " << *it << G4endl; }
     131
     132  os << "*********************************************************************"
     133     << G4endl;
    134134 
    135135  return os;
  • trunk/source/geometry/volumes/History

    r850 r921  
    1 $Id: History,v 1.153 2008/08/19 15:32:14 gcosmo Exp $
     1$Id: History,v 1.155 2008/11/13 09:35:03 gcosmo Exp $
    22-------------------------------------------------------------------
    33
     
    1717     * Reverse chronological order (last date on top), please *
    1818     ----------------------------------------------------------
     19
     20Nov 13th, 2008      G.Cosmo - geomvol-V09-01-03
     21- Corrected singleton definition for G4ReflectionFactory.
     22- Return 'const G4String&' instead of copy in GetVolumesNameExtension().
    1923
    2024Aug 19th, 2008      G.Cosmo - geomvol-V09-01-02
  • trunk/source/geometry/volumes/include/G4ReflectionFactory.hh

    r850 r921  
    2525//
    2626//
    27 // $Id: G4ReflectionFactory.hh,v 1.3 2006/06/29 18:57:39 gunter Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4ReflectionFactory.hh,v 1.4 2008/11/13 09:33:20 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    152152
    153153    void     SetVolumesNameExtension(const G4String& nameExtension);
    154     G4String GetVolumesNameExtension() const;
     154    const G4String& GetVolumesNameExtension() const;
    155155      // Returns the name extension for the reflected solids
    156156      // and logical volumes.
  • trunk/source/geometry/volumes/src/G4ReflectionFactory.cc

    r850 r921  
    2525//
    2626//
    27 // $Id: G4ReflectionFactory.cc,v 1.6 2007/05/11 13:58:35 gcosmo Exp $
    28 // GEANT4 tag $Name: HEAD $
     27// $Id: G4ReflectionFactory.cc,v 1.9 2008/11/13 09:33:20 gcosmo Exp $
     28// GEANT4 tag $Name: geant4-09-02-cand-01 $
    2929//
    3030//
     
    7575  // ---
    7676
    77   if (!fInstance) new G4ReflectionFactory();
    78  
     77  if (!fInstance) { fInstance = new G4ReflectionFactory(); }
     78
    7979  return fInstance;
    8080
     
    9898G4ReflectionFactory::~G4ReflectionFactory()
    9999{
     100  delete fInstance;
    100101}
    101102
     
    862863//_____________________________________________________________________________
    863864
    864 G4String G4ReflectionFactory::GetVolumesNameExtension() const
     865const G4String& G4ReflectionFactory::GetVolumesNameExtension() const
    865866{
    866867  return fNameExtension;
Note: See TracChangeset for help on using the changeset viewer.