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

User stepping action used to print the details of a step. More...

#include <StepPrinter.h>

Public Member Functions

 StepPrinter (const std::string &name, framework::config::Parameters &parameters)
 Constructor.
 
virtual ~StepPrinter ()=default
 Destructor.
 
void stepping (const G4Step *step) override
 Stepping action called when a step is taken during tracking of a particle.
 
std::vector< simcore::TYPE > getTypes () override
 Retrieve the type of actions this class defines.
 
- Public Member Functions inherited from simcore::UserAction
 UserAction (const std::string &name, framework::config::Parameters &parameters)
 Constructor.
 
virtual ~UserAction ()=default
 Destructor.
 
virtual void BeginOfEventAction (const G4Event *)
 Method called at the beginning of every event.
 
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 G4ClassificationOfNewTrack ClassifyNewTrack (const G4Track *, const G4ClassificationOfNewTrack &cl)
 Method called when a track is updated.
 
virtual void NewStage ()
 Method called at the beginning of a new stage.
 
virtual void PrepareNewEvent ()
 Method called at the beginning of a new event.
 

Private Attributes

int trackID_ {-9999}
 The track ID to filter on.
 
std::string processName_ {"UNDEFINED"}
 
int depth_ {0}
 
std::unordered_map< int, int > trackParents_ {}
 

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

User stepping action used to print the details of a step.

Definition at line 16 of file StepPrinter.h.

Constructor & Destructor Documentation

◆ StepPrinter()

biasing::utility::StepPrinter::StepPrinter ( 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 12 of file StepPrinter.cxx.

14 : simcore::UserAction(name, parameters) {
15 trackID_ = parameters.getParameter<int>("track_id");
16 processName_ = parameters.getParameter<std::string>("process_name");
17 depth_ = parameters.getParameter<int>("depth");
18}
int trackID_
The track ID to filter on.
Definition StepPrinter.h:46
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 trackID_.

Member Function Documentation

◆ getTypes()

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

Retrieve the type of actions this class defines.

Implements simcore::UserAction.

Definition at line 40 of file StepPrinter.h.

40 {
41 return {simcore::TYPE::STEPPING};
42 }

◆ stepping()

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

Stepping action called when a step is taken during tracking of a particle.

Parameters
[in]stepGeant4 step

Reimplemented from simcore::UserAction.

Definition at line 20 of file StepPrinter.cxx.

20 {
21 // Get the track associated with this step
22 auto track{step->GetTrack()};
23
24 const auto trackID{track->GetTrackID()};
25 const auto parent{track->GetParentID()};
26 // Don't bother filling the map if we aren't going to use it
27 if (depth_ > 0) {
28 trackParents_[trackID] = parent;
29 }
30
31 auto process{track->GetCreatorProcess()};
32 std::string processName{process ? process->GetProcessName() : "Primary"};
33 // Unwrap biasing part of process name if present
34 if (processName.find("biasWrapper") != std::string::npos) {
35 std::size_t pos = processName.find_first_of("(") + 1;
36 processName = processName.substr(pos, processName.size() - pos - 1);
37 }
38
39 // This could be a negated condition, but it is easier to read this way
40 //
42 if (trackID == trackID_ || // We are the track of interest
43 trackMap.isDescendant(
44 trackID, trackID_,
45 depth_) || // We are a descendent of the track of interest
46 processName ==
47 processName_ // The parent process was the process of interest
48 ) {
49 // This is an interesting track -> Carry on processing
50 } else {
51 return;
52 }
53 // Get the particle name.
54 const auto particleName{track->GetParticleDefinition()->GetParticleName()};
55
56 // Get the energy of the particle
57 const auto energy{step->GetPostStepPoint()->GetTotalEnergy()};
58
59 // Get the volume the particle is in.
60 auto volume{track->GetVolume()};
61 auto volumeName{volume->GetName()};
62
63 // Get the next volume (can fail if current volume is WorldPV and next is
64 // outside the world)
65 auto nextVolume{track->GetNextVolume() ? track->GetNextVolume()->GetName()
66 : "undefined"};
67
68 // Get the region
69 auto regionName{volume->GetLogicalVolume()->GetRegion()->GetName()};
70
71 std::cout << " Step " << track->GetCurrentStepNumber() << " ("
72 << track->GetParticleDefinition()->GetParticleName() << ") {"
73 << " Energy: " << energy << " Track ID: " << track->GetTrackID()
74 << " Particle currently in: " << volumeName
75 << " Region: " << regionName << " Next volume: " << nextVolume
76 << " Weight: " << track->GetWeight() << " Parent: " << parent
77 << " (" << processName << ") "
78 << " Children:";
79 for (auto const& child : *(step->GetSecondaryInCurrentStep())) {
80 std::cout << " (" << child->GetTotalEnergy()
81 << "): " << child->GetParticleDefinition()->GetPDGEncoding();
82 }
83
84 std::cout << " }" << std::endl;
85}
TrackMap & getTrackMap()
Get a handle to the current TrackMap for the event.
static TrackingAction * get()
Get a pointer to the current UserTrackingAction from the G4RunManager.

References simcore::g4user::TrackingAction::get(), simcore::g4user::TrackingAction::getTrackMap(), and trackID_.

Member Data Documentation

◆ depth_

int biasing::utility::StepPrinter::depth_ {0}
private

Definition at line 48 of file StepPrinter.h.

48{0};

◆ processName_

std::string biasing::utility::StepPrinter::processName_ {"UNDEFINED"}
private

Definition at line 47 of file StepPrinter.h.

47{"UNDEFINED"};

◆ trackID_

int biasing::utility::StepPrinter::trackID_ {-9999}
private

The track ID to filter on.

Definition at line 46 of file StepPrinter.h.

46{-9999};

Referenced by stepping(), and StepPrinter().

◆ trackParents_

std::unordered_map<int, int> biasing::utility::StepPrinter::trackParents_ {}
private

Definition at line 49 of file StepPrinter.h.

49{};

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