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