Geometry

Q: I have a generic point and I would like to know in which physical volume I’m located in my detector geometry.

A: The best way of doing this is by invoking the G4Navigator. First get a pointer of the navigator through the G4TransportationManager, and then locate the point. i.e.

#include "G4TransportationManager.hh"
#include "G4Navigator.hh"
G4ThreeVector myPoint = ....;
G4Navigator* theNavigator = G4TransportationManager::GetTransportationManager()
                             ->GetNavigatorForTracking();
G4VPhysicalVolume* myVolume = theNavigator->LocateGlobalPointAndSetup(myPoint);

Note: by using the navigator for tracking as shown above, the actual particle gets also -relocated- in the specified position. Therefore, if this information is needed during tracking time, in order to avoid affecting tracking, you should either use an alternative G4Navigator object (which you then assign to your world-volume), or you access the information through the track or touchable as specified in the FAQ for tracking and steps.

Q: How can I access the daughter volumes of a specific physical volume?

A: Through the associated logical volume.

G4VPhysicalVolume* myPVolume = ....;
G4LogicalVolume* myLVolume = myPVolume->GetLogicalVolume();
for (G4int i=0; iGetNoDaughters(); i++) myPVolume = myLVolume->GetDaughter(i);

Q: How can I identify the exact copy-number of a specific physical volume in my mass geometry? I tried with GetCopyNo() from my physical volume pointer, but it doesn’t seem to work!

A: The correct way to identify -uniquely- a physical volume in your mass geometry is by using the touchables (see also chapter 4.1.5 of the User’s Guide for Application Developers), as follows:

G4Step* aStep = ..;
G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
G4TouchableHandle theTouchable = preStepPoint->GetTouchableHandle();
G4int copyNo = theTouchable->GetCopyNumber();
G4int motherCopyNo = theTouchable->GetCopyNumber(1);

where Copy here stays for any duplicated instance of a physical volume, either if it is a G4PVPlacement (multiple placements of the same logical volume) or a G4PVReplica/G4PVParameterised. The method GetCopyNo() is meant to return only the serial number of placements not duplicated in the geometry tree.

Conversion Global to Local Co-ordinates

Q: How can I determine the exact position in global coordinates in my mass geometry during tracking and how can I convert it to coordinates local to the current volume ?

A: You need again to do it through the touchables (see also chapter 4.1.5 of the User’s Guide for Application Developers), as follows:

G4Step* aStep = ..;
G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
G4TouchableHandle theTouchable = preStepPoint->GetTouchableHandle();
G4ThreeVector worldPosition = preStepPoint->GetPosition();
G4ThreeVector localPosition = theTouchable->GetHistory()->GetTopTransform().
TransformPoint(worldPosition);

where worldPosition here stays for the position related to the world volume, while localPosition refers to the coordinates local to the volume where the particle is currently placed.