メイン関数したい(main()
)
1// ユーザー定義クラスを読み込む
2#include "Geometry.hh"
3#include "ActionInitialization.hh"
4
5// Geant4のクラスを読み込む
6#include "G4RunManagerFactory.hh"
7#include "FTFP_BERT.hh" // 標準の物理モデルのひとつ
8
9int main(int argc, char** argv)
10{
11 auto rm = G4RunManagerFactory::CreateRunManager();
12
13 // ジオメトリの設定
14 auto geometry = new Geometry{};
15 rm->SetUserInitialization(detector);
16
17 // 物理モデルの設定
18 auto physics = new FTFP_BERT{};
19 rm->SetUserInitialization(physics);
20
21 // ユーザーアクションの設定
22 auto actions = new ActionInitialization{};
23 rm->SetUserInitialization(actions);
24
25 // 実験開始
26 rm->Initialize();
27 G4int n_events = 100;
28 rm->BeamOn(n_events);
29
30 // 実験終了
31 delete rm;
32 return 0;
33}
Geant4でシミュレーションを実行する場合の、
バッチモード用の必要最低限のmain()
関数の構成例です。
このサンプルでは、次の3つの要素を設定しています。
geometry
:G4VUserDetectorConstruction
を継承したユーザー定義クラスphysics
:FTFP_BERT
(Geant4標準の物理モデルのひとつ)actions
:G4VUserActionInitialization
を継承したユーザー定義クラス
参考
クラスが呼ばれる順番
1{
2G4RunManagerFactory::CreateRunManager();
3new Geometry{};
4new FTFP_BERT{};
5new ActionInitialization{};
6ActionInitialization::BuildForMaster();
7
8// G4RunManager::Initializeを実行すると、測定器がセットアップがされる
9G4RunManager::Initialize();
10Geometry::Construct() {
11 SetupVolumes()
12};
13Geometry::ConstructSDandField() {
14 new TrackerSD{"/TrackerSD", "TrackerHitsCollection"}
15 new TrackerSD{"/ShieldSD", "ShieldHitsCollection"}
16};
17
18// G4RunManager::BeamOn()を実行すると、入射粒子がセットアップされる
19G4RunManager::BeamOn()
20ActionInitialization::Build();
21new PrimaryGenerator{};
22PrimaryGenerator::GeneratePrimaries() {
23 SetupGunMuons();
24};
25// 有感検出器での処理
26TrackerSD::Initialize();
27TrackerSD::ProcessHits() {
28 TrackerHit::operator new
29 TrackerHit::TrackerHit()
30 TrackerHit::Fill()
31 TrackerHit::Print()
32}
33TrackerSD::ProcessHits() { ... }
34TrackerSD::ProcessHits() { ... }
35TrackerSD::EndOfEvent()
36{
37 "File opened: mc_data/kamaboko_00000_2024-07-30T13h05m.csv"
38 TrackerHit::ToCsvString();
39 TrackerHit::ToCsvString();
40 TrackerHit::ToCsvString();
41 "File closed: mc_data/kamaboko_00000_2024-07-30T13h05m.csv"
42 TrackerHit::operator delete
43}
44delete G4RunManager();
45delete Geometry();
46delete FTFP_BERT();
47delete ActionInitialization();
クラスが呼ばれる順番を確認しました。
G4RunManager::Initialize
すると測定器がセットアップされることを確認しました。
G4RunManager::BeamOn
すると入射粒子がセットアップされることを確認しました。
有感検出器(ここではTrackerSD
)のヒット処理の流れを確認しました。