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:
- Trace particles in the
TrackingAction
at the level ofPreUserTrackingAction
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;
fEvent->SetTrackValidity(true);
}
}
SetTrackValidity
is the new method I’ve set up in the EventAction
to be passed to the event.
- By default, in the
EventAction
at the level of BeginOfEventAction, I define SetTrackValidity(false) so that after theTrackingAction
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;
//G4RunManager::GetRunManager()->AbortEvent();
// 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:
restTrack->Initialize();
restG4Event->SetID(event_number);
restG4Event->SetOK(true);
time_t system_time = time(nullptr);
restG4Event->SetTime((Double_t)system_time);
// 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)
restG4Event->ActivateVolumeForStorage(i);
else
restG4Event->DisableVolumeForStorage(i);
}
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,
Andrii