Geant4安装和测试运行

Geant4网站:https://geant4.web.cern.ch/

Geant4文档:https://geant4.web.cern.ch/support/user_documentation/

Geant4安装指南:https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/html/installguide.html

Linux下安装Geant4

打开下载页面https://geant4.web.cern.ch/support/download 下载Geant4 11.0.1的源代码,解压得到geant4-v11.0.1目录。在geant4-v11.0.1同级目录中,新建geant4-v11.0.1-build目录。在Terminal中cd到geant4-v11.0.1-build目录中,执行以下cmake,注意PREFIX路径必须为绝对路径,是将要放置Geant4文件的地方:

1
cmake -DCMAKE_INSTALL_PREFIX=/path/to/geant4-v11.0.1-install /path/to/geant4-v11.0.1

推荐打开的设置:

1
2
3
4
5
6
-DGEANT4_USE_GDML=ON
-DGEANT4_BUILD_MULTITHREADED=ON
-DGEANT4_USE_RAYTRACER_X11=ON
-DGEANT4_USE_QT=ON
-DGEANT4_USE_OPENGL_X11=ON
-DGEANT4_INSTALL_DATA=ON

执行编译和安装:

1
2
make -j8
make install

在系统的bashrc中增加:

1
2
source /path/to/geant4-v11.0.1-install/share/Geant4-11.0.1/geant4make/geant4make.sh
export G4PATH=/path/to/geant4-v11.0.1-install/share/Geant4-11.0.1/

到这里安装完成。geant4-v11.0.1geant4-v11.0.1-build两个目录不再需要了。

第一个程序例子

Geant4的示例文件在geant4-v11.0.1-install/share/Geant4-11.0.1/examples中。为了防止编译和修改代码污染原始文件,建议将示例复制到其他地方编译运行。

basic/B1复制到其他地方,cd到B1下,建立新目录build,在其中编译:

1
2
cmake ..
make

然后运行编译好的exampleB1程序:

1
./exampleB1

如果编译都正常,运行的效果是打开一个QT窗口:

点击工具栏中的绿色运行按钮可以产生一个事例。

在Session栏中可以尝试以下指令:

  • 旋转视角 /vis/viewer/set/viewpointThetaPhi [theta] [phi] [deg|rad]
  • 缩放 /vis/viewer/zoom [倍数]
  • 粒子种类 /gun/particle gamma
  • 粒子能量 /gun/energy 6 MeV
  • 运行 /run/beamOn 1