2// ********************************************************************
3// * License and Disclaimer *
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. *
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. *
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// ********************************************************************
26// class G4Navigator Inline implementation
28// ********************************************************************
30// ********************************************************************
31// GetCurrentLocalCoordinate
33// Returns the local coordinate of the current track
34// ********************************************************************
37G4ThreeVector G4Navigator::GetCurrentLocalCoordinate() const
39 return fLastLocatedPointLocal;
42// ********************************************************************
45// Returns local direction of vector direction in world coord system
46// ********************************************************************
49G4ThreeVector G4Navigator::ComputeLocalAxis(const G4ThreeVector& pVec) const
51 return fHistory.GetTopTransform().TransformAxis(pVec);
54// ********************************************************************
57// Returns local coordinates of a point in the world coord system
58// ********************************************************************
62G4Navigator::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const
64 return fHistory.GetTopTransform().TransformPoint(pGlobalPoint);
67// ********************************************************************
70// Returns the current world (`topmost') volume
71// ********************************************************************
74G4VPhysicalVolume* G4Navigator::GetWorldVolume() const
79// ********************************************************************
82// Sets the world (`topmost') volume
83// ********************************************************************
86void G4Navigator::SetWorldVolume(G4VPhysicalVolume* pWorld)
88 if ( !(pWorld->GetTranslation() == G4ThreeVector(0,0,0)) )
90 G4Exception ("G4Navigator::SetWorldVolume()", "GeomNav0002",
91 FatalException, "Volume must be centered on the origin.");
93 const G4RotationMatrix* rm = pWorld->GetRotation();
94 if ( rm && (!rm->isIdentity()) )
96 G4Exception ("G4Navigator::SetWorldVolume()", "GeomNav0002",
97 FatalException, "Volume must not be rotated.");
99 fTopPhysical = pWorld;
100 fHistory.SetFirstEntry(pWorld);
103// ********************************************************************
104// SetGeometrycallyLimitedStep
106// Informs the navigator that the previous Step calculated
107// by the geometry was taken in its entirety
108// ********************************************************************
111void G4Navigator::SetGeometricallyLimitedStep()
113 fWasLimitedByGeometry = true;
116// ********************************************************************
119// Resets stack and minimum of navigator state `machine'
120// ********************************************************************
123void G4Navigator::ResetStackAndState()
129// ********************************************************************
131// ********************************************************************
134EVolume G4Navigator::VolumeType(const G4VPhysicalVolume *pVol) const
136 return pVol->VolumeType();
139// ********************************************************************
140// CharacteriseDaughters
141// ********************************************************************
144EVolume G4Navigator::CharacteriseDaughters(const G4LogicalVolume *pLog) const
146 return pLog->CharacteriseDaughters();
149// ********************************************************************
150// GetDaughtersRegularStructureId
151// ********************************************************************
155GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
158 G4VPhysicalVolume *pVol;
160 if ( pLog->GetNoDaughters() == 1 )
162 pVol = pLog->GetDaughter(0);
163 regId = pVol->GetRegularStructureId();
168// ********************************************************************
169// GetGlobalToLocalTransform
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// ********************************************************************
177const G4AffineTransform& G4Navigator::GetGlobalToLocalTransform() const
179 return fHistory.GetTopTransform();
182// ********************************************************************
183// GetLocalToGlobalTransform
185// Returns global to local transformation
186// ********************************************************************
189const G4AffineTransform G4Navigator::GetLocalToGlobalTransform() const
191 return fHistory.GetTopTransform().Inverse();
194// ********************************************************************
197// Computes+returns the local->global translation of current volume
198// ********************************************************************
201G4ThreeVector G4Navigator::NetTranslation() const
203 return fHistory.GetTopTransform().InverseNetTranslation();
206// ********************************************************************
209// Computes+returns the local->global rotation of current volume
210// ********************************************************************
213G4RotationMatrix G4Navigator::NetRotation() const
215 return fHistory.GetTopTransform().InverseNetRotation();
218// ********************************************************************
221// `Touchable' creation method: caller has deletion responsibility
222// ********************************************************************
225G4GRSVolume* G4Navigator::CreateGRSVolume() const
227 const G4AffineTransform& tf = fHistory.GetTopTransform();
228 return new G4GRSVolume(fHistory.GetTopVolume(),
229 tf.InverseNetRotation(),
230 tf.InverseNetTranslation());
233// ********************************************************************
236// `Touchable' creation method: caller has deletion responsibility
237// ********************************************************************
240G4GRSSolid* G4Navigator::CreateGRSSolid() const
242 const G4AffineTransform& tf = fHistory.GetTopTransform();
243 return new G4GRSSolid(fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
244 tf.InverseNetRotation(),
245 tf.InverseNetTranslation());
248// ********************************************************************
249// CreateTouchableHistory
251// `Touchable' creation method: caller has deletion responsibility
252// ********************************************************************
255G4TouchableHistory* G4Navigator::CreateTouchableHistory() const
257 return new G4TouchableHistory(fHistory);
260// ********************************************************************
261// CreateTouchableHistory(history)
263// `Touchable' creation method: caller has deletion responsibility
264// ********************************************************************
268G4Navigator::CreateTouchableHistory(const G4NavigationHistory* history) const
270 return new G4TouchableHistory(*history);
273// ********************************************************************
274// LocateGlobalPointAndUpdateTouchableHandle
275// ********************************************************************
278void G4Navigator::LocateGlobalPointAndUpdateTouchableHandle(
279 const G4ThreeVector& position,
280 const G4ThreeVector& direction,
281 G4TouchableHandle& oldTouchableToUpdate,
282 const G4bool RelativeSearch )
284 G4VPhysicalVolume* pPhysVol;
285 pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
286 if( fEnteredDaughter || fExitedMother )
288 oldTouchableToUpdate = CreateTouchableHistory();
289 if( pPhysVol == nullptr )
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 ....
294 oldTouchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
300// ********************************************************************
301// LocateGlobalPointAndUpdateTouchable
304// ********************************************************************
307void G4Navigator::LocateGlobalPointAndUpdateTouchable(
308 const G4ThreeVector& position,
309 const G4ThreeVector& direction,
310 G4VTouchable* touchableToUpdate,
311 const G4bool RelativeSearch )
313 G4VPhysicalVolume* pPhysVol;
314 pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);
315 touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
318// ********************************************************************
319// LocateGlobalPointAndUpdateTouchable
320// ********************************************************************
323void G4Navigator::LocateGlobalPointAndUpdateTouchable(
324 const G4ThreeVector& position,
325 G4VTouchable* touchableToUpdate,
326 const G4bool RelativeSearch )
328 G4VPhysicalVolume* pPhysVol;
329 pPhysVol = LocateGlobalPointAndSetup( position, 0, RelativeSearch);
330 touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
333// ********************************************************************
335// ********************************************************************
338G4int G4Navigator::GetVerboseLevel() const
343// ********************************************************************
345// ********************************************************************
348void G4Navigator::SetVerboseLevel(G4int 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);
359// ********************************************************************
361// ********************************************************************
364G4bool G4Navigator::IsActive() const
369// ********************************************************************
371// ********************************************************************
374void G4Navigator::Activate(G4bool flag)
379// ********************************************************************
380// EnteredDaughterVolume
382// To inform the caller if the track is entering a daughter volume
383// ********************************************************************
386G4bool G4Navigator::EnteredDaughterVolume() const
388 return fEnteredDaughter;
391// ********************************************************************
393// ********************************************************************
396G4bool G4Navigator::ExitedMotherVolume() const
398 return fExitedMother;
401// ********************************************************************
403// ********************************************************************
406void G4Navigator::CheckMode(G4bool 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);
417// ********************************************************************
419// ********************************************************************
422G4bool G4Navigator::IsCheckModeActive() const
427// ********************************************************************
429// ********************************************************************
432void G4Navigator::SetPushVerbosity(G4bool mode)
437// ********************************************************************
438// SeverityOfZeroStepping
440// Reports on severity of error in case Navigator is stuck
441// and is returning zero steps
442// ********************************************************************
445G4int G4Navigator::SeverityOfZeroStepping( G4int* noZeroSteps ) const
447 G4int severity = 0, noZeros = fNumberZeroSteps;
450 *noZeroSteps = fNumberZeroSteps;
452 if( noZeros >= fAbandonThreshold_NoZeroSteps )
456 if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
458 severity = 5 * noZeros / fActionThreshold_NoZeroSteps;
460 else if( noZeros == fActionThreshold_NoZeroSteps )
464 else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
468 else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
470 severity = 5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
471 / fActionThreshold_NoZeroSteps;
476// ********************************************************************
478// ********************************************************************
481G4VoxelNavigation& G4Navigator::GetVoxelNavigator() {
482#ifdef ALTERNATIVE_VOXEL_NAV
489// ********************************************************************
491// ********************************************************************
493inline void G4Navigator::EnableBestSafety( G4bool value )
495 GetVoxelNavigator().EnableBestSafety( value );
498// ********************************************************************
499// SetExternalNavigation
500// ********************************************************************
503G4VExternalNavigation* G4Navigator::GetExternalNavigation() const
505 return fpExternalNav;
508// ********************************************************************
509// SetExternalNavigation
510// ********************************************************************
513void G4Navigator::SetExternalNavigation(G4VExternalNavigation* externalNav)
515 fpExternalNav = externalNav;
518// ********************************************************************
520// ********************************************************************
523G4Navigator* G4Navigator::Clone() const
525 G4Navigator* clone_nav = new G4Navigator();
526 clone_nav->SetWorldVolume(fTopPhysical);
527 if( fpExternalNav != nullptr )
529 clone_nav->SetExternalNavigation(fpExternalNav->Clone());