编译方式等见上一篇: 粒子物理蒙特卡罗模拟库Geant4源码编译安装手记(Ubuntu16.04+cmake)
Geant4程序运行后
运行后出现idle>提示符进入交互模式,可以持续输入命令,继续向场景中添加事件命令、材料命令、可视化命令、跟踪命令等14种命令,具体输入help查看:
Idle> help
Command directory path : /
Sub-directories :
1) /control/ UI control commands.
2) /units/ Available units.
3) /analysis/ analysis control
4) /process/ Process Table control commands.
5) /geometry/ Geometry control commands.
6) /tracking/ TrackingManager and SteppingManager control commands.
7) /particle/ Particle control commands.
8) /event/ EventManager control commands.
9) /cuts/ Commands for G4VUserPhysicsList.
10) /run/ Run control commands.
11) /random/ Random number status control commands.
12) /material/ Commands for materials
13) /gun/ Particle Gun control commands.
14) /vis/ Visualization commands.
Commands :
Type the number ( 0:end, -n:n level back ) :
如果想图形显示探测器以及物理过程的信息,可以输入
Idle> /control/execute vis.mac
一些文件的意义
- vis.mac文件:定义了跟图形显示有关的一些命令,比如观看角度、缩放比例等
- .rndm:一些相关随机数文件
最基础的主函数
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "ExN01DetectorConstruction.hh"
#include "ExN01PhysicsList.hh"
#include "ExN01PrimaryGeneratorAction.hh"
int main()
{
//构造默认的运行管理器(强制)
G4RunManager* runManager = new G4RunManager;
//用探测器以及物理过程初始化运行管理器(强制)
G4VUserDetectorConstruction* detector = new ExN01DetectorConstruction;
runManager->SetUserInitialization(detector);
G4VUserPhysicsList* physics = new ExN01PhysicsList;
runManager->SetUserInitialization(physics);
// 设置用户行为(强制)
G4VUserPrimaryGeneratorAction* gen_action = new ExN01PrimaryGeneratorAction;
runManager->SetUserAction(gen_action);
// 初始化G4 内核
runManager->Initialize();
// 获取UI管理器的指针,并设置verbosities。
G4UImanager* UI = G4UImanager::GetUIpointer();
UI->ApplyCommand("/run/verbose 1");
UI->ApplyCommand("/event/verbose 1");
UI->ApplyCommand("/tracking/verbose 1");
// 开始一次运行
G4int numberOfEvent = 3;
runManager->BeamOn(numberOfEvent);
// 结束作业
// 释放内存:用户行为、物理过程以及探测器描述属于运行管理器,
// 将被运行管理器自动删除,所以不应该在主函数中删除之。
// 只需要删除运行管理器和其它动态指针即可。
delete runManager;
return 0;
}
明确仿真的必要流程
- 定义探测器几何 (具有有限接受范围的探测器)
- 定义探测器材料 (各种材料)
- 定义物理过程与粒子 (什么东西在探测器中干了什么)
- 产生原始事例 (模拟重复实验n次)
- 数据收集和分析 (取出探测器可以获得的信息并处理分析)
定义探测器几何
三个概念层面
- G4VSolid – 形状,尺寸
- G4LogicalVolume – 子物理体积,材料,灵敏区,
磁场,用户限制等等。 - G4VPhysicalVolume – 位置,转动
定义一个G4Box:长方体
G4double expHall_x = 3.0*m;
G4double expHall_y = 1.0*m;
G4double expHall_z = 1.0*m;
//Solid,指定几何形状和尺寸
G4Box* experimentalHall_box
= new G4Box(“expHall_box”,expHall_x,expHall_y,expHall_z);
//Logical,指定具体物理特性,如其中物质为Ar气
experimentalHall_log = new G4LogicalVolume(experimentalHall_box,
Ar,"expHall_log",0,0,0);
//Physical,指定放置位置以及旋转角度等
experimentalHall_phys = new G4PVPlacement(0,G4ThreeVector(),
experimentalHall_log,"expHall",0,false,0);
定义探测器材料
G4Material属性包括温度、压强、状态、密度等,定义时有时需要明显指出属性。
double density = 1.390*g/cm3;//密度
double a = 39.95*g/mole;//原子量
double z=18.;//原子序数
G4Material* lAr = new G4Material(“liquidArgon”,z,a,dentsity);
G4Element* H = new G4Element(name="Hydrogen",symbol="H" , z= 1., a);
G4Element* O = new G4Element(name="Oxygen" ,symbol="O" , z= 8., a);
density = 1.000*g/cm3;
G4Material* H2O = new G4Material(name="Water", density,
ncomponents=2);
H2O->AddElement(H, natoms=2);
H2O->AddElement(O, natoms=1); //定义水,给定密度、元素种类数目、添加元素
空气的定义
G4Element* N = new G4Element("Nitrogen", "N", z=7., a= 14.01*g/mole);
G4Element* O = new G4Element("Oxygen" , "O", z=8., a= 16.00*g/mole);
G4Material* Air = new G4Material("Air", density= 1.29*mg/cm3, nel=2);
Air->AddElement(N, 70*perCent);
Air->AddElement(O, 30*perCent); //指定百分比
真空的定义
G4double a, z;
G4double density, temperature, pressure;
G4int nel;
G4Material* Vacuum =
new G4Material("Galactic", z=1., a=1.01*g/mole,
density= universe_mean_density,kStateGas, 2.73*kelvin, 3.e-18*pascal);//指定温度、压强等属性