LDMX Software
EcalDarkBremFilter.cxx
1/*
2 * @file EcalDarkBremFilter.cxx
3 * @class EcalDarkBremFilter
4 * @brief Class defining a UserActionPlugin that allows a user to filter out
5 * events that don't result in a dark brem within a given volume
6 * @author Michael Revering, University of Minnesota
7 * @author Tom Eichlersmith, University of Minnesota
8 */
9
11
12namespace biasing {
13
15 const std::string& name, framework::config::Parameters& parameters)
16 : simcore::UserAction(name, parameters) {
17 threshold_ = parameters.get<double>("threshold");
18
19 /*
20 * We look for the logical volumes that match the following pattern:
21 * - 'volume' is in the name AND
22 * - 'Si' OR 'W' OR 'CFMix' OR 'PCB' are in the name
23 */
24 for (G4LogicalVolume* volume : *G4LogicalVolumeStore::GetInstance()) {
25 G4String volume_name = volume->GetName();
26 // looking for ecal volumes
27 if (volume_name.contains("volume") and
28 (volume_name.contains("Si") or volume_name.contains("W") or
29 volume_name.contains("CFMix") or volume_name.contains("PCB") or
30 volume_name.contains("Al"))) {
31 volumes_.push_back(volume);
32 }
33 }
34
35 ldmx_log(trace) << "Looking for A' in: ";
36 for (auto const& volume : volumes_) {
37 ldmx_log(trace) << "\t" << volume->GetName() << ", ";
38 }
39}
40
42 found_ap_ = false;
43 return;
44}
45
46G4ClassificationOfNewTrack EcalDarkBremFilter::ClassifyNewTrack(
47 const G4Track* aTrack, const G4ClassificationOfNewTrack& cl) {
48 if (aTrack->GetParticleDefinition() == G4APrime::APrime()) {
49 // there is an A'! Yay!
50 ldmx_log(trace) << "Found A', still need to check if it originated in "
51 "requested volume.";
52
53 if (not found_ap_ and aTrack->GetTotalEnergy() > threshold_) {
54 // The A' is the first one created in this event and is above the energy
55 // threshold
56 found_ap_ = true;
57 } else if (found_ap_) {
58 AbortEvent("Found more than one A' during filtering.");
59 } else {
60 AbortEvent("A' was not produced above the required threshold.");
61 }
62 }
63
64 return cl;
65}
66
68 if (not found_ap_) AbortEvent("A' wasn't produced.");
69
70 return;
71}
72
74 // Check that generational stacking is working
75 ldmx_log(trace) << track->GetTrackID() << " "
76 << track->GetParticleDefinition()->GetPDGEncoding();
77
78 const G4VProcess* creator = track->GetCreatorProcess();
79 if (creator and
80 creator->GetProcessName().contains(G4DarkBremsstrahlung::PROCESS_NAME)) {
81 // make sure all secondaries of dark brem process are saved
84 // make sure A' is persisted into output file
85 user_info->setSaveFlag(true);
86 if (track->GetParticleDefinition() == G4APrime::APrime()) {
87 // check if A' was made in the desired volume and has the minimum energy
88 if (not inDesiredVolume(track)) {
89 AbortEvent("A' wasn't produced inside of the requested volume.");
90 } // A' was made in desired volume and has the minimum energy
91 } // track was A'
92 } // track created by dark brem process
93
94 return;
95}
96
97bool EcalDarkBremFilter::inDesiredVolume(const G4Track* track) const {
103 auto in_vol = track->GetLogicalVolumeAtVertex();
104 for (auto const& volume : volumes_) {
105 if (in_vol == volume) return true;
106 }
107
108 return false;
109}
110
111void EcalDarkBremFilter::AbortEvent(const std::string& reason) const {
112 ldmx_log(trace)
113 << "("
114 << G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID()
115 << ") " << reason << " Aborting event.";
116
117 G4RunManager::GetRunManager()->AbortEvent();
118 return;
119}
120} // namespace biasing
121
#define DECLARE_ACTION(CLASS)
register a new UserAction with its factory
Definition UserAction.h:206
This class is meant to filter for events that produce a dark brem occuring within the ECal and produc...
void BeginOfEventAction(const G4Event *event) override
Reset flag on if A' has been found.
void NewStage() override
When using the PartialEnergySorter, the first time that a new stage begins is when all particles are ...
bool found_ap_
Have we found the A' yet?
double threshold_
Minimum energy [MeV] that the A' should have to keep the event.
void PostUserTrackingAction(const G4Track *track) override
Make sure A' is saved.
void AbortEvent(const std::string &reason) const
Helper to abort an event with a message.
bool inDesiredVolume(const G4Track *) const
Check if input volume is in the desired volume name.
std::vector< G4LogicalVolume * > volumes_
The volumes that the filter will be applied to.
EcalDarkBremFilter(const std::string &name, framework::config::Parameters &parameters)
Class constructor.
G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack, const G4ClassificationOfNewTrack &currentTrackClass) override
We return the classification of the track done by the PartialEnergySorter, but we can check here if t...
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
Provides user defined information to associate with a Geant4 track.
static UserTrackInformation * get(const G4Track *track)
get
void setSaveFlag(bool saveFlag)
Set the save flag so the associated track will be persisted as a Trajectory.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...