LDMX Software
PrimaryToEcalFilter.cxx
1#include "Biasing/PrimaryToEcalFilter.h"
2
3#include "G4EventManager.hh"
4#include "G4RunManager.hh"
5#include "SimCore/G4User/PtrRetrieval.h"
6
7namespace biasing {
8
10 const std::string& name, framework::config::Parameters& parameters)
11 : simcore::UserAction(name, parameters) {
12 threshold_ = parameters.get<double>("threshold");
13}
14
15void PrimaryToEcalFilter::stepping(const G4Step* step) {
16 // Only process the primary electron track
17 if (int parent_id{step->GetTrack()->GetParentID()}; parent_id != 0) return;
18
19 if (G4EventManager::GetEventManager()->GetConstCurrentEvent()->IsAborted())
20 return;
21
22 // Get the region the particle is currently in. Continue processing
23 // the particle only if it's NOT in the calorimeter region
24 auto current_region =
25 step->GetTrack()->GetVolume()->GetLogicalVolume()->GetRegion();
26 auto calorimeter_region =
27 simcore::g4user::ptrretrieval::getRegion("CalorimeterRegion");
28 if (!calorimeter_region) {
29 ldmx_log(warn)
30 << "Region 'CalorimeterRegion' not found in Geant4 region store";
31 }
32 if (current_region == calorimeter_region) return;
33
34 // If the energy of the particle fell below threshold, stop processing the
35 // event.
36 if (auto energy{step->GetPostStepPoint()->GetTotalEnergy()};
37 energy < threshold_) {
38 ldmx_log(trace) << "Aborting "
39 << G4EventManager::GetEventManager()
40 ->GetConstCurrentEvent()
41 ->GetEventID();
42
43 step->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries);
44 G4RunManager::GetRunManager()->AbortEvent();
45 return;
46 }
47}
48
49} // namespace biasing
50
#define DECLARE_ACTION(CLASS)
register a new UserAction with its factory
Definition UserAction.h:215
User stepping action used to filter events where the primary particle falls below a threshold before ...
void stepping(const G4Step *step) override
Only process if the track is a primary (parentID == 0) and if the event is not aborted and the partic...
double threshold_
Energy [MeV] below which a primary should be vetoed.
PrimaryToEcalFilter(const std::string &name, framework::config::Parameters &parameters)
Constructor.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...