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/VolumeChecks.h"
20#include "SimCore/UserEventInformation.h"
21#include "SimCore/UserTrackInformation.h"
22
23namespace biasing {
24
25bool nonFiducial_ = false;
26
29 : simcore::UserAction(name, parameters) {
30 recoil_max_p_ = parameters.getParameter<double>("recoil_max_p");
31 abort_fiducial_ = parameters.getParameter<bool>("abort_fiducial");
32}
33
34void NonFiducialFilter::stepping(const G4Step* step) {
35 // Get the track associated with this step.
36 auto track{step->GetTrack()};
37
38 // Get the PDG ID of the track and make sure it's an electron.
39 if (auto pdgID{track->GetParticleDefinition()->GetPDGEncoding()};
40 pdgID != 11) {
41 return;
42 }
43
44 // Only process the primary electron track
45 int parentID{step->GetTrack()->GetParentID()};
46 if (parentID != 0) {
47 return;
48 }
49
50 // Check in which volume the electron is currently
51 auto phys_vol = track->GetVolume();
52 auto volume{phys_vol ? phys_vol->GetLogicalVolume() : nullptr};
53
54 // Check if the track is tagged.
55 auto electronCheck{simcore::UserTrackInformation::get(track)};
56 if (electronCheck->isRecoilElectron() == true) {
57 if (track->GetMomentum().mag() > recoil_max_p_) {
58 // Kill the track if its momemntum is too high
59 track->SetTrackStatus(fKillTrackAndSecondaries);
60 G4RunManager::GetRunManager()->AbortEvent();
61 ldmx_log(debug) << " Recoil track momentum is too high, expected to be "
62 "fiducial, exiting\n";
63 return;
64 }
65 // Check if the track ever enters the ECal. If it does, kill the track and
66 // abort the event.
67 auto volume_name{volume ? volume->GetName() : "undefined"};
68 auto is_in_ecal =
69 simcore::g4user::volumechecks::isInEcal(volume, volume_name);
70 if (abort_fiducial_ && is_in_ecal) {
71 track->SetTrackStatus(fKillTrackAndSecondaries);
72 G4RunManager::GetRunManager()->AbortEvent();
73 ldmx_log(debug) << ">> This event is fiducial, exiting";
74 nonFiducial_ = false;
75 return;
76 }
77 // I comment the following debug out since it would print per step and it's
78 // hard to read but it could be otherwise useful if somebody wants to do a
79 // step-by-step debugging ldmx_log(debug) << " >> In this step this is
80 // non-fiducial, keeping it so far";
81 nonFiducial_ = true;
82 return;
83 } else {
84 // Check if the particle enters the recoil tracker.
85 static auto recoil_volume =
86 simcore::g4user::ptrretrieval::getLogicalVolume("recoil");
87 if (!recoil_volume) {
88 ldmx_log(warn) << "Volume 'recoil' not found in Geant4 volume store";
89 }
90 if (volume == recoil_volume) {
91 /* Tag the tracks that:
92 1) Have a recoil electron
93 2) Enter/Exit the Target */
94 auto trackInfo{simcore::UserTrackInformation::get(track)};
95 trackInfo->tagRecoilElectron(); // tag the target recoil electron
96 ldmx_log(debug) << " >> This track is the recoil electron, tagging it";
97 return;
98 }
99 }
100}
101
103 if (nonFiducial_) {
104 ldmx_log(debug) << " >> This event is non-fiducial in ECAL, keeping it";
105 } else {
106 ldmx_log(debug) << ">> This event is fiducial, exiting";
107 }
108}
109} // namespace biasing
110
111DECLARE_ACTION(biasing, NonFiducialFilter)
Class defining a UserActionPlugin that allows a user to filter out non-fiducial events,...
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.
void EndOfEventAction(const G4Event *) override
Method called at the end of every event.
bool abort_fiducial_
If turned on, this aborts fiducial events.
double recoil_max_p_
Recoil electron threshold.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
static UserTrackInformation * get(const G4Track *track)
get