36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
#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
|