LDMX Software
PartialEnergySorter.cxx
1
2#include "Biasing/Utility/PartialEnergySorter.h"
3
4/*~~~~~~~~~~~~*/
5/* Geant4 */
6/*~~~~~~~~~~~~*/
7#include "G4EventManager.hh"
8#include "G4RunManager.hh"
9#include "G4Step.hh"
10
11namespace biasing {
12namespace utility {
13
15 const std::string& name, framework::config::Parameters& parameters)
16 : simcore::UserAction(name, parameters) {
17 threshold_ = parameters.getParameter<double>("threshold");
18}
19
26 below_threshold_ = false;
27}
28
29G4ClassificationOfNewTrack PartialEnergySorter::ClassifyNewTrack(
30 const G4Track* aTrack,
31 const G4ClassificationOfNewTrack& currentTrackClassification) {
39 if (aTrack->GetKineticEnergy() > threshold_) {
46 return fUrgent;
47 }
48
49 /*
50 * Track has kinetic energy less than or equal to
51 * the threshold, so we put it on the waiting stack
52 * if there are still particles above threshold to be processed.
53 */
54 return below_threshold_ ? currentTrackClassification : fWaiting;
55}
56
57void PartialEnergySorter::stepping(const G4Step* step) {
58 if (below_threshold_) return;
59
60 auto pre_energy{step->GetPreStepPoint()->GetKineticEnergy()};
61 auto post_energy{step->GetPostStepPoint()->GetKineticEnergy()};
62
63 if (pre_energy >= threshold_ and post_energy <= threshold_) {
71 step->GetTrack()->SetTrackStatus(fSuspend);
72 }
73}
74
75} // namespace utility
76} // namespace biasing
77
78DECLARE_ACTION(biasing::utility, PartialEnergySorter)
bool below_threshold_
Are we simulating below the threshold yet?
PartialEnergySorter(const std::string &name, framework::config::Parameters &parameters)
Constructor.
double threshold_
Minimum Kinetic Energy [MeV] we want to simulate first.
G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack, const G4ClassificationOfNewTrack &currentTrackClass) override
Classify a "new" track.
void stepping(const G4Step *step) override
Checks if a particle steps from above the threshold to below it.
void BeginOfEventAction(const G4Event *event) override
At the beginning of a new event, we reset the counter for the number of particles above the energy th...
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