LDMX Software
PhotoNuclearTopologyFilters.cxx
1#include "Biasing/PhotoNuclearTopologyFilters.h"
2
3namespace biasing {
4
5bool NothingHardFilter::rejectEvent(
6 const std::vector<G4Track*>& secondaries) const {
7 for (const auto& secondary : secondaries) {
8 // Get the PDG ID of the track
9 const auto pdgID{
10 std::abs(secondary->GetParticleDefinition()->GetPDGEncoding())};
11 if (skipCountingParticle(pdgID)) {
12 continue;
13 }
14 auto energy{secondary->GetKineticEnergy()};
15 if (energy > hard_particle_threshold_) {
16 return true;
17 }
18 }
19 return false;
20}
21bool SingleNeutronFilter::rejectEvent(
22 const std::vector<G4Track*>& secondaries) const {
23 int hard_particles{0};
24 int hard_neutrons{0};
25 for (const auto& secondary : secondaries) {
26 // Get the PDG ID of the track
27 const auto pdgID{
28 std::abs(secondary->GetParticleDefinition()->GetPDGEncoding())};
29 if (skipCountingParticle(pdgID)) {
30 continue;
31 }
32 auto energy{secondary->GetKineticEnergy()};
33 if (energy > hard_particle_threshold_) {
34 hard_particles++;
35 if (isNeutron(pdgID)) {
36 hard_neutrons++;
37 }
38 }
39 }
40 auto reject{hard_particles != hard_neutrons || hard_particles != 1};
41 return reject;
42}
43
45 const std::string& name, framework::config::Parameters& parameters)
46 : UserAction{name, parameters},
47 count_light_ions_{parameters.getParameter<bool>("count_light_ions")},
48 hard_particle_threshold_{
49 parameters.getParameter<double>("hard_particle_threshold")} {}
50
51void PhotoNuclearTopologyFilter::stepping(const G4Step* step) {
52 // Get the track associated with this step.
53 auto track{step->GetTrack()};
54
55 // Get the track info and check if this track has been tagged as the
56 // photon that underwent a photo-nuclear reaction. Only those tracks
57 // tagged as PN photos will be processed. The track is currently only
58 // tagged by the UserAction ECalProcessFilter which needs to be run
59 // before this UserAction.
60 auto trackInfo{simcore::UserTrackInformation::get(track)};
61 if ((trackInfo != nullptr) && !trackInfo->isPNGamma()) return;
62
63 // Get the PN photon daughters.
64 auto secondaries{step->GetSecondary()};
65
66 if (rejectEvent(*secondaries)) {
67 track->SetTrackStatus(fKillTrackAndSecondaries);
68 G4RunManager::GetRunManager()->AbortEvent();
69 }
70
71 // Once the PN gamma has been procesed, untag it so its not reprocessed
72 // again.
73 if (trackInfo) {
74 trackInfo->tagPNGamma(false);
75 }
76}
77
78} // namespace biasing
79
80DECLARE_ACTION(biasing, NothingHardFilter)
81DECLARE_ACTION(biasing, SingleNeutronFilter)
PhotoNuclearTopologyFilter(const std::string &name, framework::config::Parameters &parameters)
Constructor.
void stepping(const G4Step *step) override
Callback that allows a user to take some actions at the end of a step.
constexpr bool skipCountingParticle(const int pdgcode) const
Whether or not to include a particular particle type in any counting.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
static UserTrackInformation * get(const G4Track *track)
get
void tagPNGamma(bool isPNGamma=true)
Tag this track as a photon that has undergone a photo-nuclear reaction.