LDMX Software
TargetDarkBremFilter.cxx
1/*
2 * @file TargetDarkBremFilter.cxx
3 * @class TargetDarkBremFilter
4 * @brief Class defining a UserActionPlugin that allows a user to filter out
5 * events that don't result in a dark brem within a given volume
6 * @author Michael Revering, University of Minnesota
7 * @author Tom Eichlersmith, University of Minnesota
8 */
9
11
12#include "G4DarkBreM/G4APrime.h" //checking if particles match A'
13#include "G4Electron.hh" //to check if track is electron
14
15namespace biasing {
16
18 const std::string& name, framework::config::Parameters& parameters)
19 : simcore::UserAction(name, parameters) {
20 threshold_ = parameters.get<double>("threshold");
21}
22
24 found_aprime_ = false;
25}
26
27void TargetDarkBremFilter::stepping(const G4Step* step) {
28 // don't process if event is already aborted
29 if (G4EventManager::GetEventManager()->GetConstCurrentEvent()->IsAborted())
30 return;
31
32 // Get the track associated with this step.
33 auto track{step->GetTrack()};
34
35 // Leave if track is not an electron
36 auto particle_def{track->GetParticleDefinition()};
37 if (particle_def != G4Electron::Electron()) {
38 if (particle_def == G4APrime::APrime() and
39 track->GetCurrentStepNumber() == 1) {
52 if (isOutsideTargetRegion(track->GetLogicalVolumeAtVertex()))
53 abortEvent("A' was not created within target.");
54 // A' was found and originated in correct region
55 found_aprime_ = true;
56 } // first step of A'
57 return;
58 }
59
60 // Leave if track is not primary
61 if (track->GetParentID() != 0) return;
62
63 // Leave if track is not in target region
64 if (isOutsideTargetRegion(track->GetVolume())) return;
65
66 if (isOutsideTargetRegion(track->GetNextVolume()) // leaving target region
67 or
68 track->GetTrackStatus() == fStopAndKill // stopping within target region
69 or track->GetKineticEnergy() == 0. // stopping within target region
70 ) {
71 // Get the electron secondries
72 const std::vector<G4Track*>* secondaries{step->GetSecondary()};
73 if (not secondaries or secondaries->size() == 0) {
74 abortEvent("Primary electron did not create secondaries.");
75 return;
76 } else {
77 // check secondaries to see if we made a dark brem
78 for (auto& secondary_track : *secondaries) {
79 if (secondary_track->GetParticleDefinition() == G4APrime::APrime()) {
80 // we found an A', woo-hoo!
81
82 if (secondary_track->GetTotalEnergy() < threshold_) {
84 "A' was not created with total energy above input threshold.");
85 return;
86 }
87
88 if (isOutsideTargetRegion(secondary_track->GetVolume())) {
89 abortEvent("A' was not created within target.");
90 return;
91 }
92
93 /* debug message
94 std::cout << "[ TargetDarkBremFilter ] : "
95 << "(" <<
96 G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID()
97 << ") "
98 << "Found an A' weighted " << secondary_track->GetWeight()
99 << " originating in " <<
100 secondary_track->GetVolume()->GetLogicalVolume()->GetName()
101 << " with energy " << secondary_track->GetTotalEnergy() << " MeV."
102 << std::endl;
103 */
104
105 // we found a good A', so we can leave
106 return;
107 } // this secondary is an A'
108 } // loop through secondaries
109 } // are there secondaries to loop through
110
111 // got here without finding A'
112 abortEvent("Primary electron did not create A'.");
113 return;
114 } // should check secondaries of primary
115
116 // get here if we are the primary in the target region,
117 // but shouldn't check the secondaries yet
118 return;
119}
120
121void TargetDarkBremFilter::endOfEventAction(const G4Event* event) {
122 if (not event->IsAborted() and not found_aprime_) {
123 abortEvent("Did not find an A' after entire event was simulated.");
124 }
125}
126
127} // namespace biasing
128
#define DECLARE_ACTION(CLASS)
register a new UserAction with its factory
Definition UserAction.h:215
This class is meant to filter for events that produce a dark brem matching originating in the target ...
void stepping(const G4Step *step) override
Looking for A' while primary is stepping.
TargetDarkBremFilter(const std::string &name, framework::config::Parameters &parameters)
Class constructor.
void endOfEventAction(const G4Event *event) override
Check flag signaling finding of A', if false, abort the event so it isn't saved.
double threshold_
Minimum energy [MeV] that the A' should have to keep the event.
bool isOutsideTargetRegion(const G4VPhysicalVolume *vol) const
Check if the volume is outside the target region.
bool found_aprime_
flag to signal that we saw an A'
void beginOfEventAction(const G4Event *e) override
Reset flag signaling finding of A' to false.
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
void abortEvent(const std::string &reason) const
Helper to abort an event with a message.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...