Garfield++安装(Ubuntu20.04)
Garfield++安装(Ubuntu20.04)
1.简介
Garfield++是一个面向对象的工具包,用于基于气体或半导体中电离测量的粒子探测器的详细模拟。这个工具包的官方网页是https://garfieldpp.web.cern.ch/garfieldpp/,其中可以找到更多的示例和官方用户指南。
为了能够安装Garfield++程序需要有前置软件:
2.软件安装:ROOT和Garfield++
2.1 升级Ubuntu并安装软件包
首先你需要使用下列命令升级软件包:
sudo apt update
sudo apt upgrade
接下来安装一些基础软件包以便后续安装。
sudo apt-get install cmake
sudo apt-get install build-essential binutils-gold libtool gfortran
sudo apt-get install libx11-dev libxft-dev libxext-dev libxpm-dev
sudo apt-get install freeglut3 freeglut3-dev g++ libglew-dev
sudo apt-get install libglew1.5-dev libglm-dev libssl-dev
sudo apt-get install libxi-dev libxmu-dev libftgl-dev automake
sudo apt-get install python-dev mesa-common-dev mesa-utils
sudo apt-get install libgsl-dev git
sudo apt-get install dpkg-dev g++ binutils libssl-dev
sudo apt-get install gfortran libpcre3-dev \
xlibmesa-glu-dev libglew1.5-dev libftgl-dev \
libmysqlclient-dev libfftw3-dev libcfitsio-dev \
graphviz-dev libavahi-compat-libdnssd-dev \
libldap2-dev python-dev libxml2-dev libkrb5-dev libgsl0-dev libqt4-dev
2.2 安装ROOT
本文使用的是ROOT版本为6.28,(2023年10月9日),gcc版本为9.4。
可以参考自己的系统配置在ROOT发布页找到适合自己的版本。
ROOT的安装可以下载源码自己进行编译,也可以直接下载编译好的文件进行配置。
2.2.1 源码编译(不建议)
在Ubuntu终端按照步骤输入下列指令:
wget https://root.cern/download/root_v6.28.06.source.tar.gz --no-hsts
tar xvzf root_v6.28.06.source.tar.gz
cd root-6.28.06/build
cmake -builtin-glew=ON -opengl=ON-tmva=OFF ../
make clean
libtoolize
sudo make -j4
sudo make install
wget中的命令——no-hsts用于禁用关于hsts (HTTPS之上的可选安全度量)的警告,并且不是必需的,用户也可以忽略警告。
在代码的第3行中,目录被更改为ROOT文件解压缩到的文件夹,这可能取决于所下载的ROOT版本。在命令cmake目录../对应解压缩ROOT tar文件所在的文件夹名(例如~/ ROOT -6.28.06/)。
只有在以前安装过(或尝试过)时才需要make clean命令。
命令make -j4使用4个内核,因此比简单的make命令快4倍,后者也可以工作,但时间更密集。安装ROOT非常耗时,因此强烈建议使用多个内核。如果需要,可以使用Ctrl+ C强制终止make命令在其运行过程中。
编译过程中错误代码Makefile:151:recipe for target 'all' failed,表明虚拟机的RAM太小。只需通过重新运行前面的命令继续,安装将在它停止的地方继续。
2.2.2 下载ROOT Binary distributions(推荐)
可以直接在ROOT发布页下载编译好的ROOT程序进行配置。
2.2.3 ROOT配置
为了测试ROOT是否安装成功,请执行下列命令:
source ~/root-6.28.06/build/bin/thisroot.sh
root -b
如果安装成功,root -b的命令会开启一个ROOT环境的欢迎界面。
2.3 Garfield++安装(源码编译)
Garfield++是一个工具包,用于详细模拟CERN开发的气体和半导体中基于洋葱化测量的粒子探测器。它是基于C++的。
在安装Garfield++,之前,必须安装ROOT并初始化它,您可以检查它是否已通过运行root-b正确初始化,如2.2节所解释的那样。为了在Ubuntu终端上安装Garfield++,请运行以下命令:
cd ~
git clone https://gitlab.cern.ch/garfield/garfieldpp.git
export GARFIELD_HOME=/home/<username>/garfieldpp
cd garfieldpp
mkdir build
cd build
cmake $GARFIELD_HOME
make && make install
注意
Garfield++将安装在一个名为garfieldpp/install的文件夹中。
在命令cmake $GARFIELD_HOME中,用户可以选择不同的参数,例如安装文件夹(参见DCMAKE_INSTALL_PREFIX的代码行)或选择调试/优化模式(参见DCMAKE_BUILD_TYPE的代码行)。DCMAKE_BUILD_TYPE有不同的选项,比如Debug、Release和RelWithDebInfo。
接下来两个命令可以使Garfield++程序在运行时更高效:
cmake -DCMAKE_INSTALL_PREFIX=/home/mygarfield $GARFIELD_HOME
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo $GARFIELD_HOME
在安装garfield++之后,需要一个环境变量HEED_DATABASE来标识Heed截面数据库的位置,该数据库将位于安装路径(share/Heed/database)的子文件夹中。为了简化这个过程,构建过程将生成一个简短的shell脚本,名为setupgarfield.sh,位于子文件夹share/Garfield中,它可以正确识别诸如HEED_DATABASE或CMAKE_PREFIX_PATH之类的变量。如果希望自动设置该脚本的执行,可以将其添加到shell初始化脚本中(例如,添加到Bash shell的.bashrc中)。
建议将以下代码行添加到.bashrc文件中:
source root-6.28.06/build/bin/thisroot.sh
source garfieldpp/install/share/Garfield/setupGarfield.sh
这意味着无论何时启动终端,ROOT都会自动进行源化,并且garfield++变量也会通过setupGarfield.sh文件进行链接。
PS:如果不是编译安装ROOT第一行命令应该改为source root-6.28.06/bin/thisroot.sh
这也可以每次手动完成。更多信息和安装过程的详细描述可以在Garfield++用户指南的第2.3章中找到。用户手册也可在“DOC”子文件夹中的源代码中找到。
2.3.1 安装过程中可能出现的警告
Warning: "Could not find Geant4Cong”
在本安装指南中,没有安装Geant4,因此在的cmake过程中会出现一个警告,因为Garfield++ (Geant4GarfieldInterface)的一个示例使用了Geant4。如果您不希望使用Geant4并且不希望执行said例如,可以忽略此警告。
CMake Warning at Examples/Geant4GarfieldInterface/CMakeLists.txt:14
(find_package):By not providing "FindGeant4.cmake" in CMAKE_MODULE_PATH
this project has asked CMake to find a package configuration file
provided by "Geant4", but CMake did not find one.
Could not find a package configuration file provided by "Geant4" with any
of the following names:
Geant4Config.cmake
geant4-config.cmake
Add the installation prefix of "Geant4" to CMAKE_PREFIX_PATH or set
"Geant4_DIR" to a directory containing one of the above files. If
"Geant4"provides a separate development package or SDK, be sure it
has been installed.
Warning: Cycle in constraint graph
在使用cmake编译Garfield++过程发生的另一个警告。
CMake Warning at CMakeLists.txt:128 (add_library):
Cannot generate a safe runtime search path for target Garfield because
there is a cycle in the constraint graph:
dir 0 is [/usr/local/lib]
dir 1 must precede it due to runtime library [libtbb.so]
dir 1 is [/home/<username>/root-6.16.00/build/lib]
dir 0 must precede it due to runtime library [libGdml.so]
Some of these libraries may not be found correctly.
这是由于路径定义中的错误造成的。如果发生此错误,请重新检查路径。
Warning: ROOTSYS
CMake Warning:
Manually-specified variables were not used by the project:
ROOTSYS
这说明Gareld未成功找到ROOT程序,请检查ROOT是否正确安装。
Error: "ComponentXXX.hh not found”
如果用户在运行示例中遇到错误,如“ComponentAnsys123.hh”文件未找到,这很可能是由于路径定义中的错误所致。错误代码如下:
/home/<username>/garfieldpp/Examples/Gem/gem.C:8:10: fatal error: Garfield/ComponentAnsys123.hh:
No such file or directory
#include "Garfield/ComponentAnsys123.hh"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/gem.dir/build.make:62: recipe for target 'CMakeFiles/gem.dir/gem.C.o' failed
make[2]: *** [CMakeFiles/gem.dir/gem.C.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/gem.dir/all' failed
make[1]: *** [CMakeFiles/gem.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
检查Garfield_HOME和HEED_DATABASE是否设置为正确的路径,并确保正确设置了Garfield。安装步骤中的DROOTSYS路径(root文件夹的路径,而不是root/build路径)。
.bashrc文件应该包含以下代码:
export GARFIELD_HOME=/home/wang/garfieldpp
export CMAKE_PREFIX_PATH=/home/wang/garfieldpp/install:$CMAKE_PREFIX_PATH
export HEED_DATABASE=$GARFIELD_INSTALL/share/Heed/database
source root/bin/thisroot.sh
2.4 运行Gareld++示例
在完成上述所有安装步骤之后,用户可以打开一个Ubuntu终端,并尝试运行Garfield++提供的一些示例。
Example "Gem”
接下来是关于如何运行示例“Gem”的说明
cd garfieldpp/Examples/Gem
若要查看此文件夹中的所有文件,用户可以使用命令ls。
要生成并最后执行示例,请运行:
cmake .
make
./gem
如果程序已经完成,没有错误,两个弹出窗口的图形应该已经打开。关于Gem示例的更多细节可以在官方的Garfield++网站上找到

浙公网安备 33010602011771号