Filtering electrons from secondary particles

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

Hi,
you can do that in your stepping_action.cc :

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

Thibault

Thanks for the answer! Just another quick question, I’m completely new to Geant. I didn’t write a steppingaction.cc, 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.

Thibault

1 Like

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

Anita

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.

Thibault

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?
Thanks,
Anita

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

Thibault

This is the part related to what you suggested.

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

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

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

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

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

}
Thanks a lot for the help,
Anita