Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4NormalNavigation Class Reference

G4NormalNavigation is a concrete utility class for navigation in volumes containing only G4PVPlacement daughter volumes. More...

#include <G4NormalNavigation.hh>

Inheritance diagram for G4NormalNavigation:

Public Member Functions

 G4NormalNavigation ()
 ~G4NormalNavigation () override
G4bool LevelLocate (G4NavigationHistory &history, const G4VPhysicalVolume *blockedVol, const G4int blockedNum, const G4ThreeVector &globalPoint, const G4ThreeVector *globalDirection, const G4bool pLocatedOnEdge, G4ThreeVector &localPoint) final
G4double ComputeStep (const G4ThreeVector &localPoint, const G4ThreeVector &localDirection, const G4double currentProposedStepLength, G4double &newSafety, G4NavigationHistory &history, G4bool &validExitNormal, G4ThreeVector &exitNormal, G4bool &exiting, G4bool &entering, G4VPhysicalVolume *(*pBlockedPhysical), G4int &blockedReplicaNo) final
G4double ComputeSafety (const G4ThreeVector &localpoint, const G4NavigationHistory &history, const G4double pMaxLength=DBL_MAX) final
G4int GetVerboseLevel () const final
void SetVerboseLevel (G4int level) final
Public Member Functions inherited from G4VNavigation
virtual ~G4VNavigation ()=default
virtual void RelocateWithinVolume (G4VPhysicalVolume *, const G4ThreeVector &)
void CheckMode (G4bool mode)

Additional Inherited Members

Protected Attributes inherited from G4VNavigation
G4int fVerbose = 0
G4bool fCheck = false

Detailed Description

G4NormalNavigation is a concrete utility class for navigation in volumes containing only G4PVPlacement daughter volumes.

Definition at line 56 of file G4NormalNavigation.hh.

Constructor & Destructor Documentation

◆ G4NormalNavigation()

G4NormalNavigation::G4NormalNavigation ( )

Constructor and Destructor.

Definition at line 39 of file G4NormalNavigation.cc.

40{
41 fLogger = new G4NavigationLogger("G4NormalNavigation");
42}

◆ ~G4NormalNavigation()

G4NormalNavigation::~G4NormalNavigation ( )
override

Definition at line 48 of file G4NormalNavigation.cc.

49{
50 delete fLogger;
51}

Member Function Documentation

◆ ComputeSafety()

G4double G4NormalNavigation::ComputeSafety ( const G4ThreeVector & localpoint,
const G4NavigationHistory & history,
const G4double pMaxLength = DBL_MAX )
finalvirtual

Calculates the isotropic distance to the nearest boundary from the specified point in the local coordinate system. The localpoint utilised must be within the current volume.

Parameters
[in]localPointLocal point.
[in]historyNavigation history.
[in]pMaxLengthMaximum step length beyond which volumes need not be checked.
Returns
Length from current point to closest surface.

Implements G4VNavigation.

Definition at line 333 of file G4NormalNavigation.cc.

336{
337 G4VPhysicalVolume *motherPhysical, *samplePhysical;
338 G4LogicalVolume *motherLogical;
339 G4VSolid *motherSolid;
340 G4double motherSafety, ourSafety;
341 G4long localNoDaughters, sampleNo;
342
343 motherPhysical = history.GetTopVolume();
344 motherLogical = motherPhysical->GetLogicalVolume();
345 motherSolid = motherLogical->GetSolid();
346
347 // Compute mother safety
348 //
349 motherSafety = motherSolid->DistanceToOut(localPoint);
350 ourSafety = motherSafety; // Working isotropic safety
351
352#ifdef G4VERBOSE
353 if( fCheck )
354 {
355 fLogger->ComputeSafetyLog(motherSolid,localPoint,motherSafety,true,1);
356 }
357#endif
358
359 // Compute daughter safeties
360 //
361 localNoDaughters = motherLogical->GetNoDaughters();
362 for ( sampleNo=localNoDaughters-1; sampleNo>=0; sampleNo-- )
363 {
364 samplePhysical = motherLogical->GetDaughter(sampleNo);
365 G4AffineTransform sampleTf(samplePhysical->GetRotation(),
366 samplePhysical->GetTranslation());
367 sampleTf.Invert();
368 const G4ThreeVector samplePoint =
369 sampleTf.TransformPoint(localPoint);
370 const G4VSolid *sampleSolid =
371 samplePhysical->GetLogicalVolume()->GetSolid();
372 const G4double sampleSafety =
373 sampleSolid->DistanceToIn(samplePoint);
374 if ( sampleSafety<ourSafety )
375 {
376 ourSafety = sampleSafety;
377 }
378#ifdef G4VERBOSE
379 if(fCheck)
380 {
381 fLogger->ComputeSafetyLog(sampleSolid, samplePoint,
382 sampleSafety, false, 0);
383 // Not mother, no banner
384 }
385#endif
386 }
387 return ourSafety;
388}
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
long G4long
Definition G4Types.hh:87
G4VSolid * GetSolid() const
std::size_t GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const std::size_t i) const
G4VPhysicalVolume * GetTopVolume() const
const G4RotationMatrix * GetRotation() const
const G4ThreeVector GetTranslation() const
G4LogicalVolume * GetLogicalVolume() const
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0

◆ ComputeStep()

G4double G4NormalNavigation::ComputeStep ( const G4ThreeVector & localPoint,
const G4ThreeVector & localDirection,
const G4double currentProposedStepLength,
G4double & newSafety,
G4NavigationHistory & history,
G4bool & validExitNormal,
G4ThreeVector & exitNormal,
G4bool & exiting,
G4bool & entering,
G4VPhysicalVolume ** pBlockedPhysical,
G4int & blockedReplicaNo )
finalvirtual

Computes the length of a step to the next boundary. Does not test against pBlockedPhysical. Identifies the next candidate volume (if a daughter of the current volume), and returns it in: pBlockedPhysical, blockedReplicaNo.

Parameters
[in]localPointLocal point.
[in]localDirectionPointer to local direction or null pointer.
[in]currentProposedStepLengthCurrent proposed step length.
[in,out]newSafetyNew safety.
[in,out]historyNavigation history.
[in,out]validExitNormalFlag to indicate whether exit normal is valid or not.
[in,out]exitNormalExit normal.
[in,out]exitingFlag to indicate whether exiting a volume.
[in,out]enteringFlag to indicate whether entering a volume.
[in,out]pBlockedPhysicalBlocked physical volume that should be ignored in queries.
[in,out]blockedReplicaNoCopy number for blocked replica volumes.
Returns
Length from current point to next boundary surface along localDirection.

Implements G4VNavigation.

Definition at line 63 of file G4NormalNavigation.cc.

74{
75 G4VPhysicalVolume *motherPhysical, *samplePhysical,
76 *blockedExitedVol = nullptr;
77 G4LogicalVolume *motherLogical;
78 G4VSolid *motherSolid;
79 G4ThreeVector sampleDirection;
80 G4double ourStep = currentProposedStepLength, ourSafety;
81 G4double motherSafety, motherStep = DBL_MAX;
82 G4long localNoDaughters, sampleNo;
83 G4bool motherValidExitNormal = false;
84 G4ThreeVector motherExitNormal;
85
86 motherPhysical = history.GetTopVolume();
87 motherLogical = motherPhysical->GetLogicalVolume();
88 motherSolid = motherLogical->GetSolid();
89
90 // Compute mother safety
91 //
92 motherSafety = motherSolid->DistanceToOut(localPoint);
93 ourSafety = motherSafety; // Working isotropic safety
94
95 localNoDaughters = motherLogical->GetNoDaughters();
96
97#ifdef G4VERBOSE
98 if ( fCheck && ( (localNoDaughters>0) || (ourStep < motherSafety) ) )
99 {
100 fLogger->PreComputeStepLog(motherPhysical, motherSafety, localPoint);
101 }
102#endif
103 // Compute daughter safeties & intersections
104 //
105
106 // Exiting normal optimisation
107 //
108 if ( exiting && validExitNormal )
109 {
110 if ( localDirection.dot(exitNormal)>=kMinExitingNormalCosine )
111 {
112 // Block exited daughter volume
113 //
114 blockedExitedVol = (*pBlockedPhysical);
115 ourSafety = 0;
116 }
117 }
118 exiting = false;
119 entering = false;
120
121#ifdef G4VERBOSE
122 if ( fCheck )
123 {
124 // Compute early:
125 // a) to check whether point is (wrongly) outside
126 // (signaled if step < 0 or step == kInfinity )
127 // b) to check value against answer of daughters!
128
129 motherStep = motherSolid->DistanceToOut(localPoint,
130 localDirection,
131 true,
132 &motherValidExitNormal,
133 &motherExitNormal);
134
135 if( (motherStep >= kInfinity) || (motherStep < 0.0) )
136 {
137 // Error - indication of being outside solid !!
138 fLogger->ReportOutsideMother(localPoint, localDirection, motherPhysical);
139
140 ourStep = motherStep = 0.0;
141
142 exiting = true;
143 entering = false;
144
145 // If we are outside the solid does the normal make sense?
146 validExitNormal = motherValidExitNormal;
147 exitNormal = motherExitNormal;
148
149 *pBlockedPhysical = nullptr; // or motherPhysical ?
150 blockedReplicaNo = 0; // or motherReplicaNumber ?
151
152 newSafety = 0.0;
153 return ourStep;
154 }
155 }
156#endif
157
158 for ( sampleNo=localNoDaughters-1; sampleNo>=0; sampleNo--)
159 {
160 samplePhysical = motherLogical->GetDaughter(sampleNo);
161 if ( samplePhysical!=blockedExitedVol )
162 {
163 G4AffineTransform sampleTf(samplePhysical->GetRotation(),
164 samplePhysical->GetTranslation());
165 sampleTf.Invert();
166 const G4ThreeVector samplePoint = sampleTf.TransformPoint(localPoint);
167 const G4VSolid *sampleSolid =
168 samplePhysical->GetLogicalVolume()->GetSolid();
169 const G4double sampleSafety =
170 sampleSolid->DistanceToIn(samplePoint);
171
172 if ( sampleSafety<ourSafety )
173 {
174 ourSafety=sampleSafety;
175 }
176
177 if ( sampleSafety<=ourStep )
178 {
179 sampleDirection = sampleTf.TransformAxis(localDirection);
180 const G4double sampleStep =
181 sampleSolid->DistanceToIn(samplePoint,sampleDirection);
182#ifdef G4VERBOSE
183 if( fCheck )
184 {
185 fLogger->PrintDaughterLog(sampleSolid, samplePoint,
186 sampleSafety, true,
187 sampleDirection, sampleStep);
188 }
189#endif
190 if ( sampleStep<=ourStep )
191 {
192 ourStep = sampleStep;
193 entering = true;
194 exiting = false;
195 *pBlockedPhysical = samplePhysical;
196 blockedReplicaNo = -1;
197#ifdef G4VERBOSE
198 if( fCheck )
199 {
200 fLogger->AlongComputeStepLog(sampleSolid, samplePoint,
201 sampleDirection, localDirection,
202 sampleSafety, sampleStep);
203 }
204#endif
205 }
206
207#ifdef G4VERBOSE
208 if( fCheck && (sampleStep < kInfinity) && (sampleStep >= motherStep) )
209 {
210 // The intersection point with the daughter is at or after the exit
211 // point from the mother volume. Double check!
212 fLogger->CheckDaughterEntryPoint(sampleSolid,
213 samplePoint, sampleDirection,
214 motherSolid,
215 localPoint, localDirection,
216 motherStep, sampleStep);
217 }
218#endif
219 } // end of if ( sampleSafety <= ourStep )
220#ifdef G4VERBOSE
221 else if ( fCheck )
222 {
223 fLogger->PrintDaughterLog(sampleSolid, samplePoint,
224 sampleSafety, false,
225 G4ThreeVector(0.,0.,0.), -1.0 );
226 }
227#endif
228 }
229 }
230 if ( currentProposedStepLength<ourSafety )
231 {
232 // Guaranteed physics limited
233 //
234 entering = false;
235 exiting = false;
236 *pBlockedPhysical = nullptr;
237 ourStep = kInfinity;
238 }
239 else
240 {
241 // Consider intersection with mother solid
242 //
243 if ( motherSafety<=ourStep )
244 {
245 if ( !fCheck ) // The call is moved above when running in check_mode
246 {
247 motherStep = motherSolid->DistanceToOut(localPoint,
248 localDirection,
249 true,
250 &motherValidExitNormal,
251 &motherExitNormal);
252 }
253#ifdef G4VERBOSE
254 else // check_mode
255 {
256 fLogger->PostComputeStepLog(motherSolid, localPoint, localDirection,
257 motherStep, motherSafety);
258 if( motherValidExitNormal )
259 {
260 fLogger->CheckAndReportBadNormal(motherExitNormal,
261 localPoint,
262 localDirection,
263 motherStep,
264 motherSolid,
265 "From motherSolid::DistanceToOut" );
266 }
267 }
268#endif
269
270 if( (motherStep >= kInfinity) || (motherStep < 0.0) )
271 {
272#ifdef G4VERBOSE
273 if( fCheck ) // Clearly outside the mother solid!
274 {
275 fLogger->ReportOutsideMother(localPoint, localDirection,
276 motherPhysical);
277 }
278#endif
279 ourStep = motherStep = 0.0;
280 exiting = true;
281 entering = false;
282 // validExitNormal= motherValidExitNormal;
283 // exitNormal= motherExitNormal;
284 // The normal could be useful - but only if near the mother
285 // But it could be unreliable!
286 validExitNormal = false;
287 *pBlockedPhysical = nullptr; // or motherPhysical ?
288 blockedReplicaNo = 0; // or motherReplicaNumber ?
289 newSafety= 0.0;
290 return ourStep;
291 }
292
293 if ( motherStep<=ourStep )
294 {
295 ourStep = motherStep;
296 exiting = true;
297 entering = false;
298 validExitNormal = motherValidExitNormal;
299 exitNormal = motherExitNormal;
300
301 if ( motherValidExitNormal )
302 {
303 const G4RotationMatrix *rot = motherPhysical->GetRotation();
304 if (rot != nullptr)
305 {
306 exitNormal *= rot->inverse();
307#ifdef G4VERBOSE
308 if( fCheck )
309 {
310 fLogger->CheckAndReportBadNormal(exitNormal, // rotated
311 motherExitNormal, // original
312 *rot,
313 "From RotationMatrix" );
314 }
315#endif
316 }
317 }
318 }
319 else
320 {
321 validExitNormal = false;
322 }
323 }
324 }
325 newSafety = ourSafety;
326 return ourStep;
327}
CLHEP::HepRotation G4RotationMatrix
bool G4bool
Definition G4Types.hh:86
double dot(const Hep3Vector &) const
HepRotation inverse() const
#define DBL_MAX
Definition templates.hh:62

◆ GetVerboseLevel()

G4int G4NormalNavigation::GetVerboseLevel ( ) const
finalvirtual

Verbosity control.

Note
If level>0 && G4VERBOSE, printout can occur.

Reimplemented from G4VNavigation.

Definition at line 398 of file G4NormalNavigation.cc.

399{
400 return fLogger->GetVerboseLevel();
401}

◆ LevelLocate()

G4bool G4NormalNavigation::LevelLocate ( G4NavigationHistory & history,
const G4VPhysicalVolume * blockedVol,
const G4int blockedNum,
const G4ThreeVector & globalPoint,
const G4ThreeVector * globalDirection,
const G4bool pLocatedOnEdge,
G4ThreeVector & localPoint )
inlinefinalvirtual

Searches positioned volumes in mother at current top level of history for volume containing globalPoint. Do not test against blockedVol. If a containing volume is found, push it onto navigation history state and return true, else return false (the point lying in the mother but not any of the daughters).

Parameters
[in,out]historyNavigation history.
[in,out]blockedVolBlocked volume to be ignored in queries.
[in,out]blockedNumCopy number for blocked volumes.
[in,out]globalPointPoint in global coordinates system.
[in,out]globalDirectionPointer to global direction or null.
[in]pLocatedOnEdgeFlag specifying if point is located on edge.
[in,out]localPointPoint in local coordinates system.
Returns
Whether a containing volume has been found.

Implements G4VNavigation.

◆ SetVerboseLevel()

void G4NormalNavigation::SetVerboseLevel ( G4int level)
finalvirtual

Sets current verbosity level.

Reimplemented from G4VNavigation.

Definition at line 407 of file G4NormalNavigation.cc.

408{
409 fLogger->SetVerboseLevel(level);
410}

Referenced by LevelLocate().


The documentation for this class was generated from the following files: