Volumes around a boundary

I was wondering how I can get the name of the previous volume of a track when the step is at a boundary and it is in the next volume. I couldn’t find any information regarding the previous step except for the previous step size. Your comments are so much appreciated.
Thank you

G4Step::GetPostStepPoint() and G4Step::GetPreStepPoint().

Thank you Michael but I need this when the process hasn’t been defined yet so the pre and post step point are the same. For a particle at a boundary I need to check what volume the particle comes from to decide if I need to add a process or not. Then the step size and post step point will be defined. Do you have any other comment?

Can you give more detail about what you are trying to do? It might make it easier to describe the best way to get this information.

while a little clunky, you could use some boolean variable. Say you have 3 volumes, A,B,C, and you only want to track particles that traveled from A->C, and not B->C.

So you can check when a particle enters C:

(Presteppoint != C and poststeppoint == C)

and then check what pretsteppoint is. If

(presteppoint == A)

Then you can have a flag

Bool fromA

That you can set to true. Then turn it off when your particle dies, or leaves volume C

I’m defining a new process (Bragg reflection) at a crystal-air boundary by writing a PostStepDoIt method. At this level both Pre&PostStepPoint are at the same point because the new process and the step size hasn’t been defined yet. It seems PostStepPoint is a copy of PreStepPoint and it’ll be updated after process is defined.

In the PostStepDoIt, I can see if the step is at a boundary (by if StepStatus == fGeomBoundary) and in what volume it is (Pre&PostPoint->GetVolume()). But I can’t see what volume it’s coming from. I tried track->GetOriginTouchable(). but for some reason it doesn’t give me a constant answer especially when the photon is at the boundary but comes from the crystal. I was looking for other reliable way to get the pre&post boundary volumes name.

Hope I could explain my situation a little :slight_smile:

If you are defining a G4VDiscreteProcess, that is simply not true. In your PostStepDoIt(), the step will have properly set pre- and post-step points. You will test the PostStepPoint to see whether the fGeomBoundary status is set, indicating that the track has reached the boundary of the current volume. You should see that the pre-step volume is the current volume the track is in, while the post-step volume is the next volume that it is going into.

I’m not using G4DiscreteProcess since I also have AlongStepDoIt so I derive it from G4VProcess but I see what you mean. Sorry for misleading I was wrong to say PostStepDoIt because I need that in GetPhysicalInteractionPathLength of the post step process and to return the process interaction path length if some conditions come true. There I don’t see any differences between what PreStepPoint and PostStepPoint returns which make sense since wit doesn’t know the winner process.

Right! GPIL is called before the step: it’s the quantity that is used to decide where the end of the step should be. Do you really need “AlongStepDoIt()” for Bragg reflection? Why don’t you inherit from G4VDiscreteProcess, which

You said you want to implement Bragg reflection at a boundary. Why don’t you look into how the G4 optical boundary process works.

It has two parts, inside the crystal and at its boundary. For the inside crystal, I made the AlongStepDoIt based on our logic and it works fine so far. But at boundaries and when the new step is in the Air (meaning both Pre&PostStepPoints are the same and in the Air), I can’t recognize if it is crystal-air boundary or not.

Oh! I see your problem. You cannot detect the boundary in GPIL, because that function is only called for steps fully within a single volume. For the boundary case, you can detect it in PostStepDoIt() (and probably in AlongStepDoIt() as well) because the post-step point will have status = fGeomBoundary. I think you can interrogate the tracking Navigator to find out what the adjacent volume is.

Thank you Michael! I’ll try tracking navigator and will update this post if I get anything