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 9.0.p2)


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