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 recoilEnergyThreshold_ = parameters.getParameter<double>("recoilThreshold");
28}
29
31
32void TargetENProcessFilter::stepping(const G4Step* step) {
33 if (reactionOccurred_) 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 pdgID = track->GetParticleDefinition()->GetPDGEncoding();
43
44 // Make sure that the particle being processed is an electron.
45 if (pdgID != 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 /*std::cout << "*******************************" << std::endl;
58 std::cout << "* Step " << track->GetCurrentStepNumber() << std::endl;
59 std::cout << "********************************" << std::endl;*/
60
61 if (track->GetMomentum().mag() > recoilEnergyThreshold_) {
62 track->SetTrackStatus(fKillTrackAndSecondaries);
63 G4RunManager::GetRunManager()->AbortEvent();
64 return;
65 }
66
67 // Get the particles daughters.
68 const G4TrackVector* secondaries = step->GetSecondary();
69
70 // If the brem photon doesn't undergo any reaction in the target, stop
71 // processing the rest of the event.
72 if (secondaries->size() == 0) {
73 /*std::cout << "[ TargetENProcessFilter ]: "
74 << "Electron did not interact in the target. --> Postponing
75 tracks."
76 << std::endl;*/
77
78 track->SetTrackStatus(fKillTrackAndSecondaries);
79 G4RunManager::GetRunManager()->AbortEvent();
80 return;
81 } else {
82 G4String processName =
83 secondaries->at(0)->GetCreatorProcess()->GetProcessName();
84
85 /*std::cout << "[ TargetENProcessFilter ]: "
86 << "Electron produced " << secondaries->size()
87 << " particle via " << processName << " process."
88 << std::endl;*/
89
90 // Only record the process that is being biased
91 if (!processName.contains(process_)) {
92 /*std::cout << "[ TargetENProcessFilter ]: "
93 << "Process was not " << BiasingMessenger::getProcess() << "-->
94 Killing all tracks!"
95 << std::endl;*/
96
97 track->SetTrackStatus(fKillTrackAndSecondaries);
98 G4RunManager::GetRunManager()->AbortEvent();
99 return;
100 }
101
102 std::cout << "[ TargetENProcessFilter ]: "
103 << "Electronuclear reaction resulted in " << secondaries->size()
104 << " particles via " << processName << " process." << std::endl;
105 // BiasingMessenger::setEventWeight(track->GetWeight());
106 reactionOccurred_ = true;
107 }
108}
109
111 reactionOccurred_ = false;
112}
113} // namespace biasing
114
115DECLARE_ACTION(biasing, TargetENProcessFilter)
Class defining a UserActionPlugin that biases Geant4 to only process events which involve an electron...
void EndOfEventAction(const G4Event *) override
End of event action.
TargetENProcessFilter(const std::string &name, framework::config::Parameters &parameters)
Class constructor.
bool reactionOccurred_
Flag indicating if the reaction of intereset occurred.
void stepping(const G4Step *step) override
Implementmthe stepping action which performs the target volume biasing.
double recoilEnergyThreshold_
Energy that the recoil electron must not surpass.
std::string process_
Process to filter on.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29