Geant4-11
G4Navigator.icc
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 G4Navigator Inline implementation
27//
28// ********************************************************************
29
30// ********************************************************************
31// GetCurrentLocalCoordinate
32//
33// Returns the local coordinate of the current track
34// ********************************************************************
35//
36inline
37G4ThreeVector G4Navigator::GetCurrentLocalCoordinate() const
38{
39 return fLastLocatedPointLocal;
40}
41
42// ********************************************************************
43// ComputeLocalAxis
44//
45// Returns local direction of vector direction in world coord system
46// ********************************************************************
47//
48inline
49G4ThreeVector G4Navigator::ComputeLocalAxis(const G4ThreeVector& pVec) const
50{
51 return fHistory.GetTopTransform().TransformAxis(pVec);
52}
53
54// ********************************************************************
55// ComputeLocalPoint
56//
57// Returns local coordinates of a point in the world coord system
58// ********************************************************************
59//
60inline
61G4ThreeVector
62G4Navigator::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const
63{
64 return fHistory.GetTopTransform().TransformPoint(pGlobalPoint);
65}
66
67// ********************************************************************
68// GetWorldVolume
69//
70// Returns the current world (`topmost') volume
71// ********************************************************************
72//
73inline
74G4VPhysicalVolume* G4Navigator::GetWorldVolume() const
75{
76 return fTopPhysical;
77}
78
79// ********************************************************************
80// SetWorldVolume
81//
82// Sets the world (`topmost') volume
83// ********************************************************************
84//
85inline
86void G4Navigator::SetWorldVolume(G4VPhysicalVolume* pWorld)
87{
88 if ( !(pWorld->GetTranslation() == G4ThreeVector(0,0,0)) )
89 {
90 G4Exception ("G4Navigator::SetWorldVolume()", "GeomNav0002",
91 FatalException, "Volume must be centered on the origin.");
92 }
93 const G4RotationMatrix* rm = pWorld->GetRotation();
94 if ( rm && (!rm->isIdentity()) )
95 {
96 G4Exception ("G4Navigator::SetWorldVolume()", "GeomNav0002",
97 FatalException, "Volume must not be rotated.");
98 }
99 fTopPhysical = pWorld;
100 fHistory.SetFirstEntry(pWorld);
101}
102
103// ********************************************************************
104// SetGeometrycallyLimitedStep
105//
106// Informs the navigator that the previous Step calculated
107// by the geometry was taken in its entirety
108// ********************************************************************
109//
110inline
111void G4Navigator::SetGeometricallyLimitedStep()
112{
113 fWasLimitedByGeometry = true;
114}
115
116// ********************************************************************
117// ResetStackAndState
118//
119// Resets stack and minimum of navigator state `machine'
120// ********************************************************************
121//
122inline
123void G4Navigator::ResetStackAndState()
124{
125 fHistory.Reset();
126 ResetState();
127}
128
129// ********************************************************************
130// VolumeType
131// ********************************************************************
132//
133inline
134EVolume G4Navigator::VolumeType(const G4VPhysicalVolume *pVol) const
135{
136 return pVol->VolumeType();
137}
138
139// ********************************************************************
140// CharacteriseDaughters
141// ********************************************************************
142//
143inline
144EVolume G4Navigator::CharacteriseDaughters(const G4LogicalVolume *pLog) const
145{
146 return pLog->CharacteriseDaughters();
147}
148
149// ********************************************************************
150// GetDaughtersRegularStructureId
151// ********************************************************************
152//
153inline
154G4int G4Navigator::
155GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
156{
157 G4int regId = 0;
158 G4VPhysicalVolume *pVol;
159
160 if ( pLog->GetNoDaughters() == 1 )
161 {
162 pVol = pLog->GetDaughter(0);
163 regId = pVol->GetRegularStructureId();
164 }
165 return regId;
166}
167
168// ********************************************************************
169// GetGlobalToLocalTransform
170//
171// Returns local to global transformation.
172// I.e. transformation that will take point or axis in world coord system
173// and return one in the local coord system
174// ********************************************************************
175//
176inline
177const G4AffineTransform& G4Navigator::GetGlobalToLocalTransform() const
178{
179 return fHistory.GetTopTransform();
180}
181
182// ********************************************************************
183// GetLocalToGlobalTransform
184//
185// Returns global to local transformation
186// ********************************************************************
187//
188inline
189const G4AffineTransform G4Navigator::GetLocalToGlobalTransform() const
190{
191 return fHistory.GetTopTransform().Inverse();
192}
193
194// ********************************************************************
195// NetTranslation
196//
197// Computes+returns the local->global translation of current volume
198// ********************************************************************
199//
200inline
201G4ThreeVector G4Navigator::NetTranslation() const
202{
203 return fHistory.GetTopTransform().InverseNetTranslation();
204}
205
206// ********************************************************************
207// NetRotation
208//
209// Computes+returns the local->global rotation of current volume
210// ********************************************************************
211//
212inline
213G4RotationMatrix G4Navigator::NetRotation() const
214{
215 return fHistory.GetTopTransform().InverseNetRotation();
216}
217
218// ********************************************************************
219// CreateGRSVolume
220//
221// `Touchable' creation method: caller has deletion responsibility
222// ********************************************************************
223//
224inline
225G4GRSVolume* G4Navigator::CreateGRSVolume() const
226{
227 const G4AffineTransform& tf = fHistory.GetTopTransform();
228 return new G4GRSVolume(fHistory.GetTopVolume(),
229 tf.InverseNetRotation(),
230 tf.InverseNetTranslation());
231}
232
233// ********************************************************************
234// CreateGRSSolid
235//
236// `Touchable' creation method: caller has deletion responsibility
237// ********************************************************************
238//
239inline
240G4GRSSolid* G4Navigator::CreateGRSSolid() const
241{
242 const G4AffineTransform& tf = fHistory.GetTopTransform();
243 return new G4GRSSolid(fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
244 tf.InverseNetRotation(),
245 tf.InverseNetTranslation());
246}
247
248// ********************************************************************
249// CreateTouchableHistory
250//
251// `Touchable' creation method: caller has deletion responsibility
252// ********************************************************************
253//
254inline
255G4TouchableHistory* G4Navigator::CreateTouchableHistory() const
256{
257 return new G4TouchableHistory(fHistory);
258}
259
260// ********************************************************************
261// CreateTouchableHistory(history)
262//
263// `Touchable' creation method: caller has deletion responsibility
264// ********************************************************************
265//
266inline
267G4TouchableHistory*
268G4Navigator::CreateTouchableHistory(const G4NavigationHistory* history) const
269{
270 return new G4TouchableHistory(*history);
271}
272
273// ********************************************************************
274// LocateGlobalPointAndUpdateTouchableHandle
275// ********************************************************************
276//
277inline
278void G4Navigator::LocateGlobalPointAndUpdateTouchableHandle(
279 const G4ThreeVector& position,
280 const G4ThreeVector& direction,
281 G4TouchableHandle& oldTouchableToUpdate,
282 const G4bool RelativeSearch )
283{
284 G4VPhysicalVolume* pPhysVol;
285 pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
286 if( fEnteredDaughter || fExitedMother )
287 {
288 oldTouchableToUpdate = CreateTouchableHistory();
289 if( pPhysVol == nullptr )
290 {
291 // We want to ensure that the touchable is correct in this case.
292 // The method below should do this and recalculate a lot more ....
293 //
294 oldTouchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
295 }
296 }
297 return;
298}
299
300// ********************************************************************
301// LocateGlobalPointAndUpdateTouchable
302//
303// Use direction
304// ********************************************************************
305//
306inline
307void G4Navigator::LocateGlobalPointAndUpdateTouchable(
308 const G4ThreeVector& position,
309 const G4ThreeVector& direction,
310 G4VTouchable* touchableToUpdate,
311 const G4bool RelativeSearch )
312{
313 G4VPhysicalVolume* pPhysVol;
314 pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);
315 touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
316}
317
318// ********************************************************************
319// LocateGlobalPointAndUpdateTouchable
320// ********************************************************************
321//
322inline
323void G4Navigator::LocateGlobalPointAndUpdateTouchable(
324 const G4ThreeVector& position,
325 G4VTouchable* touchableToUpdate,
326 const G4bool RelativeSearch )
327{
328 G4VPhysicalVolume* pPhysVol;
329 pPhysVol = LocateGlobalPointAndSetup( position, 0, RelativeSearch);
330 touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
331}
332
333// ********************************************************************
334// GetVerboseLevel
335// ********************************************************************
336//
337inline
338G4int G4Navigator::GetVerboseLevel() const
339{
340 return fVerbose;
341}
342
343// ********************************************************************
344// SetVerboseLevel
345// ********************************************************************
346//
347inline
348void G4Navigator::SetVerboseLevel(G4int level)
349{
350 fVerbose = level;
351 fnormalNav.SetVerboseLevel(level);
352 GetVoxelNavigator().SetVerboseLevel(level);
353 fparamNav.SetVerboseLevel(level);
354 freplicaNav.SetVerboseLevel(level);
355 fregularNav.SetVerboseLevel(level);
356 if (fpExternalNav != nullptr) fpExternalNav->SetVerboseLevel(level);
357}
358
359// ********************************************************************
360// IsActive
361// ********************************************************************
362//
363inline
364G4bool G4Navigator::IsActive() const
365{
366 return fActive;
367}
368
369// ********************************************************************
370// Activate
371// ********************************************************************
372//
373inline
374void G4Navigator::Activate(G4bool flag)
375{
376 fActive = flag;
377}
378
379// ********************************************************************
380// EnteredDaughterVolume
381//
382// To inform the caller if the track is entering a daughter volume
383// ********************************************************************
384//
385inline
386G4bool G4Navigator::EnteredDaughterVolume() const
387{
388 return fEnteredDaughter;
389}
390
391// ********************************************************************
392// ExitedMotherVolume
393// ********************************************************************
394//
395inline
396G4bool G4Navigator::ExitedMotherVolume() const
397{
398 return fExitedMother;
399}
400
401// ********************************************************************
402// CheckMode
403// ********************************************************************
404//
405inline
406void G4Navigator::CheckMode(G4bool mode)
407{
408 fCheck = mode;
409 fnormalNav.CheckMode(mode);
410 GetVoxelNavigator().CheckMode(mode);
411 fparamNav.CheckMode(mode);
412 freplicaNav.CheckMode(mode);
413 fregularNav.CheckMode(mode);
414 if (fpExternalNav != nullptr) fpExternalNav->CheckMode(mode);
415}
416
417// ********************************************************************
418// IsCheckModeActive
419// ********************************************************************
420//
421inline
422G4bool G4Navigator::IsCheckModeActive() const
423{
424 return fCheck;
425}
426
427// ********************************************************************
428// SetPushVerbosity
429// ********************************************************************
430//
431inline
432void G4Navigator::SetPushVerbosity(G4bool mode)
433{
434 fWarnPush = mode;
435}
436
437// ********************************************************************
438// SeverityOfZeroStepping
439//
440// Reports on severity of error in case Navigator is stuck
441// and is returning zero steps
442// ********************************************************************
443//
444inline
445G4int G4Navigator::SeverityOfZeroStepping( G4int* noZeroSteps ) const
446{
447 G4int severity = 0, noZeros = fNumberZeroSteps;
448 if( noZeroSteps )
449 {
450 *noZeroSteps = fNumberZeroSteps;
451 }
452 if( noZeros >= fAbandonThreshold_NoZeroSteps )
453 {
454 severity = 10;
455 }
456 if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
457 {
458 severity = 5 * noZeros / fActionThreshold_NoZeroSteps;
459 }
460 else if( noZeros == fActionThreshold_NoZeroSteps )
461 {
462 severity = 5;
463 }
464 else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
465 {
466 severity = 9;
467 }
468 else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
469 {
470 severity = 5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
471 / fActionThreshold_NoZeroSteps;
472 }
473 return severity;
474}
475
476// ********************************************************************
477// GetVoxelNavigator
478// ********************************************************************
479//
480inline
481G4VoxelNavigation& G4Navigator::GetVoxelNavigator() {
482#ifdef ALTERNATIVE_VOXEL_NAV
483 return *fpvoxelNav;
484#else
485 return fvoxelNav;
486#endif
487}
488
489// ********************************************************************
490// EnableBestSafety
491// ********************************************************************
492//
493inline void G4Navigator::EnableBestSafety( G4bool value )
494{
495 GetVoxelNavigator().EnableBestSafety( value );
496}
497
498// ********************************************************************
499// SetExternalNavigation
500// ********************************************************************
501//
502inline
503G4VExternalNavigation* G4Navigator::GetExternalNavigation() const
504{
505 return fpExternalNav;
506}
507
508// ********************************************************************
509// SetExternalNavigation
510// ********************************************************************
511//
512inline
513void G4Navigator::SetExternalNavigation(G4VExternalNavigation* externalNav)
514{
515 fpExternalNav = externalNav;
516}
517
518// ********************************************************************
519// Clone
520// ********************************************************************
521//
522inline
523G4Navigator* G4Navigator::Clone() const
524{
525 G4Navigator* clone_nav = new G4Navigator();
526 clone_nav->SetWorldVolume(fTopPhysical);
527 if( fpExternalNav != nullptr )
528 {
529 clone_nav->SetExternalNavigation(fpExternalNav->Clone());
530 }
531 return clone_nav;
532}