G4-ExampleB1/src/SteppingAction.cc

36 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "SteppingAction.hh"
#include "DetectorConstruction.hh"
#include "EventAction.hh"
#include "G4Event.hh"
#include "G4LogicalVolume.hh"
#include "G4RunManager.hh"
#include "G4Step.hh"
namespace B1 {
SteppingAction::SteppingAction(EventAction* eventAction) : fEventAction(eventAction) {} // 初始化 eventAction 类
SteppingAction::~SteppingAction() {}
// 每个 step 调用一次
void SteppingAction::UserSteppingAction(const G4Step* step) {
if (!fScoringVolume) {
const DetectorConstruction* detConstruction =
static_cast<const DetectorConstruction*>(G4RunManager::GetRunManager()->GetUserDetectorConstruction());
fScoringVolume = detConstruction->GetScoringVolume();
}
// 获取当前的 Volume
G4LogicalVolume* volume = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
// 检查是否在计算的 Volume Shape 2
if (volume != fScoringVolume) return;
// 获取当前 step 的沉积能量
G4double edepStep = step->GetTotalEnergyDeposit();
fEventAction->AddEdep(edepStep);
}
} // namespace B1