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