ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4PropagatorInField.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4PropagatorInField.hh
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 // Class G4PropagatorInField
27 //
28 // class description:
29 //
30 // This class performs the navigation/propagation of a particle/track
31 // in a magnetic field. The field is in general non-uniform.
32 // For the calculation of the path, it relies on the class G4ChordFinder.
33 
34 // History:
35 // -------
36 // 25.10.96 John Apostolakis, design and implementation
37 // 25.03.97 John Apostolakis, adaptation for G4Transportation and cleanup
38 // 8.11.02 John Apostolakis, changes to enable use of safety in intersecting
39 // ---------------------------------------------------------------------------
40 #ifndef G4PropagatorInField_hh
41 #define G4PropagatorInField_hh 1
42 
43 #include "G4Types.hh"
44 
45 #include <vector>
46 
47 #include "G4FieldTrack.hh"
48 #include "G4FieldManager.hh"
50 
51 class G4ChordFinder;
52 
53 class G4Navigator;
54 class G4VPhysicalVolume;
56 
58 {
59 
60  public: // with description
61 
62  G4PropagatorInField( G4Navigator* theNavigator,
63  G4FieldManager* detectorFieldMgr,
64  G4VIntersectionLocator* vLocator = nullptr );
66 
67  G4double ComputeStep( G4FieldTrack& pFieldTrack,
68  G4double pCurrentProposedStepLength,
69  G4double& pNewSafety,
70  G4VPhysicalVolume* pPhysVol = nullptr,
71  G4bool canRelaxDeltaChord = false);
72  // Compute the next geometric Step
73 
74  inline G4ThreeVector EndPosition() const;
75  inline G4ThreeVector EndMomentumDir() const;
76  inline G4bool IsParticleLooping() const;
77  // Return the state after the Step
78 
79  inline G4double GetEpsilonStep() const;
80  // Relative accuracy for current Step (Calc.)
81  inline void SetEpsilonStep(G4double newEps);
82  // The ratio DeltaOneStep()/h_current_step
83 
85  // Set (and return) the correct field manager (global or local),
86  // if it exists.
87  // Should be called before ComputeStep is called;
88  // Currently, ComputeStep will call it, if it has not been called.
89 
90  inline G4ChordFinder* GetChordFinder();
91 
92  G4int SetVerboseLevel( G4int verbose );
93  inline G4int GetVerboseLevel() const;
94  inline G4int Verbose() const;
95 
96  inline void SetVerboseTrace( G4bool enable );
97  inline G4bool GetVerboseTrace();
98  // Tracing key parts of Compute Step
99 
100  inline G4int GetMaxLoopCount() const;
101  inline void SetMaxLoopCount( G4int new_max );
102  // A maximum for the number of substeps that a particle can take.
103  // Above this number it is signaled as 'looping'.
104 
105  void printStatus( const G4FieldTrack& startFT,
106  const G4FieldTrack& currentFT,
107  G4double requestStep,
108  G4double safety,
109  G4int step,
110  G4VPhysicalVolume* startVolume);
111  // Print Method - useful mostly for debugging.
112 
113  inline G4FieldTrack GetEndState() const;
114 
115  inline G4double GetMinimumEpsilonStep() const; // Min for relative accuracy
116  inline void SetMinimumEpsilonStep( G4double newEpsMin ); // of any step
117  inline G4double GetMaximumEpsilonStep() const;
118  inline void SetMaximumEpsilonStep( G4double newEpsMax );
119  // The 4 above methods are now obsolescent but *for now* will work
120  // They are being replaced by same-name methods in G4FieldManager,
121  // allowing the specialisation in different volumes.
122  // Their new behaviour is to change the values for the global field
123  // manager
124 
125  inline void SetLargestAcceptableStep( G4double newBigDist );
127 
129  // Set the filter that examines & stores 'intermediate'
130  // curved trajectory points. Currently only position is stored.
131 
132  std::vector<G4ThreeVector>* GimmeTrajectoryVectorAndForgetIt() const;
133  // Access the points which have passed by the filter.
134  // Responsibility for deleting the points lies with the client.
135  // This method MUST BE called exactly ONCE per step.
136 
137  void ClearPropagatorState();
138  // Clear all the State of this class and its current associates
139  // --> the current field manager & chord finder will also be called
140 
141  inline void SetDetectorFieldManager( G4FieldManager* newGlobalFieldManager );
142  // Update this (dangerous) state -- for the time being
143 
144  inline void SetUseSafetyForOptimization( G4bool );
146  // Toggle & view parameter for using safety to discard
147  // unneccesary calls to navigator (thus 'optimising' performance)
148  inline G4bool IntersectChord( const G4ThreeVector& StartPointA,
149  const G4ThreeVector& EndPointB,
150  G4double& NewSafety,
151  G4double& LinearStepLength,
152  G4ThreeVector& IntersectionPoint);
153  // Intersect the chord from StartPointA to EndPointB
154  // and return whether an intersection occurred
155  // NOTE: Safety is changed!
156 
157  inline G4bool IsFirstStepInVolume();
158  inline G4bool IsLastStepInVolume();
159  inline void PrepareNewTrack();
160 
162  inline void SetIntersectionLocator(G4VIntersectionLocator* pLocator );
163  // Change or get the object which calculates the exact
164  // intersection point with the next boundary
165 
167  inline void SetIterationsToIncreaseChordDistance(G4int numIters);
168  // Control the parameter which enables the temporary 'relaxation'
169  // which ensures that chord segments are short enough so that
170  // their sagitta is small than delta-chord parameter.
171  // The Set method increases the value of delta-chord temporarily,
172  // doubling it once the number of iterations substeps reach
173  // value of 'IncreaseChordDistanceThreshold'. It is also doubled
174  // again every time the iteration count reaches a multiple of this
175  // value.
176  // Note: delta-chord is reset to its original value at the end of
177  // each call to ComputeStep.
178 
179  public: // without description
180 
181  inline G4double GetDeltaIntersection() const;
182  inline G4double GetDeltaOneStep() const;
183 
186  // Auxiliary methods - their results can/will change during propagation
187 
188  inline void SetNavigatorForPropagating(G4Navigator* SimpleOrMultiNavigator);
190 
191  inline void SetThresholdNoZeroStep( G4int noAct,
192  G4int noHarsh,
193  G4int noAbandon );
194  inline G4int GetThresholdNoZeroSteps( G4int i );
195 
196  inline G4double GetZeroStepThreshold();
197  inline void SetZeroStepThreshold( G4double newLength );
198 
200  // Update the Locator with parameters from this class
201  // and from current field manager
202 
203  protected: // without description
204 
205  void PrintStepLengthDiagnostic( G4double currentProposedStepLength,
206  G4double decreaseFactor,
207  G4double stepTrial,
208  const G4FieldTrack& aFieldTrack);
209 
210  void ReportLoopingParticle( G4int count, G4double StepTaken,
211  G4double stepRequest, const char* methodName,
212  G4ThreeVector momentumVec,
213  G4VPhysicalVolume* physVol);
214  void ReportStuckParticle(G4int noZeroSteps, G4double proposedStep,
215  G4double lastTriedStep, G4VPhysicalVolume* physVol);
216 
217  private:
218 
219  // ----------------------------------------------------------------------
220  // DATA Members
221  // ----------------------------------------------------------------------
222 
223  // ==================================================================
224  // INVARIANTS - Must not change during tracking
225 
226  // ** PARAMETERS -----------
228  // Limit for the number of sub-steps taken in one call to ComputeStep
231  // (false) is less sensitive to incorrect safety
232 
233  // Thresholds for identifying "abnormal" cases - which cause looping
234  //
235  G4int fActionThreshold_NoZeroSteps = 2; // Threshold # - above it act
236  G4int fSevereActionThreshold_NoZeroSteps = 10; // Threshold # to act harshly
237  G4int fAbandonThreshold_NoZeroSteps = 50; // Threshold # to abandon
239  // Threshold *length* for counting of tiny or 'zero' steps
240 
242  // Maximum size of a step - for optimization (and to avoid problems)
243  // ** End of PARAMETERS -----
244 
246  // Geometrical tolerance defining surface thickness
247 
248  G4bool fAllocatedLocator; // Book-keeping
249 
250  // --------------------------------------------------------
251  // ** Dependent Objects - to which work is delegated
252 
254  // The Field Manager of the whole Detector. (default)
255 
257  // Refines candidate intersection
258 
260  // The filter encapsulates the algorithm which selects which
261  // intermediate points should be stored in a trajectory.
262  // When it is NULL, no intermediate points will be stored.
263  // Else PIF::ComputeStep must submit (all) intermediate
264  // points it calculates, to this filter. (jacek 04/11/2002)
265 
267  // Set externally - only by tracking / run manager
268  //
269  // ** End of Dependent Objects ----------------------------
270 
271  // End of INVARIANTS
272  // ==================================================================
273 
274  // STATE information
275  // -----------------
277  // The Field Manager of the current volume (may be the global)
278  G4bool fSetFieldMgr = false; // Has it been set for the current step?
279 
280  // Parameters of current step
281  G4double fEpsilonStep; // Relative accuracy of current Step
282  G4FieldTrack End_PointAndTangent; // End point storage
284  G4int fNoZeroStep = 0; // Count of zero Steps
285 
286  // State used for Optimisation
289  // Previous step information -- for use in adjust step size
292  // Last safety origin & value: for optimisation
293 
296  // For debugging purposes
297 
301 };
302 
303 // Inline methods
304 //
305 #include "G4PropagatorInField.icc"
306 
307 #endif