LDMX Software
Public Member Functions | Private Attributes | List of all members
biasing::utility::PartialEnergySorter Class Reference

A simulation action that makes sure that all particles above a certain threshold are processed first. More...

#include <PartialEnergySorter.h>

Public Member Functions

 PartialEnergySorter (const std::string &name, framework::config::Parameters &parameters)
 Constructor.
 
virtual ~PartialEnergySorter ()
 Destructor.
 
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 threshold.
 
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.
 
std::vector< simcore::TYPE > getTypes () override
 Retrieve the type of actions this class defines.
 
void NewStage () override
 Flag that we are now going below threshold.
 
- Public Member Functions inherited from simcore::UserAction
 UserAction (const std::string &name, framework::config::Parameters &parameters)
 Constructor.
 
virtual ~UserAction ()=default
 Destructor.
 
virtual void EndOfEventAction (const G4Event *)
 Method called at the end of every event.
 
virtual void BeginOfRunAction (const G4Run *)
 Method called at the beginning of a run.
 
virtual void EndOfRunAction (const G4Run *)
 Method called at the end of a run.
 
virtual void PreUserTrackingAction (const G4Track *)
 Method called before the UserTrackingAction.
 
virtual void PostUserTrackingAction (const G4Track *)
 Method called after the UserTrackingAction.
 
virtual void PrepareNewEvent ()
 Method called at the beginning of a new event.
 

Private Attributes

double threshold_
 Minimum Kinetic Energy [MeV] we want to simulate first.
 
bool below_threshold_
 Are we simulating below the threshold yet?
 

Additional Inherited Members

- Public Types inherited from simcore::UserAction
using Factory = ::simcore::Factory< UserAction, std::shared_ptr< UserAction >, const std::string &, framework::config::Parameters & >
 factory for user actions
 
- Protected Member Functions inherited from simcore::UserAction
UserEventInformationgetEventInfo () const
 Get a handle to the event information.
 
const std::map< int, ldmx::SimParticle > & getCurrentParticleMap () const
 Get the current particle map.
 
- Protected Attributes inherited from simcore::UserAction
std::string name_ {""}
 Name of the UserAction.
 
framework::config::Parameters parameters_
 The set of parameters used to configure this class.
 

Detailed Description

A simulation action that makes sure that all particles above a certain threshold are processed first.

This is not intended to modify any physics or perform any filters, only to improve efficiency by processing the more important, higher energy particles first before applying filtering.

This UserAction can run on its own or combined with other actions doing the filtering.

Note
The threshold in this sorter is for kinetic energy. It was implemented in this way to avoid processing slower-moving but heavier particles, but you should keep this in mind when setting the threshold.

Necessities for Filters Run in Sequence

Definition at line 41 of file PartialEnergySorter.h.

Constructor & Destructor Documentation

◆ PartialEnergySorter()

biasing::utility::PartialEnergySorter::PartialEnergySorter ( const std::string &  name,
framework::config::Parameters parameters 
)

Constructor.

Parameters
[in]namethe name of the instance of this UserAction.
[in]parametersthe parameters used to configure this UserAction.

Definition at line 14 of file PartialEnergySorter.cxx.

16 : simcore::UserAction(name, parameters) {
17 threshold_ = parameters.getParameter<double>("threshold");
18}
double threshold_
Minimum Kinetic Energy [MeV] we want to simulate first.
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
Interface that defines a user action.
Definition UserAction.h:42

References framework::config::Parameters::getParameter(), and threshold_.

◆ ~PartialEnergySorter()

virtual biasing::utility::PartialEnergySorter::~PartialEnergySorter ( )
inlinevirtual

Destructor.

Definition at line 53 of file PartialEnergySorter.h.

53{}

Member Function Documentation

◆ BeginOfEventAction()

void biasing::utility::PartialEnergySorter::BeginOfEventAction ( const G4Event *  event)
overridevirtual

At the beginning of a new event, we reset the counter for the number of particles above the energy threshold.

This reset is mandatory because sometimes previous events will be aborted before all of the particles above threshold are processed.

Parameters
[in]eventunused

debug printout std::cout << "[ PartialEnergySorter ] : " << "Starting a new event." << std::endl;

Reimplemented from simcore::UserAction.

Definition at line 20 of file PartialEnergySorter.cxx.

20 {
26 below_threshold_ = false;
27}
bool below_threshold_
Are we simulating below the threshold yet?

References below_threshold_.

◆ ClassifyNewTrack()

G4ClassificationOfNewTrack biasing::utility::PartialEnergySorter::ClassifyNewTrack ( const G4Track *  aTrack,
const G4ClassificationOfNewTrack &  currentTrackClass 
)
overridevirtual

Classify a "new" track.

This is called when a new track is created or when a current track is suspended. We can use this functionality to move any tracks below the energy threshold to the waiting stack.

All tracks with kinetic energy above the threshold are put onto the urgent stack while any other particles are put onto the waiting stack if there are particles still above threshold.

Parameters
aTrackThe Geant4 track.
currentTrackClassThe current track classification.
Returns
the updated classification

debug printout std::cout << "[ PartialEnergySorter ] : Classifying track " << aTrack->GetTrackID() << " with energy " << aTrack->GetKineticEnergy() << " MeV." << std::endl;

debug printout std::cout << "[ PartialEnergySorter ] : Classifying track " << aTrack->GetTrackID() << " with energy " << aTrack->GetKineticEnergy() << " MeV." << std::endl;

Reimplemented from simcore::UserAction.

Definition at line 29 of file PartialEnergySorter.cxx.

31 {
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}

References below_threshold_, and threshold_.

◆ getTypes()

std::vector< simcore::TYPE > biasing::utility::PartialEnergySorter::getTypes ( )
inlineoverridevirtual

Retrieve the type of actions this class defines.

Implements simcore::UserAction.

Definition at line 101 of file PartialEnergySorter.h.

101 {
102 return {simcore::TYPE::STEPPING, simcore::TYPE::STACKING,
103 simcore::TYPE::EVENT};
104 }

◆ NewStage()

void biasing::utility::PartialEnergySorter::NewStage ( )
inlineoverridevirtual

Flag that we are now going below threshold.

This function is called when the urgent stack is empty and the waiting stack is transferred to the urgent stack.

With all tracks below threshold being pushed to the waiting stack, the first time this occurs during the event is when the rest of the particles are below the threshold energy, so we reset the counter on the number of particles above the threshold here.

This function can be called several times in an event, but the first time it is called in an event is when there is no more particles with kinetic energy above the threshold left to be processed.

Sometimes (e.g. in the case when you are using this with the custom dark brem process) there will still be particles "left-over" that are above the threshold. These particles are the electron that went dark brem and the A' which are above the threshold but both don't interact with anything else. Since they don't interact with anything else, they finish tracking without "stepping" from above the threshold to below it.

debug printout std::cout << "[ PartialEnergySorter ] : " << "Starting new stage with " << num_particles_above_threshold_ << " particles above threshold." << std::endl;

Reimplemented from simcore::UserAction.

Definition at line 131 of file PartialEnergySorter.h.

131 {
139 below_threshold_ = true;
140 }

References below_threshold_.

◆ stepping()

void biasing::utility::PartialEnergySorter::stepping ( const G4Step *  step)
overridevirtual

Checks if a particle steps from above the threshold to below it.

If the particle does step below the threshold it is suspended, so that it can be re-classifed onto the waiting stack.

Nothing happens if we are already below threshold (i.e. below_threshold_ is true).

Parameters
[in]stepGeant4 step

debug printout std::cout << "[ PartialEnergySorter ] : Stepping track " << step->GetTrack()->GetTrackID() << " going from " << pre_energy << " MeV to " << post_energy << " MeV." << std::endl;

Reimplemented from simcore::UserAction.

Definition at line 57 of file PartialEnergySorter.cxx.

57 {
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}

References below_threshold_, and threshold_.

Member Data Documentation

◆ below_threshold_

bool biasing::utility::PartialEnergySorter::below_threshold_
private

Are we simulating below the threshold yet?

Definition at line 147 of file PartialEnergySorter.h.

Referenced by BeginOfEventAction(), ClassifyNewTrack(), NewStage(), and stepping().

◆ threshold_

double biasing::utility::PartialEnergySorter::threshold_
private

Minimum Kinetic Energy [MeV] we want to simulate first.

Definition at line 144 of file PartialEnergySorter.h.

Referenced by ClassifyNewTrack(), PartialEnergySorter(), and stepping().


The documentation for this class was generated from the following files: