LDMX Software
DeepEcalProcessFilter.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/G4User/UserEventInformation.h"
16#include "SimCore/G4User/UserTrackInformation.h"
17#include "SimCore/G4User/VolumeChecks.h"
18
19namespace biasing {
20
22 const std::string& name, framework::config::Parameters& parameters)
23 : simcore::UserAction(name, parameters) {
24 bias_threshold_ = parameters.get<double>("bias_threshold");
25 processes_ = parameters.get<std::vector<std::string>>("processes");
26 ecal_min_z_ = parameters.get<double>("ecal_min_z");
28 parameters.get<bool>("require_photon_from_target");
29}
30
33 photon_from_target_ = false;
34}
35
36void DeepEcalProcessFilter::stepping(const G4Step* step) {
37 // Get the track associated with this step.
38 auto track{step->GetTrack()};
39
40 // Check the creation process and PDG ID of the particle
41 auto process_name = track->GetCreatorProcess()
42 ? track->GetCreatorProcess()->GetProcessName()
43 : "unknown";
44 auto pd_gid = track->GetParticleDefinition()->GetPDGEncoding();
45
46 // Skip the steps that are for the recoil electron
47 // PrimaryToEcalFilter made sure there is a fiducial e-
48 if (process_name.contains("unknown")) return;
49
50 // Energy of the particle is below threshold, move to next step
51 if (track->GetKineticEnergy() < bias_threshold_) {
52 return;
53 }
54
55 // Check in which volume the particle is currently
56 auto phys_vol{track->GetVolume()};
57 auto volume{phys_vol ? phys_vol->GetLogicalVolume() : nullptr};
58 auto volume_name{volume ? volume->GetName() : "undefined"};
59
60 auto track_info{simcore::UserTrackInformation::get(track)};
61 // Tag the brem photon from the primary electron
62 if (process_name.contains("eBrem") and (track->GetParentID() == 1)) {
63 track_info->tagBremCandidate();
65 track_info->setSaveFlag(true);
66 if (volume_name.contains("target")) {
68 }
69 }
70
71 // If we require that the photon comes from the target and
72 // and if it does not, let's skip the event
74 return;
75 }
76
77 // Tag if the event has the processes we are looking for
78 bool has_process_needed{false};
79 for (auto& process : processes_) {
80 // ldmx_log(debug) << "Allowed processed " << process << " now we have " <<
81 // processName;
82 if (process_name.contains(process)) {
83 has_process_needed = true;
84 break;
85 }
86 }
87 // skip this step if it does not have any of the processes needed
88 if (not has_process_needed) return;
89
90 auto is_in_ecal =
91 simcore::g4user::volumechecks::isInEcal(volume, volume_name);
92
93 // Skip this step if it does not have the processes needed
94 // or if it's not in the ECAL
95 if (not is_in_ecal) return;
96
97 // Check the z position of the particle, and
98 // flag if it is deeper than the min Z we are considering (but in ECAL)
99 auto z_position = step->GetPreStepPoint()->GetPosition().z();
100 // Printout for testing
101 if (z_position > (0.75 * ecal_min_z_)) {
102 ldmx_log(debug) << " Particle ID " << pd_gid << " with energy "
103 << track->GetKineticEnergy() << " on " << volume << " from "
104 << process_name << " at Z = " << z_position;
105 if (z_position > ecal_min_z_) {
107 }
108 }
109 return;
110}
111
114 ldmx_log(debug) << "> Event with a hard deep conversion found, yaaay!";
115 ldmx_log(debug) << "> -----------------------------------------";
116 } else {
117 // ldmx_log(debug) << "> -----------------------------------------";
118 G4RunManager::GetRunManager()->AbortEvent();
119 }
120}
121} // namespace biasing
122
#define DECLARE_ACTION(CLASS)
register a new UserAction with its factory
Definition UserAction.h:216
User action that allows a user to filter out events where the interaction happened deep in the ECAL.
bool require_photon_from_target_
Require that the hard brem photon originates from the target.
double ecal_min_z_
Minimum Z location where the deep process should happen.
DeepEcalProcessFilter(const std::string &name, framework::config::Parameters &parameters)
Constructor.
void stepping(const G4Step *step) override
Implement the stepping action which performs the target volume biasing.
bool has_deep_ecal_process_
member used to help tag events that have a deep-ecal process ocurr
double bias_threshold_
Minimal energy the products should have.
void beginOfEventAction(const G4Event *event) override
Method to set flags in the beginning of the event.
bool photon_from_target_
member used to help tag events where the photon comes from the target
std::vector< std::string > processes_
The allowed processes that can happen deep inside the ECAL, default is conversion (conv) and photoele...
void newStage() override
Method called at the end of every event.
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
UserEventInformation * getEventInfo() const
Get a handle to the event information.
void incBremCandidateCount()
Increment the number of brem candidates in an event.
static UserTrackInformation * get(const G4Track *track)
get
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...