1#include "Biasing/MidShowerDiMuonBkgdFilter.h"
3#include "G4EventManager.hh"
5#include "G4RunManager.hh"
7#include "SimCore/G4User/PtrRetrieval.h"
8#include "SimCore/UserTrackInformation.h"
14 : simcore::UserAction(name, parameters) {
15 threshold_ = parameters.getParameter<
double>(
"threshold");
39 if (step->GetTrack()->GetParticleDefinition() != G4Gamma::Gamma())
return;
43 const G4TrackVector* secondaries{step->GetSecondary()};
44 if (secondaries ==
nullptr or secondaries->size() == 0)
return;
46 bool found_muon{
false};
47 for (
const G4Track* secondary : *secondaries) {
48 if (abs(secondary->GetParticleDefinition()->GetPDGEncoding()) == 13) {
53 if (not found_muon)
return;
55 double pre_energy = step->GetPreStepPoint()->GetTotalEnergy();
56 double post_energy = step->GetPostStepPoint()->GetTotalEnergy();
58 const G4Track* track = step->GetTrack();
84 AbortEvent(
"Not enough energy went to the input process.");
89 const G4Step* step)
const {
90 static auto calorimeter_region =
91 simcore::g4user::ptrretrieval::getRegion(
"CalorimeterRegion");
92 if (!calorimeter_region) {
94 <<
"Region 'CalorimeterRegion' not found in Geant4 region store";
97 auto phys_vol{step->GetTrack()->GetVolume()};
98 auto log_vol{phys_vol ? phys_vol->GetLogicalVolume() :
nullptr};
99 auto reg{log_vol ? log_vol->GetRegion() :
nullptr};
100 return (reg != calorimeter_region);
105 track_info->setSaveFlag(
true);
110 if (G4RunManager::GetRunManager()->GetVerboseLevel() > 1) {
111 std::cout <<
"[ MidShowerDiMuonBkgdFilter ]: "
113 << G4EventManager::GetEventManager()
114 ->GetConstCurrentEvent()
116 <<
") " << reason <<
" Aborting event." << std::endl;
118 G4RunManager::GetRunManager()->AbortEvent();
123DECLARE_ACTION(biasing, MidShowerDiMuonBkgdFilter)
bool isOutsideCalorimeterRegion(const G4Step *step) const
Checks if the passed step is outside of the CalorimeterRegion.
double total_process_energy_
Total energy gone to the process in the current event.
MidShowerDiMuonBkgdFilter(const std::string &name, framework::config::Parameters ¶meters)
Class constructor.
void AbortEvent(const std::string &reason) const
Helper to abort an event with a message.
void save(const G4Track *track) const
Helper to save the passed track.
double threshold_
Minimum energy [MeV] that the process products need to have to keep the event.
void NewStage() override
When using the PartialEnergySorter, the first time that a new stage begins is when all particles are ...
void BeginOfEventAction(const G4Event *event) override
Reset the total energy going to the muons.
void stepping(const G4Step *step) override
We follow the simulation along each step and check if any secondaries of the input process were creat...
Class encapsulating parameters for configuring a processor.