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/VolumeChecks.h"
16#include "SimCore/UserEventInformation.h"
17#include "SimCore/UserTrackInformation.h"
18
19namespace biasing {
20
22 const std::string& name, framework::config::Parameters& parameters)
23 : simcore::UserAction(name, parameters) {
24 bias_threshold_ = parameters.getParameter<double>("bias_threshold");
25 processes_ = parameters.getParameter<std::vector<std::string>>("processes");
26 ecal_min_Z_ = parameters.getParameter<double>("ecal_min_Z");
28 parameters.getParameter<bool>("require_photon_fromTarget");
29}
30
32 hasDeepEcalProcess_ = false;
33 photonFromTarget_ = 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 processName = track->GetCreatorProcess()
42 ? track->GetCreatorProcess()->GetProcessName()
43 : "unknown";
44 auto PDGid = 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 (processName.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 trackInfo{simcore::UserTrackInformation::get(track)};
61 // Tag the brem photon from the primary electron
62 if (processName.contains("eBrem") and (track->GetParentID() == 1)) {
63 trackInfo->tagBremCandidate();
65 trackInfo->setSaveFlag(true);
66 if (volume_name.contains("target")) {
67 photonFromTarget_ = true;
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 hasProcessNeeded{false};
79 for (auto& process : processes_) {
80 // ldmx_log(debug) << "Allowed processed " << process << " now we have " <<
81 // processName;
82 if (processName.contains(process)) {
83 hasProcessNeeded = true;
84 break;
85 }
86 }
87 // skip this step if it does not have any of the processes needed
88 if (not hasProcessNeeded) 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 zPosition = step->GetPreStepPoint()->GetPosition().z();
100 // Printout for testing
101 if (zPosition > (0.75 * ecal_min_Z_)) {
102 ldmx_log(debug) << " Particle ID " << PDGid << " with energy "
103 << track->GetKineticEnergy() << " on " << volume << " from "
104 << processName << " at Z = " << zPosition;
105 if (zPosition > ecal_min_Z_) {
106 hasDeepEcalProcess_ = true;
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
123DECLARE_ACTION(biasing, DeepEcalProcessFilter)
Class defining a UserActionPlugin that allows a user to filter out events where the interaction happe...
void NewStage() override
Method called at the end of every event.
bool hasDeepEcalProcess_
member used to help tag events that have a deep-ecal process ocurr
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.
double bias_threshold_
Minimal energy the products should have.
std::vector< std::string > processes_
The allowed processes that can happen deep inside the ECAL, default is conversion (conv) and photoele...
void BeginOfEventAction(const G4Event *event) override
Method to set flags in the beginning of the event.
bool photonFromTarget_
member used to help tag events where the photon comes from the target
double ecal_min_Z_
Minimum Z location where the deep process should happen.
bool require_photon_fromTarget_
Require that the hard brem photon originates from the target.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
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