Geant4 Note
一般的Program目录结构
+- Program/
| CMakeLists.txt //CMake编译时需要的文件
| Program.cc // main()函数
| +- include
| | ...include.hh... //放置头文件,声明需要的类
| +- src
| | ...source.cc... //放置源文件,定义相应的类和方法
一个活的程序需要什么
+- Program/
| CMakeLists.txt // CMake编译时需要的文件
| Program.cc // main()函数
| +- include // 用来存放头文件
| | ProgramDetectorConstruction.hh // 声明探测器结构的类
| | ProgramPrimaryGeneratorAction.hh // 声明初始事件类
| +- src // C++中,定义函数原型
| | ProgramDetectorConstruction.cc //设置探测器结构
| | ProgramPrimaryGeneratorAction.cc //设置初始粒子的位置,速度等信息(搭建粒子枪)
main()函数的一般内容:
项目
- runManager
- DetectorConstruction
- PhysicsList
- ActionInitialization
- PrimaryGeneratorAction
- UI mode
- ‘Purely hard-coded’ batch mode 硬编码批处理模式,即完全交由main()函数完成,不存在交互
硬编码是将数据直接嵌入到程序或其他可执行对象的源代码中的软件开发实践,与从外部获取数据或在运行时生成数据不同。 硬编码数据通常只能通过编辑源代码和重新编译可执行文件来修改…… ——百度百科·硬编码
- batch mode, but reading a macro of commands 批处理模式,但读取一个宏。这时用户可以在编译后通过输入不同的宏文本来调整一部分信息,而不需要重新编译源代码
- interactive mode, driven by command lines 命令行交互模式
- interactive mode via a Graphical User Interface GUI用户图形界面交互模式
- ‘Purely hard-coded’ batch mode 硬编码批处理模式,即完全交由main()函数完成,不存在交互
流程
/*
* Example of main()
*/
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "ExG4DetectorConstruction01.hh"
#include "ExG4PhysicsList00.hh"
#include "ExG4ActionInitialization01.hh"
int main()
{
// construct the default run manager
G4RunManager* runManager = new G4RunManager;
// set mandatory initialization classes
runManager->SetUserInitialization(new ExG4DetectorConstruction01);
runManager->SetUserInitialization(new ExG4PhysicsList00);
runManager->SetUserInitialization(new ExG4ActionInitialization01);
// set mandatory user action classes
runManager->SetUserAction(new ExG4PrimaryGeneratorAction);
// initialize G4 kernel
runManager->Initialize();
// get the pointer to the UI manager and set verbosities
G4UImanager* UI = G4UImanager::GetUIpointer();
UI->ApplyCommand("/run/verbose 1");
UI->ApplyCommand("/event/verbose 1");
UI->ApplyCommand("/tracking/verbose 1");
// start a run
int numberOfEvent = 3;
runManager->BeamOn(numberOfEvent);
// job termination
delete runManager;
return 0;
}
探测器构建DetectorConstruction
几何信息
声明用到的粒子与物理过程PhysicsList()
Geant4给出一些常用的PhysicsList方案,分别适用于不同的物理过程。
创建ExPhysicsList()类,继承G4UserPhysicsList()类。
完成两项必要设置:
ConstructParticle(); //construction of particles
ConstructProcess(); //construct processes and register them to particles
以及边界阈值(Range cut value)
SetCuts();
Particale Definition
编辑ExPhysicsList::ConstructParticle()
void ExPhysicsList::ConstructParticle()
{
G4Proton::ProtonDefinition();
G4Geantino::GeantinoDefinition();
}
或者批量添加某一类型的粒子:
void ExN05PhysicsList::ConstructLeptons()
{
// Construct all leptons
G4LeptonConstructor pConstructor;
pConstructor.ConstructParticle();
}
/*************************
*G4BosonConstructor
*G4LeptonConstructor
*G4MesonConstructor
*G4BaryonConstructor
*G4IonConstructor
*G4ShortlivedConstructor.
*/
Physics Processes
同样是编辑一个方法:
void ExPhysicsList::ConstructProcess()
{
// Define transportation process
AddTransportation();
// electromagnetic processes
ConstructEM(); //不用区分物理过程在程序实现层面的类别,直接加入物理过程的方法
}
void MyPhysicsList::ConstructEM()
{
// Get pointer to G4PhysicsListHelper
G4PhysicsListHelper* ph = G4PhysicsListHelper::GetPhysicsListHelper();
// Get pointer to gamma
G4ParticleDefinition* particle = G4Gamma::GammaDefinition();
// Construct and register processes for gamma
ph->RegisterProcess(new G4PhotoElectricEffect(), particle);
ph->RegisterProcess(new G4ComptonScattering(), particle);
ph->RegisterProcess(new G4GammaConversion(), particle);
ph->RegisterProcess(new G4RayleighScattering(), particle);
}
设置初始粒子源信息PrimaryGeneratorAction
设置UI
编译运行
输出?
geant4.10.05-install 目录结构及功能
- bin: 存放配置文件
- include: 存放基础的头文件,包括各种Geant4基类
- lib: 应该是编译用的东西,暂时用不到
- share: 放了一些例子