LDMX Software
Public Member Functions | Private Attributes | List of all members
simcore::g4user::SteppingAction Class Reference

Implements the Geant4 user stepping action. More...

#include <SteppingAction.h>

Public Member Functions

 ~SteppingAction ()
 Destructor.
 
void UserSteppingAction (const G4Step *step) override
 Callback used to process a step.
 
void registerAction (UserAction *steppingAction)
 Register a user action of type SteppingAction with this class.
 

Private Attributes

std::vector< UserAction * > steppingActions_
 Collection of user stepping actions.
 

Detailed Description

Implements the Geant4 user stepping action.

Definition at line 31 of file SteppingAction.h.

Constructor & Destructor Documentation

◆ ~SteppingAction()

simcore::g4user::SteppingAction::~SteppingAction ( )
inline

Destructor.

Definition at line 34 of file SteppingAction.h.

34{}

Member Function Documentation

◆ registerAction()

void simcore::g4user::SteppingAction::registerAction ( UserAction steppingAction)
inline

Register a user action of type SteppingAction with this class.

Parameters
actionUser action of type SteppingAction

Definition at line 48 of file SteppingAction.h.

48 {
49 steppingActions_.push_back(steppingAction);
50 }
std::vector< UserAction * > steppingActions_
Collection of user stepping actions.

References steppingActions_.

◆ UserSteppingAction()

void simcore::g4user::SteppingAction::UserSteppingAction ( const G4Step *  step)
override

Callback used to process a step.

Parameters
stepThe Geant4 step.

Reset PN/EN flags and updating running energy totals

The process of looping through the secondaries of every step may slow down our simulation. I (Tom E) do not know how much it would slow us down, but we could implement a procedure to make this configurable if we wish.

Definition at line 5 of file SteppingAction.cxx.

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

References simcore::UserEventInformation::incWeight(), and steppingActions_.

Member Data Documentation

◆ steppingActions_

std::vector<UserAction*> simcore::g4user::SteppingAction::steppingActions_
private

Collection of user stepping actions.

Definition at line 54 of file SteppingAction.h.

Referenced by registerAction(), and UserSteppingAction().


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