Normal surface access

How can I find the surface normal to a shape in my geometry in the World system of coordinates?
I am willing to get the cosinus between my particle entering or exiting a volume.
For this I have to compute the dot product between my particle direction ( in the world system of coordinates) with my shape normal at the crossing point (in the world system of coordinates).

Until now, I am trying to do this way:

G4StepPoint* aStepPoint = 0;
// OUT
if(aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary && aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() == "myvolume")
        aStepPoint = aStep->GetPostStepPoint();
//IN
else if(aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary && aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName() == "myvolume")
        aStepPoint = aStep->GetPreStepPoint();
//NOT CROSSING VOLUME
else return;
G4ThreeVector pointInSurf = aStepPoint->GetPosition();
G4ThreeVector localPointInSurf = aStep->GetPreStepPoint()->GetTouchableHandle()->GetHistory()->GetTopTransform().TransformPoint(pointInSurf);
G4ThreeVector localNormal = aStep->GetPreStepPoint()->GetTouchableHandle()->GetSolid()->SurfaceNormal(localPointInSurf);
G4ThreeVector globalNormal = aStep->GetPreStepPoint()->GetTouchableHandle()->GetHistory()->GetTopTransform().Inverse().TransformPoint(localNormal).unit();
G4double dot = globalNormal.dot(aStepPoint->GetMomentumDirection().unit());

I am not sure what I am doing wrong but it s quite easy to be wrong to decide if you need to use the post or pre step point, to change the coordinate system, to normalize the vector… I am a bit confuse with the local/global coordinate system and any help would be appreciated

2 Likes

I am also interested by this topic since I need the surface normal for particles crossing shape boundaries to obtain the crossing angle

Dear Geant4 community,
Do you have a solution to my request or at least could you please review my code and let me know where I am mistaken?
Thanks in advance for your appreciated help.