LDMX Software
EcalProcessFilter.cxx
1
2#include "Biasing/EcalProcessFilter.h"
3
4/*~~~~~~~~~~~~*/
5/* Geant4 */
6/*~~~~~~~~~~~~*/
7#include "G4EventManager.hh"
8#include "G4RunManager.hh"
9#include "G4Step.hh"
10#include "G4Track.hh"
11
12/*~~~~~~~~~~~~~*/
13/* SimCore */
14/*~~~~~~~~~~~~~*/
15#include "SimCore/UserTrackInformation.h"
16
17namespace biasing {
18
19EcalProcessFilter::EcalProcessFilter(const std::string& name,
21 : simcore::UserAction(name, parameters) {
22 process_ = parameters.getParameter<std::string>("process");
23}
24
25EcalProcessFilter::~EcalProcessFilter() {}
26
27G4ClassificationOfNewTrack EcalProcessFilter::ClassifyNewTrack(
28 const G4Track* track, const G4ClassificationOfNewTrack& currentTrackClass) {
29 // Get the particle type.
30 G4String particleName = track->GetParticleDefinition()->GetParticleName();
31
32 if (track == currentTrack_) {
33 /*
34 std::cout << "[ EcalProcessFilter ]: "
35 << "Putting track " << track->GetTrackID()
36 << " onto waiting stack." << std::endl;
37 */
38 currentTrack_ = nullptr;
39 return fWaiting;
40 }
41
42 // Use current classification by default so values from other plugins are not
43 // overridden.
44 G4ClassificationOfNewTrack classification = currentTrackClass;
45
46 return classification;
47}
48
49void EcalProcessFilter::stepping(const G4Step* step) {
50 // Get the track associated with this step.
51 auto track{step->GetTrack()};
52
53 if (G4EventManager::GetEventManager()->GetConstCurrentEvent()->IsAborted())
54 return;
55
56 // Get the track info and check if this track is a brem candidate
57 auto trackInfo{simcore::UserTrackInformation::get(track)};
58 if ((trackInfo != nullptr) && !trackInfo->isBremCandidate()) return;
59
60 // Get the particles daughters.
61 auto secondaries{step->GetSecondary()};
62
63 // Get the region the particle is currently in. Continue processing
64 // the particle only if it's in the calorimeter region.
65 if (auto region{
66 track->GetVolume()->GetLogicalVolume()->GetRegion()->GetName()};
67 region.compareTo("CalorimeterRegion") != 0) {
68 // If secondaries were produced outside of the volume of interest,
69 // and there aren't additional brems to process, abort the
70 // event. Otherwise, suspend the track and move on to the next
71 // brem.
72 if (secondaries->size() != 0) {
73 /*
74 std::cout << "[ EcalProcessFilter ]: "
75 <<
76 G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID()
77 << " secondaries outside ecal...";
78 */
79 if (getEventInfo()->bremCandidateCount() == 1) {
80 // std::cout << "aborting the event." << std::endl;
81 track->SetTrackStatus(fKillTrackAndSecondaries);
82 G4RunManager::GetRunManager()->AbortEvent();
83 currentTrack_ = nullptr;
84 } else {
85 /*
86 std::cout << "suspending the track " << track->GetTrackID()
87 << " , " << getEventInfo()->bremCandidateCount() << " brems left."
88 << std::endl;
89 */
90 currentTrack_ = track;
91 track->SetTrackStatus(fSuspend);
92 getEventInfo()->decBremCandidateCount();
93 trackInfo->tagBremCandidate(false);
94 }
95 }
96 return;
97 }
98
99 // If the particle doesn't interact, then move on to the next step.
100 if (secondaries->size() == 0) {
110 if (auto volume{track->GetNextVolume()->GetName()};
111 volume.compareTo("hcal_PV") == 0) {
112 /*
113 std::cout << "[ EcalProcessFilter ]: "
114 <<
115 G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID()
116 << " no secondaries when leaving ecal...";
117 */
118 if (getEventInfo()->bremCandidateCount() == 1) {
119 // std::cout << "aborting the event." << std::endl;
120 track->SetTrackStatus(fKillTrackAndSecondaries);
121 G4RunManager::GetRunManager()->AbortEvent();
122 currentTrack_ = nullptr;
123 } else {
124 /*
125 std::cout << "suspending the track " << track->GetTrackID()
126 << " , " << getEventInfo()->bremCandidateCount() << " brems left."
127 << std::endl;
128 */
129 currentTrack_ = track;
130 track->SetTrackStatus(fSuspend);
131 getEventInfo()->decBremCandidateCount();
132 trackInfo->tagBremCandidate(false);
133 }
134 }
135
136 return;
137 } else {
138 // If the brem gamma interacts and produces secondaries, get the
139 // process used to create them.
140 auto processName{secondaries->at(0)->GetCreatorProcess()->GetProcessName()};
141
142 // Only record the process that is being biased
143 if (!processName.contains(process_)) {
144 /*
145 std::cout << "[ EcalProcessFilter ]: "
146 <<
147 G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID()
148 << " not PN products...";
149 */
150 if (getEventInfo()->bremCandidateCount() == 1) {
151 // std::cout << "aborting the event." << std::endl;
152 track->SetTrackStatus(fKillTrackAndSecondaries);
153 G4RunManager::GetRunManager()->AbortEvent();
154 currentTrack_ = nullptr;
155 } else {
156 /*
157 std::cout << "suspending the track " << track->GetTrackID()
158 << " , " << getEventInfo()->bremCandidateCount() << " brems left."
159 << std::endl;
160 */
161 currentTrack_ = track;
162 track->SetTrackStatus(fSuspend);
163 getEventInfo()->decBremCandidateCount();
164 trackInfo->tagBremCandidate(false);
165 }
166 return;
167 }
168
169 ldmx_log(debug) << "[ EcalProcessFilter ]: "
170 << G4EventManager::GetEventManager()
171 ->GetConstCurrentEvent()
172 ->GetEventID()
173 << " Brem photon produced " << secondaries->size()
174 << " particle via " << processName << " process.";
175 trackInfo->tagBremCandidate(false);
176 trackInfo->setSaveFlag(true);
177 trackInfo->tagPNGamma();
178 getEventInfo()->decBremCandidateCount();
179 }
180}
181} // namespace biasing
182
183DECLARE_ACTION(biasing, EcalProcessFilter)
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 tagBremCandidate(bool isBremCandidate=true)
Tag this track as a brem candidate by the biasing filters.