LDMX Software
TargetBremFilter.cxx
1
2#include "Biasing/TargetBremFilter.h"
3
4/*~~~~~~~~~~~~*/
5/* Geant4 */
6/*~~~~~~~~~~~~*/
7#include "G4EventManager.hh"
8#include "G4RunManager.hh"
9
10/*~~~~~~~~~~~~~*/
11/* SimCore */
12/*~~~~~~~~~~~~~*/
13#include "SimCore/UserEventInformation.h"
14#include "SimCore/UserTrackInformation.h"
15
16namespace biasing {
17
18TargetBremFilter::TargetBremFilter(const std::string& name,
20 : simcore::UserAction(name, parameters) {
22 parameters.getParameter<double>("recoil_max_p_threshold");
24 parameters.getParameter<double>("brem_min_energy_threshold");
25 killRecoil_ = parameters.getParameter<bool>("kill_recoil_track");
26}
27
29
30G4ClassificationOfNewTrack TargetBremFilter::ClassifyNewTrack(
31 const G4Track* track, const G4ClassificationOfNewTrack& currentTrackClass) {
32 // get the PDGID of the track.
33 G4int pdgID = track->GetParticleDefinition()->GetPDGEncoding();
34
35 // Get the particle type.
36 G4String particleName = track->GetParticleDefinition()->GetParticleName();
37
38 // Use current classification by default so values from other plugins are not
39 // overridden.
40 G4ClassificationOfNewTrack classification = currentTrackClass;
41
42 if (track->GetTrackID() == 1 && pdgID == 11) {
43 return fWaiting;
44 }
45
46 return classification;
47}
48
49void TargetBremFilter::stepping(const G4Step* step) {
50 // Get the track associated with this step.
51 auto track{step->GetTrack()};
52
53 // Only process the primary electron track
54 if (track->GetParentID() != 0) return;
55
56 // Get the PDG ID of the track and make sure it's an electron. If
57 // another particle type is found, thrown an exception.
58 if (auto pdgID{track->GetParticleDefinition()->GetPDGEncoding()}; pdgID != 11)
59 return;
60
61 // Get the region the particle is currently in. Continue processing
62 // the particle only if it's in the target region.
63 if (auto region{
64 track->GetVolume()->GetLogicalVolume()->GetRegion()->GetName()};
65 region.compareTo("target") != 0)
66 return;
67
68 /*
69 std::cout << "[TargetBremFilter] : Stepping primary electron in 'target'
70 region into "
71 << track->GetNextVolume()->GetName()
72 << std::endl;
73 */
74
87 if (auto volume{track->GetNextVolume()->GetName()};
88 volume.compareTo("recoil_PV") == 0 or volume.compareTo("World_PV") == 0) {
89 // If the recoil electron
90 if (track->GetMomentum().mag() >= recoilMaxPThreshold_) {
91 track->SetTrackStatus(fKillTrackAndSecondaries);
92 G4RunManager::GetRunManager()->AbortEvent();
93 return;
94 }
95
96 // Get the electron secondries
97 bool hasBremCandidate = false;
98 if (auto secondaries = step->GetSecondary(); secondaries->size() == 0) {
99 track->SetTrackStatus(fKillTrackAndSecondaries);
100 G4RunManager::GetRunManager()->AbortEvent();
101 return;
102 } else {
103 for (auto& secondary_track : *secondaries) {
104 G4String processName =
105 secondary_track->GetCreatorProcess()->GetProcessName();
106
107 if (processName.compareTo("eBrem") == 0 &&
108 secondary_track->GetKineticEnergy() > bremEnergyThreshold_) {
109 auto trackInfo{simcore::UserTrackInformation::get(secondary_track)};
110 trackInfo->tagBremCandidate();
111
113
114 hasBremCandidate = true;
115 }
116 }
117 }
118
119 if (!hasBremCandidate) {
120 track->SetTrackStatus(fKillTrackAndSecondaries);
121 G4RunManager::GetRunManager()->AbortEvent();
122 return;
123 }
124
125 /*
126 std::cout << "[TargetBremFilter] : Found brem candidate" << std::endl;
127 */
128
129 // Check if the recoil electron should be killed. If not, postpone
130 // its processing until the brem gamma has been processed.
131 if (killRecoil_)
132 track->SetTrackStatus(fStopAndKill);
133 else
134 track->SetTrackStatus(fSuspend);
135
136 } else if (step->GetPostStepPoint()->GetKineticEnergy() == 0) {
137 track->SetTrackStatus(fKillTrackAndSecondaries);
138 G4RunManager::GetRunManager()->AbortEvent();
139 return;
140 }
141}
142
144} // namespace biasing
145
146DECLARE_ACTION(biasing, TargetBremFilter)
bool killRecoil_
Flag indicating if the recoil electron track should be killed.
void EndOfEventAction(const G4Event *) override
Method called at the end of every event.
TargetBremFilter(const std::string &name, framework::config::Parameters &parameters)
Constructor.
void stepping(const G4Step *step) override
Implement the stepping action which performs the target volume biasing.
G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack, const G4ClassificationOfNewTrack &currentTrackClass) override
Classify a new track which postpones track processing.
double recoilMaxPThreshold_
Recoil electron threshold.
double bremEnergyThreshold_
Brem gamma energy treshold.
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
UserEventInformation * getEventInfo() const
Get a handle to the event information.
void incBremCandidateCount()
Increment the number of brem candidates in an event.
static UserTrackInformation * get(const G4Track *track)
get
void tagBremCandidate(bool isBremCandidate=true)
Tag this track as a brem candidate by the biasing filters.