イベントアクションしたい(G4UserEventAction

イベントごとのデータを収集したい場合は、 G4UserEventActionクラスを継承したクラスを作成します。

親クラス

1G4UserEventAction();
2virtual ~G4UserEventAction() = default;
3virtual void BeginOfEventAction(const G4Event* aEvent);
4virtual void EndOfEventAction(const G4Event* aEvent);

親クラスのメンバー関数を抜粋しました。 コンストラクターとデストラクターは、この設定を引き継げばよさそうです。 BeginOfEventAction()は、イベントの開始時に実行される関数です。 EndOfEventAction()は、イベント終了時に実行される関数です。 どちらも仮想関数になっているため、設定は必須ではありません。 必要に応じて自作クラスでoverrideします。

EventActionクラス

 1// include/EventAction.hh
 2
 3#ifndef EventAction_h
 4#define EventAction_h 1
 5
 6#include "G4UserEventAction.hh"
 7
 8#include "RunAction.hh"
 9
10namespace ToyMC
11{
12
13class EventAction: public G4UserEventAction
14{
15  public:
16    EventAction() = default;
17    ~EventAction() = default;
18
19    void BeginOfEventAction(const G4Event *aEvent) override;
20    void EndOfEventAction(const G4Event *aEvent) override;
21};
22
23};  // namespace ToyMC
24
25#endif

初期化したい(EventAction

1EventAction::EventAction(RunAction* /* aAction */)
2{
3
4}

イベント開始したい(BeginOfEventAction

 1void EventAction::BeginOfEventAction(const G4Event *aEvent)
 2{
 3    // イベント操作
 4    aEvent->Print();
 5    G4int event_id = aEvent->GetEventID();
 6    G4String random_status = aEvent->GetRandomNumberStatus();
 7
 8    // 内部変数(プライベート変数など)の初期化など
 9    fEnergyDeposit = 0;
10}

BeginOfEventActionはイベント開始に実行されるメソッドです。 イベントごとのデータを代入するために用意した変数は、ここで初期化できます。

注釈

ヒット情報(G4THitMapG4THitsCollection)はここで初期化します。

イベント終了したい(EndOfEventAction

1void EventAction::EndOfEventAction(const G4Event *aEvent)
2{
3
4    auto am = G4AnalysisManager::Instance();
5    G4int id1 = am->GetH1Id("名前");
6    am->FillH1(id1, );
7
8}

EndOfEventActionはイベントの終わりに実行されるメソッドです。 イベントごとデータを集計して、イベントサマリーを表示できます。