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/G4User/UserTrackInformation.h"
19
20namespace biasing {
21
23 const std::string& name, framework::config::Parameters& parameters)
24 : simcore::UserAction(name, parameters) {
25 products_pdg_id_ = parameters.get<std::vector<int> >("pdg_ids");
26 min_e_ = parameters.get<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 track_info{simcore::UserTrackInformation::get(track)};
41 if ((track_info != nullptr) && !track_info->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 product_found{false};
51 for (const auto& secondary : *secondaries) {
52 // Get the PDG ID of the track
53 auto pdg_id{std::abs(secondary->GetParticleDefinition()->GetPDGEncoding())};
54
55 // Check if the PDG ID is in the list of products of interest
56 if (std::find(products_pdg_id_.begin(), products_pdg_id_.end(), pdg_id) !=
57 products_pdg_id_.end()) {
58 if (secondary->GetKineticEnergy() > min_e_) {
59 product_found = 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 (!product_found) {
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 (track_info) {
76 track_info->tagPNGamma(false);
77 }
78}
79} // namespace biasing
80
#define DECLARE_ACTION(CLASS)
register a new UserAction with its factory
Definition UserAction.h:206
User action used to filter out photo-nuclear events that don't see the photo-nuclear gamma produce sp...
std::vector< int > products_pdg_id_
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:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
static UserTrackInformation * get(const G4Track *track)
get
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...