How to kill secondaries(?) without affecting other tracks

im doing some xray simulations and have very weird peaks in the <2keV range, which should be filtered out via my Beryllium window. my thought was that the photons hitting my detector generate free electrons via photo/compton effects and their energy gets detected as well. when i tried killing the tracks via this code:
if (step->GetTrack()->GetDefinition() == G4Electron::ElectronDefinition()) {


my detector only shows the Si-Lines at 1.7keV…
i dont know if i just donw understand how the GetEnergyDeposit works or if it is something else…
this is my complete stepping action code:
#include “stepping.hh”
#include “G4ParticleDefinition.hh”
#include “G4TrackStatus.hh”
#include “G4Track.hh”
#include “G4Material.hh”
MySteppingAction::MySteppingAction(MyEventAction *eventAction)


void MySteppingAction::UserSteppingAction(const G4Step step)
track = step->GetTrack();
G4double edep = 0.;
G4double backscatter=0.;
G4LogicalVolume *volume = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
G4String volumeName= volume->GetName();

const construction detectorConstruction = static_cast<const construction>(G4RunManager::GetRunManager()->GetUserDetectorConstruction());
G4LogicalVolume *fScoringVolume =detectorConstruction->GetScoringVolume();

if (volume != fScoringVolume)

// if(volume==fScoringVolume){
// if (step->GetTrack()->GetDefinition() == G4Electron::ElectronDefinition()) {

// step->GetTrack()->SetTrackStatus(fStopAndKill);
// }}

edep = step → GetTotalEnergyDeposit();
fEventAction->AddfEdep(edep); // this adds up the energy deposited , to get the total ammount lost by the photon passing throught the detector