LDMX Software
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::TYPEgetTypes () 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.
 
 DECLARE_FACTORY (UserAction, std::shared_ptr< UserAction >, const std::string &, framework::config::Parameters &)
 factory for user actions
 
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 track_id_ {-9999}
 The track ID to filter on.
 
std::string process_name_ {"UNDEFINED"}
 
int depth_ {0}
 
std::unordered_map< int, int > track_parents_ {}
 

Additional Inherited Members

- 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.
 
mutable::framework::logging::logger the_log_
 the logging channel user actions can use ldmx_log with
 

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 track_id_ = parameters.get<int>("track_id");
16 process_name_ = parameters.get<std::string>("process_name");
17 depth_ = parameters.get<int>("depth");
18}
int track_id_
The track ID to filter on.
Definition StepPrinter.h:46
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
Interface that defines a user action.
Definition UserAction.h:47

References framework::config::Parameters::get(), and track_id_.

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 track_id{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 track_parents_[track_id] = parent;
29 }
30
31 auto process{track->GetCreatorProcess()};
32 std::string process_name{process ? process->GetProcessName() : "Primary"};
33 // Unwrap biasing part of process name if present
34 if (process_name.find("biasWrapper") != std::string::npos) {
35 std::size_t pos_ = process_name.find_first_of("(") + 1;
36 process_name = process_name.substr(pos_, process_name.size() - pos_ - 1);
37 }
38
39 // This could be a negated condition, but it is easier to read this way
40 //
42 if (track_id == track_id_ || // We are the track of interest
43 track_map.isDescendant(
44 track_id, track_id_,
45 depth_) || // We are a descendent of the track of interest
46 process_name ==
47 process_name_ // 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 particle_name{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 volume_name{volume ? volume->GetName() : "undefined"};
62
63 // Get the next volume (can fail if current volume is WorldPV and next is
64 // outside the world)
65 auto next_volume_ptr{track->GetNextVolume()};
66 auto next_volume{next_volume_ptr ? next_volume_ptr->GetName() : "undefined"};
67
68 // Get the region
69 G4String region_name{"undefined"};
70 if (volume) {
71 auto lv{volume->GetLogicalVolume()};
72 if (lv) {
73 auto region{lv->GetRegion()};
74 if (region) {
75 region_name = region->GetName();
76 }
77 }
78 }
79
80 std::cout << " Step " << track->GetCurrentStepNumber() << " ("
81 << track->GetParticleDefinition()->GetParticleName() << ") {"
82 << " Energy: " << energy << " Track ID: " << track->GetTrackID()
83 << " Particle currently in: " << volume_name
84 << " Region: " << region_name << " Next volume: " << next_volume
85 << " Weight: " << track->GetWeight() << " Parent: " << parent
86 << " (" << process_name << ") " << " Children:";
87 for (auto const& child : *(step->GetSecondaryInCurrentStep())) {
88 std::cout << " (" << child->GetTotalEnergy()
89 << "): " << child->GetParticleDefinition()->GetPDGEncoding();
90 }
91
92 std::cout << " }" << std::endl;
93}
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 track_id_.

Member Data Documentation

◆ depth_

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

Definition at line 48 of file StepPrinter.h.

48{0};

◆ process_name_

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

Definition at line 47 of file StepPrinter.h.

47{"UNDEFINED"};

◆ track_id_

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

The track ID to filter on.

Definition at line 46 of file StepPrinter.h.

46{-9999};

Referenced by stepping(), and StepPrinter().

◆ track_parents_

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

Definition at line 49 of file StepPrinter.h.

49{};

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