Geant4 最简单的模拟程序
G4 运行至少需要 3 个最基本的 class :
- DetectorConstruction : 继承自 G4VUserDetectorConstruction,必须实现的虚函数是 G4VPhysicalVolume* Construct(); 作用:定义空间中所有的物质(探测器,靶,磁场等)
- PrimaryGeneratorAction : 继承自 G4VUserPrimaryGeneratorAction,必须实现的虚函数是 void GeneratePrimaries(G4Event* anEvent); 作用:定义待发射的初级粒子(粒子种类,能量,动量方向,初始位置等)
- PhysicsList : 继承自 G4VModularPhysicsList;作用:为所有初级粒子和可能产生的次级粒子定义物理过程
在主函数中需要如下部分:
1 //Run管理器 2 G4RunManager* runManager = new G4RunManager(); 3 4 //Detector 5 DetectorConstruction* detector = new DetectorConstruction(); 6 runManager->SetUserInitialization(detector); 7 8 //PhysicsList 9 PhysicsList* physics= new PhysicsList(); 10 runManager->SetUserInitialization(physics); 11 12 //Action 13 PrimaryGeneratorAction* gen_action = new PrimaryGeneratorAction; 14 runManager->SetUserAction(gen_action); 15 16 //=============Initialize G4 kernel============// 17 runManager->Initialize(); 18 runManager->BeamOn(1); // 一次Run