LDMX Software
NonFiducialFilter.cxx
2
3/*~~~~~~~~~~~~*/
4/* Geant4 */
5/*~~~~~~~~~~~~*/
6#include "G4EventManager.hh"
7#include "G4RunManager.hh"
8#include "G4Step.hh"
9#include "G4String.hh"
10#include "G4Track.hh"
11
12/*~~~~~~~~~~~~~*/
13/* SimCore */
14/*~~~~~~~~~~~~~*/
15#include "SimCore/UserEventInformation.h"
16#include "SimCore/UserTrackInformation.h"
17
18namespace biasing {
19
20bool nonFiducial_ = false;
21
24 : simcore::UserAction(name, parameters) {
25 recoil_max_p_ = parameters.getParameter<double>("recoil_max_p");
26 abort_fiducial_ = parameters.getParameter<bool>("abort_fiducial");
27}
28
29void NonFiducialFilter::stepping(const G4Step* step) {
30 // Get the track associated with this step.
31 auto track{step->GetTrack()};
32
33 // Get the PDG ID of the track and make sure it's an electron.
34 if (auto pdgID{track->GetParticleDefinition()->GetPDGEncoding()};
35 pdgID != 11) {
36 return;
37 }
38
39 // Only process the primary electron track
40 int parentID{step->GetTrack()->GetParentID()};
41 if (parentID != 0) {
42 return;
43 }
44
45 // Check in which volume the electron is currently
46 auto volume{track->GetVolume()->GetLogicalVolume()
47 ? track->GetVolume()->GetLogicalVolume()->GetName()
48 : "undefined"};
49
50 // Check if the track is tagged.
51 auto electronCheck{simcore::UserTrackInformation::get(track)};
52 if (electronCheck->isRecoilElectron() == true) {
53 if (track->GetMomentum().mag() > recoil_max_p_) {
54 // Kill the track if its momemntum is too high
55 track->SetTrackStatus(fKillTrackAndSecondaries);
56 G4RunManager::GetRunManager()->AbortEvent();
57 ldmx_log(debug) << " Recoil track momentum is too high, expected to be "
58 "fiducial, exiting\n";
59 return;
60 }
61 // Check if the track ever enters the ECal. If it does, kill the track and
62 // abort the event.
63 auto isInEcal{((volume.contains("Si") || volume.contains("W") ||
64 volume.contains("PCB") || volume.contains("strongback") ||
65 volume.contains("Glue") || volume.contains("CFMix") ||
66 volume.contains("Al") || volume.contains("C")) &&
67 volume.contains("volume")) ||
68 (volume.contains("nohole_motherboard"))};
69
70 // isInEcal should be taken from
71 // simcore::logical_volume_tests::isInEcal(volume) but for now it's under
72 // its own namespace so I cannot reach it here see issue
73 // https://github.com/LDMX-Software/ldmx-sw/issues/1286
74 if (abort_fiducial_ && isInEcal) {
75 track->SetTrackStatus(fKillTrackAndSecondaries);
76 G4RunManager::GetRunManager()->AbortEvent();
77 ldmx_log(debug) << ">> This event is fiducial, exiting";
78 nonFiducial_ = false;
79 return;
80 }
81 // I comment the following debug out since it would print per step and it's
82 // hard to read but it could be otherwise useful if somebody wants to do a
83 // step-by-step debugging ldmx_log(debug) << " >> In this step this is
84 // non-fiducial, keeping it so far";
85 nonFiducial_ = true;
86 return;
87 } else {
88 // Check if the particle enters the recoil tracker.
89 if (volume.compareTo("recoil") == 0) {
90 /* Tag the tracks that:
91 1) Have a recoil electron
92 2) Enter/Exit the Target */
93 auto trackInfo{simcore::UserTrackInformation::get(track)};
94 trackInfo->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 (nonFiducial_) {
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
110DECLARE_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: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 tagRecoilElectron(bool isRecoilElectron=true)
Tag this track as a recoil electron by the biasing filters.