LDMX Software
PhotoNuclearProductsFilter.cxx
1#include "Biasing/PhotoNuclearProductsFilter.h"
2
3/*~~~~~~~~~~~~~~~~*/
4/* C++ StdLib */
5/*~~~~~~~~~~~~~~~~*/
6#include <cmath>
7
8/*~~~~~~~~~~~~*/
9/* Geant4 */
10/*~~~~~~~~~~~~*/
11#include "G4RunManager.hh"
12#include "G4Step.hh"
13#include "G4Track.hh"
14
15/*~~~~~~~~~~~~~*/
16/* SimCore */
17/*~~~~~~~~~~~~~*/
18#include "SimCore/UserTrackInformation.h"
19
20namespace biasing {
21
23 const std::string& name, framework::config::Parameters& parameters)
24 : simcore::UserAction(name, parameters) {
25 productsPdgID_ = parameters.getParameter<std::vector<int> >("pdg_ids");
26 min_e = parameters.getParameter<double>("min_e");
27}
28
30
31void PhotoNuclearProductsFilter::stepping(const G4Step* step) {
32 // Get the track associated with this step.
33 auto track{step->GetTrack()};
34
35 // Get the track info and check if this track has been tagged as the
36 // photon that underwent a photo-nuclear reaction. Only those tracks
37 // tagged as PN photos will be processed. The track is currently only
38 // tagged by the UserAction ECalProcessFilter which needs to be run
39 // before this UserAction.
40 auto trackInfo{simcore::UserTrackInformation::get(track)};
41 if ((trackInfo != nullptr) && !trackInfo->isPNGamma()) return;
42
43 // Get the PN photon daughters.
44 auto secondaries{step->GetSecondary()};
45
46 // Loop through all of the secondaries and check for the product of
47 // interest. This is done by getting the PDG ID of a daughter and
48 // checking that it's in the vector of PDG IDs passed to this
49 // UserAction.
50 bool productFound{false};
51 for (const auto& secondary : *secondaries) {
52 // Get the PDG ID of the track
53 auto pdgID{std::abs(secondary->GetParticleDefinition()->GetPDGEncoding())};
54
55 // Check if the PDG ID is in the list of products of interest
56 if (std::find(productsPdgID_.begin(), productsPdgID_.end(), pdgID) !=
57 productsPdgID_.end()) {
58 if (secondary->GetKineticEnergy() > min_e) {
59 productFound = true;
60 }
61 break;
62 }
63 }
64
65 // If the product of interest was not found, kill the track and abort
66 // the event.
67 if (!productFound) {
68 track->SetTrackStatus(fKillTrackAndSecondaries);
69 G4RunManager::GetRunManager()->AbortEvent();
70 return;
71 }
72
73 // Once the PN gamma has been procesed, untag it so its not reprocessed
74 // again.
75 if (trackInfo) {
76 trackInfo->tagPNGamma(false);
77 }
78}
79} // namespace biasing
80
81DECLARE_ACTION(biasing, PhotoNuclearProductsFilter)
std::vector< int > productsPdgID_
Container to hold the PDG IDs of products of interest.
void stepping(const G4Step *step) override
Callback that allows a user to take some actions at the end of a step.
PhotoNuclearProductsFilter(const std::string &name, framework::config::Parameters &parameters)
Constructor.
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
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.