Sensitive Detectorしたい(G4VSensitiveDetector

測定器のヒット情報を取得するためには、論理ボリュームにSensitive Detector(以下SD)を設定します。 SDはG4VSensitiveDetectorクラスを継承して作成します。 ひとつの論理ボリュームに複数のSDを設定できます。

 1#ifndef SensitiveDetector_h
 2#define SensitiveDetector_h 1
 3
 4#include "G4HCofThisEvent.hh"
 5#include "G4Step.hh"
 6#include "G4TouchableHistory.hh"
 7#include "G4VSensitiveDetector.hh"
 8
 9class SensitiveDetector : public G4VSensitiveDetector
10{
11    public:
12        SensitiveDetector(const G4String name)
13        void Initialize(G4HCofThisEvent *aHCE) override
14        void EndOfEvent(G4HCofThisEvent *aHCE) override
15        G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *aTouchable) override
16}
17
18#endif // SensitiveDetector_h

SDのクラスを自作する場合、 InitializeEndOfEventProcessHits、 の3つのメソッドを実装する必要があります。

Initialize

1void SensitiveDetector::Initialize(G4HCofThisEvent *aHCE)
2{
3
4
5}

Initializeはイベントの開始時に呼ばれます。 このイベントのヒットコレクションを初期化します。 自前のデータ構造も定義できます。

EndOfEvent

1void SensitiveDetector::EndOfEvent(G4HCofThisEvent *aHCE)
2{
3
4}

EndOfEventはイベントの最後に呼ばれます。 ステップごとに足し上げたスコアをヒットコレクションなどに保存します。

ProcessHits

1void SensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHitory *aTouchable)
2{
3    // スコアリングの本体を記述する
4    // ステップのあるジオメトリを取得するためにG4TouchableHistoryを使う
5
6}

ProcessHitssにスコアリングしたい内容を記述します。 この関数はステップが発生するたびに自動的に呼び出されます。

論理ボリュームに割り当てたい(SetSensitiveDetector

 1G4VPhysicalVolume* DetectorConstruction::Construct()
 2{
 3    // 自作のSDインスタンスを作成する
 4    SensitiveDetector *pSD = new SensitiveDetector("/myDetector/検出器名");
 5
 6    // SD管理者に追加する
 7    auto sdManager = G4SDManager::GetSDMpointer();
 8    sdManager->AddNewDetector(pSD);
 9
10    // 論理ボリュームに割り当てる
11    SetSensitiveDetector(pLogicalVolume, pSD);
12}

DetectorConstruction::Constructで、論理ボリュームにSensitiveDetectorを設定します。 設定の手順は以下のとおりです。

  1. 自作SDのインスタンスを作成します

  2. SD Managerに追加します

  3. SDにしたい論理ボリュームに割り当てます