Overview Contents Previous Next Geant4 User's Guide
For Application Developers
Geometry


4.1.8 The Geometry Navigator

Navigation through the geometry at tracking time is implemented by the class G4Navigator. The navigator is used to locate points in the geometry and compute distances to geometry boundaries. At tracking time, the navigator is intended to be the only point of interaction with tracking.
Internally, the G4Navigator has several private helper/utility classes:

In addition, the navigator maintains a set of flags for exiting/entry optimisation. A navigator is not a singleton class; this is mainly to allow a design extension in future (e.g geometrical event biasing).

4.1.8.1 Navigation and Tracking

The main functions required for tracking in the geometry are described below. Additional functions are provided to return the net transformation of volumes and for the creation of touchables. None of the functions implicitly requires that the geometry be described hierarchically.

As stated previously, the navigator makes use of utility classes to perform location and step computation functions. The different navigation utilities manipulate the G4NavigationHistory object.
In LocateGlobalPointAndSetup() the process of locating a point breaks down into three main stages - optimisation, determination that the point is contained with a subtree (mother and daughters), and determination of the actual containing daughter. The latter two can be thought of as scanning first 'up' the hierarchy until a volume that is guaranteed to contain the point is found, and then scanning 'down' until the actual volume that contains the point is found.
In ComputeStep() three types of computation are treated depending on the current containing volume:

4.1.8.2 Using the navigator to locate points

More than one navigator objects can be created inside an application; these navigators can act independently for different purposes. The main navigator which is activated automatically at the startup of a simulation program is the navigator used for the tracking and attached the world volume of the main tracking (or mass) geometry.
The navigator for tracking can be retrieved at any state of the application by messagging the G4TransportationManager:

     G4Navigator* tracking_navigator =
       G4TransportationManager::GetInstance()->GetNavigatorForTracking();
The navigator for tracking also retains all the information of the current history of volumes transversed at a precise moment of the tracking during a run. Therefore, if the navigator for tracking is used during tracking for locating a generic point in the tree of volumes, the actual particle gets also -relocated- in the specified position and tracking will be of course affected !
In order to avoid the problem above and provide information about location of a point without affecting the tracking, it is suggested to either use an alternative G4Navigator object (which can then be assigned to the world-volume), or access the information through the step.

Using the 'step' to retrieve geometrical information

During the tracking run, geometrical information can be retrieved through the touchable handle associated to the current step. For example, to identify the exact copy-number of a specific physical volume in the mass geometry, one should do the following:

      // Given the pointer to the step object ...
      //
      G4Step* aStep = ..;

      // ... retrieve the 'pre-step' point
      //
      G4StepPoint* preStepPoint = aStep->GetPreStepPoint();

      // ... retrieve a touchable handle and access to the information
      //
      G4TouchableHandle theTouchable = preStepPoint->GetTouchableHandle();
      G4int copyNo = theTouchable->GetCopyNumber();
      G4int motherCopyNo = theTouchable->GetCopyNumber(1);
To determine the exact position in global coordinates in the mass geometry and convert to local coordinates (local to the current volume):
      G4ThreeVector worldPosition = preStepPoint->GetPosition();
      G4ThreeVector localPosition = theTouchable->GetHistory()->
                    GetTopTransform().TransformPoint(worldPosition);

Using an alternative navigator to locate points

In order to know (when in the idle state of the application) in which physical volume a given point is located in the detector geometry, it is necessary to create an alternative navigator object first and assign it to the world volume:

     G4Navigator* aNavigator = new G4Navigator();
     aNavigator->SetWorldVolume(worldVolumePointer);
Then, locate the point myPoint (defined in global coordinates), retrieve a touchable handle and do whatever you need with it:
     aNavigator->LocateGlobalPointAndSetup(myPoint);
     G4TouchableHistoryHandle aTouchable =
       aNavigator->CreateTouchableHistoryHandle();

     // Do whatever you need with it ...
     // ... convert point in local coordinates (local to the current volume)
     //
     G4ThreeVector localPosition = aTouchable->GetHistory()->
                   GetTopTransform().TransformPoint(myPoint);

     // ... convert back to global coordinates system
     G4ThreeVector globalPosition = aTouchable->GetHistory()->
                   GetTopTransform().Inverse().TransformPoint(localPosition);
If outside of the tracking run and given a generic local position (local to a given volume in the geometry tree), it is -not- possible to determine a priori its global position and convert it to the global coordinates system. The reason for this is rather simple, nobody can guarantee that the given (local) point is located in the right -copy- of the physical volume ! In order to retrieve this information, some extra knowledge related to the absolute position of the physical volume is required first, i.e. one should first determine a global point belonging to that volume, eventually making a dedicated scan of the geometry tree through a dedicated G4Navigator object and then apply the method above after having created the touchable for it.

4.1.8.3 Navigation in parallel geometries

Since release 8.2 of Geant4, it is possible to define geometry trees which are parallel to the tracking geometry and having them assigned to navigator objects that transparently communicate in sync with the normal tracking geometry.

Parallel geometries can be defined for several uses (fast shower parameterisation, geometrical biasing, particle scoring, readout geometries, etc ...) and can overlap with the mass geometry defined for the tracking. The parallel transportation will be activated only after the registration of the parallel geometry in the detector description setup; see Section 4.7 for how to define a parallel geometry and register it to the run-manager.
The G4TransportationManager provides all the utilities to verify, retrieve and activate the navigators associated to the various parallel geometries defined.

4.1.8.4 Run-time commands

When running in verbose mode (i.e. the default, G4VERBOSE set while installing the Geant4 kernel libraries), the navigator provides a few commands to control its behavior. It is possible to select different verbosity levels (up to 5), with the command:

     geometry/navigator/verbose [verbose_level]
or to force the navigator to run in check mode:
     geometry/navigator/check_mode [true/false]
The latter will force more strict and less tolerant checks in step/safety computation to verify the correctness of the solids' response in the geometry.
By combining check_mode with verbosity level-1, additional verbosity checks on the response from the solids can be activated.


About the authors