ステッピングアクションしたい(G4UserSteppingAction

 1// SteppingAction.hh
 2#ifndef SteppingAction_H
 3#define SteppingAction_H 1
 4
 5#include "G4UserSteppingAction.hh"
 6
 7namespace プロジェクト名
 8{
 9class SteppingAction : public G4UserSteppingAction
10{
11    public:
12        SteppingAction();
13        ~SteppingAction() override = default;
14
15        // 基底クラスを上書きする
16        void UserSteppingAction(const G4Step* aStep) override;
17
18    private:
19        EventAction *fEventAction = nullptr;
20        G4LogicalVolume *fScoringVolume = nullptr;
21
22}
23
24}  // プロジェクト名
25#endif

ステッピングアクションはG4UserSteppingActionを継承したクラスを自作します。 仮想関数として定義されているUserSteppingActionを実装します。

注釈

ステップ処理をするときに、ステップが測定したいボリュームにあるかどうかの判断も必要になりますが、G4VSensitiveDetectorを使うとGeant4にお任せできます。

 1void SteppingAction::UserSteppingAction(const G4Step *aStep)
 2{
 3    // スコアリングボリュームを取得する
 4    if (!fScoringVolume) {
 5        const auto detector = static_cast<const DetectorConstruction*>(G4RunManager::GetRunManager()->GetUserDetectorConstruction());
 6        fScoringVolume = detector->GetScoringVolume();
 7    }
 8
 9    // ステップがあるボリュームを取得する
10    G4LogicalVolume *pVolume = aStep->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
11
12    // スコアリングすべきか判断する
13    if (pVolume != fScoringVolume) return;
14
15    // このステップのエネルギー損失を取得する
16    G4double energy_deposit = aStep->GetTotalEnergyDeposit();
17}

ステップの現在情報が欲しい

1G4ThreeVector position = aStep->GetPreStepPoint()->GetPosition();
2G4double local_time = aStep->GetPreStepPoint()->GetLocalTime();
3G4ThreeVector momentum = aStep->GetPreStepPoint()->GetMomentum();
4G4double total_energy = aStep->GetPreStepPoint()->GetTotalEnergy();
5G4double kinetic_energy = aStep->GetPreStepPoint()->GetKineticEnergy();

現在のステップの情報は、ステップの始点aStep->GetPreStepPoint)から取得します。 始点(と終点)はG4StepPointクラスのオブジェクトなのでG4StepPoint Class Referenceを参照しながら、欲しい物理量を探します。

ボリュームをしりたい

1G4LogicalVolume *current_volume = aStep->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume()

現在のステップの論理ボリュームを取得します。 スコアリング対象のボリュームかどうかの条件に利用できます。

エネルギー損失を知りたい(GetTotalEnergyDeposit

1G4double the_total_energy_deposit = aStep->GetTotalEnergyDeposit();
2G4double the_non_ionizing_energy_deposit = aStep->GetNonIonizingEnergyDeposit();

現在のステップで発生したエネルギー損失を取得できます。 この値を足し上げると、トラック全体のエネルギー損失が計算できます。

注釈

aStep->GetPreStepPoint()->GetTotalEnergy() との関係がよく分かっていません。

トラックが欲しい(GetTrack

1G4Track *pTrack = aStep->GetTrack()

ステップの長さが欲しい(GetStepLength

1G4double the_step_length = aStep->GetStepLength();

ステップ前後の差をしりたい

1G4double delta_energy = aStep->GetDeltaEnergy();
2G4double delta_time->GetDeltaTime();
3G4ThreeVector delta_momentum = aStep->GetDeltaMomentum();
4G4ThreeVector delta_position->GetDeltaPosition();

GetDelta*メソッドで、ステップの始点(PreStepPoint)と終点(PostStepPoint)の差を取得できます。