28G4ClassificationOfNewTrack EcalProcessFilter::ClassifyNewTrack(
29 const G4Track* track,
const G4ClassificationOfNewTrack& currentTrackClass) {
31 G4String particleName = track->GetParticleDefinition()->GetParticleName();
33 if (track == currentTrack_) {
39 currentTrack_ =
nullptr;
45 G4ClassificationOfNewTrack classification = currentTrackClass;
47 return classification;
50void EcalProcessFilter::stepping(
const G4Step* step) {
51 static auto calorimeter_region =
52 simcore::g4user::ptrretrieval::getRegion(
"CalorimeterRegion");
53 if (!calorimeter_region) {
55 <<
"Region 'CalorimeterRegion' not found in Geant4 region store";
58 auto track{step->GetTrack()};
60 if (G4EventManager::GetEventManager()->GetConstCurrentEvent()->IsAborted())
65 if ((trackInfo !=
nullptr) && !trackInfo->isBremCandidate())
return;
68 auto secondaries{step->GetSecondary()};
72 auto phys_vol{track->GetVolume()};
73 auto lv{phys_vol ? phys_vol->GetLogicalVolume() :
nullptr};
74 auto region{lv ? lv->GetRegion() :
nullptr};
75 if (region != calorimeter_region) {
80 if (secondaries->size() != 0) {
87 if (getEventInfo()->bremCandidateCount() == 1) {
89 track->SetTrackStatus(fKillTrackAndSecondaries);
90 G4RunManager::GetRunManager()->AbortEvent();
91 currentTrack_ =
nullptr;
98 currentTrack_ = track;
99 track->SetTrackStatus(fSuspend);
100 getEventInfo()->decBremCandidateCount();
101 trackInfo->tagBremCandidate(
false);
108 if (secondaries->size() == 0) {
115 static auto volume_after_exiting_ecal =
116 simcore::g4user::ptrretrieval::getLogicalVolume(
"hadronic_calorimeter");
117 if (!volume_after_exiting_ecal) {
118 ldmx_log(warn) <<
"Unable to find 'hadronic_calorimeter' logical volume.";
120 auto next_phys_vol = track->GetNextVolume();
121 auto next_log_vol{next_phys_vol ? next_phys_vol->GetLogicalVolume()
123 if (next_log_vol == volume_after_exiting_ecal) {
130 if (getEventInfo()->bremCandidateCount() == 1) {
132 track->SetTrackStatus(fKillTrackAndSecondaries);
133 G4RunManager::GetRunManager()->AbortEvent();
134 currentTrack_ =
nullptr;
141 currentTrack_ = track;
142 track->SetTrackStatus(fSuspend);
143 getEventInfo()->decBremCandidateCount();
144 trackInfo->tagBremCandidate(
false);
152 auto processName{secondaries->at(0)->GetCreatorProcess()->GetProcessName()};
155 if (!processName.contains(process_)) {
162 if (getEventInfo()->bremCandidateCount() == 1) {
164 track->SetTrackStatus(fKillTrackAndSecondaries);
165 G4RunManager::GetRunManager()->AbortEvent();
166 currentTrack_ =
nullptr;
173 currentTrack_ = track;
174 track->SetTrackStatus(fSuspend);
175 getEventInfo()->decBremCandidateCount();
176 trackInfo->tagBremCandidate(
false);
181 ldmx_log(info) <<
" Brem photon produced " << secondaries->size()
182 <<
" particles via " << processName <<
" process.";
183 trackInfo->tagBremCandidate(
false);
184 trackInfo->setSaveFlag(
true);
185 trackInfo->tagPNGamma();
186 getEventInfo()->decBremCandidateCount();