LDMX Software
TargetENProcessFilter.cxx
Go to the documentation of this file.
1
7/*~~~~~~~~~~~~~*/
8/* Biasing */
9/*~~~~~~~~~~~~~*/
11
12/*~~~~~~~~~~~~*/
13/* Geant4 */
14/*~~~~~~~~~~~~*/
15#include "G4RunManager.hh"
16
17/*~~~~~~~~~~~~~*/
18/* SimCore */
19/*~~~~~~~~~~~~~*/
20#include "SimCore/G4User/PtrRetrieval.h"
21
22namespace biasing {
23
25 const std::string& name, framework::config::Parameters& parameters)
26 : simcore::UserAction(name, parameters) {
27 recoil_energy_threshold_ = parameters.get<double>("recoilThreshold");
28}
29
31
32void TargetENProcessFilter::stepping(const G4Step* step) {
33 if (reaction_occurred_) return;
34
35 // Get the track associated with this step.
36 G4Track* track = step->GetTrack();
37
38 // Only process tracks whose parent is the primary particle
39 if (track->GetParentID() != 0) return;
40
41 // get the PDGID of the track.
42 G4int pdg_id = track->GetParticleDefinition()->GetPDGEncoding();
43
44 // Make sure that the particle being processed is an electron.
45 if (pdg_id != 11) return; // Throw an exception
46
47 // Get the volume the particle is in.
48 G4VPhysicalVolume* track_volume = track->GetVolume();
49 auto target_volume =
50 simcore::g4user::ptrretrieval::getPhysicalVolume("target_PV");
51 if (!target_volume) {
52 ldmx_log(warn) << "Volume 'target_PV' not found in Geant4 volume store";
53 }
54 // If the particle isn't in the target, don't continue with the processing.
55 if (track_volume != target_volume) return;
56
57 // ldmx_log(trace)<< "* Step " << track->GetCurrentStepNumber();
58
59 if (track->GetMomentum().mag() > recoil_energy_threshold_) {
60 track->SetTrackStatus(fKillTrackAndSecondaries);
61 G4RunManager::GetRunManager()->AbortEvent();
62 return;
63 }
64
65 // Get the particles daughters.
66 const G4TrackVector* secondaries = step->GetSecondary();
67
68 // If the brem photon doesn't undergo any reaction in the target, stop
69 // processing the rest of the event.
70 if (secondaries->size() == 0) {
71 ldmx_log(debug)
72 << "Electron did not interact in the target. --> Postponing tracks.";
73
74 track->SetTrackStatus(fKillTrackAndSecondaries);
75 G4RunManager::GetRunManager()->AbortEvent();
76 return;
77 } else {
78 G4String process_name =
79 secondaries->at(0)->GetCreatorProcess()->GetProcessName();
80
81 ldmx_log(debug) << "Electron produced " << secondaries->size()
82 << " particle via " << process_name << " process.";
83
84 // Only record the process that is being biased
85 if (!process_name.contains(process_)) {
86 ldmx_log(debug) << "Process was not " << process_
87 << "--> Killing all tracks!";
88
89 track->SetTrackStatus(fKillTrackAndSecondaries);
90 G4RunManager::GetRunManager()->AbortEvent();
91 return;
92 }
93
94 ldmx_log(info) << "Electronuclear reaction resulted in "
95 << secondaries->size() << " particles via " << process_name
96 << " process.";
97 // BiasingMessenger::setEventWeight(track->GetWeight());
98 reaction_occurred_ = true;
99 }
100}
101
103 reaction_occurred_ = false;
104}
105} // namespace biasing
106
Class defining a UserActionPlugin that biases Geant4 to only process events which involve an electron...
#define DECLARE_ACTION(CLASS)
register a new UserAction with its factory
Definition UserAction.h:206
void EndOfEventAction(const G4Event *) override
End of event action.
bool reaction_occurred_
Flag indicating if the reaction of intereset occurred.
double recoil_energy_threshold_
Energy that the recoil electron must not surpass.
TargetENProcessFilter(const std::string &name, framework::config::Parameters &parameters)
Class constructor.
void stepping(const G4Step *step) override
Implementmthe stepping action which performs the target volume biasing.
std::string process_
Process to filter on.
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 ...