G4-ExampleB1/src/SteppingAction.cc

38 lines
1.2 KiB
C++
Raw Permalink 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 {
// 初始化 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