LDMX Software
NonFiducialFilter.cxx
1/*~~~~~~~~~~~~~*/
2/* Biasing */
3/*~~~~~~~~~~~~~*/
5
6/*~~~~~~~~~~~~*/
7/* Geant4 */
8/*~~~~~~~~~~~~*/
9#include "G4EventManager.hh"
10#include "G4RunManager.hh"
11#include "G4Step.hh"
12#include "G4String.hh"
13#include "G4Track.hh"
14
15/*~~~~~~~~~~~~~*/
16/* SimCore */
17/*~~~~~~~~~~~~~*/
18#include "SimCore/G4User/PtrRetrieval.h"
19#include "SimCore/G4User/UserTrackInformation.h"
20#include "SimCore/G4User/VolumeChecks.h"
21
22namespace biasing {
23
24bool non_fiducial = false;
25
28 : simcore::UserAction(name, parameters) {
29 recoil_max_p_ = parameters.get<double>("recoil_max_p");
30 abort_fiducial_ = parameters.get<bool>("abort_fiducial");
31}
32
33void NonFiducialFilter::stepping(const G4Step* step) {
34 // Get the track associated with this step.
35 auto track{step->GetTrack()};
36
37 // Get the PDG ID of the track and make sure it's an electron.
38 if (auto pdg_id{track->GetParticleDefinition()->GetPDGEncoding()};
39 pdg_id != 11) {
40 return;
41 }
42
43 // Only process the primary electron track
44 int parent_id{step->GetTrack()->GetParentID()};
45 if (parent_id != 0) {
46 return;
47 }
48
49 // Check in which volume the electron is currently
50 auto phys_vol = track->GetVolume();
51 auto volume{phys_vol ? phys_vol->GetLogicalVolume() : nullptr};
52
53 // Check if the track is tagged.
54 auto electron_check{simcore::UserTrackInformation::get(track)};
55 if (electron_check->isRecoilElectron() == true) {
56 if (track->GetMomentum().mag() > recoil_max_p_) {
57 // Kill the track if its momemntum is too high
58 track->SetTrackStatus(fKillTrackAndSecondaries);
59 G4RunManager::GetRunManager()->AbortEvent();
60 ldmx_log(debug) << " Recoil track momentum is too high, expected to be "
61 "fiducial, exiting\n";
62 return;
63 }
64 // Check if the track ever enters the ECal. If it does, kill the track and
65 // abort the event.
66 auto volume_name{volume ? volume->GetName() : "undefined"};
67 auto is_in_ecal =
68 simcore::g4user::volumechecks::isInEcal(volume, volume_name);
69 if (abort_fiducial_ && is_in_ecal) {
70 track->SetTrackStatus(fKillTrackAndSecondaries);
71 G4RunManager::GetRunManager()->AbortEvent();
72 ldmx_log(debug) << ">> This event is fiducial, exiting";
73 non_fiducial = false;
74 return;
75 }
76 // I comment the following debug out since it would print per step and it's
77 // hard to read but it could be otherwise useful if somebody wants to do a
78 // step-by-step debugging ldmx_log(debug) << " >> In this step this is
79 // non-fiducial, keeping it so far";
80 non_fiducial = true;
81 return;
82 } else {
83 // Check if the particle enters the recoil tracker.
84 static auto recoil_volume =
85 simcore::g4user::ptrretrieval::getLogicalVolume("recoil");
86 if (!recoil_volume) {
87 ldmx_log(warn) << "Volume 'recoil' not found in Geant4 volume store";
88 }
89 if (volume == recoil_volume) {
90 /* Tag the tracks that:
91 1) Have a recoil electron
92 2) Enter/Exit the Target */
93 auto track_info{simcore::UserTrackInformation::get(track)};
94 track_info->tagRecoilElectron(); // tag the target recoil electron
95 ldmx_log(debug) << " >> This track is the recoil electron, tagging it";
96 return;
97 }
98 }
99}
100
102 if (non_fiducial) {
103 ldmx_log(debug) << " >> This event is non-fiducial in ECAL, keeping it";
104 } else {
105 ldmx_log(debug) << ">> This event is fiducial, exiting";
106 }
107}
108} // namespace biasing
109
#define DECLARE_ACTION(CLASS)
register a new UserAction with its factory
Definition UserAction.h:215
User action that allows a user to filter out events that are non-fiducial, i.e.
void stepping(const G4Step *step) override
Implement the stepping action which performs the target volume biasing.
NonFiducialFilter(const std::string &name, framework::config::Parameters &parameters)
Constructor.
bool abort_fiducial_
If turned on, this aborts fiducial events.
void endOfEventAction(const G4Event *) override
Method called at the end of every event.
double recoil_max_p_
Recoil electron threshold.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
static UserTrackInformation * get(const G4Track *track)
get
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...