How to get energy deposit only from incident particle

Hello.

I made detector and I get total energy deposit. But I want to get energy deposit only from incident particle. I also want the particle to be taken out of the entry if the incident particle collapses during the interaction. I solved how to get an inelastic process but couldn’t find a way to exclude it from entry and energy deposit.

How can I solve this problem?

How do you record the total energy?
If you implement your sensitive detector, you can check for many things in ProcessHits method before making the decision whether to record the energy or not. For instance, you can check if the energy is deposited by the primary particle (G4Step::GetTrack()::GetParentID() == 0).

Thank you for your answer.

Below is my code for record total energy.

auto edep = step->GetTotalEnergyDeposit();

if(step->GetTrack()->GetTrackID() != 1)
{
const G4VProcess* PhysicsProcess = step->GetTrack()->GetCreatorProcess();
auto processName = PhysicsProcess->GetProcessName();
}
if(step->GetTrack()->GetTrackID() != 1 )
{
if(step->GetTrack()->GetCreatorProcess()->GetProcessName() != “protonInelasitc”)
{
if ( volume == fDetConstruction->GetScintillatorPV() )
{
fEventAction->AddAbs(edep);
}
}
}
if(step->GetTrack()->GetParentID() == 0)
{
if ( volume == fDetConstruction->GetScintillatorPV() )
{
fEventAction->AddAbs(edep);
}
}

I need to exclude primary particle which do inelastic process from entry. however my code can not do that. this is my problem.

I’ll try again the method you told me.