38 lines
1.2 KiB
C++
38 lines
1.2 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 {
|
||
|
||
// 初始化 fEventAction,即获取到当前 Step 所在的 Event
|
||
SteppingAction::SteppingAction(EventAction* eventAction) : fEventAction(eventAction) {}
|
||
|
||
SteppingAction::~SteppingAction() {}
|
||
|
||
// 每个 step 调用一次
|
||
void SteppingAction::UserSteppingAction(const G4Step* step) {
|
||
// 这段代码的目的是获得 Shape2 所代表的 Logical Volume
|
||
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
|