Ubuntu20.04和Ubuntu22.04中安装Geant4和Cern ROOT。
1、准备安装文件
(1)下载root
(2)下载geant4
(3)将下载的文件以下面这个目录结构存放在~目录下
~
└─geant4
├─G4ABLA.3.3.tar.gz
├─G4EMLOW.8.5.tar.gz
├─G4ENSDFSTATE.2.3.tar.gz
├─G4INCL.1.2.tar.gz
├─G4NDL.4.7.tar.gz
├─G4PARTICLEXS.4.0.tar.gz
├─G4PhotonEvaporation.5.7.tar.gz
├─G4PII.1.3.tar.gz
├─G4RadioactiveDecay.5.6.tar.gz
├─G4RealSurface.2.2.tar.gz
├─G4SAIDDATA.2.0.tar.gz
├─G4TENDL.1.4.tar.gz
├─geant4-v11.2.0.tar.gz
└─root_v6.30.04.Linux-ubuntu20.04-x86_64-gcc9.4.tar.gz
2、安装
打开终端,执行以下命令(ps:将-j6换成自己电脑的核心数)
cd ~ && \
sudo cp -r geant4/ /usr/local/ && \
cd /usr/local/geant4/ && \
sudo tar -zxvf geant4*.tar.gz && \
sudo apt install curl g++ libgl1-mesa-dev cmake libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev libhdf5-serial-dev hdf5-tools libexpat1 libexpat1-dev build-essential -y && \
sudo apt install qt5* qtbase5-dev -y && \
sudo mkdir geant4-install && \
sudo mkdir geant4-build &&\
cd geant4-build && \
sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local/geant4/geant4-install -DGEANT4_USE_OPENGL_X11=ON -DGEANT4_USE_RAYTRACER_X11=ON -DGEANT4_USE_QT=ON -DGEANT4_BUILD_MULTITHREADED=ON /usr/local/geant4/geant4-v* && \
sudo make -j6 && \
sudo make install -j6 && \
echo "source /usr/local/geant4/geant4-install/bin/geant4.sh" >> ~/.bashrc && \
cd /usr/local/geant4/ && \
sudo mkdir -p /usr/local/geant4/geant4-install/share/Geant4/data && \
sudo mv G4*.tar.gz /usr/local/geant4/geant4-install/share/Geant4/data && \
cd /usr/local/geant4/geant4-install/share/Geant4/data && \
sudo ls *.tar.gz | sudo xargs -n1 tar xzvf && \
sudo rm -rf G4*.tar.gz && \
cd /usr/local/geant4/ && \
sudo tar -zxvf root*.tar.gz && \
sudo mv root /usr/local/ && \
sudo rm -rf root*.tar.gz && \
sudo rm -rf geant4*.tar.gz && \
echo "source /usr/local/root/bin/thisroot.sh" >> ~/.bashrc && \
source ~/.bashrc && \
mkdir ~/geant4_ws && \
cd ~/geant4_ws && \
cp -r /usr/local/geant4/geant4-install/share/Geant4/examples ~/geant4_ws &&
命令解释
-DCMAKE_INSTALL_PREFIX用于指定安装目录(Geant4 库、头文件和支持文件的安装目录)
-DGEANT4_INSTALL_DATA=ON表示在在编译 Geant4 时自动下载和安装外部数据库
-DGEANT4_USE_OPENGL_X11=ON表示编译X11 OpenGL可视化驱动程序
-DGEANT4_USE_RAYTRACER_X11=ON表示编译支持 X11 的 RayTracer可视化驱动程序
-DGEANT4_USE_QT=ON表示编译 Qt 用户界面和可视化驱动程序
-DGEANT4_BUILD_MULTITHREADED=ON表示编译支持多线程的 Geant4 库
-DGEANT4_INSTALL_DATADIR用于指定外部数据库目录
-j6用于指定编译和安装线程数
3、验证
cp -r ~/geant4ws/examples/basic/B1 ~/geant4ws
cd ~/geant4ws/B1
mkdir build
cd build
cmake ..
make -j6
./exampleB1
4、补充
在Ubuntu22.04中遇到可视化界面不显示问题,可能是NVIDIA驱动问题,换成推荐的驱动版本可解决。
ubuntu-drivers devices
sudo ubuntu-drivers autoinstall