LDMX Software
TargetENProcessFilter.cxx
Go to the documentation of this file.
1
9
10/*~~~~~~~~~~~~*/
11/* Geant4 */
12/*~~~~~~~~~~~~*/
13#include "G4RunManager.hh"
14
15namespace biasing {
16
18 const std::string& name, framework::config::Parameters& parameters)
19 : simcore::UserAction(name, parameters) {
20 recoilEnergyThreshold_ = parameters.getParameter<double>("recoilThreshold");
21}
22
24
25void TargetENProcessFilter::stepping(const G4Step* step) {
26 if (reactionOccurred_) return;
27
28 // Get the track associated with this step.
29 G4Track* track = step->GetTrack();
30
31 // Only process tracks whose parent is the primary particle
32 if (track->GetParentID() != 0) return;
33
34 // get the PDGID of the track.
35 G4int pdgID = track->GetParticleDefinition()->GetPDGEncoding();
36
37 // Make sure that the particle being processed is an electron.
38 if (pdgID != 11) return; // Throw an exception
39
40 // Get the volume the particle is in.
41 G4VPhysicalVolume* volume = track->GetVolume();
42 G4String volumeName = volume->GetName();
43
44 // If the particle isn't in the target, don't continue with the processing.
45 if (volumeName.compareTo(volumeName_) != 0) return;
46
47 /*std::cout << "*******************************" << std::endl;
48 std::cout << "* Step " << track->GetCurrentStepNumber() << std::endl;
49 std::cout << "********************************" << std::endl;*/
50
51 if (track->GetMomentum().mag() > recoilEnergyThreshold_) {
52 track->SetTrackStatus(fKillTrackAndSecondaries);
53 G4RunManager::GetRunManager()->AbortEvent();
54 return;
55 }
56
57 // Get the particles daughters.
58 const G4TrackVector* secondaries = step->GetSecondary();
59
60 // If the brem photon doesn't undergo any reaction in the target, stop
61 // processing the rest of the event.
62 if (secondaries->size() == 0) {
63 /*std::cout << "[ TargetENProcessFilter ]: "
64 << "Electron did not interact in the target. --> Postponing
65 tracks."
66 << std::endl;*/
67
68 track->SetTrackStatus(fKillTrackAndSecondaries);
69 G4RunManager::GetRunManager()->AbortEvent();
70 return;
71 } else {
72 G4String processName =
73 secondaries->at(0)->GetCreatorProcess()->GetProcessName();
74
75 /*std::cout << "[ TargetENProcessFilter ]: "
76 << "Electron produced " << secondaries->size()
77 << " particle via " << processName << " process."
78 << std::endl;*/
79
80 // Only record the process that is being biased
81 if (!processName.contains(process_)) {
82 /*std::cout << "[ TargetENProcessFilter ]: "
83 << "Process was not " << BiasingMessenger::getProcess() << "-->
84 Killing all tracks!"
85 << std::endl;*/
86
87 track->SetTrackStatus(fKillTrackAndSecondaries);
88 G4RunManager::GetRunManager()->AbortEvent();
89 return;
90 }
91
92 std::cout << "[ TargetENProcessFilter ]: "
93 << "Electronuclear reaction resulted in " << secondaries->size()
94 << " particles via " << processName << " process." << std::endl;
95 // BiasingMessenger::setEventWeight(track->GetWeight());
96 reactionOccurred_ = true;
97 }
98}
99
101 reactionOccurred_ = false;
102}
103} // namespace biasing
104
105DECLARE_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.
std::string volumeName_
The volume name of the LDMX target.
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:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89