Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/transportation/src/G4Transportation.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/transportation/src/G4Transportation.cc (Version 11.3.0) and /processes/transportation/src/G4Transportation.cc (Version 7.0)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 //                                                 23 //
                                                   >>  24 // $Id: G4Transportation.cc,v 1.51 2004/12/07 08:28:39 gcosmo Exp $
                                                   >>  25 // GEANT4 tag $Name: geant4-07-00-cand-03 $
 27 //                                                 26 // 
 28 // -------------------------------------------     27 // ------------------------------------------------------------
 29 //  GEANT 4  include file implementation           28 //  GEANT 4  include file implementation
 30 //                                                 29 //
 31 // -------------------------------------------     30 // ------------------------------------------------------------
 32 //                                                 31 //
 33 // This class is a process responsible for the     32 // This class is a process responsible for the transportation of 
 34 // a particle, ie the geometrical propagation      33 // a particle, ie the geometrical propagation that encounters the 
 35 // geometrical sub-volumes of the detectors.       34 // geometrical sub-volumes of the detectors.
 36 //                                                 35 //
 37 // It is also tasked with the key role of prop <<  36 // It is also tasked with part of updating the "safety".
 38 //   which will be used to update the post-ste << 
 39 //                                                 37 //
 40 // ===========================================     38 // =======================================================================
                                                   >>  39 // Modified:   
                                                   >>  40 //            11 Aug  2004, M.Asai: Add G4VSensitiveDetector* for updating stepPoint.
                                                   >>  41 //            21 June 2003, J.Apostolakis: Calling field manager with 
                                                   >>  42 //                            track, to enable it to configure its accuracy
                                                   >>  43 //            13 May  2003, J.Apostolakis: Zero field areas now taken into
                                                   >>  44 //                            account correclty in all cases (thanks to W Pokorski).
                                                   >>  45 //            29 June 2001, J.Apostolakis, D.Cote-Ahern, P.Gumplinger: 
                                                   >>  46 //                          correction for spin tracking   
                                                   >>  47 //            20 Febr 2001, J.Apostolakis:  update for new FieldTrack
                                                   >>  48 //            22 Sept 2000, V.Grichine:     update of Kinetic Energy
                                                   >>  49 //             9 June 1999, J.Apostolakis & S.Giani: protect full relocation
                                                   >>  50 //                          in DEBUG for track  starting on surface that
                                                   >>  51 //                          goes step < tolerance.
 41 // Created:  19 March 1997, J. Apostolakis         52 // Created:  19 March 1997, J. Apostolakis
 42 // ===========================================     53 // =======================================================================
 43                                                    54 
 44 #include "G4Transportation.hh"                     55 #include "G4Transportation.hh"
 45 #include "G4TransportationProcessType.hh"      << 
 46 #include "G4TransportationLogger.hh"           << 
 47                                                << 
 48 #include "G4PhysicalConstants.hh"              << 
 49 #include "G4SystemOfUnits.hh"                  << 
 50 #include "G4ProductionCutsTable.hh"                56 #include "G4ProductionCutsTable.hh"
 51 #include "G4ParticleTable.hh"                      57 #include "G4ParticleTable.hh"
 52                                                <<  58 #include "G4ChordFinder.hh"
 53 #include "G4ChargeState.hh"                    << 
 54 #include "G4EquationOfMotion.hh"               << 
 55                                                << 
 56 #include "G4FieldManagerStore.hh"              << 
 57                                                << 
 58 #include "G4Navigator.hh"                      << 
 59 #include "G4PropagatorInField.hh"              << 
 60 #include "G4TransportationManager.hh"          << 
 61                                                << 
 62 #include "G4TransportationParameters.hh"       << 
 63                                                << 
 64 class G4VSensitiveDetector;                        59 class G4VSensitiveDetector;
 65                                                    60 
 66 G4bool G4Transportation::fUseMagneticMoment=fa << 
 67 G4bool G4Transportation::fUseGravity= false;   << 
 68 G4bool G4Transportation::fSilenceLooperWarning << 
 69                                                << 
 70 //////////////////////////////////////////////     61 //////////////////////////////////////////////////////////////////////////
 71 //                                                 62 //
 72 // Constructor                                     63 // Constructor
 73                                                    64 
 74 G4Transportation::G4Transportation( G4int verb <<  65 G4Transportation::G4Transportation( G4int verboseLevel )
 75   : G4VProcess( aName, fTransportation ),      <<  66   : G4VProcess( G4String("Transportation") ),
 76     fFieldExertedForce( false ),               <<  67     fParticleIsLooping( false ),
 77     fPreviousSftOrigin( 0.,0.,0. ),            <<  68     fPreviousSftOrigin (0.,0.,0.),
 78     fPreviousSafety( 0.0 ),                    <<  69     fPreviousSafety    ( 0.0 ),
 79     fEndPointDistance( -1.0 ),                 <<  70     fThreshold_Warning_Energy( 100 * MeV ),  
 80     fShortStepOptimisation( false ) // Old def <<  71     fThreshold_Important_Energy( 250 * MeV ), 
                                                   >>  72     fThresholdTrials( 10 ), 
                                                   >>  73     fUnimportant_Energy( 1 * MeV ), 
                                                   >>  74     fNoLooperTrials(0),
                                                   >>  75     fSumEnergyKilled( 0.0 ), fMaxEnergyKilled( 0.0 ), 
                                                   >>  76   
                                                   >>  77     fVerboseLevel( verboseLevel )
 81 {                                                  78 {
 82   SetProcessSubType(static_cast<G4int>(TRANSPO << 
 83   pParticleChange= &fParticleChange;   // Requ << 
 84   SetVerboseLevel(verbosity);                  << 
 85                                                << 
 86   G4TransportationManager* transportMgr ;          79   G4TransportationManager* transportMgr ; 
 87                                                    80 
 88   transportMgr = G4TransportationManager::GetT     81   transportMgr = G4TransportationManager::GetTransportationManager() ; 
 89                                                    82 
 90   fLinearNavigator = transportMgr->GetNavigato     83   fLinearNavigator = transportMgr->GetNavigatorForTracking() ; 
 91                                                    84 
 92   fFieldPropagator = transportMgr->GetPropagat <<  85   // fGlobalFieldMgr = transportMgr->GetFieldManager() ;
 93                                                    86 
 94   fpSafetyHelper =   transportMgr->GetSafetyHe <<  87   fFieldPropagator = transportMgr->GetPropagatorInField() ;
 95                                                << 
 96   fpLogger = new G4TransportationLogger("G4Tra << 
 97                                                << 
 98   if( G4TransportationParameters::Exists() )   << 
 99   {                                            << 
100     auto trParams= G4TransportationParameters: << 
101                                                << 
102     SetThresholdWarningEnergy(  trParams->GetW << 
103     SetThresholdImportantEnergy( trParams->Get << 
104     SetThresholdTrials( trParams->GetNumberOfT << 
105     G4Transportation::fSilenceLooperWarnings=  << 
106   }                                            << 
107   else {                                       << 
108      SetHighLooperThresholds();                << 
109      // Use the old defaults: Warning = 100 Me << 
110   }                                            << 
111                                                    88 
112   PushThresholdsToLogger();                    <<  89   // Cannot determine whether a field exists here,
113   // Should be done by Set methods in SetHighL <<  90   //  because it would only work if the field manager has informed 
114                                                <<  91   //  about the detector's field before this transportation process 
115   static G4ThreadLocal G4TouchableHandle* pNul <<  92   //  is constructed.
116   if ( !pNullTouchableHandle)                  <<  93   // Instead later the method DoesGlobalFieldExist() is called
117   {                                            << 
118     pNullTouchableHandle = new G4TouchableHand << 
119   }                                            << 
120   fCurrentTouchableHandle = *pNullTouchableHan << 
121     // Points to (G4VTouchable*) 0             << 
122                                                    94 
                                                   >>  95   fCurrentTouchableHandle = new G4TouchableHistory();
123                                                    96   
124 #ifdef G4VERBOSE                               <<  97   fEndGlobalTimeComputed  = false;
125   if( verboseLevel > 0)                        <<  98   fCandidateEndGlobalTime = 0;
126   {                                            << 
127      G4cout << " G4Transportation constructor> << 
128      if ( fShortStepOptimisation )  { G4cout < << 
129      else                           { G4cout < << 
130   }                                            << 
131 #endif                                         << 
132 }                                                  99 }
133                                                   100 
134 //////////////////////////////////////////////    101 //////////////////////////////////////////////////////////////////////////
135                                                   102 
136 G4Transportation::~G4Transportation()             103 G4Transportation::~G4Transportation()
137 {                                                 104 {
138   if( fSumEnergyKilled > 0.0 )                 << 105   if( (fVerboseLevel > 0) && (fSumEnergyKilled > 0.0 ) ){ 
139   {                                            << 106     G4cout << " G4Transportation: Statistics for looping particles " << G4endl;
140      PrintStatistics( G4cout );                << 107     G4cout << "   Sum of energy of loopers killed: " <<  fSumEnergyKilled << G4endl;
141   }                                            << 108     G4cout << "   Max energy of loopers killed: " <<  fMaxEnergyKilled << G4endl;
142   delete fpLogger;                             << 109   } 
143 }                                              << 
144                                                << 
145 ////////////////////////////////////////////// << 
146                                                << 
147 void                                           << 
148 G4Transportation::PrintStatistics( std::ostrea << 
149 {                                              << 
150    outStr << " G4Transportation: Statistics fo << 
151    if( fSumEnergyKilled > 0.0 || fNumLoopersKi << 
152    {                                           << 
153       outStr << "   Sum of energy of looping t << 
154              <<  fSumEnergyKilled / CLHEP::MeV << 
155              << " from " << fNumLoopersKilled  << 
156              <<  "  Sum of energy of non-elect << 
157              << fSumEnergyKilled_NonElectron / << 
158              << "  from " << fNumLoopersKilled << 
159              << G4endl;                        << 
160       outStr << "   Max energy of  *any type*  << 
161              << "    its PDG was " << fMaxEner << 
162       if( fMaxEnergyKilled_NonElectron > 0.0 ) << 
163       {                                        << 
164          outStr << "   Max energy of non-elect << 
165                 << fMaxEnergyKilled_NonElectro << 
166                 << "    its PDG was " << fMaxE << 
167       }                                        << 
168       if( fMaxEnergySaved > 0.0 )              << 
169       {                                        << 
170          outStr << "   Max energy of loopers ' << 
171          outStr << "   Sum of energy of looper << 
172                 <<  fSumEnergySaved << G4endl; << 
173          outStr << "   Sum of energy of unstab << 
174                 << fSumEnergyUnstableSaved <<  << 
175       }                                        << 
176    }                                           << 
177    else                                        << 
178    {                                           << 
179       outStr << " No looping tracks found or k << 
180    }                                           << 
181 }                                                 110 }
182                                                   111 
183 //////////////////////////////////////////////    112 //////////////////////////////////////////////////////////////////////////
184 //                                                113 //
185 // Responsibilities:                              114 // Responsibilities:
186 //    Find whether the geometry limits the Ste    115 //    Find whether the geometry limits the Step, and to what length
187 //    Calculate the new value of the safety an    116 //    Calculate the new value of the safety and return it.
188 //    Store the final time, position and momen    117 //    Store the final time, position and momentum.
189                                                   118 
190 G4double G4Transportation::AlongStepGetPhysica << 119 G4double G4Transportation::
191   const G4Track& track,                        << 120 AlongStepGetPhysicalInteractionLength( const G4Track&  track,
192   G4double,  //  previousStepSize              << 121                                              G4double, //  previousStepSize
193   G4double currentMinimumStep, G4double& curre << 122                                              G4double  currentMinimumStep,
194   G4GPILSelection* selection)                  << 123                                              G4double& currentSafety,
                                                   >> 124                                              G4GPILSelection* selection )
195 {                                                 125 {
196   // Initial actions moved to  StartTrack()    << 126   G4double geometryStepLength, newSafety ; 
197   // --------------------------------------    << 127   fParticleIsLooping = false ;
198   // Note: in case another process changes tou << 128 
199   //    it will be necessary to add here (for  << 129   if( track.GetCurrentStepNumber()==1 )
200   // fCurrentTouchableHandle = aTrack->GetTouc << 130   {
                                                   >> 131      // reset safety value
                                                   >> 132      //
                                                   >> 133      fPreviousSafety    = 0.0 ; 
                                                   >> 134      fPreviousSftOrigin = G4ThreeVector(0.,0.,0.) ;
                                                   >> 135  
                                                   >> 136      // reset counter for looping particles in field
                                                   >> 137      fNoLooperTrials= 0; 
                                                   >> 138 
                                                   >> 139      // ChordFinder reset internal state
                                                   >> 140      //
                                                   >> 141      if ( DoesGlobalFieldExist() )
                                                   >> 142      {
                                                   >> 143         G4ChordFinder* chordF= fFieldPropagator->GetChordFinder();
                                                   >> 144         if( chordF ) chordF->ResetStepEstimate();
                                                   >> 145      }
                                                   >> 146 
                                                   >> 147      // We need to update the current transportation's touchable handle
                                                   >> 148      // to the track's one
                                                   >> 149      //
                                                   >> 150      fCurrentTouchableHandle = track.GetTouchableHandle();
                                                   >> 151   }
201                                                   152 
202   // GPILSelection is set to defaule value of     153   // GPILSelection is set to defaule value of CandidateForSelection
203   // It is a return value                         154   // It is a return value
204   //                                              155   //
205   *selection = CandidateForSelection;          << 156   *selection = CandidateForSelection ;
206                                                   157 
207   // Get initial Energy/Momentum of the track     158   // Get initial Energy/Momentum of the track
208   //                                              159   //
209   const G4ThreeVector startPosition    = track << 160   const G4DynamicParticle*  pParticle  = track.GetDynamicParticle() ;
210   const G4ThreeVector startMomentumDir = track << 161   G4ThreeVector startMomentumDir       = pParticle->GetMomentumDirection() ;
                                                   >> 162   G4ThreeVector startPosition          = track.GetPosition() ;
211                                                   163 
212   // The Step Point safety can be limited by o << 164   // G4double   theTime        = track.GetGlobalTime() ;
                                                   >> 165 
                                                   >> 166   // The Step Point safety can be limited by other geometries and/or the 
213   // assumptions of any process - it's not alw    167   // assumptions of any process - it's not always the geometrical safety.
214   // We calculate the starting point's isotrop    168   // We calculate the starting point's isotropic safety here.
                                                   >> 169   //
                                                   >> 170   G4ThreeVector OriginShift = startPosition - fPreviousSftOrigin ;
                                                   >> 171   G4double      MagSqShift  = OriginShift.mag2() ;
                                                   >> 172   if( MagSqShift >= sqr(fPreviousSafety) )
215   {                                               173   {
216     const G4double MagSqShift = (startPosition << 174      currentSafety = 0.0 ;
217                                                << 175   }
218     if(MagSqShift >= sqr(fPreviousSafety))     << 176   else
219       currentSafety = 0.0;                     << 177   {
220     else                                       << 178      currentSafety = fPreviousSafety - std::sqrt(MagSqShift) ;
221       currentSafety = fPreviousSafety - std::s << 
222   }                                               179   }
223                                                   180 
224   // Is the particle charged or has it a magne << 181   // Is the particle charged ?
225   //                                              182   //
226   const G4DynamicParticle* pParticle = track.G << 183   G4ParticleDefinition* pParticleDef   = pParticle->GetDefinition() ;
                                                   >> 184   G4double              particleCharge = pParticleDef->GetPDGCharge() ; 
227                                                   185 
228   const G4double particleMass   = pParticle->G << 186   fGeometryLimitedStep = false ;
229   const G4double particleCharge = pParticle->G << 187   // fEndGlobalTimeComputed = false ;
230   const G4double kineticEnergy = pParticle->Ge << 
231                                                << 
232   const G4double magneticMoment    = pParticle << 
233   const G4ThreeVector particleSpin = pParticle << 
234                                                   188 
235   // There is no need to locate the current vo    189   // There is no need to locate the current volume. It is Done elsewhere:
236   //   On track construction                   << 190   //   On track construction 
237   //   By the tracking, after all AlongStepDoI    191   //   By the tracking, after all AlongStepDoIts, in "Relocation"
238                                                   192 
239   // Check if the particle has a force, EM or  << 193   // Check whether the particle have an (EM) field force exerting upon it
240   //                                              194   //
                                                   >> 195   G4FieldManager* fieldMgr=0;
                                                   >> 196   G4bool          fieldExertsForce = false ;
                                                   >> 197   if( (particleCharge != 0.0) )
                                                   >> 198   {
                                                   >> 199      fieldMgr= fFieldPropagator->FindAndSetFieldManager( track.GetVolume() ); 
                                                   >> 200      if (fieldMgr != 0) {
                                                   >> 201         // If the field manager has no field, there is no field !
                                                   >> 202         fieldExertsForce = (fieldMgr->GetDetectorField() != 0);
                                                   >> 203      } 
                                                   >> 204   }
                                                   >> 205 
                                                   >> 206   // Choose the calculation of the transportation: Field or not 
                                                   >> 207   //
                                                   >> 208   if( !fieldExertsForce ) 
                                                   >> 209   {
                                                   >> 210      G4double linearStepLength ;
                                                   >> 211      if( currentMinimumStep <= currentSafety )
                                                   >> 212      {
                                                   >> 213        // The Step is guaranteed to be taken
                                                   >> 214        //
                                                   >> 215        geometryStepLength   = currentMinimumStep ;
                                                   >> 216        fGeometryLimitedStep = false ;
                                                   >> 217      }
                                                   >> 218      else
                                                   >> 219      {
                                                   >> 220        //  Find whether the straight path intersects a volume
                                                   >> 221        //
                                                   >> 222        linearStepLength = fLinearNavigator->ComputeStep( startPosition, 
                                                   >> 223                                                          startMomentumDir,
                                                   >> 224                                                          currentMinimumStep, 
                                                   >> 225                                                          newSafety) ;
                                                   >> 226        // Remember last safety origin & value.
                                                   >> 227        //
                                                   >> 228        fPreviousSftOrigin = startPosition ;
                                                   >> 229        fPreviousSafety    = newSafety ; 
                                                   >> 230 
                                                   >> 231        // The safety at the initial point has been re-calculated:
                                                   >> 232        //
                                                   >> 233        currentSafety = newSafety ;
                                                   >> 234           
                                                   >> 235        if( linearStepLength <= currentMinimumStep)
                                                   >> 236        {
                                                   >> 237          // The geometry limits the Step size (an intersection was found.)
                                                   >> 238          //
                                                   >> 239          geometryStepLength   = linearStepLength ;
                                                   >> 240          fGeometryLimitedStep = true ;
                                                   >> 241        }
                                                   >> 242        else
                                                   >> 243        {
                                                   >> 244          // The full Step is taken.
                                                   >> 245          //
                                                   >> 246          geometryStepLength   = currentMinimumStep ;
                                                   >> 247          fGeometryLimitedStep = false ;
                                                   >> 248        }
                                                   >> 249      }
                                                   >> 250      endpointDistance = geometryStepLength ;
241                                                   251 
242   G4bool eligibleEM =                          << 252      // Calculate final position
243     (particleCharge != 0.0) || ((magneticMomen << 253      //
244   G4bool eligibleGrav = (particleMass != 0.0)  << 254      fTransportEndPosition = startPosition+geometryStepLength*startMomentumDir ;
245                                                << 
246   fFieldExertedForce = false;                  << 
247                                                << 
248   if(eligibleEM || eligibleGrav)               << 
249   {                                            << 
250     if(G4FieldManager* fieldMgr =              << 
251          fFieldPropagator->FindAndSetFieldMana << 
252     {                                          << 
253       // User can configure the field Manager  << 
254       fieldMgr->ConfigureForTrack(&track);     << 
255       // Called here to allow a transition fro << 
256       // to finite field (non-zero pointer).   << 
257                                                << 
258       // If the field manager has no field ptr << 
259       //   by definition ( = there is no field << 
260       if(const G4Field* ptrField = fieldMgr->G << 
261         fFieldExertedForce =                   << 
262           eligibleEM || (eligibleGrav && ptrFi << 
263     }                                          << 
264   }                                            << 
265                                                << 
266   G4double geometryStepLength = currentMinimum << 
267                                                << 
268   if(currentMinimumStep == 0.0)                << 
269   {                                            << 
270     fEndPointDistance = 0.0;                   << 
271     fGeometryLimitedStep = false;  //  Old cod << 
272     // Changed to avoid problems when setting  << 
273     fMomentumChanged           = false;        << 
274     fParticleIsLooping         = false;        << 
275     fEndGlobalTimeComputed     = false;        << 
276     fTransportEndPosition      = startPosition << 
277     fTransportEndMomentumDir   = startMomentum << 
278     fTransportEndKineticEnergy = kineticEnergy << 
279     fTransportEndSpin          = particleSpin; << 
280   }                                            << 
281   else if(!fFieldExertedForce)                 << 
282   {                                            << 
283     fGeometryLimitedStep = false;              << 
284     if(geometryStepLength > currentSafety || ! << 
285     {                                          << 
286       const G4double linearStepLength = fLinea << 
287         startPosition, startMomentumDir, curre << 
288                                                << 
289       if(linearStepLength <= currentMinimumSte << 
290       {                                        << 
291         geometryStepLength = linearStepLength; << 
292         fGeometryLimitedStep = true;           << 
293       }                                        << 
294       // Remember last safety origin & value.  << 
295       //                                       << 
296       fPreviousSftOrigin = startPosition;      << 
297       fPreviousSafety    = currentSafety;      << 
298       fpSafetyHelper->SetCurrentSafety(current << 
299     }                                          << 
300                                                << 
301     fEndPointDistance    = geometryStepLength; << 
302                                                << 
303     fMomentumChanged       = false;            << 
304     fParticleIsLooping     = false;            << 
305     fEndGlobalTimeComputed = false;            << 
306     fTransportEndPosition =                    << 
307       startPosition + geometryStepLength * sta << 
308     fTransportEndMomentumDir   = startMomentum << 
309     fTransportEndKineticEnergy = kineticEnergy << 
310     fTransportEndSpin          = particleSpin; << 
311   }                                            << 
312   else  //  A field exerts force               << 
313   {                                            << 
314     const auto pParticleDef    = pParticle->Ge << 
315     const auto particlePDGSpin = pParticleDef- << 
316     const auto particlePDGMagM = pParticleDef- << 
317                                                << 
318     auto equationOfMotion = fFieldPropagator-> << 
319                                                << 
320     // The charge can change (dynamic), theref << 
321     //                                         << 
322     equationOfMotion->SetChargeMomentumMass(   << 
323       G4ChargeState(particleCharge, magneticMo << 
324       pParticle->GetTotalMomentum(), particleM << 
325                                                << 
326     G4FieldTrack aFieldTrack(startPosition,    << 
327                              track.GetGlobalTi << 
328                              startMomentumDir, << 
329                              particleCharge, p << 
330                              0.0,  // Length a << 
331                              particlePDGSpin); << 
332                                                << 
333     // Do the Transport in the field (non rect << 
334     //                                         << 
335     const G4double lengthAlongCurve = fFieldPr << 
336       aFieldTrack, currentMinimumStep, current << 
337       kineticEnergy < fThreshold_Important_Ene << 
338                                                << 
339     if(lengthAlongCurve < geometryStepLength)  << 
340       geometryStepLength = lengthAlongCurve;   << 
341                                                << 
342     // Remember last safety origin & value.    << 
343     //                                         << 
344     fPreviousSftOrigin = startPosition;        << 
345     fPreviousSafety    = currentSafety;        << 
346     fpSafetyHelper->SetCurrentSafety(currentSa << 
347                                                   255 
348     fGeometryLimitedStep = fFieldPropagator->I << 256      // Momentum direction, energy and polarisation are unchanged by transport
349     //                                         << 257      //
350     // It is possible that step was reduced in << 258      fTransportEndMomentumDir   = startMomentumDir ; 
351     // previous zero steps. To cope with case  << 259      fTransportEndKineticEnergy = track.GetKineticEnergy() ;
352     // in full, we must rely on PiF to obtain  << 260      fTransportEndSpin          = track.GetPolarization();
                                                   >> 261      fParticleIsLooping         = false ;
                                                   >> 262      fMomentumChanged           = false ; 
                                                   >> 263      fEndGlobalTimeComputed     = false ;
                                                   >> 264   }
                                                   >> 265   else   //  A field exerts force
                                                   >> 266   {
                                                   >> 267      G4double       momentumMagnitude = pParticle->GetTotalMomentum() ;
                                                   >> 268      G4ThreeVector  EndUnitMomentum ;
                                                   >> 269      G4double       lengthAlongCurve ;
                                                   >> 270      G4double       restMass = pParticleDef->GetPDGMass() ;
                                                   >> 271  
                                                   >> 272      fFieldPropagator->SetChargeMomentumMass( particleCharge,    // in e+ units
                                                   >> 273                                               momentumMagnitude, // in Mev/c 
                                                   >> 274                                               restMass           ) ;  
353                                                   275 
354     G4bool changesEnergy =                     << 276      // Message the field Manager, to configure it for this track
355       fFieldPropagator->GetCurrentFieldManager << 277      fieldMgr->ConfigureForTrack( &track );
356                                                   278 
357     fMomentumChanged   = true;                 << 279      G4ThreeVector spin        = track.GetPolarization() ;
358     fParticleIsLooping = fFieldPropagator->IsP << 280      G4FieldTrack  aFieldTrack = G4FieldTrack( startPosition, 
                                                   >> 281                                                track.GetMomentumDirection(),
                                                   >> 282                                                0.0, 
                                                   >> 283                                                track.GetKineticEnergy(),
                                                   >> 284                                                restMass,
                                                   >> 285                                                track.GetVelocity(),
                                                   >> 286                                                track.GetGlobalTime(), // Lab.
                                                   >> 287                                                track.GetProperTime(), // Part.
                                                   >> 288                                                &spin                  ) ;
                                                   >> 289      if( currentMinimumStep > 0 ) 
                                                   >> 290      {
                                                   >> 291         // Do the Transport in the field (non recti-linear)
                                                   >> 292         //
                                                   >> 293         lengthAlongCurve = fFieldPropagator->ComputeStep( aFieldTrack,
                                                   >> 294                                                           currentMinimumStep, 
                                                   >> 295                                                           currentSafety,
                                                   >> 296                                                           track.GetVolume() ) ;
                                                   >> 297         if( lengthAlongCurve < currentMinimumStep)
                                                   >> 298         {
                                                   >> 299            geometryStepLength   = lengthAlongCurve ;
                                                   >> 300            fGeometryLimitedStep = true ;
                                                   >> 301         }
                                                   >> 302         else
                                                   >> 303         {
                                                   >> 304            geometryStepLength   = currentMinimumStep ;
                                                   >> 305            fGeometryLimitedStep = false ;
                                                   >> 306         }
                                                   >> 307      }
                                                   >> 308      else
                                                   >> 309      {
                                                   >> 310         geometryStepLength   = lengthAlongCurve= 0.0 ;
                                                   >> 311         fGeometryLimitedStep = false ;
                                                   >> 312      }
359                                                   313 
360     fEndGlobalTimeComputed = changesEnergy;    << 314      // Remember last safety origin & value.
361     fTransportEndPosition    = aFieldTrack.Get << 315      //
362     fTransportEndMomentumDir = aFieldTrack.Get << 316      fPreviousSftOrigin = startPosition ;
                                                   >> 317      fPreviousSafety    = currentSafety ;         
                                                   >> 318         
                                                   >> 319      // Get the End-Position and End-Momentum (Dir-ection)
                                                   >> 320      //
                                                   >> 321      fTransportEndPosition = aFieldTrack.GetPosition() ;
363                                                   322 
364     // G4cout << " G4Transport: End of step pM << 323      // Momentum:  Magnitude and direction can be changed too now ...
                                                   >> 324      //
                                                   >> 325      fMomentumChanged         = true ; 
                                                   >> 326      fTransportEndMomentumDir = aFieldTrack.GetMomentumDir() ;
365                                                   327 
366     fEndPointDistance  = (fTransportEndPositio << 328      fTransportEndKineticEnergy  = aFieldTrack.GetKineticEnergy() ; 
367                                                   329 
368     // Ignore change in energy for fields that << 330      if( fFieldPropagator->GetCurrentFieldManager()->DoesFieldChangeEnergy() )
369     // This hides the integration error, but g << 331      {
370     fTransportEndKineticEnergy =               << 332         // If the field can change energy, then the time must be integrated
371       changesEnergy ? aFieldTrack.GetKineticEn << 333         //    - so this should have been updated
372     fTransportEndSpin = aFieldTrack.GetSpin(); << 334         //
                                                   >> 335         fCandidateEndGlobalTime   = aFieldTrack.GetLabTimeOfFlight();
                                                   >> 336         fEndGlobalTimeComputed    = true;
373                                                   337 
374     if(fEndGlobalTimeComputed)                 << 338         // was ( fCandidateEndGlobalTime != track.GetGlobalTime() );
375     {                                          << 339         // a cleaner way is to have FieldTrack knowing whether time is updated.
376       // If the field can change energy, then  << 340      }
377       //    - so this should have been updated << 341      else
378       //                                       << 342      {
379       fCandidateEndGlobalTime = aFieldTrack.Ge << 343         // The energy should be unchanged by field transport,
                                                   >> 344         //    - so the time changed will be calculated elsewhere
                                                   >> 345         //
                                                   >> 346         fEndGlobalTimeComputed = false;
380                                                   347 
381       // was ( fCandidateEndGlobalTime != trac << 348         // Check that the integration preserved the energy 
382       // a cleaner way is to have FieldTrack k << 349         //     -  and if not correct this!
383     }                                          << 350         G4double  startEnergy= track.GetKineticEnergy();
384 #if defined(G4VERBOSE) || defined(G4DEBUG_TRAN << 351         G4double  endEnergy= fTransportEndKineticEnergy; 
385     else                                       << 352 
386     {                                          << 353         static G4int no_inexact_steps=0, no_large_ediff;
387       // The energy should be unchanged by fie << 354         G4double absEdiff = std::fabs(startEnergy- endEnergy);
388       //    - so the time changed will be calc << 355         if( absEdiff > perMillion * endEnergy )
389       //                                       << 356         {
390       // Check that the integration preserved  << 357           no_inexact_steps++;
391       //     -  and if not correct this!       << 358           // Possible statistics keeping here ...
392       G4double startEnergy = kineticEnergy;    << 359         }
393       G4double endEnergy   = fTransportEndKine << 360         if( fVerboseLevel > 1 )
394                                                << 
395       static G4ThreadLocal G4int no_large_edif << 
396       if(verboseLevel > 1)                     << 
397       {                                        << 
398         if(std::fabs(startEnergy - endEnergy)  << 
399         {                                         361         {
400           static G4ThreadLocal G4int no_warnin << 362           if( std::fabs(startEnergy- endEnergy) > perThousand * endEnergy )
401                                      moduloFac << 
402           no_large_ediff++;                    << 
403           if((no_large_ediff % warnModulo) ==  << 
404           {                                       363           {
405             no_warnings++;                     << 364             static G4int no_warnings= 0, warnModulo=1,  moduloFactor= 10; 
406             std::ostringstream message;        << 365             no_large_ediff ++;
407             message << "Energy change in Step  << 366             if( (no_large_ediff% warnModulo) == 0 )
408                     << G4endl << "     Relativ << 
409                     << std::setw(15) << (endEn << 
410                     << G4endl << "     Startin << 
411                     << startEnergy / MeV << "  << 
412                     << "     Ending   E= " <<  << 
413                     << " MeV " << G4endl       << 
414                     << "Energy has been correc << 
415                     << " field propagation par << 
416             if((verboseLevel > 2) || (no_warni << 
417                (no_large_ediff == warnModulo * << 
418             {                                     367             {
419               message << "These include Epsilo << 368                no_warnings++;
420                       << G4endl                << 369                G4cout << "WARNING - G4Transportation::AlongStepGetPIL()" << G4endl
421                       << "which determine frac << 370                 << "   Energy changed in Step, more than 1/1000: " << G4endl
422                          "integrated quantitie << 371                       << "          Start= " << startEnergy   << G4endl
423                       << G4endl                << 372                       << "          End= "   << endEnergy     << G4endl
424                       << "Note also the influe << 373                       << "          Relative change= "
425                          "integration steps."  << 374                       << (startEnergy-endEnergy)/startEnergy << G4endl;
426                       << G4endl;               << 375                G4cout << " Energy has been corrected -- however, review"
427             }                                  << 376                       << " field propagation parameters for accuracy." << G4endl;
428             message << "Bad 'endpoint'. Energy << 377                G4cerr << "ERROR - G4Transportation::AlongStepGetPIL()" << G4endl
429                     << G4endl << "Has occurred << 378                 << "        Bad 'endpoint'. Energy change detected"
430                     << " times.";              << 379                       << " and corrected,"                      << G4endl
431             G4Exception("G4Transportation::Alo << 380                       << "        occurred already "
432                         JustWarning, message); << 381                       << no_large_ediff << " times." << G4endl;
433             if(no_large_ediff == warnModulo *  << 382                if( no_large_ediff == warnModulo * moduloFactor )
434             {                                  << 383                {
435               warnModulo *= moduloFactor;      << 384                   warnModulo *= moduloFactor;
                                                   >> 385                }
436             }                                     386             }
437           }                                       387           }
438         }                                      << 388         }  // end of if (fVerboseLevel)
439       }  // end of if (verboseLevel)           << 389 
440     }                                          << 390         // Correct the energy for fields that conserve it
441 #endif                                         << 391         //  This - hides the integration error
                                                   >> 392         //       - but gives a better physical answer
                                                   >> 393         fTransportEndKineticEnergy= track.GetKineticEnergy(); 
                                                   >> 394      }
                                                   >> 395 
                                                   >> 396      fTransportEndSpin = aFieldTrack.GetSpin();
                                                   >> 397      fParticleIsLooping = fFieldPropagator->IsParticleLooping() ;
                                                   >> 398      endpointDistance   = (fTransportEndPosition - startPosition).mag() ;
                                                   >> 399   }
                                                   >> 400 
                                                   >> 401   // If we are asked to go a step length of 0, and we are on a boundary
                                                   >> 402   // then a boundary will also limit the step -> we must flag this.
                                                   >> 403   //
                                                   >> 404   if( currentMinimumStep == 0.0 ) 
                                                   >> 405   {
                                                   >> 406       if( currentSafety == 0.0 )  fGeometryLimitedStep = true ;
442   }                                               407   }
443                                                   408 
444   // Update the safety starting from the end-p    409   // Update the safety starting from the end-point,
445   // if it will become negative at the end-poi    410   // if it will become negative at the end-point.
446   //                                              411   //
447   if(currentSafety < fEndPointDistance)        << 412   if( currentSafety < endpointDistance ) 
448   {                                               413   {
449     if(particleCharge != 0.0)                  << 
450     {                                          << 
451       G4double endSafety =                        414       G4double endSafety =
452         fLinearNavigator->ComputeSafety(fTrans << 415                fLinearNavigator->ComputeSafety( fTransportEndPosition) ;
453       currentSafety      = endSafety;          << 416       currentSafety      = endSafety ;
454       fPreviousSftOrigin = fTransportEndPositi << 417       fPreviousSftOrigin = fTransportEndPosition ;
455       fPreviousSafety    = currentSafety;      << 418       fPreviousSafety    = currentSafety ; 
456       fpSafetyHelper->SetCurrentSafety(current << 
457                                                   419 
458       // Because the Stepping Manager assumes  << 420       // Because the Stepping Manager assumes it is from the start point, 
459       //  add the StepLength                      421       //  add the StepLength
460       //                                          422       //
461       currentSafety += fEndPointDistance;      << 423       currentSafety     += endpointDistance ;
462                                                   424 
463 #ifdef G4DEBUG_TRANSPORT                       << 425 #ifdef G4DEBUG_TRANSPORT 
464       G4cout.precision(12);                    << 426       G4cout.precision(16) ;
465       G4cout << "***G4Transportation::AlongSte << 427       G4cout << "***Transportation::AlongStepGPIL ** " << G4endl  ;
466       G4cout << "  Called Navigator->ComputeSa << 428       G4cout << "  Called Navigator->ComputeSafety at "
467              << "    and it returned safety=   << 429              << fTransportEndPosition
468       G4cout << "  Adding endpoint distance    << 430              << "    and it returned safety= " << endSafety << G4endl ; 
469              << "    to obtain pseudo-safety=  << 431       G4cout << "  Adding endpoint distance " << endpointDistance 
470     }                                          << 432              << "   we obtain pseudo-safety= " << currentSafety << G4endl ; 
471     else                                       << 
472     {                                          << 
473       G4cout << "***G4Transportation::AlongSte << 
474       G4cout << "  Avoiding call to ComputeSaf << 
475       G4cout << "    charge     = " << particl << 
476       G4cout << "    mag moment = " << magneti << 
477 #endif                                            433 #endif
478     }                                          << 434   }            
479   }                                            << 
480                                                << 
481   fFirstStepInVolume = fNewTrack || fLastStepI << 
482   fLastStepInVolume  = false;                  << 
483   fNewTrack          = false;                  << 
484                                                   435 
485   fParticleChange.ProposeFirstStepInVolume(fFi << 436   fParticleChange.ProposeTrueStepLength(geometryStepLength) ;
486   fParticleChange.ProposeTrueStepLength(geomet << 
487                                                   437 
488   return geometryStepLength;                   << 438   return geometryStepLength ;
489 }                                                 439 }
490                                                   440 
491 //////////////////////////////////////////////    441 //////////////////////////////////////////////////////////////////////////
492 //                                                442 //
493 //   Initialize ParticleChange  (by setting al    443 //   Initialize ParticleChange  (by setting all its members equal
494 //                               to correspond    444 //                               to corresponding members in G4Track)
495                                                   445 
496 G4VParticleChange* G4Transportation::AlongStep    446 G4VParticleChange* G4Transportation::AlongStepDoIt( const G4Track& track,
497                                                   447                                                     const G4Step&  stepData )
498 {                                                 448 {
499 #if defined(G4VERBOSE) || defined(G4DEBUG_TRAN << 
500   static G4ThreadLocal G4long noCallsASDI=0;   << 
501   noCallsASDI++;                               << 
502 #else                                          << 
503   #define noCallsASDI 0                        << 
504 #endif                                         << 
505                                                << 
506   if(fGeometryLimitedStep)                     << 
507   {                                            << 
508     stepData.GetPostStepPoint()->SetStepStatus << 
509   }                                            << 
510                                                << 
511   fParticleChange.Initialize(track) ;             449   fParticleChange.Initialize(track) ;
512                                                   450 
513   //  Code for specific process                   451   //  Code for specific process 
514   //                                              452   //
515   fParticleChange.ProposePosition(fTransportEn    453   fParticleChange.ProposePosition(fTransportEndPosition) ;
516   fParticleChange.ProposeMomentumDirection(fTr    454   fParticleChange.ProposeMomentumDirection(fTransportEndMomentumDir) ;
517   fParticleChange.ProposeEnergy(fTransportEndK    455   fParticleChange.ProposeEnergy(fTransportEndKineticEnergy) ;
518   fParticleChange.SetMomentumChanged(fMomentum    456   fParticleChange.SetMomentumChanged(fMomentumChanged) ;
519                                                   457 
520   fParticleChange.ProposePolarization(fTranspo    458   fParticleChange.ProposePolarization(fTransportEndSpin);
521                                                << 459   
522   G4double deltaTime = 0.0 ;                      460   G4double deltaTime = 0.0 ;
523                                                   461 
524   // Calculate  Lab Time of Flight (ONLY if fi    462   // Calculate  Lab Time of Flight (ONLY if field Equations used it!)
525   // G4double endTime   = fCandidateEndGlobalT << 463      // G4double endTime   = fCandidateEndGlobalTime;
526   // G4double delta_time = endTime - startTime << 464      // G4double delta_time = endTime - startTime;
527                                                   465 
528   G4double startTime = track.GetGlobalTime() ;    466   G4double startTime = track.GetGlobalTime() ;
529                                                   467   
530   if (!fEndGlobalTimeComputed)                    468   if (!fEndGlobalTimeComputed)
531   {                                               469   {
532      // The time was not integrated .. make th    470      // The time was not integrated .. make the best estimate possible
533      //                                           471      //
534      G4double initialVelocity = stepData.GetPr << 472      G4double finalVelocity   = track.GetVelocity() ;
535      G4double stepLength      = track.GetStepL << 473      G4double initialVelocity = stepData.GetPreStepPoint()->GetVelocity() ;
536                                                << 474      G4double stepLength      = track.GetStepLength() ;
537      deltaTime= 0.0;  // in case initialVeloci << 475 
538      if ( initialVelocity > 0.0 )  { deltaTime << 476      static const G4ParticleDefinition* fOpticalPhoton =
539                                                << 477            G4ParticleTable::GetParticleTable()->FindParticle("opticalphoton");
                                                   >> 478      const G4DynamicParticle* fpDynamicParticle = track.GetDynamicParticle();
                                                   >> 479      if (fpDynamicParticle->GetDefinition()== fOpticalPhoton)
                                                   >> 480      {
                                                   >> 481         //  A photon is in the medium of the final point
                                                   >> 482         //  during the step, so it has the final velocity.
                                                   >> 483         deltaTime = stepLength/finalVelocity ;
                                                   >> 484      }
                                                   >> 485      else if (finalVelocity > 0.0)
                                                   >> 486      {
                                                   >> 487         G4double meanInverseVelocity ;
                                                   >> 488         // deltaTime = stepLength/finalVelocity ;
                                                   >> 489         meanInverseVelocity = 0.5
                                                   >> 490                             * ( 1.0 / initialVelocity + 1.0 / finalVelocity ) ;
                                                   >> 491         deltaTime = stepLength * meanInverseVelocity ;
                                                   >> 492      }
                                                   >> 493      else
                                                   >> 494      {
                                                   >> 495         deltaTime = stepLength/initialVelocity ;
                                                   >> 496      }
540      fCandidateEndGlobalTime   = startTime + d    497      fCandidateEndGlobalTime   = startTime + deltaTime ;
541      fParticleChange.ProposeLocalTime(  track. << 
542   }                                               498   }
543   else                                            499   else
544   {                                               500   {
545      deltaTime = fCandidateEndGlobalTime - sta    501      deltaTime = fCandidateEndGlobalTime - startTime ;
546      fParticleChange.ProposeGlobalTime( fCandi << 
547   }                                               502   }
548                                                   503 
                                                   >> 504   fParticleChange.ProposeGlobalTime( fCandidateEndGlobalTime ) ;
549                                                   505 
550   // Now Correct by Lorentz factor to get delt << 506   // Now Correct by Lorentz factor to get "proper" deltaTime
551                                                   507   
552   G4double  restMass       = track.GetDynamicP    508   G4double  restMass       = track.GetDynamicParticle()->GetMass() ;
553   G4double deltaProperTime = deltaTime*( restM    509   G4double deltaProperTime = deltaTime*( restMass/track.GetTotalEnergy() ) ;
554                                                   510 
555   fParticleChange.ProposeProperTime(track.GetP    511   fParticleChange.ProposeProperTime(track.GetProperTime() + deltaProperTime) ;
556   //fParticleChange.ProposeTrueStepLength( tra << 512   //fParticleChange. ProposeTrueStepLength( track.GetStepLength() ) ;
557                                                   513 
558   // If the particle is caught looping or is s    514   // If the particle is caught looping or is stuck (in very difficult
559   // boundaries) in a magnetic field (doing ma << 515   // boundaries) in a magnetic field (doing many steps) 
                                                   >> 516   //   THEN this kills it ...
560   //                                              517   //
561   if ( fParticleIsLooping )                       518   if ( fParticleIsLooping )
562   {                                               519   {
563       G4double endEnergy= fTransportEndKinetic    520       G4double endEnergy= fTransportEndKineticEnergy;
564       fNoLooperTrials ++;                      << 
565       auto particleType= track.GetDynamicParti << 
566                                                << 
567       G4bool stable = particleType->GetPDGStab << 
568       G4bool candidateForEnd = (endEnergy < fT << 
569                             || (fNoLooperTrial << 
570       G4bool unstableAndKillable = !stable &&  << 
571       G4bool unstableForEnd = (endEnergy < fTh << 
572                               && (fNoLooperTri << 
573       if( (candidateForEnd && stable) || (unst << 
574       {                                        << 
575         // Kill the looping particle           << 
576         //                                     << 
577         fParticleChange.ProposeTrackStatus( fS << 
578         G4int particlePDG= particleType->GetPD << 
579         const G4int electronPDG= 11; // G4Elec << 
580                                                << 
581         // Simple statistics                   << 
582         fSumEnergyKilled += endEnergy;         << 
583         fSumEnerSqKilled += endEnergy * endEne << 
584         fNumLoopersKilled++;                   << 
585                                                << 
586         if( endEnergy > fMaxEnergyKilled ) {   << 
587            fMaxEnergyKilled = endEnergy;       << 
588            fMaxEnergyKilledPDG = particlePDG;  << 
589         }                                      << 
590         if(  particleType->GetPDGEncoding() != << 
591         {                                      << 
592            fSumEnergyKilled_NonElectron += end << 
593            fSumEnerSqKilled_NonElectron += end << 
594            fNumLoopersKilled_NonElectron++;    << 
595                                                << 
596            if( endEnergy > fMaxEnergyKilled_No << 
597            {                                   << 
598               fMaxEnergyKilled_NonElectron = e << 
599               fMaxEnergyKilled_NonElecPDG =  p << 
600            }                                   << 
601         }                                      << 
602                                                   521 
603         if( endEnergy > fThreshold_Warning_Ene << 522       if( (endEnergy < fThreshold_Important_Energy) 
604         {                                      << 523     || (fNoLooperTrials >= fThresholdTrials ) ){
605           fpLogger->ReportLoopingTrack( track, << 524   // Kill the looping particle 
606                                         noCall << 525   //
607         }                                      << 526   fParticleChange.ProposeTrackStatus( fStopAndKill )  ;
608         fNoLooperTrials=0;                     << 527 
609       }                                        << 528         // 'Bare' statistics
610       else                                     << 529         fSumEnergyKilled += endEnergy; 
611       {                                        << 530   if( endEnergy > fMaxEnergyKilled) { fMaxEnergyKilled= endEnergy; }
612         fMaxEnergySaved = std::max( endEnergy, << 531 
613         if( fNoLooperTrials == 1 ) {           << 
614           fSumEnergySaved += endEnergy;        << 
615           if ( !stable )                       << 
616              fSumEnergyUnstableSaved += endEne << 
617         }                                      << 
618 #ifdef G4VERBOSE                                  532 #ifdef G4VERBOSE
619         if( verboseLevel > 2 && ! fSilenceLoop << 533   if( (fVerboseLevel > 1) || 
620         {                                      << 534       ( endEnergy > fThreshold_Warning_Energy )  ) { 
621           G4cout << "   " << __func__          << 535     G4cout << " G4Transportation is killing track that is looping or stuck "
622                  << " Particle is looping but  << 536      << G4endl
623                  << "   Number of trials = " < << 537      << "   This track has " << track.GetKineticEnergy() / MeV
624                  << "   No of calls to  = " << << 538      << " MeV energy." << G4endl;
625         }                                      << 539   }
626 #endif                                            540 #endif
                                                   >> 541   fNoLooperTrials=0; 
627       }                                           542       }
628   }                                            << 543       else{
629   else                                         << 544   fNoLooperTrials ++; 
630   {                                            << 545       }
                                                   >> 546   }else{
631       fNoLooperTrials=0;                          547       fNoLooperTrials=0; 
632   }                                               548   }
633                                                   549 
634   // Another (sometimes better way) is to use     550   // Another (sometimes better way) is to use a user-limit maximum Step size
635   // to alleviate this problem ..                 551   // to alleviate this problem .. 
636                                                   552 
637   // Introduce smooth curved trajectories to p    553   // Introduce smooth curved trajectories to particle-change
638   //                                              554   //
639   fParticleChange.SetPointerToVectorOfAuxiliar    555   fParticleChange.SetPointerToVectorOfAuxiliaryPoints
640     (fFieldPropagator->GimmeTrajectoryVectorAn    556     (fFieldPropagator->GimmeTrajectoryVectorAndForgetIt() );
641                                                   557 
642   return &fParticleChange ;                       558   return &fParticleChange ;
643 }                                                 559 }
644                                                   560 
645 //////////////////////////////////////////////    561 //////////////////////////////////////////////////////////////////////////
646 //                                                562 //
647 //  This ensures that the PostStep action is a    563 //  This ensures that the PostStep action is always called,
648 //  so that it can do the relocation if it is     564 //  so that it can do the relocation if it is needed.
649 //                                                565 // 
650                                                   566 
651 G4double G4Transportation::                       567 G4double G4Transportation::
652 PostStepGetPhysicalInteractionLength( const G4    568 PostStepGetPhysicalInteractionLength( const G4Track&,
653                                             G4    569                                             G4double, // previousStepSize
654                                             G4    570                                             G4ForceCondition* pForceCond )
655 {                                              << 571 { 
656   fFieldExertedForce = false; // Not known     << 
657   *pForceCond = Forced ;                          572   *pForceCond = Forced ; 
658   return DBL_MAX ;  // was kInfinity ; but con    573   return DBL_MAX ;  // was kInfinity ; but convention now is DBL_MAX
659 }                                                 574 }
660                                                   575 
661 //////////////////////////////////////////////    576 /////////////////////////////////////////////////////////////////////////////
662                                                << 
663 void G4Transportation::SetTouchableInformation << 
664 {                                              << 
665   const G4VPhysicalVolume* pNewVol = touchable << 
666   const G4Material* pNewMaterial   = 0 ;       << 
667   G4VSensitiveDetector* pNewSensitiveDetector  << 
668                                                << 
669   if( pNewVol != 0 )                           << 
670   {                                            << 
671     pNewMaterial= pNewVol->GetLogicalVolume()- << 
672     pNewSensitiveDetector= pNewVol->GetLogical << 
673   }                                            << 
674                                                << 
675   fParticleChange.SetMaterialInTouchable( (G4M << 
676   fParticleChange.SetSensitiveDetectorInToucha << 
677   // temporarily until Get/Set Material of Par << 
678   // and StepPoint can be made const.          << 
679                                                << 
680   const G4MaterialCutsCouple* pNewMaterialCuts << 
681   if( pNewVol != 0 )                           << 
682   {                                            << 
683     pNewMaterialCutsCouple=pNewVol->GetLogical << 
684   }                                            << 
685                                                << 
686   if ( pNewVol!=0 && pNewMaterialCutsCouple!=0 << 
687     && pNewMaterialCutsCouple->GetMaterial()!= << 
688   {                                            << 
689     // for parametrized volume                 << 
690     //                                         << 
691     pNewMaterialCutsCouple =                   << 
692       G4ProductionCutsTable::GetProductionCuts << 
693                              ->GetMaterialCuts << 
694                                pNewMaterialCut << 
695   }                                            << 
696   fParticleChange.SetMaterialCutsCoupleInTouch << 
697                                                << 
698   // Set the touchable in ParticleChange       << 
699   // this must always be done because the part << 
700   // uses this value to overwrite the current  << 
701   //                                           << 
702   fParticleChange.SetTouchableHandle(touchable << 
703 }                                              << 
704                                                << 
705 ////////////////////////////////////////////// << 
706 //                                                577 //
707                                                   578 
708 G4VParticleChange* G4Transportation::PostStepD    579 G4VParticleChange* G4Transportation::PostStepDoIt( const G4Track& track,
709                                                   580                                                    const G4Step& )
710 {                                                 581 {
711    G4TouchableHandle retCurrentTouchable ;   / << 582   G4TouchableHandle retCurrentTouchable ;   // The one to return
712    G4bool isLastStep= false;                   << 
713                                                   583 
714   // Initialize ParticleChange  (by setting al    584   // Initialize ParticleChange  (by setting all its members equal
715   //                             to correspond    585   //                             to corresponding members in G4Track)
716   // fParticleChange.Initialize(track) ;  // T    586   // fParticleChange.Initialize(track) ;  // To initialise TouchableChange
717                                                   587 
718   fParticleChange.ProposeTrackStatus(track.Get    588   fParticleChange.ProposeTrackStatus(track.GetTrackStatus()) ;
719                                                   589 
720   // If the Step was determined by the volume     590   // If the Step was determined by the volume boundary,
721   // logically relocate the particle              591   // logically relocate the particle
722                                                << 592   
723   if(fGeometryLimitedStep)                        593   if(fGeometryLimitedStep)
724   {                                               594   {  
725     // fCurrentTouchable will now become the p    595     // fCurrentTouchable will now become the previous touchable, 
726     // and what was the previous will be freed    596     // and what was the previous will be freed.
727     // (Needed because the preStepPoint can po    597     // (Needed because the preStepPoint can point to the previous touchable)
728                                                   598 
729     fLinearNavigator->SetGeometricallyLimitedS    599     fLinearNavigator->SetGeometricallyLimitedStep() ;
730     fLinearNavigator->                            600     fLinearNavigator->
731     LocateGlobalPointAndUpdateTouchableHandle(    601     LocateGlobalPointAndUpdateTouchableHandle( track.GetPosition(),
732                                                   602                                                track.GetMomentumDirection(),
733                                                   603                                                fCurrentTouchableHandle,
734                                                   604                                                true                      ) ;
735     // Check whether the particle is out of th    605     // Check whether the particle is out of the world volume 
736     // If so it has exited and must be killed.    606     // If so it has exited and must be killed.
737     //                                            607     //
738     if( fCurrentTouchableHandle->GetVolume() =    608     if( fCurrentTouchableHandle->GetVolume() == 0 )
739     {                                             609     {
740        fParticleChange.ProposeTrackStatus( fSt    610        fParticleChange.ProposeTrackStatus( fStopAndKill ) ;
741     }                                             611     }
742     retCurrentTouchable = fCurrentTouchableHan    612     retCurrentTouchable = fCurrentTouchableHandle ;
743     fParticleChange.SetTouchableHandle( fCurre    613     fParticleChange.SetTouchableHandle( fCurrentTouchableHandle ) ;
744                                                << 
745     // Update the Step flag which identifies t << 
746     if( !fFieldExertedForce )                  << 
747        isLastStep =  fLinearNavigator->ExitedM << 
748                   || fLinearNavigator->Entered << 
749     else                                       << 
750        isLastStep = fFieldPropagator->IsLastSt << 
751   }                                               614   }
752   else                 // fGeometryLimitedStep    615   else                 // fGeometryLimitedStep  is false
753   {                                               616   {                    
                                                   >> 617 #ifdef G4DEBUG_POSTSTEP_TRANSPORT
                                                   >> 618 
                                                   >> 619     // Although the location is changed, we know that the physical 
                                                   >> 620     // volume remains constant. 
                                                   >> 621     // In order to help in checking the user geometry
                                                   >> 622     // we perform a full-relocation and check its result 
                                                   >> 623     // *except* if we have made a very small step from a boundary
                                                   >> 624     // (i.e. remaining inside the tolerance)
                                                   >> 625 
                                                   >> 626     G4bool  startAtSurface_And_MoveEpsilon ;
                                                   >> 627     startAtSurface_And_MoveEpsilon =
                                                   >> 628              (stepData.GetPreStepPoint()->GetSafety() == 0.0) && 
                                                   >> 629              (stepData.GetStepLength() < kCarTolerance ) ;
                                                   >> 630 
                                                   >> 631     if( startAtSurface_And_MoveEpsilon ) 
                                                   >> 632     {
                                                   >> 633        fLinearNavigator->
                                                   >> 634        LocateGlobalPointAndUpdateTouchableHandle( track.GetPosition(),
                                                   >> 635                                                   track.GetMomentumDirection(),
                                                   >> 636                                                   fCurrentTouchableHandle,
                                                   >> 637                                                   true                     );
                                                   >> 638        if( fCurrentTouchableHandle->GetVolume() != track.GetVolume() )
                                                   >> 639        {
                                                   >> 640          G4cerr << " ERROR: A relocation within safety has"
                                                   >> 641                 << " caused a volume change! " << G4endl  ; 
                                                   >> 642          G4cerr << "   The old volume is called " 
                                                   >> 643                 << track.GetVolume()->GetName() << G4endl ; 
                                                   >> 644          G4cerr << "   The new volume is called " ;
                                                   >> 645 
                                                   >> 646          if ( fCurrentTouchableHandle->GetVolume() != 0 )
                                                   >> 647          {
                                                   >> 648             G4cerr << fCurrentTouchableHandle->GetVolume()->GetName()
                                                   >> 649                    << G4endl ; 
                                                   >> 650          }
                                                   >> 651          else
                                                   >> 652          {
                                                   >> 653             G4cerr << "Out of World" << G4endl ; 
                                                   >> 654          }
                                                   >> 655          G4cerr.precision(7) ;
                                                   >> 656          G4cerr << "   The position is " << track.GetPosition() <<  G4endl ;
                                                   >> 657 
                                                   >> 658          // Let us relocate again, for debuging
                                                   >> 659          //
                                                   >> 660          fLinearNavigator->
                                                   >> 661          LocateGlobalPointAndUpdateTouchableHandle(track.GetPosition(),
                                                   >> 662                                                    track.GetMomentumDirection(),
                                                   >> 663                                                    fCurrentTouchableHandle,
                                                   >> 664                                                    true                     ) ;
                                                   >> 665          G4cerr << "   The newer volume is called "  ;
                                                   >> 666 
                                                   >> 667          if ( fCurrentTouchableHandle->GetVolume() != 0 )
                                                   >> 668          {
                                                   >> 669             G4cerr << fCurrentTouchableHandle->GetVolume()->GetName()
                                                   >> 670                    << G4endl ;
                                                   >> 671          } 
                                                   >> 672          else
                                                   >> 673          {
                                                   >> 674             G4cerr << "Out of World" << G4endl ; 
                                                   >> 675          }
                                                   >> 676        }
                                                   >> 677 
                                                   >> 678        assert( fCurrentTouchableHandle->GetVolume()->GetName() ==
                                                   >> 679                track.GetVolume()->GetName() ) ;
                                                   >> 680 
                                                   >> 681        retCurrentTouchable = fCurrentTouchableHandle ; 
                                                   >> 682        fParticleChange.SetTouchableHandle( fCurrentTouchableHandle ) ;
                                                   >> 683        
                                                   >> 684     }
                                                   >> 685     else
                                                   >> 686     {
                                                   >> 687        retCurrentTouchable = track.GetTouchableHandle() ;
                                                   >> 688        fParticleChange.SetTouchableHandle( track.GetTouchableHandle() ) ;
                                                   >> 689     }
                                                   >> 690 
                                                   >> 691     //  This must be done in the above if ( AtSur ) fails
                                                   >> 692     //  We also do it for if (true) in order to get debug/opt to  
                                                   >> 693     //  behave as exactly the same way as possible.
                                                   >> 694     //
                                                   >> 695     fLinearNavigator->LocateGlobalPointWithinVolume( track.GetPosition() ) ;
                                                   >> 696 
                                                   >> 697 #else    // ie #ifndef G4DEBUG_POSTSTEP_TRANSPORT does a quick relocation
                                                   >> 698 
754     // This serves only to move the Navigator'    699     // This serves only to move the Navigator's location
755     //                                            700     //
756     fLinearNavigator->LocateGlobalPointWithinV    701     fLinearNavigator->LocateGlobalPointWithinVolume( track.GetPosition() ) ;
757                                                   702 
758     // The value of the track's current Toucha    703     // The value of the track's current Touchable is retained. 
759     // (and it must be correct because we must    704     // (and it must be correct because we must use it below to
760     // overwrite the (unset) one in particle c    705     // overwrite the (unset) one in particle change)
761     //  It must be fCurrentTouchable too ??    << 706     // Although in general this is fCurrentTouchable, at the start of
                                                   >> 707     // a step it could be different ... ??
762     //                                            708     //
763     fParticleChange.SetTouchableHandle( track.    709     fParticleChange.SetTouchableHandle( track.GetTouchableHandle() ) ;
764     retCurrentTouchable = track.GetTouchableHa    710     retCurrentTouchable = track.GetTouchableHandle() ;
765                                                   711 
766     isLastStep= false;                         << 712 #endif
767   }         // endif ( fGeometryLimitedStep )     713   }         // endif ( fGeometryLimitedStep ) 
768   fLastStepInVolume= isLastStep;               << 
769                                                << 
770   fParticleChange.ProposeFirstStepInVolume(fFi << 
771   fParticleChange.ProposeLastStepInVolume(isLa << 
772                                                << 
773   SetTouchableInformation(retCurrentTouchable) << 
774                                                   714 
775   return &fParticleChange ;                    << 715   const G4VPhysicalVolume* pNewVol = retCurrentTouchable->GetVolume() ;
776 }                                              << 716   const G4Material* pNewMaterial   = 0 ;
777                                                << 717   const G4VSensitiveDetector* pNewSensitiveDetector   = 0 ;
778 ////////////////////////////////////////////// << 718                                                                                        
779 // New method takes over the responsibility to << 719   if( pNewVol != 0 )
780 // G4Transportation object at the start of a n << 720   {
781 // of a suspended track.                       << 721     pNewMaterial= pNewVol->GetLogicalVolume()->GetMaterial();
782 //                                             << 722     pNewSensitiveDetector= pNewVol->GetLogicalVolume()->GetSensitiveDetector();
                                                   >> 723   }
783                                                   724 
784 void                                           << 725   // ( <const_cast> pNewMaterial ) ;
785 G4Transportation::StartTracking(G4Track* aTrac << 726   // ( <const_cast> pNewSensitiveDetector) ;
786 {                                              << 
787   G4VProcess::StartTracking(aTrack);           << 
788   fNewTrack= true;                             << 
789   fFirstStepInVolume= true;                    << 
790   fLastStepInVolume= false;                    << 
791                                                << 
792   // The actions here are those that were take << 
793   // when track.GetCurrentStepNumber()==1      << 
794                                                   727 
795   // Whether field exists should be determined << 728   fParticleChange.SetMaterialInTouchable( (G4Material *) pNewMaterial ) ;
796   G4FieldManagerStore* fieldMgrStore= G4FieldM << 729   fParticleChange.SetSensitiveDetectorInTouchable( (G4VSensitiveDetector *) pNewSensitiveDetector ) ;
797   fAnyFieldExists = fieldMgrStore->size() > 0; << 
798                                                << 
799   // reset safety value and center             << 
800   //                                           << 
801   fPreviousSafety    = 0.0 ;                   << 
802   fPreviousSftOrigin = G4ThreeVector(0.,0.,0.) << 
803                                                << 
804   // reset looping counter -- for motion in fi << 
805   fNoLooperTrials= 0;                          << 
806   // Must clear this state .. else it depends  << 
807   //  --> a better solution would set this fro << 
808   // Was if( aTrack->GetCurrentStepNumber()==1 << 
809                                                   730 
810   // ChordFinder reset internal state          << 731   const G4MaterialCutsCouple* pNewMaterialCutsCouple = 0;
811   //                                           << 732   if( pNewVol != 0 )
812   if( fFieldPropagator && fAnyFieldExists )    << 
813   {                                               733   {
814      fFieldPropagator->ClearPropagatorState(); << 734     pNewMaterialCutsCouple=pNewVol->GetLogicalVolume()->GetMaterialCutsCouple();
815        // Resets all state of field propagator << 
816        // values (in case of overlaps and to w << 
817   }                                               735   }
818                                                   736 
819   // Make sure to clear the chord finders of a << 737   if( pNewVol!=0 && pNewMaterialCutsCouple!=0 && pNewMaterialCutsCouple->GetMaterial()!=pNewMaterial )
820   //                                           << 738   {
821   fieldMgrStore->ClearAllChordFindersState();  << 739     // for parametrized volume
822                                                << 740     //
823   // Update the current touchable handle  (fro << 741     pNewMaterialCutsCouple =
824   //                                           << 742       G4ProductionCutsTable::GetProductionCutsTable()
825   fCurrentTouchableHandle = aTrack->GetTouchab << 743                              ->GetMaterialCutsCouple(pNewMaterial,
                                                   >> 744                                pNewMaterialCutsCouple->GetProductionCuts());
                                                   >> 745   }
                                                   >> 746   fParticleChange.SetMaterialCutsCoupleInTouchable( pNewMaterialCutsCouple );
826                                                   747 
827   // Inform field propagator of new track      << 748   // temporarily until Get/Set Material of ParticleChange, 
                                                   >> 749   // and StepPoint can be made const. 
                                                   >> 750   // Set the touchable in ParticleChange
                                                   >> 751   // this must always be done because the particle change always
                                                   >> 752   // uses this value to overwrite the current touchable pointer.
828   //                                              753   //
829   fFieldPropagator->PrepareNewTrack();         << 754   fParticleChange.SetTouchableHandle(retCurrentTouchable) ;
830 }                                              << 
831                                                << 
832 ////////////////////////////////////////////// << 
833 //                                             << 
834                                                << 
835 G4bool G4Transportation::EnableMagneticMoment( << 
836 {                                              << 
837   G4bool lastValue= fUseMagneticMoment;        << 
838   fUseMagneticMoment= useMoment;               << 
839   return lastValue;                            << 
840 }                                              << 
841                                                << 
842 ////////////////////////////////////////////// << 
843 //                                             << 
844                                                << 
845 G4bool G4Transportation::EnableGravity(G4bool  << 
846 {                                              << 
847   G4bool lastValue= fUseGravity;               << 
848   fUseGravity= useGravity;                     << 
849   return lastValue;                            << 
850 }                                              << 
851                                                << 
852 ////////////////////////////////////////////// << 
853 //                                             << 
854 //  Supress (or not) warnings about 'looping'  << 
855                                                << 
856 void G4Transportation::SetSilenceLooperWarning << 
857 {                                              << 
858   fSilenceLooperWarnings= val;  // Flag to *Su << 
859 }                                              << 
860                                                << 
861 ////////////////////////////////////////////// << 
862 //                                             << 
863 G4bool G4Transportation::GetSilenceLooperWarni << 
864 {                                              << 
865   return fSilenceLooperWarnings;               << 
866 }                                              << 
867                                                << 
868                                                << 
869 ////////////////////////////////////////////// << 
870 //                                             << 
871 void G4Transportation::SetHighLooperThresholds << 
872 {                                              << 
873   // Restores the old high values -- potential << 
874   //   HEP experiments.                        << 
875   // Caution:  All tracks with E < 100 MeV tha << 
876   SetThresholdWarningEnergy(    100.0 * CLHEP: << 
877   SetThresholdImportantEnergy(  250.0 * CLHEP: << 
878                                                << 
879   G4int maxTrials = 10;                        << 
880   SetThresholdTrials( maxTrials );             << 
881                                                << 
882   PushThresholdsToLogger();  // Again, to be s << 
883   if( verboseLevel )  ReportLooperThresholds() << 
884 }                                              << 
885                                                << 
886 ////////////////////////////////////////////// << 
887 void G4Transportation::SetLowLooperThresholds( << 
888 {                                              << 
889   // These values were the default in Geant4 1 << 
890   SetThresholdWarningEnergy(     1.0 * CLHEP:: << 
891   SetThresholdImportantEnergy(   1.0 * CLHEP:: << 
892                                                << 
893   G4int maxTrials = 30; //  A new value - was  << 
894   SetThresholdTrials( maxTrials );             << 
895                                                   755 
896   PushThresholdsToLogger();  // Again, to be s << 756   return &fParticleChange ;
897   if( verboseLevel )  ReportLooperThresholds() << 
898 }                                              << 
899                                                << 
900 ////////////////////////////////////////////// << 
901 //                                             << 
902 void                                           << 
903 G4Transportation::ReportMissingLogger( const c << 
904 {                                              << 
905    const char* message= "Logger object missing << 
906    G4String classAndMethod= G4String("G4Transp << 
907    G4Exception(classAndMethod, "Missing Logger << 
908 }                                              << 
909                                                << 
910                                                << 
911 ////////////////////////////////////////////// << 
912 //                                             << 
913 void                                           << 
914 G4Transportation::ReportLooperThresholds()     << 
915 {                                              << 
916    PushThresholdsToLogger();  // To be absolut << 
917    fpLogger->ReportLooperThresholds("G4Transpo << 
918 }                                              << 
919                                                << 
920 ////////////////////////////////////////////// << 
921 //                                             << 
922 void G4Transportation::ProcessDescription(std: << 
923                                                << 
924 // StreamInfo(std::ostream& out, const G4Parti << 
925                                                << 
926 {                                              << 
927   G4String indent = "  "; //  : "");           << 
928   G4long oldPrec= outStr.precision(6);         << 
929   // outStr << std::setprecision(6);           << 
930   outStr << G4endl << indent << GetProcessName << 
931                                                << 
932   outStr << "   Parameters for looping particl << 
933          << "     warning-E = " << fThreshold_ << 
934          << "     important E = " << fThreshol << 
935          << "     thresholdTrials " << fThresh << 
936   outStr.precision(oldPrec);                   << 
937 }                                                 757 }
938                                                   758