LDMX Software
StepPrinter.cxx
1
2#include "Biasing/Utility/StepPrinter.h"
3
5
6/*~~~~~~~~~~~~*/
7/* Geant4 */
8/*~~~~~~~~~~~~*/
9#include "G4Step.hh"
10
11namespace biasing {
12namespace utility {
13
14StepPrinter::StepPrinter(const std::string& name,
16 : simcore::UserAction(name, parameters) {
17 track_id_ = parameters.get<int>("track_id");
18 process_name_ = parameters.get<std::string>("process_name");
19 depth_ = parameters.get<int>("depth");
20}
21
22void StepPrinter::stepping(const G4Step* step) {
23 // Get the track associated with this step
24 auto track{step->GetTrack()};
25
26 const auto track_id{track->GetTrackID()};
27 const auto parent{track->GetParentID()};
28 // Don't bother filling the map if we aren't going to use it
29 if (depth_ > 0) {
30 track_parents_[track_id] = parent;
31 }
32
33 auto process{track->GetCreatorProcess()};
34 std::string process_name{process ? process->GetProcessName() : "Primary"};
35 // Unwrap biasing part of process name if present
36 if (process_name.find("biasWrapper") != std::string::npos) {
37 std::size_t pos = process_name.find_first_of("(") + 1;
38 process_name = process_name.substr(pos, process_name.size() - pos - 1);
39 }
40
41 // This could be a negated condition, but it is easier to read this way
42 //
44 if (track_id == track_id_ || // We are the track of interest
45 track_map.isDescendant(
46 track_id, track_id_,
47 depth_) || // We are a descendent of the track of interest
48 process_name ==
49 process_name_ // The parent process was the process of interest
50 ) {
51 // This is an interesting track -> Carry on processing
52 } else {
53 return;
54 }
55 // Get the particle name.
56 const auto particle_name{track->GetParticleDefinition()->GetParticleName()};
57
58 // Get the energy of the particle
59 const auto energy{step->GetPostStepPoint()->GetTotalEnergy()};
60
61 // Get the volume the particle is in.
62 auto volume{track->GetVolume()};
63 auto volume_name{volume ? volume->GetName() : "undefined"};
64
65 // Get the next volume (can fail if current volume is WorldPV and next is
66 // outside the world)
67 auto next_volume_ptr{track->GetNextVolume()};
68 auto next_volume{next_volume_ptr ? next_volume_ptr->GetName() : "undefined"};
69
70 // Get the region
71 G4String region_name{"undefined"};
72 if (volume) {
73 auto lv{volume->GetLogicalVolume()};
74 if (lv) {
75 auto region{lv->GetRegion()};
76 if (region) {
77 region_name = region->GetName();
78 }
79 }
80 }
81
82 std::cout << " Step " << track->GetCurrentStepNumber() << " ("
83 << track->GetParticleDefinition()->GetParticleName() << ") {"
84 << " Energy: " << energy << " Track ID: " << track->GetTrackID()
85 << " Particle currently in: " << volume_name
86 << " Region: " << region_name << " Next volume: " << next_volume
87 << " Weight: " << track->GetWeight() << " Parent: " << parent
88 << " (" << process_name << ") " << " Children:";
89 for (auto const& child : *(step->GetSecondaryInCurrentStep())) {
90 std::cout << " (" << child->GetTotalEnergy()
91 << "): " << child->GetParticleDefinition()->GetPDGEncoding();
92 }
93
94 std::cout << " }" << std::endl;
95}
96
97} // namespace utility
98} // namespace biasing
99
Class which implements the user tracking action.
#define DECLARE_ACTION(CLASS)
register a new UserAction with its factory
Definition UserAction.h:215
User stepping action used to print the details of a step.
Definition StepPrinter.h:15
StepPrinter(const std::string &name, framework::config::Parameters &parameters)
Constructor.
int track_id_
The track ID to filter on.
Definition StepPrinter.h:45
void stepping(const G4Step *step) override
Stepping action called when a step is taken during tracking of a particle.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
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.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...