LDMX Software
SteppingAction.cxx
1#include "SimCore/G4User/SteppingAction.h"
2
3namespace simcore::g4user {
4
5void SteppingAction::UserSteppingAction(const G4Step* step) {
6 auto event_info{static_cast<UserEventInformation*>(
7 G4EventManager::GetEventManager()->GetUserInformation())};
8
9 // get the track weights before this step and after this step
10 // ** these weights include the factors of all upstream step weights **
11 double track_weight_pre_step = step->GetPreStepPoint()->GetWeight();
12 double track_weight_post_step = step->GetPostStepPoint()->GetWeight();
13
14 // so, to get _this_ step's weight, we divide post_weight by pre_weight
15 double weight_of_this_step_alone =
16 track_weight_post_step / track_weight_pre_step;
17
18 event_info->incWeight(weight_of_this_step_alone);
19
20 const std::vector<const G4Track*>* secondaries{
21 step->GetSecondaryInCurrentStep()};
22
31 event_info->lastStepWasPN(false);
32 event_info->lastStepWasEN(false);
33 if (secondaries) {
34 double delta_energy = step->GetPreStepPoint()->GetKineticEnergy() -
35 step->GetPostStepPoint()->GetKineticEnergy();
36 for (const G4Track* secondary : *secondaries) {
37 const G4VProcess* creator{secondary->GetCreatorProcess()};
38 if (creator) {
39 const G4String& creator_name{creator->GetProcessName()};
40 if (creator_name.contains("photonNuclear")) {
41 event_info->addPNEnergy(delta_energy);
42 event_info->lastStepWasPN(true);
43 break; // done <- assumes first match determines step process
44 }
45 if (creator_name.contains("electronNuclear")) {
46 event_info->addENEnergy(delta_energy);
47 event_info->lastStepWasEN(true);
48 break; // done <- assumes first match determines step process
49 } // creator name matches PN or EN
50 } // creator exists
51 } // loop over secondaries
52 } // secondaries list was created
53 // now stepping actions can use getEventInfo()->wasLastStep{P,E}N()
54 // to determine if last step was PN or EN
55 for (auto& steppingAction : steppingActions_) steppingAction->stepping(step);
56}
57
58} // namespace simcore::g4user
Encapsulates user defined information associated with a Geant4 event.
void incWeight(double step_weight)
Increment the event weight by the input weight for an individual step.
void UserSteppingAction(const G4Step *step) override
Callback used to process a step.
std::vector< UserAction * > steppingActions_
Collection of user stepping actions.