Problem in accessing the hadElastic process in TrackingAction

Hello everyone,

I’m doing a simulation that fast neutrons (10-20 MeV) are impinging on a polythene (PE) sample. I’m interested in the elastic scattering that happed between the incident neutrons and the hydrogen in the PE sample. I want to retrieve this hadElastic process in the TrackingAction but I failed.

I think the elastic scattering process did happen since I saw it when I set the tracking verbose as 1. You may see it in the below picture.

When I try to access and print the physics process name in the PE sample with following codes in TrackingAction:

void EDTrackingAction::PostUserTrackingAction(const G4Track* aTrack)
{
const G4StepPoint* endPoint = aTrack->GetStep()->GetPostStepPoint() ;
const G4VProcess* process = endPoint->GetProcessDefinedStep() ;
G4String ProcessName = process->GetProcessName() ;

if(process && process->GetProcessType()==fHadronic)
{
if(endPoint->GetPhysicalVolume()->GetName()==“PE”)
{
G4cout << "ProcessName: " << ProcessName << G4endl ;
}
}
}

It only printed “neutronInelastic” process, but the “hadElastic” process was not printed at all. I do not understand this.

Anybody know the reason of this? Any help or advice will be much appreciated! Thank you.

Hello,

please, try to remove check on “fHadronic”.

VI

Hello @civanch ,

Thank you for your kind suggestion.
In fact, I had already checked this, but the hadElastic process was still missing.

The problem is solved by implementing the SteppingAction. I did something like:

void EDSteppingAction::UserSteppingAction(const G4Step* step)
{
const G4StepPoint* endPoint = step->GetPostStepPoint() ;
const G4VProcess* process = endPoint->GetProcessDefinedStep() ;
G4String ProcessName = process->GetProcessName() ;

/* more details */
}

The hadElastic process can be accessed with above code.

Cheers!

The TrackingAction::PostUserTrackingAction() is called after a track has stopped and is going to be killed. In that case, the GetProcessDefinedStep() is only telling you about which process finally stopped the track at it’s last step.

To see steps in the middle of tracking, your solution with SteppingAction is correct.

1 Like

Hi @mkelsey ,

Thank you very much for your explanation. It does make sense and resolves my puzzle.
Cheers.