LDMX Software
PrimaryToEcalFilter.cxx
1
2#include "Biasing/PrimaryToEcalFilter.h"
3
4/*~~~~~~~~~~~~*/
5/* Geant4 */
6/*~~~~~~~~~~~~*/
7#include "G4EventManager.hh"
8#include "G4RunManager.hh"
9#include "G4Step.hh"
10
11namespace biasing {
12
14 const std::string& name, framework::config::Parameters& parameters)
15 : simcore::UserAction(name, parameters) {
16 threshold_ = parameters.getParameter<double>("threshold");
17}
18
19void PrimaryToEcalFilter::stepping(const G4Step* step) {
20 // Only process the primary electron track
21 if (int parentID{step->GetTrack()->GetParentID()}; parentID != 0) return;
22
23 if (G4EventManager::GetEventManager()->GetConstCurrentEvent()->IsAborted())
24 return;
25
26 // Get the region the particle is currently in. Continue processing
27 // the particle only if it's NOT in the calorimeter region
28 if (auto region{step->GetTrack()
29 ->GetVolume()
30 ->GetLogicalVolume()
31 ->GetRegion()
32 ->GetName()};
33 region.compareTo("CalorimeterRegion") == 0)
34 return;
35
36 // If the energy of the particle fell below threshold, stop processing the
37 // event.
38 if (auto energy{step->GetPostStepPoint()->GetTotalEnergy()};
39 energy < threshold_) {
40 /*
41 std::cout << "[ PrimaryToEcalFilter ] : Aborting "
42 <<
43 G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID() <<
44 std::endl;
45 */
46 step->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries);
47 G4RunManager::GetRunManager()->AbortEvent();
48 return;
49 }
50}
51
52} // namespace biasing
53
54DECLARE_ACTION(biasing, PrimaryToEcalFilter)
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:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89