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