Geant4  10.01.p01
G4CoupledTransportation.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4CoupledTransportation.cc 89285 2015-03-31 08:14:25Z gcosmo $
28 //
29 // ------------------------------------------------------------
30 // GEANT 4 class implementation
31 // =======================================================================
32 // Modified:
33 // 10 Jan 2015, M.Kelsey: Use G4DynamicParticle mass, NOT PDGMass
34 // 13 May 2006, J. Apostolakis: Revised for parallel navigation (PathFinder)
35 // 19 Jan 2006, P.MoraDeFreitas: Fix for suspended tracks (StartTracking)
36 // 11 Aug 2004, M.Asai: Add G4VSensitiveDetector* for updating stepPoint.
37 // 21 June 2003, J.Apostolakis: Calling field manager with
38 // track, to enable it to configure its accuracy
39 // 13 May 2003, J.Apostolakis: Zero field areas now taken into
40 // account correclty in all cases (thanks to W Pokorski).
41 // 29 June 2001, J.Apostolakis, D.Cote-Ahern, P.Gumplinger:
42 // correction for spin tracking
43 // 20 Febr 2001, J.Apostolakis: update for new FieldTrack
44 // 22 Sept 2000, V.Grichine: update of Kinetic Energy
45 // Created: 19 March 1997, J. Apostolakis
46 // =======================================================================
47 
49 
50 #include "G4PhysicalConstants.hh"
51 #include "G4SystemOfUnits.hh"
53 #include "G4ProductionCutsTable.hh"
54 #include "G4ParticleTable.hh"
55 #include "G4ChordFinder.hh"
56 #include "G4Field.hh"
57 #include "G4FieldTrack.hh"
58 #include "G4FieldManagerStore.hh"
59 
61 
64 //
65 // Constructor
66 
68  : G4VProcess( G4String("CoupledTransportation"), fTransportation ),
69  fTransportEndPosition(0.0, 0.0, 0.0),
70  fTransportEndMomentumDir(0.0, 0.0, 0.0),
71  fTransportEndKineticEnergy(0.0),
72  fTransportEndSpin(0.0, 0.0, 0.0), // fTransportEndPolarization(0.0, 0.0, 0.0),
73  fMomentumChanged(false),
74  fEndGlobalTimeComputed(false),
75  fCandidateEndGlobalTime(0.0),
76  fParticleIsLooping( false ),
77  fPreviousSftOrigin( 0.,0.,0. ),
78  fPreviousMassSafety( 0.0 ),
79  fPreviousFullSafety( 0.0 ),
80  fMassGeometryLimitedStep( false ),
81  fAnyGeometryLimitedStep( false ),
82  fEndpointDistance( -1.0 ),
83  fThreshold_Warning_Energy( 100 * MeV ),
84  fThreshold_Important_Energy( 250 * MeV ),
85  fThresholdTrials( 10 ),
86  fNoLooperTrials( 0 ),
87  fSumEnergyKilled( 0.0 ), fMaxEnergyKilled( 0.0 ),
88  fVerboseLevel( verbosity )
89 {
90  // set Process Sub Type
91  SetProcessSubType(static_cast<G4int>(COUPLED_TRANSPORTATION));
92 
93  G4TransportationManager* transportMgr ;
94 
96 
97  fMassNavigator = transportMgr->GetNavigatorForTracking() ;
98  fFieldPropagator = transportMgr->GetPropagatorInField() ;
99  // fGlobalFieldMgr = transportMgr->GetFieldManager() ;
100  fNavigatorId= transportMgr->ActivateNavigator( fMassNavigator );
101  if( fVerboseLevel > 0 )
102  {
103  G4cout << " G4CoupledTransportation constructor: ----- " << G4endl;
104  G4cout << " Verbose level is " << fVerboseLevel << G4endl;
105  G4cout << " Navigator Id obtained in G4CoupledTransportation constructor "
106  << fNavigatorId << G4endl;
107  }
109  fpSafetyHelper = transportMgr->GetSafetyHelper(); // New
110 
111  // Following assignment is to fix small memory leak from simple use of 'new'
112  static G4ThreadLocal G4TouchableHandle* pNullTouchableHandle = 0;
113  if ( !pNullTouchableHandle) { pNullTouchableHandle = new G4TouchableHandle; }
114  fCurrentTouchableHandle = *pNullTouchableHandle;
115  // Points to (G4VTouchable*) 0
116 
117  G4FieldManager *globalFieldMgr= transportMgr->GetFieldManager();
118  fGlobalFieldExists= globalFieldMgr ? globalFieldMgr->GetDetectorField() : 0 ;
119 }
120 
122 
124 {
125  // fCurrentTouchableHandle is a data member - no deletion required
126 
127  if( (fVerboseLevel > 0) || (fSumEnergyKilled > 0.0 ) )
128  {
129  G4cout << " G4CoupledTransportation: Statistics for looping particles " << G4endl;
130  G4cout << " Sum of energy of loopers killed: " << fSumEnergyKilled << G4endl;
131  G4cout << " Max energy of loopers killed: " << fMaxEnergyKilled << G4endl;
132  }
133 }
134 
136 //
137 // Responsibilities:
138 // Find whether the geometry limits the Step, and to what length
139 // Calculate the new value of the safety and return it.
140 // Store the final time, position and momentum.
141 
144  G4double, // previousStepSize
145  G4double currentMinimumStep,
146  G4double& proposedSafetyForStart,
147  G4GPILSelection* selection )
148 {
149  G4double geometryStepLength;
150  G4double startMassSafety= 0.0; // estimated safety for start point (mass geometry)
151  G4double startFullSafety= 0.0; // estimated safety for start point (all geometries)
152  G4double safetyProposal= -1.0; // local copy of proposal
153 
154  G4ThreeVector EndUnitMomentum ;
155  G4double lengthAlongCurve=0.0 ;
156 
157  fParticleIsLooping = false ;
158 
159  // Initial actions moved to StartTrack()
160  // --------------------------------------
161  // Note: in case another process changes touchable handle
162  // it will be necessary to add here (for all steps)
163  // fCurrentTouchableHandle = aTrack->GetTouchableHandle();
164 
165  // GPILSelection is set to defaule value of CandidateForSelection
166  // It is a return value
167  //
168  *selection = CandidateForSelection ;
169 
170  // Get initial Energy/Momentum of the track
171  //
172  const G4DynamicParticle* pParticle = track.GetDynamicParticle() ;
173  const G4ParticleDefinition* pParticleDef = pParticle->GetDefinition() ;
174  G4ThreeVector startMomentumDir = pParticle->GetMomentumDirection() ;
175  G4ThreeVector startPosition = track.GetPosition() ;
176  G4VPhysicalVolume* currentVolume= track.GetVolume();
177 
178 #ifdef G4DEBUG_TRANSPORT
179  if( fVerboseLevel > 1 )
180  {
181  G4cout << "G4CoupledTransportation::AlongStepGPIL> called in volume "
182  << currentVolume->GetName() << G4endl;
183  }
184 #endif
185  // G4double theTime = track.GetGlobalTime() ;
186 
187  // The Step Point safety can be limited by other geometries and/or the
188  // assumptions of any process - it's not always the geometrical safety.
189  // We calculate the starting point's isotropic safety here.
190  //
191  G4ThreeVector OriginShift = startPosition - fPreviousSftOrigin ;
192  G4double MagSqShift = OriginShift.mag2() ;
193  startMassSafety = 0.0;
194  startFullSafety= 0.0;
195 
196  // Recall that FullSafety <= MassSafety
197  // Original: if( MagSqShift < sqr(fPreviousMassSafety) ) {
198  if( MagSqShift < sqr(fPreviousFullSafety) ) // Revision proposed by Alex H, 2 Oct 07
199  {
200  G4double mag_shift= std::sqrt(MagSqShift);
201  startMassSafety = std::max( (fPreviousMassSafety - mag_shift), 0.0);
202  startFullSafety = std::max( (fPreviousFullSafety - mag_shift), 0.0);
203  // Need to be consistent between full safety with Mass safety
204  // in order reproduce results in simple case --> use same calculation method
205 
206  // Only compute full safety if massSafety > 0. Else it remains 0
207  // startFullSafety = fPathFinder->ComputeSafety( startPosition );
208  }
209 
210  // Is the particle charged or has it a magnetic moment?
211  //
212  G4double particleCharge = pParticle->GetCharge() ;
213  G4double magneticMoment = pParticle->GetMagneticMoment() ;
214  G4double restMass = pParticle->GetMass() ;
215 
216  fMassGeometryLimitedStep = false ; // Set default - alex
217  fAnyGeometryLimitedStep = false;
218 
219  // fEndGlobalTimeComputed = false ;
220 
221  // There is no need to locate the current volume. It is Done elsewhere:
222  // On track construction
223  // By the tracking, after all AlongStepDoIts, in "Relocation"
224 
225  // Check if the particle has a force, EM or gravitational, exerted on it
226  //
227  G4FieldManager* fieldMgr=0;
228  G4bool fieldExertsForce = false ;
229 
230  G4bool gravityOn = false;
231  const G4Field* ptrField= 0;
232 
233  fieldMgr = fFieldPropagator->FindAndSetFieldManager( track.GetVolume() );
234  if( fieldMgr != 0 )
235  {
236  // Message the field Manager, to configure it for this track
237  fieldMgr->ConfigureForTrack( &track );
238  // Here it can transition from a null field-ptr to a finite field
239 
240  // If the field manager has no field ptr, the field is zero
241  // by definition ( = there is no field ! )
242  ptrField= fieldMgr->GetDetectorField();
243 
244  if( ptrField != 0)
245  {
246  gravityOn= ptrField->IsGravityActive();
247  if( (particleCharge != 0.0)
248  || (fUseMagneticMoment && (magneticMoment != 0.0) )
249  || (gravityOn && (restMass != 0.0))
250  )
251  {
252  fieldExertsForce = true;
253  }
254  }
255  }
256  G4double momentumMagnitude = pParticle->GetTotalMomentum() ;
257 
258  if( fieldExertsForce )
259  {
260  G4EquationOfMotion* equationOfMotion = 0;
261 
262  // equationOfMotion =
263  // (fFieldPropagator->GetChordFinder()->GetIntegrationDriver()->GetStepper())
264  // ->GetEquationOfMotion();
265 
266  // Consolidate into auxiliary method G4EquationOfMotion* GetEquationOfMotion()
267  // equationOfMotion= fFieldPropagator->GetCurrentEquationOfMotion();
268  G4MagIntegratorStepper* pStepper= 0;
269 
271  if( pChordFinder )
272  {
273  G4MagInt_Driver* pIntDriver= 0;
274 
275  pIntDriver= pChordFinder->GetIntegrationDriver();
276  if( pIntDriver )
277  {
278  pStepper= pIntDriver->GetStepper();
279  }
280  if( pStepper )
281  {
282  equationOfMotion= pStepper->GetEquationOfMotion();
283  }
284  }
285  // End of proto GetEquationOfMotion()
286 
287  G4ChargeState chargeState(particleCharge, // The charge can change (dynamic)
288  magneticMoment,
289  pParticleDef->GetPDGSpin() );
290  // For insurance, could set it again
291  // chargeState.SetPDGSpin( pParticleDef->GetPDGSpin() ); // Newly/provisionally in same object
292 
293  if( equationOfMotion )
294  {
295  equationOfMotion->SetChargeMomentumMass( chargeState,
296  momentumMagnitude,
297  restMass );
298  }
299  }
300 
301  G4ThreeVector polarizationVec = track.GetPolarization() ;
302  G4FieldTrack aFieldTrack = G4FieldTrack( startPosition,
303  track.GetGlobalTime(), // Lab.
304  // track.GetProperTime(), // Particle rest frame
305  track.GetMomentumDirection(),
306  track.GetKineticEnergy(),
307  restMass,
308  particleCharge,
309  polarizationVec,
310  pParticleDef->GetPDGMagneticMoment(),
311  0.0, // Length along track
312  pParticleDef->GetPDGSpin()
313  ) ;
314  G4int stepNo= track.GetCurrentStepNumber();
315 
316  ELimited limitedStep;
317  G4FieldTrack endTrackState('a'); // Default values
318 
319  fMassGeometryLimitedStep = false ; // default
320  fAnyGeometryLimitedStep = false ;
321  if( currentMinimumStep > 0 )
322  {
323  G4double newMassSafety= 0.0; // temp. for recalculation
324 
325  // Do the Transport in the field (non recti-linear)
326  //
327  lengthAlongCurve = fPathFinder->ComputeStep( aFieldTrack,
328  currentMinimumStep,
329  fNavigatorId,
330  stepNo,
331  newMassSafety,
332  limitedStep,
333  endTrackState,
334  currentVolume ) ;
335  // G4cout << " PathFinder ComputeStep returns " << lengthAlongCurve << G4endl;
336 
337  G4double newFullSafety= fPathFinder->GetCurrentSafety();
338  // this was estimated already in step above
339  // G4double newFullStep= fPathFinder->GetMinimumStep();
340 
341  if( limitedStep == kUnique || limitedStep == kSharedTransport )
342  {
343  fMassGeometryLimitedStep = true ;
344  }
345 
347 
348 //#ifdef G4DEBUG_TRANSPORT
350  {
351  G4cerr << " Error in determining geometries limiting the step" << G4endl;
352  G4cerr << " Limiting: mass=" << fMassGeometryLimitedStep
353  << " any= " << fAnyGeometryLimitedStep << G4endl;
354  G4Exception("G4CoupledTransportation::AlongStepGetPhysicalInteractionLength()",
355  "PathFinderConfused", FatalException,
356  "Incompatible conditions - was limited by a geometry?");
357  }
358 //#endif
359 
360  // Other potential
361  // fAnyGeometryLimitedStep = newFullStep < currentMinimumStep;
362  // ^^^ Not good enough;
363  // Must compare with maximum requested step size
364  // (eg in case another process requested bigger, got this!)
365 
366  geometryStepLength = std::min( lengthAlongCurve, currentMinimumStep);
367 
368  // Momentum: Magnitude and direction can be changed too now ...
369  //
370  fMomentumChanged = true ;
371  fTransportEndMomentumDir = endTrackState.GetMomentumDir() ;
372 
373  // Remember last safety origin & value.
374  fPreviousSftOrigin = startPosition ;
375  fPreviousMassSafety = newMassSafety ;
376  fPreviousFullSafety = newFullSafety ;
377  // fpSafetyHelper->SetCurrentSafety( newFullSafety, startPosition);
378 
379 #ifdef G4DEBUG_TRANSPORT
380  if( fVerboseLevel > 1 )
381  {
382  G4cout << "G4Transport:CompStep> "
383  << " called the pathfinder for a new step at " << startPosition
384  << " and obtained step = " << lengthAlongCurve << G4endl;
385  G4cout << " New safety (preStep) = " << newMassSafety
386  << " versus precalculated = " << startMassSafety << G4endl;
387  }
388 #endif
389 
390  // Store as best estimate value
391  startMassSafety = newMassSafety ;
392  startFullSafety = newFullSafety ;
393 
394  // Get the End-Position and End-Momentum (Dir-ection)
395  fTransportEndPosition = endTrackState.GetPosition() ;
396  fTransportEndKineticEnergy = endTrackState.GetKineticEnergy() ;
397  }
398  else
399  {
400  geometryStepLength = lengthAlongCurve= 0.0 ;
401  fMomentumChanged = false ;
402  // fMassGeometryLimitedStep = false ; // --- ???
403  // fAnyGeometryLimitedStep = true;
406 
407  fTransportEndPosition = startPosition;
408 
409  endTrackState= aFieldTrack; // Ensures that time is updated
410 
411  // If the step length requested is 0, and we are on a boundary
412  // then a boundary will also limit the step.
413  if( startMassSafety == 0.0 )
414  {
415  fMassGeometryLimitedStep = true ;
417  }
418  // TODO: Add explicit logical status for being at a boundary
419  }
420  // G4FieldTrack aTrackState(endTrackState);
421 
422  if( !fieldExertsForce )
423  {
424  fParticleIsLooping = false ;
425  fMomentumChanged = false ;
426  fEndGlobalTimeComputed = false ;
427  // G4cout << " global time is false " << G4endl;
428  }
429  else
430  {
431 
432 #ifdef G4DEBUG_TRANSPORT
433  if( fVerboseLevel > 1 )
434  {
435  G4cout << " G4CT::CS End Position = " << fTransportEndPosition << G4endl;
436  G4cout << " G4CT::CS End Direction = " << fTransportEndMomentumDir << G4endl;
437  }
438 #endif
440  {
441  // If the field can change energy, then the time must be integrated
442  // - so this should have been updated
443  //
445  fEndGlobalTimeComputed = true;
446 
447  // was ( fCandidateEndGlobalTime != track.GetGlobalTime() );
448  // a cleaner way is to have FieldTrack knowing whether time is updated.
449  }
450  else
451  {
452  // The energy should be unchanged by field transport,
453  // - so the time changed will be calculated elsewhere
454  //
455  fEndGlobalTimeComputed = false;
456 
457  // Check that the integration preserved the energy
458  // - and if not correct this!
459  G4double startEnergy= track.GetKineticEnergy();
461 
462  static G4ThreadLocal G4int no_inexact_steps=0; // , no_large_ediff;
463  G4double absEdiff = std::fabs(startEnergy- endEnergy);
464  if( absEdiff > perMillion * endEnergy )
465  {
466  no_inexact_steps++;
467  // Possible statistics keeping here ...
468  }
469 #ifdef G4VERBOSE
470  if( (fVerboseLevel > 1) && ( absEdiff > perThousand * endEnergy) )
471  {
472  ReportInexactEnergy(startEnergy, endEnergy);
473  } // end of if (fVerboseLevel)
474 #endif
475  // Correct the energy for fields that conserve it
476  // This - hides the integration error
477  // - but gives a better physical answer
479  }
480  }
481 
482  fEndpointDistance = (fTransportEndPosition - startPosition).mag() ;
484 
485  fTransportEndSpin = endTrackState.GetSpin();
486 
487  // Calculate the safety
488  safetyProposal= startFullSafety; // used to be startMassSafety
489  // Changed to accomodate processes that cannot update the safety -- JA 22 Nov 06
490 
491  // Update safety for the end-point, if becomes negative at the end-point.
492 
493  if( (startFullSafety < fEndpointDistance )
494  && ( particleCharge != 0.0 ) ) // Only needed to prepare for Mult Scat.
495  // && !fAnyGeometryLimitedStep ) // To-Try: No safety update if at a boundary
496  {
497  G4double endFullSafety =
499  // Expected mission -- only mass geometry's safety
500  // fMassNavigator->ComputeSafety( fTransportEndPosition) ;
501  // Yet discrete processes only have poststep -- and this cannot
502  // currently revise the safety
503  // ==> so we use the all-geometry safety as a precaution
504 
506  // Pushing safety to Helper avoids recalculation at this point
507 
508  G4ThreeVector centerPt= G4ThreeVector(0.0, 0.0, 0.0); // Used for return value
509  G4double endMassSafety= fPathFinder->ObtainSafety( fNavigatorId, centerPt);
510  // Retrieves the mass value from PathFinder (it calculated it)
511 
512  fPreviousMassSafety = endMassSafety ;
513  fPreviousFullSafety = endFullSafety;
514  fPreviousSftOrigin = fTransportEndPosition ;
515 
516  // The convention (Stepping Manager's) is safety from the start point
517  //
518  safetyProposal = endFullSafety + fEndpointDistance;
519  // --> was endMassSafety
520  // Changed to accomodate processes that cannot update the safety -- JA 22 Nov 06
521 
522  // #define G4DEBUG_TRANSPORT 1
523 
524 #ifdef G4DEBUG_TRANSPORT
525  G4int prec= G4cout.precision(12) ;
526  G4cout << "***Transportation::AlongStepGPIL ** " << G4endl ;
527  G4cout << " Revised Safety at endpoint " << fTransportEndPosition
528  << " give safety values: Mass= " << endMassSafety
529  << " All= " << endFullSafety << G4endl ;
530  G4cout << " Adding endpoint distance " << fEndpointDistance
531  << " to obtain pseudo-safety= " << safetyProposal << G4endl ;
532  G4cout.precision(prec);
533  }
534  else
535  {
536  G4int prec= G4cout.precision(12) ;
537  G4cout << "***Transportation::AlongStepGPIL ** " << G4endl ;
538  G4cout << " Quick Safety estimate at endpoint " << fTransportEndPosition
539  << " gives safety endpoint value = " << startFullSafety - fEndpointDistance
540  << " using start-point value " << startFullSafety
541  << " and endpointDistance " << fEndpointDistance << G4endl;
542  G4cout.precision(prec);
543 #endif
544  }
545 
546  proposedSafetyForStart= safetyProposal;
547  fParticleChange.ProposeTrueStepLength(geometryStepLength) ;
548 
549  return geometryStepLength ;
550 }
551 
553 
556  const G4Step& stepData )
557 {
558  static G4ThreadLocal G4int noCalls=0;
559  noCalls++;
560 
561  fParticleChange.Initialize(track) ;
562  // sets all its members to the value of corresponding members in G4Track
563 
564  // Code specific for Transport
565  //
567  // G4cout << " G4CoupledTransportation::AlongStepDoIt"
568  // << " proposes position = " << fTransportEndPosition
569  // << " and end momentum direction = " << fTransportEndMomentumDir << G4endl;
573 
575 
576  G4double deltaTime = 0.0 ;
577 
578  // Calculate Lab Time of Flight (ONLY if field Equations used it!)
579  // G4double endTime = fCandidateEndGlobalTime;
580  // G4double delta_time = endTime - startTime;
581 
582  G4double startTime = track.GetGlobalTime() ;
583 
585  {
586  G4double finalInverseVel= DBL_MAX, initialInverseVel=DBL_MAX;
587 
588  // The time was not integrated .. make the best estimate possible
589  //
590  G4double finalVelocity = track.GetVelocity() ;
591  if( finalVelocity > 0.0 ) { finalInverseVel= 1.0 / finalVelocity; }
592  G4double initialVelocity = stepData.GetPreStepPoint()->GetVelocity() ;
593  if( initialVelocity > 0.0 ) { initialInverseVel= 1.0 / initialVelocity; }
594  G4double stepLength = track.GetStepLength() ;
595 
596  if (finalVelocity > 0.0)
597  {
598  // deltaTime = stepLength/finalVelocity ;
599  G4double meanInverseVelocity = 0.5 * ( initialInverseVel + finalInverseVel );
600  deltaTime = stepLength * meanInverseVelocity ;
601  // G4cout << " dt = s * mean(1/v) , with " << " s = " << stepLength
602  // << " mean(1/v)= " << meanInverseVelocity << G4endl;
603  }
604  else
605  {
606  deltaTime = stepLength * initialInverseVel ;
607  // G4cout << " dt = s / initV " << " s = " << stepLength
608  // << " 1 / initV= " << initialInverseVel << G4endl;
609  } // Could do with better estimate for final step (finalVelocity = 0) ?
610 
611  fCandidateEndGlobalTime = startTime + deltaTime ;
612  fParticleChange.ProposeLocalTime( track.GetLocalTime() + deltaTime) ;
613 
614  // G4cout << " Calculated global time from start = " << startTime << " and "
615  // << " delta time = " << deltaTime << G4endl;
616  }
617  else
618  {
619  deltaTime = fCandidateEndGlobalTime - startTime ;
621  // G4cout << " Calculated global time from candidate end time = "
622  // << fCandidateEndGlobalTime << " and start time = " << startTime << G4endl;
623  }
624 
625  // G4cout << " G4CoupledTransportation::AlongStepDoIt "
626  // << " flag whether computed time = " << fEndGlobalTimeComputed << " and "
627  // << " is proposes end time " << fCandidateEndGlobalTime << G4endl;
628 
629  // Now Correct by Lorentz factor to get "proper" deltaTime
630 
631  G4double restMass = track.GetDynamicParticle()->GetMass() ;
632  G4double deltaProperTime = deltaTime*( restMass/track.GetTotalEnergy() ) ;
633 
634  fParticleChange.ProposeProperTime(track.GetProperTime() + deltaProperTime) ;
635  //fParticleChange. ProposeTrueStepLength( track.GetStepLength() ) ;
636 
637  // If the particle is caught looping or is stuck (in very difficult
638  // boundaries) in a magnetic field (doing many steps)
639  // THEN this kills it ...
640  //
641  if ( fParticleIsLooping )
642  {
644 
645  if( (endEnergy < fThreshold_Important_Energy)
647  {
648  // Kill the looping particle
649  //
651 
652  // 'Bare' statistics
653  fSumEnergyKilled += endEnergy;
654  if( endEnergy > fMaxEnergyKilled) { fMaxEnergyKilled= endEnergy; }
655 
656 #ifdef G4VERBOSE
657  if((fVerboseLevel > 1) && ( endEnergy > fThreshold_Warning_Energy ))
658  {
659  G4cout << " G4CoupledTransportation is killing track that is looping or stuck " << G4endl
660  << " This track has " << track.GetKineticEnergy() / MeV
661  << " MeV energy." << G4endl;
662  }
663  if( fVerboseLevel > 0 )
664  {
665  G4cout << " Steps by this track: " << track.GetCurrentStepNumber() << G4endl;
666  }
667 #endif
668  fNoLooperTrials=0;
669  }
670  else
671  {
672  fNoLooperTrials ++;
673 #ifdef G4VERBOSE
674  if( (fVerboseLevel > 2) )
675  {
676  G4cout << " ** G4CoupledTransportation::AlongStepDoIt(): Particle looping - " << G4endl
677  << " Number of consecutive problem step (this track) = " << fNoLooperTrials << G4endl
678  << " Steps by this track: " << track.GetCurrentStepNumber() << G4endl
679  << " Total no of calls to this method (all tracks) = " << noCalls << G4endl;
680  }
681 #endif
682  }
683  }
684  else
685  {
686  fNoLooperTrials=0;
687  }
688 
689  // Another (sometimes better way) is to use a user-limit maximum Step size
690  // to alleviate this problem ..
691 
692  // Add smooth curved trajectories to particle-change
693  //
694  // fParticleChange.SetPointerToVectorOfAuxiliaryPoints
695  // (fFieldPropagator->GimmeTrajectoryVectorAndForgetIt() );
696 
697  return &fParticleChange ;
698 }
699 
701 //
702 // This ensures that the PostStep action is always called,
703 // so that it can do the relocation if it is needed.
704 //
705 
708  G4double, // previousStepSize
709  G4ForceCondition* pForceCond )
710 {
711  // Must act as PostStep action -- to relocate particle
712  *pForceCond = Forced ;
713  return DBL_MAX ;
714 }
715 
717 ReportMove( G4ThreeVector OldVector, G4ThreeVector NewVector, const G4String& Quantity )
718 {
719  G4ThreeVector moveVec = ( NewVector - OldVector );
720 
721  G4cerr << G4endl
722  << "**************************************************************" << G4endl;
723  G4cerr << "Endpoint has moved between value expected from TransportEndPosition "
724  << " and value from Track in PostStepDoIt. " << G4endl
725  << "Change of " << Quantity << " is " << moveVec.mag() / mm << " mm long, "
726  << " and its vector is " << (1.0/mm) * moveVec << " mm " << G4endl
727  << "Endpoint of ComputeStep was " << OldVector
728  << " and current position to locate is " << NewVector << G4endl;
729 }
730 
732 
734  const G4Step& )
735 {
736  G4TouchableHandle retCurrentTouchable ; // The one to return
737 
738  // Initialize ParticleChange (by setting all its members equal
739  // to corresponding members in G4Track)
740  // fParticleChange.Initialize(track) ; // To initialise TouchableChange
741 
743 
744  // Check that the end position and direction are preserved
745  // since call to AlongStepDoIt
746 
747 #ifdef G4DEBUG_TRANSPORT
748  if( ( fVerboseLevel > 0 )
749  && ((fTransportEndPosition - track.GetPosition()).mag2() >= 1.0e-16) )
750  {
751  ReportMove( track.GetPosition(), fTransportEndPosition, "End of Step Position" );
752  G4cerr << " Problem in G4CoupledTransportation::PostStepDoIt " << G4endl;
753  }
754 
755  // If the Step was determined by the volume boundary, relocate the particle
756  // The pathFinder will know that the geometry limited the step (!?)
757 
758  if( fVerboseLevel > 0 )
759  {
760  G4cout << " Calling PathFinder::Locate() from "
761  << " G4CoupledTransportation::PostStepDoIt " << G4endl;
762  G4cout << " fAnyGeometryLimitedStep is " << fAnyGeometryLimitedStep << G4endl;
763 
764  }
765 #endif
766 
768  {
769  fPathFinder->Locate( track.GetPosition(),
770  track.GetMomentumDirection(),
771  true);
772 
773  // fCurrentTouchable will now become the previous touchable,
774  // and what was the previous will be freed.
775  // (Needed because the preStepPoint can point to the previous touchable)
776 
779 
780 #ifdef G4DEBUG_TRANSPORT
781  if( fVerboseLevel > 0 )
782  {
783  G4cout << "G4CoupledTransportation::PostStepDoIt --- fNavigatorId = "
784  << fNavigatorId << G4endl;
785  }
786  if( fVerboseLevel > 1 )
787  {
789  G4cout << "CHECK !!!!!!!!!!! fCurrentTouchableHandle->GetVolume() = " << vol;
790  if( vol ) { G4cout << "Name=" << vol->GetName(); }
791  G4cout << G4endl;
792  }
793 #endif
794 
795  // Check whether the particle is out of the world volume
796  // If so it has exited and must be killed.
797  //
798  if( fCurrentTouchableHandle->GetVolume() == 0 )
799  {
801  }
802  retCurrentTouchable = fCurrentTouchableHandle ;
803  // fParticleChange.SetTouchableHandle( fCurrentTouchableHandle ) ;
804 
805  // Notify particle change that this is last step in volume
807  }
808  else // fAnyGeometryLimitedStep is false
809  {
810 #ifdef G4DEBUG_TRANSPORT
811  if( fVerboseLevel > 1 )
812  {
813  G4cout << "G4CoupledTransportation::PostStepDoIt -- "
814  << " fAnyGeometryLimitedStep = " << fAnyGeometryLimitedStep
815  << " must be false " << G4endl;
816  }
817 #endif
818  // This serves only to move each of the Navigator's location
819  //
820  // fLinearNavigator->LocateGlobalPointWithinVolume( track.GetPosition() ) ;
821 
822  // G4cout << "G4CoupledTransportation calling PathFinder::ReLocate() " << G4endl;
823  fPathFinder->ReLocate( track.GetPosition() );
824  // track.GetMomentumDirection() );
825 
826  // Keep the value of the track's current Touchable is retained,
827  // and use it to overwrite the (unset) one in particle change.
828  // Expect this must be fCurrentTouchable too
829  // - could it be different, eg at the start of a step ?
830  //
831  retCurrentTouchable = track.GetTouchableHandle() ;
832  // fParticleChange.SetTouchableHandle( track.GetTouchableHandle() ) ;
833 
834  // Have not reached a boundary
836  } // endif ( fAnyGeometryLimitedStep )
837 
838  const G4VPhysicalVolume* pNewVol = retCurrentTouchable->GetVolume() ;
839  const G4Material* pNewMaterial = 0 ;
840  const G4VSensitiveDetector* pNewSensitiveDetector = 0 ;
841 
842  if( pNewVol != 0 )
843  {
844  pNewMaterial= pNewVol->GetLogicalVolume()->GetMaterial();
845  pNewSensitiveDetector= pNewVol->GetLogicalVolume()->GetSensitiveDetector();
846  }
847 
848  // ( const_cast<G4Material *> pNewMaterial ) ;
849  // ( const_cast<G4VSensitiveDetetor *> pNewSensitiveDetector) ;
850 
853  // "temporarily" until Get/Set Material of ParticleChange,
854  // and StepPoint can be made const.
855 
856  const G4MaterialCutsCouple* pNewMaterialCutsCouple = 0;
857  if( pNewVol != 0 )
858  {
859  pNewMaterialCutsCouple=pNewVol->GetLogicalVolume()->GetMaterialCutsCouple();
860  if( pNewMaterialCutsCouple!=0
861  && pNewMaterialCutsCouple->GetMaterial()!=pNewMaterial )
862  {
863  // for parametrized volume
864  //
865  pNewMaterialCutsCouple =
867  ->GetMaterialCutsCouple(pNewMaterial,
868  pNewMaterialCutsCouple->GetProductionCuts());
869  }
870  }
871  fParticleChange.SetMaterialCutsCoupleInTouchable( pNewMaterialCutsCouple );
872 
873  // Must always set the touchable in ParticleChange, whether relocated or not
874  fParticleChange.SetTouchableHandle(retCurrentTouchable) ;
875 
876  return &fParticleChange ;
877 }
878 
879 // New method takes over the responsibility to reset the state of
880 // G4CoupledTransportation object:
881 // - at the start of a new track, and
882 // - on the resumption of a suspended track.
883 
884 void
886 {
887 
888  G4TransportationManager* transportMgr =
890 
891  // G4VProcess::StartTracking(aTrack);
892 
893  // The 'initialising' actions
894  // once taken in AlongStepGPIL -- if ( track.GetCurrentStepNumber()==1 )
895 
896  // fStartedNewTrack= true;
897 
898  fMassNavigator = transportMgr->GetNavigatorForTracking() ;
899  fNavigatorId= transportMgr->ActivateNavigator( fMassNavigator ); // Confirm it!
900 
901  // if( fVerboseLevel > 1 ){
902  // G4cout << " Navigator Id obtained in StartTracking " << fNavigatorId << G4endl;
903  // }
904  G4ThreeVector position = aTrack->GetPosition();
905  G4ThreeVector direction = aTrack->GetMomentumDirection();
906 
907  // if( fVerboseLevel > 1 ){
908  // G4cout << " Calling PathFinder::PrepareNewTrack from "
909  // << " G4CoupledTransportation::StartTracking -- which calls Locate()" << G4endl;
910  // }
911  fPathFinder->PrepareNewTrack( position, direction);
912  // This implies a call to fPathFinder->Locate( position, direction );
913 
914  // Global field, if any, must exist before tracking is started
916  // reset safety value and center
917  //
918  fPreviousMassSafety = 0.0 ;
919  fPreviousFullSafety = 0.0 ;
920  fPreviousSftOrigin = G4ThreeVector(0.,0.,0.) ;
921 
922  // reset looping counter -- for motion in field
923  fNoLooperTrials= 0;
924  // Must clear this state .. else it depends on last track's value
925  // --> a better solution would set this from state of suspended track TODO ?
926  // Was if( aTrack->GetCurrentStepNumber()==1 ) { .. }
927 
928  // ChordFinder reset internal state
929  //
930  if( fGlobalFieldExists )
931  {
933  // Resets safety values, in case of overlaps.
934 
936  if( chordF ) { chordF->ResetStepEstimate(); }
937  }
938 
939  // Clear the chord finders of all fields (ie managers) derived objects
940  //
942  fieldMgrStore->ClearAllChordFindersState();
943 
944 #ifdef G4DEBUG_TRANSPORT
945  if( fVerboseLevel > 1 )
946  {
947  G4cout << " Returning touchable handle " << fCurrentTouchableHandle << G4endl;
948  }
949 #endif
950 
951  // Update the current touchable handle (from the track's)
952  //
954 }
955 
956 void
958 {
960  fPathFinder->EndTrack(); // Resets TransportationManager to use ordinary Navigator
961 }
962 
963 void
965 ReportInexactEnergy(G4double startEnergy, G4double endEnergy)
966 {
967  static G4ThreadLocal G4int no_warnings= 0, warnModulo=1, moduloFactor= 10, no_large_ediff= 0;
968 
969  if( std::fabs(startEnergy- endEnergy) > perThousand * endEnergy )
970  {
971  no_large_ediff ++;
972  if( (no_large_ediff% warnModulo) == 0 )
973  {
974  no_warnings++;
975  G4cout << "WARNING - G4CoupledTransportation::AlongStepGetPIL() "
976  << " Energy change in Step is above 1^-3 relative value. " << G4endl
977  << " Relative change in 'tracking' step = "
978  << std::setw(15) << (endEnergy-startEnergy)/startEnergy << G4endl
979  << " Starting E= " << std::setw(12) << startEnergy / MeV << " MeV " << G4endl
980  << " Ending E= " << std::setw(12) << endEnergy / MeV << " MeV " << G4endl;
981  G4cout << " Energy has been corrected -- however, review"
982  << " field propagation parameters for accuracy." << G4endl;
983  if( (fVerboseLevel > 2 ) || (no_warnings<4) || (no_large_ediff == warnModulo * moduloFactor) )
984  {
985  G4cout << " These include EpsilonStepMax(/Min) in G4FieldManager "
986  << " which determine fractional error per step for integrated quantities. " << G4endl
987  << " Note also the influence of the permitted number of integration steps."
988  << G4endl;
989  }
990  G4cerr << "ERROR - G4CoupledTransportation::AlongStepGetPIL()" << G4endl
991  << " Bad 'endpoint'. Energy change detected"
992  << " and corrected. "
993  << " Has occurred already "
994  << no_large_ediff << " times." << G4endl;
995  if( no_large_ediff == warnModulo * moduloFactor )
996  {
997  warnModulo *= moduloFactor;
998  }
999  }
1000  }
1001 }
1002 
1003 #include "G4Transportation.hh"
1005 {
1006  G4bool lastValue= fUseMagneticMoment;
1007  fUseMagneticMoment= useMoment;
1009  return lastValue;
1010 }
void PrepareNewTrack(const G4ThreeVector &position, const G4ThreeVector &direction, G4VPhysicalVolume *massStartVol=0)
static G4PathFinder * GetInstance()
Definition: G4PathFinder.cc:57
void SetMaterialInTouchable(G4Material *fMaterial)
void SetTouchableHandle(const G4TouchableHandle &fTouchable)
const G4ThreeVector & GetPolarization() const
G4double ObtainSafety(G4int navId, G4ThreeVector &globalCenterPoint)
static const double MeV
Definition: G4SIunits.hh:193
void Locate(const G4ThreeVector &position, const G4ThreeVector &direction, G4bool relativeSearch=true)
G4SafetyHelper * GetSafetyHelper() const
G4double GetLocalTime() const
void ReportMove(G4ThreeVector OldVector, G4ThreeVector NewVector, const G4String &Quantity)
void SetMaterialCutsCoupleInTouchable(const G4MaterialCutsCouple *fMaterialCutsCouple)
void StartTracking(G4Track *aTrack)
virtual void SetChargeMomentumMass(G4ChargeState particleCharge, G4double MomentumXc, G4double MassXc2)=0
G4double GetProperTime() const
CLHEP::Hep3Vector G4ThreeVector
G4double GetVelocity() const
G4double GetCurrentSafety() const
G4double GetKineticEnergy() const
G4TouchableHandle fCurrentTouchableHandle
const G4DynamicParticle * GetDynamicParticle() const
const G4MagIntegratorStepper * GetStepper() const
G4double AlongStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4double currentMinimumStep, G4double &currentSafety, G4GPILSelection *selection)
G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &stepData)
G4Material * GetMaterial() const
void ReLocate(const G4ThreeVector &position)
ELimited
const G4ThreeVector & GetPosition() const
const G4ThreeVector & GetMomentumDir() const
G4TrackStatus GetTrackStatus() const
G4ThreeVector GetSpin() const
G4Navigator * GetNavigatorForTracking() const
G4TouchableHandle CreateTouchableHandle(G4int navId) const
void ProposePolarization(G4double Px, G4double Py, G4double Pz)
G4ParticleDefinition * GetDefinition() const
static const double perThousand
Definition: G4SIunits.hh:297
G4double GetVelocity() const
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
void ProposePosition(G4double x, G4double y, G4double z)
G4ReferenceCountedHandle< G4VTouchable > G4TouchableHandle
unsigned int GetNumberGeometriesLimitingStep() const
G4double GetTotalMomentum() const
static G4bool EnableUseMagneticMoment(G4bool useMoment=true)
G4StepPoint * GetPreStepPoint() const
virtual void Initialize(const G4Track &)
virtual void ConfigureForTrack(const G4Track *)
static const double prec
Definition: RanecuEngine.cc:58
G4double GetKineticEnergy() const
G4EquationOfMotion * GetEquationOfMotion()
#define position
Definition: xmlparse.cc:605
G4ThreeVector GetPosition() const
G4GLOB_DLL std::ostream G4cout
void ReportInexactEnergy(G4double startEnergy, G4double endEnergy)
G4int GetCurrentStepNumber() const
const G4String & GetName() const
G4double GetMass() const
bool G4bool
Definition: G4Types.hh:79
const G4ThreeVector & GetMomentumDirection() const
G4double GetCharge() const
void ProposeTrueStepLength(G4double truePathLength)
G4double ComputeStep(const G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4int navigatorId, G4int stepNo, G4double &pNewSafety, ELimited &limitedStep, G4FieldTrack &EndState, G4VPhysicalVolume *currentVolume)
void SetProcessSubType(G4int)
Definition: G4VProcess.hh:432
G4bool DoesFieldChangeEnergy() const
Definition: G4Step.hh:76
G4double ComputeSafety(const G4ThreeVector &globalPoint)
G4double GetGlobalTime() const
G4FieldManager * FindAndSetFieldManager(G4VPhysicalVolume *pCurrentPhysVol)
const G4TouchableHandle & GetTouchableHandle() const
G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &stepData)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4TransportationManager * GetTransportationManager()
G4FieldManager * GetFieldManager() const
static const double perMillion
Definition: G4SIunits.hh:298
static G4ProductionCutsTable * GetProductionCutsTable()
G4int ActivateNavigator(G4Navigator *aNavigator)
const G4ThreeVector & GetMomentumDirection() const
G4LogicalVolume * GetLogicalVolume() const
void ProposeProperTime(G4double finalProperTime)
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
static G4FieldManagerStore * GetInstance()
void SetSensitiveDetectorInTouchable(G4VSensitiveDetector *fSensitiveDetector)
#define fPreviousSftOrigin
G4bool IsParticleLooping() const
G4double GetLabTimeOfFlight() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:44
G4bool IsGravityActive() const
Definition: G4Field.hh:98
void ProposeGlobalTime(G4double t)
G4ChordFinder * GetChordFinder()
G4FieldManager * GetCurrentFieldManager()
void ProposeEnergy(G4double finalEnergy)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4VPhysicalVolume * GetVolume() const
G4double GetTotalEnergy() const
G4double GetPDGSpin() const
void SetCurrentSafety(G4double val, const G4ThreeVector &pos)
#define G4endl
Definition: G4ios.hh:61
void ProposeLastStepInVolume(G4bool flag)
void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz)
const G4MaterialCutsCouple * GetMaterialCutsCouple() const
T sqr(const T &x)
Definition: templates.hh:145
G4double GetPDGMagneticMoment() const
double G4double
Definition: G4Types.hh:76
void ProposeTrackStatus(G4TrackStatus status)
const G4Field * GetDetectorField() const
G4ForceCondition
G4MagInt_Driver * GetIntegrationDriver()
void SetMomentumChanged(G4bool b)
G4PropagatorInField * GetPropagatorInField() const
G4ProductionCuts * GetProductionCuts() const
#define DBL_MAX
Definition: templates.hh:83
G4VSensitiveDetector * GetSensitiveDetector() const
static const double mm
Definition: G4SIunits.hh:102
G4double GetMagneticMoment() const
G4double PostStepGetPhysicalInteractionLength(const G4Track &, G4double previousStepSize, G4ForceCondition *pForceCond)
void ProposeLocalTime(G4double t)
G4PropagatorInField * fFieldPropagator
G4double GetStepLength() const
void ResetStepEstimate()
G4GPILSelection
const G4Material * GetMaterial() const
G4GLOB_DLL std::ostream G4cerr
G4ParticleChangeForTransport fParticleChange
static G4bool fUseMagneticMoment
G4CoupledTransportation(G4int verbosityLevel=0)