Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MultiNavigator.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// G4MultiNavigator
27//
28// Class description:
29//
30// Utility class for polling the navigators of several geometries to
31// identify the next boundary.
32
33// Author: John Apostolakis (CERN), November 2006
34// --------------------------------------------------------------------
35#ifndef G4MULTINAVIGATOR_HH
36#define G4MULTINAVIGATOR_HH 1
37
38#include <iostream>
39
40#include "geomdefs.hh"
41#include "G4ThreeVector.hh"
42#include "G4Navigator.hh"
43
44#include "G4TouchableHandle.hh"
45
47
49
52
53/**
54 * @brief G4MultiNavigator is a utility class for polling the navigators
55 * of several geometries to identify the next boundary.
56 */
57
59{
60 public:
61
62 friend std::ostream& operator << (std::ostream& os, const G4Navigator& n);
63
64 /**
65 * Constructor and default Destructor.
66 */
68 ~G4MultiNavigator() override = default;
69
70 /**
71 * Computes the distance to the next boundary of any geometry.
72 * @param[in] pGlobalPoint The point in global coordinates system.
73 * @param[in] pDirection The normalised vector direction.
74 * @param[in] pCurrentProposedStepLength Current proposed step length.
75 * @param[in,out] newSafety New safety.
76 * @returns Length from current point to next boundary surface along
77 * @p pDirection.
78 */
79 G4double ComputeStep( const G4ThreeVector& pGlobalPoint,
80 const G4ThreeVector& pDirection,
81 const G4double pCurrentProposedStepLength,
82 G4double& pNewSafety ) override;
83
84 /**
85 * Gets values for a single geometry.
86 * @param[in] navigatorId The navigator identifier.
87 * @param[in,out] pnewSafety New safety for this geometry.
88 * @param[in,out] minStepLast The last minimum step returned.
89 * @param[in,out] limitedStep The step characterisation returned.
90 * @returns The step size for the geometry associated to 'navigatorId'.
91 */
92 G4double ObtainFinalStep( G4int navigatorId,
93 G4double& pNewSafety, // for this geom
94 G4double& minStepLast,
95 ELimited& limitedStep );
96
97 /**
98 * Finds which geometries are registered for this particles, and keeps info.
99 */
100 void PrepareNavigators();
101
102 /**
103 * Prepares Navigators and locates.
104 * @param[in] position The position point in global coordinates system.
105 * @param[in] direction The normalised vector direction.
106 */
108 const G4ThreeVector direction );
109
110 /**
111 * Resets the geometrical hierarchy for all geometries.
112 * Use the touchable history for the first (mass) geometry.
113 * @note In order to call this the geometries MUST be closed.
114 * @param[in] point The point in global coordinates system.
115 * @param[in] direction The normalised vector direction.
116 * @param[in] h The touchable history to be used for initialisation.
117 * @returns The pointer to the volume in the first (mass) geometry.
118 */
120 const G4ThreeVector& direction,
121 const G4TouchableHistory& h ) override;
122
123 /**
124 * Locates the point in all geometries.
125 * Maintains a vector of other volumes, to be returned separately.
126 * @note In order to call this the geometry MUST be closed.
127 * @param[in] point The point in global coordinates system.
128 * @param[in] direction The normalised vector direction.
129 * @param[in] pRelativeSearch Flag to specify where search starts from.
130 * @param[in] ignoreDirection Flag to specify if to use direction or not.
131 * @returns The volume in the first (mass) geometry.
132 */
134 const G4ThreeVector* direction = nullptr,
135 const G4bool pRelativeSearch = true,
136 const G4bool ignoreDirection = true) override;
137
138 /**
139 * Relocates in all geometries for point that has not changed volume,
140 * i.e. is within safety in all geometries or its distance is less that
141 * along the direction of a computed step.
142 * @param[in] position The position point in global coordinates system.
143 */
145
146 /**
147 * Calculates the isotropic distance to the nearest boundary in any
148 * geometry from the specified point in the global coordinates system.
149 * @note The geometry must be closed.
150 * @param[in] globalpoint The point in global coordinates system.
151 * The point must be within the current volume.
152 * @param[in] pProposedMaxLength The proposed maximum length is used
153 * to avoid volume safety calculations.
154 * @param[in] keepState Flag to instruct keeping the state (default false)
155 * to ensure minimum side effects from the call.
156 * @returns Length from current point to closest boundary surface.
157 * The value returned is usually an underestimate.
158 */
159 G4double ComputeSafety( const G4ThreeVector& globalpoint,
160 const G4double pProposedMaxLength = DBL_MAX,
161 const G4bool keepState = false ) override;
162
163 /**
164 * Returns a reference counted handle to a touchable history.
165 */
167
168 /**
169 * Obtains the Normal vector to a surface (in local coordinates)
170 * pointing out of previous volume and into current volume
171 * Convention: the *local* normal is in the coordinate system of the
172 * *final* volume. The method takes full care about how to calculate
173 * this normal, but if the surfaces are not convex it will return
174 * valid=false.
175 * @param[in,out] obtained Flag indicating if normal is valid.
176 * @returns A Exit Surface Normal vector and validity too.
177 */
178 G4ThreeVector GetLocalExitNormal( G4bool* obtained ) override;
179
180 /**
181 * Obtains the Normal vector to a surface (in local coordinates)
182 * pointing out of previous volume and into current volume, and
183 * checks the current point against expected 'local' value.
184 * Convention: the *local* normal is in the coordinate system of the
185 * *final* volume. The method takes full care about how to calculate
186 * this normal, but if the surfaces are not convex it will return
187 * valid=false.
188 * @param[in] point Point in global coordinates system to compare to.
189 * @param[in,out] obtained Flag indicating if normal is valid.
190 * @returns A Exit Surface Normal vector and validity too.
191 */
193 G4bool* obtained ) override;
194
195 /**
196 * Obtains the Normal vector to a surface (in global coordinates)
197 * pointing out of previous volume and into current volume
198 * The method takes full care about how to calculate the normal,
199 * but if the surfaces are not convex it will return valid=false.
200 * @param[in] point Point in global coordinates system to compare to.
201 * @param[in,out] obtained Flag indicating if normal is valid.
202 * @returns A Exit Surface Normal vector and validity too.
203 */
205 G4bool* obtained ) override;
206
207 /**
208 * Returns a pointer to a navigator, given its index.
209 */
210 inline G4Navigator* GetNavigator( G4int n ) const;
211
212 protected:
213
214 /**
215 * Utility method to reset the navigator state machine.
216 */
217 void ResetState() override;
218
219 /**
220 * Renavigates & resets hierarchy described by the current history,
221 * i.e. resets volumes and recomputes transforms and/or solids of
222 * replicated/parameterised volumes.
223 */
224 void SetupHierarchy() override;
225
226 /**
227 * Flags which processes limited the step.
228 */
229 void WhichLimited();
230
231 /**
232 * Auxiliary, debugging printing.
233 */
234 void PrintLimited();
235
236 /**
237 * Checks if mass world pointed has been changed => issues and exception.
238 */
239 void CheckMassWorld();
240
241 private:
242
243 // STATE Information
244
245 G4int fNoActiveNavigators = 0;
246 static const G4int fMaxNav = 16;
247 G4VPhysicalVolume* fLastMassWorld = nullptr;
248
249 /** Global state (retained during stepping for one track). */
250 G4Navigator* fpNavigator[fMaxNav];
251
252 // State after a step computation
253 //
254 ELimited fLimitedStep[fMaxNav];
255 G4bool fLimitTruth[fMaxNav];
256 G4double fCurrentStepSize[fMaxNav];
257 G4double fNewSafety[ fMaxNav ]; // Safety for starting point
258 G4int fNoLimitingStep = -1; // How many geometries limited the step
259 G4int fIdNavLimiting = -1; // Id of Navigator limiting step
260
261 // Lowest values - determine step length, and safety
262 //
263 G4double fMinStep = -kInfinity; // As reported by Navigators
264 G4double fMinSafety = -kInfinity;
265 G4double fTrueMinStep = -kInfinity; // Corrected if fMinStep>=proposed
266
267 // State after calling 'locate'
268 //
269 G4VPhysicalVolume* fLocatedVolume[fMaxNav];
270 G4ThreeVector fLastLocatedPosition;
271
272 // Cache of safety information
273 //
274 G4ThreeVector fSafetyLocation; // point where ComputeSafety() is called
275 G4double fMinSafety_atSafLocation = -1.0; // - corresponding value of safety
276 G4ThreeVector fPreStepLocation; // point where last ComputeStep() called
277 G4double fMinSafety_PreStepPt = -1.0; // - corresponding value of safety
278
279 G4TransportationManager* pTransportManager; // Cache for frequent use
280};
281
282// --------------------------------------------------------------------
283// Inline methods
284// --------------------------------------------------------------------
285
287{
288 if( (n>fNoActiveNavigators) || (n<0) ) { n=0; }
289 return fpNavigator[n];
290}
291
292#endif
@ kDoNot
@ kUndefLimited
@ kUnique
@ kSharedOther
@ kSharedTransport
CLHEP::Hep3Vector G4ThreeVector
G4ReferenceCountedHandle< G4VTouchable > G4TouchableHandle
G4TouchableHandle is a type providing reference counting mechanism for any kind of touchable objects....
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4ThreeVector GetLocalExitNormalAndCheck(const G4ThreeVector &point, G4bool *obtained) override
G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true) override
G4Navigator * GetNavigator(G4int n) const
G4double ObtainFinalStep(G4int navigatorId, G4double &pNewSafety, G4double &minStepLast, ELimited &limitedStep)
void ResetState() override
~G4MultiNavigator() override=default
void SetupHierarchy() override
G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &point, G4bool *obtained) override
void LocateGlobalPointWithinVolume(const G4ThreeVector &position) override
G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=false) override
G4double ComputeStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety) override
G4ThreeVector GetLocalExitNormal(G4bool *obtained) override
void PrepareNewTrack(const G4ThreeVector &position, const G4ThreeVector direction)
friend std::ostream & operator<<(std::ostream &os, const G4Navigator &n)
G4VPhysicalVolume * ResetHierarchyAndLocate(const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &h) override
G4TouchableHandle CreateTouchableHistoryHandle() const override
G4TouchableHistory is an object representing a touchable detector element, and its history in the geo...
G4TransportationManager is a singleton class which stores the navigator used by the transportation pr...
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
#define DBL_MAX
Definition templates.hh:62