Filtering electrons from secondary particles

I would like to have reported only secondary particles different from electrons. Do you have any idea how can I do it? Thanks

you can do that in your :

G4String particle=step->GetTrack()->GetParticleDefinition()->GetParticleName();
if (particle==“e-”) {return step->GetTrack()->SetTrackStatus(fStopAndKill);}


Thanks for the answer! Just another quick question, I’m completely new to Geant. I didn’t write a, just the detector, physic list and primary generator files. Do I need to have a stepping action? Thanks a lot

If you are new to Geant4, I suggest you to reuse files from example in “example/basic/” directory or at least to follow their structure : ActionInitialization, Detector Construction, EventAction, PhysicList, PrimaryGenerator, RunAction and SteppingAction.
If you have already build a geometry and a physicList you can easily reuse one of the example.


1 Like

Do I have to add it in some spacific place inside the Thanks a lot for the help.


I tried to add in SteppingAction::UseSteppingAction() but it is not doing anything really. Is it the wrond subsection?

I think it’s in the good place but maybe the name of your G4Step object is not step but Step or aStep. I can say no more without code.


Should I share the code? I check and the variable is step. I read that for some process it is not possible to filter them, can be this the case?

If you don’t mind, you can share the code,
this way it will be easier to help you.


This is the part related to what you suggested.

void SteppingAction::UserSteppingAction(const G4Step* step)
if (!fScoringVolume) {
const DetectorConstruction* detectorConstruction
= static_cast<const DetectorConstruction*>
fScoringVolume = detectorConstruction->GetScoringVolume();

// get volume of the current step
G4LogicalVolume* volume
    = step->GetPreStepPoint()->GetTouchableHandle()

// check if we are in scoring volume
if (volume != fScoringVolume) return;

// collect energy deposited in this step
G4double edepStep = step->GetTotalEnergyDeposit();

G4String particle = step->GetTrack()->GetParticleDefinition()->GetParticleName();
if (particle == 'e-') { return step->GetTrack()->SetTrackStatus(fStopAndKill); }

Thanks a lot for the help,