Event selection at the level of production in restG4

System : Rocky Linux release 8.5
REST version : v2.3.12

Hi, I have a question regarding the event selection in restG4.
I am generating the decay events of an isotope (Bi214, to be exact). I want to save only those events that produce gammas as secondary particles with energies higher than the defined threshold by me.

I am doing that in the following way:

  1. Trace particles in the TrackingAction at the level of PreUserTrackingAction and check if the produced gammas with ParentID==2 have kinetic energy higher than Ethr
void TrackingAction::PreUserTrackingAction(const G4Track* track) {
   /// more code lines
    G4ParticleDefinition* particle = track->GetDefinition();
    G4String name = particle->GetParticleName();
    fCharge = particle->GetPDGCharge();
    G4double kineticEnergy = track->GetKineticEnergy();
        if (track->GetParentID() == 2) {
            G4double energyThr_forSelection = restG4Metadata->GetEnergySelectionForParticleGeneration() * keV;
            if (name.contains("gamma")) {
                G4cout << "Track ID: " << track->GetTrackID() << " Parent ID: " << track->GetParentID() 
                    << " Name: " << name << " Charge: " << fCharge << " Kinetic Energy: " << kineticEnergy / keV << " (keV)" 
                    << " Energy for particle selection: " << energyThr_forSelection / keV << " (keV)" << G4endl;
                if (kineticEnergy >= energyThr_forSelection){
                    // fTrackIsValid = true;

SetTrackValidity is the new method I’ve set up in the EventAction to be passed to the event.

  1. By default, in the EventAction at the level of BeginOfEventAction, I define SetTrackValidity(false) so that after the TrackingAction is executed, I can check the validity of the track, which is what I am doing in the EndOfEventAction.
cout << "Checking if track is valid(END): " << CheckTrackValidity() << endl;
    if (CheckTrackValidity() == false) {
        cout << "Track is not valid" << endl;
        // continue;
        // delete restG4Event;
        // restG4Event = new TRestGeant4Event();
        // restG4Event->SetID(-1);

The problem is that I do not understand how not to save this event into restG4event if CheckTrackValidity() == false, as in the Preformatted text these initializations are present:

   time_t system_time = time(nullptr);


   // Defining if the hits in a given volume will be stored
   for (int i = 0; i < restG4Metadata->GetNumberOfActiveVolumes(); i++) {
       Double_t rndNumber = G4UniformRand();

       if (restG4Metadata->GetStorageChance(i) >= rndNumber)

I am a bit lost for the moment. Is there an easier way to do this certain thing, maybe?
I do not understand how to remove the event at the production level in restG4.
I see the TRestGeant4Event::ClearVolumes() method in the documentation, but I’d like to exclude all of the information regarding the event.

Thank you in advance for any ideas
Kind regards,