Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PathFinder.hh
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// class G4PathFinder
27//
28// Class description:
29//
30// This class directs the lock-stepped propagation of a track in the
31// 'mass' and other parallel geometries. It ensures that tracking
32// in a magnetic field sees these parallel geometries at each trial step,
33// and that the earliest boundary limits the step.
34//
35// For the movement in field, it relies on the class G4PropagatorInField
36
37// History:
38// -------
39// 7.10.05 John Apostolakis, Draft design
40// 26.04.06 John Apostolakis, Revised design and first implementation
41// ---------------------------------------------------------------------------
42#ifndef G4PATHFINDER_HH
43#define G4PATHFINDER_HH 1
44
45#include <vector>
46#include "G4Types.hh"
47
48#include "G4FieldTrack.hh"
49
51class G4Navigator;
52
53#include "G4TouchableHandle.hh"
54#include "G4FieldTrack.hh"
55#include "G4MultiNavigator.hh"
56
58
60{
61
62 public: // with description
63
64 static G4PathFinder* GetInstance();
65 // Retrieve singleton instance and create it if not existing.
66
68 // Retrieve singleton instance pointer.
69
70 G4double ComputeStep( const G4FieldTrack& pFieldTrack,
71 G4double pCurrentProposedStepLength,
72 G4int navigatorId, // Identifies the geometry
73 G4int stepNo, // See next step/check
74 G4double& pNewSafety, // Only for this geometry
75 ELimited& limitedStep,
76 G4FieldTrack& EndState,
77 G4VPhysicalVolume* currentVolume );
78 // Compute the next geometric Step -- curved or linear
79 // If it is called with a larger 'stepNo' it will execute a new step;
80 // if 'stepNo' is same as last call, then the results for
81 // the geometry with Id. number 'navigatorId' will be returned.
82
83 void Locate( const G4ThreeVector& position,
84 const G4ThreeVector& direction,
85 G4bool relativeSearch = true);
86 // Make primary relocation of global point in all navigators,
87 // and update them.
88
89 void ReLocate( const G4ThreeVector& position );
90 // Make secondary relocation of global point (within safety only)
91 // in all navigators, and update them.
92
94 const G4ThreeVector& direction,
95 G4VPhysicalVolume* massStartVol = nullptr);
96 // Check and cache set of active navigators.
97
98 void EndTrack();
99 // Signal end of tracking of current track.
100 // Reset internal state
101 // Inform TransportationManager to use 'ordinary' Navigator
102
104 inline G4VPhysicalVolume* GetLocatedVolume( G4int navId ) const;
105
106 // -----------------------------------------------------------------
107
108 inline G4bool IsParticleLooping() const;
109
110 inline G4double GetCurrentSafety() const;
111 // Minimum value of safety after last ComputeStep
112 inline G4double GetMinimumStep() const;
113 // Get the minimum step size from the last ComputeStep call
114 // - in case full step is taken, this is kInfinity
115 inline unsigned int GetNumberGeometriesLimitingStep() const;
116
117 G4double ComputeSafety( const G4ThreeVector& globalPoint);
118 // Recompute safety for the relevant point the endpoint of the last step!!
119 // Maintain vector of individual safety values (for next method)
120
121 G4double ObtainSafety( G4int navId, G4ThreeVector& globalCenterPoint );
122 // Obtain safety for navigator/geometry navId for last point 'computed'
123 // --> last point for which ComputeSafety was called
124 // Returns the point (center) for which this safety is valid
125
126 void EnableParallelNavigation( G4bool enableChoice = true );
127 // Must call it to ensure that PathFinder is prepared,
128 // especially for curved tracks. If true it switches PropagatorInField
129 // to use MultiNavigator. Must call it with false to undo (=PiF use
130 // Navigator for tracking!)
131
132 inline G4int SetVerboseLevel(G4int lev = -1);
133
134 public: // with description
135
136 inline G4int GetMaxLoopCount() const;
137 inline void SetMaxLoopCount( G4int new_max );
138 // A maximum for the number of steps that a (looping) particle can take
139
140 public: // without description
141
142 inline void MovePoint();
143 // Signal that location will be moved -- internal use primarily
144
145 // To provide best compatibility between Coupled and Old Transportation
146 // the next two methods are provided:
147
148 G4double LastPreSafety( G4int navId, G4ThreeVector& globalCenterPoint,
149 G4double& minSafety );
150 // Obtain last safety needed in ComputeStep (for geometry navId)
151 // --> last point at which ComputeStep recalculated safety
152 // Returns the point (center) for which this safety is valid
153 // and also the minimum safety over all navigators (i.e. full)
154
156 // Tell PathFinder to copy PostStep Safety to PreSafety
157 // (for use at next step)
158
160 // Convert ELimited to string
161
163 // Destructor
164
165 protected: // without description
166
167 G4double DoNextLinearStep( const G4FieldTrack& FieldTrack,
168 G4double proposedStepLength);
169
170 G4double DoNextCurvedStep( const G4FieldTrack& FieldTrack,
171 G4double proposedStepLength,
172 G4VPhysicalVolume* pCurrentPhysVolume);
173
174 void WhichLimited();
175 void PrintLimited();
176 // Print key details out for debugging
177
179 // Whether use safety to discard unneccesary calls to navigator
180
181 void ReportMove( const G4ThreeVector& OldV,
182 const G4ThreeVector& NewV,
183 const G4String& Quantity ) const;
184 // Helper method to report movement (likely of initial point)
185
186 protected:
187
188 G4PathFinder(); // Singleton
189
190 inline G4Navigator* GetNavigator(G4int n) const;
191
192 private:
193
194 // ----------------------------------------------------------------------
195 // DATA Members
196 // ----------------------------------------------------------------------
197
198 G4MultiNavigator* fpMultiNavigator;
199 // Object that enables G4PropagatorInField to see many geometries
200
201 G4int fNoActiveNavigators = 0;
202 G4bool fNewTrack = false; // Flag a new track (ensure first step)
203
204 static const G4int fMaxNav = 16;
205
206 // Global state (retained during stepping for one track)
207
208 G4Navigator* fpNavigator[fMaxNav];
209
210 // State changed in a step computation
211
212 ELimited fLimitedStep[fMaxNav];
213 G4bool fLimitTruth[fMaxNav];
214 G4double fCurrentStepSize[fMaxNav];
215 G4int fNoGeometriesLimiting = 0; // How many processes contribute to limit
216
217 G4ThreeVector fPreSafetyLocation;
218 // last initial position for which safety evaluated
219 G4double fPreSafetyMinValue = -1.0;
220 // - corresponding value of full safety
221 G4double fPreSafetyValues[ fMaxNav ];
222 // Safeties for the above point
223
224 // This part of the state can be retained for several calls --> CARE
225
226 G4ThreeVector fPreStepLocation;
227 // point where last ComputeStep called
228 G4double fMinSafety_PreStepPt = -1.0;
229 // - corresponding value of full safety
230 G4double fCurrentPreStepSafety[ fMaxNav ];
231 // Safeties for the above point.
232 // This changes at each step, so it can differ when steps
233 // inside min-safety are made
234
235 G4bool fPreStepCenterRenewed = false;
236 // Whether PreSafety coincides with PreStep point
237
238 G4double fMinStep = -1.0; // As reported by Navigators -- can be kInfinity
239 G4double fTrueMinStep = -1.0; // Corrected in case >= proposed
240
241 // State after calling 'locate'
242 //
243 G4VPhysicalVolume* fLocatedVolume[fMaxNav];
244 G4ThreeVector fLastLocatedPosition;
245
246 // State after calling 'ComputeStep'
247 // (others member variables will be affected)
248 //
249 G4FieldTrack fEndState; // Point, velocity, ... at proposed step end
250 G4bool fFieldExertedForce = false; // In current proposed step
251
252 G4bool fRelocatedPoint = false; // Signals that point was or is being moved
253 // from the position of the last location or
254 // the endpoint resulting from ComputeStep()
255 // -- invalidates fEndState
256
257 // State for 'ComputeSafety' and related methods
258 //
259 G4ThreeVector fSafetyLocation;
260 // point where ComputeSafety is called
261 G4double fMinSafety_atSafLocation = -1.0;
262 // - corresponding value of safety
263 G4double fNewSafetyComputed[ fMaxNav ];
264 // Safeties for last ComputeSafety
265
266 // State for Step numbers
267 //
268 G4int fLastStepNo = -1, fCurrentStepNo = -1;
269
270 G4int fVerboseLevel = 0; // For debugging purposes
271
272 G4TransportationManager* fpTransportManager; // Cache for frequent use
273 G4PropagatorInField* fpFieldPropagator;
274
275 G4double kCarTolerance;
276
277 static G4ThreadLocal G4PathFinder* fpPathFinder;
278};
279
280// ********************************************************************
281// Inline methods.
282// ********************************************************************
283
285{
286 G4VPhysicalVolume* vol = nullptr;
287 if( (navId < fMaxNav) && (navId >= 0) ) { vol= fLocatedVolume[navId]; }
288 return vol;
289}
290
292{
293 G4int old = fVerboseLevel;
294 fVerboseLevel = newLevel;
295 return old;
296}
297
299{
300 return fMinStep;
301}
302
304{
305 unsigned int noGeometries = fNoGeometriesLimiting;
306 return noGeometries;
307}
308
310{
311 return fMinSafety_PreStepPt;
312}
313
315{
316 fRelocatedPoint = true;
317}
318
320{
321 if( (n>fNoActiveNavigators) || (n<0) ) { n=0; }
322 return fpNavigator[n];
323}
324
325inline G4double
327{
328 globalCenterPoint = fSafetyLocation;
329 return fNewSafetyComputed[ navId ];
330}
331
332inline G4double
334 G4double& minSafety )
335{
336 globalCenterPoint = fPreSafetyLocation;
337 minSafety = fPreSafetyMinValue;
338 return fPreSafetyValues[ navId ];
339}
340
341#endif
ELimited
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4double ComputeSafety(const G4ThreeVector &globalPoint)
void EnableParallelNavigation(G4bool enableChoice=true)
G4Navigator * GetNavigator(G4int n) const
void ReLocate(const G4ThreeVector &position)
void ReportMove(const G4ThreeVector &OldV, const G4ThreeVector &NewV, const G4String &Quantity) const
void WhichLimited()
G4double DoNextLinearStep(const G4FieldTrack &FieldTrack, G4double proposedStepLength)
G4bool IsParticleLooping() const
unsigned int GetNumberGeometriesLimitingStep() const
void PushPostSafetyToPreSafety()
G4double ObtainSafety(G4int navId, G4ThreeVector &globalCenterPoint)
G4VPhysicalVolume * GetLocatedVolume(G4int navId) const
G4double ComputeStep(const G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4int navigatorId, G4int stepNo, G4double &pNewSafety, ELimited &limitedStep, G4FieldTrack &EndState, G4VPhysicalVolume *currentVolume)
G4double DoNextCurvedStep(const G4FieldTrack &FieldTrack, G4double proposedStepLength, G4VPhysicalVolume *pCurrentPhysVolume)
void Locate(const G4ThreeVector &position, const G4ThreeVector &direction, G4bool relativeSearch=true)
void MovePoint()
G4bool UseSafetyForOptimization(G4bool)
G4double LastPreSafety(G4int navId, G4ThreeVector &globalCenterPoint, G4double &minSafety)
G4String & LimitedString(ELimited lim)
G4double GetCurrentSafety() const
void PrintLimited()
G4int GetMaxLoopCount() const
void PrepareNewTrack(const G4ThreeVector &position, const G4ThreeVector &direction, G4VPhysicalVolume *massStartVol=nullptr)
void SetMaxLoopCount(G4int new_max)
G4double GetMinimumStep() const
static G4PathFinder * GetInstance()
Definition: G4PathFinder.cc:52
G4int SetVerboseLevel(G4int lev=-1)
G4TouchableHandle CreateTouchableHandle(G4int navId) const
static G4PathFinder * GetInstanceIfExist()
Definition: G4PathFinder.cc:66
#define G4ThreadLocal
Definition: tls.hh:77