Skip to content

Instantly share code, notes, and snippets.

@pn11
Last active June 1, 2019 00:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pn11/9f68e56b36b0d23214ce to your computer and use it in GitHub Desktop.
Save pn11/9f68e56b36b0d23214ce to your computer and use it in GitHub Desktop.
Geant4.10.01をMac OS X Yosemiteにインストールしたメモ。

Geant4.10.01インストールメモ

今後Mac上でGeant4のversionを上げるときに見るためのメモ。今回の環境は

  • OS X Yosemite 10.10.2
  • Homebrew 使用

Geant4 10.1以降だとG4AnalysisManagerでNtupleにvectorを入れられるようなのでversionを上げてみた。 手順はインストールするたびにお世話になっている奥村さんの

をなぞっただけ。

1. 落としてきて展開

~/Downloads以下に展開しておく。フルパスは/Users/oka/Downloads/geant4.10.01

最新版は http://geant4.web.cern.ch/geant4/support/download.shtml

古い版は http://geant4.web.cern.ch/geant4/support/source_archive.shtml から。

2. Xerces-Cを入れる

自分の使用目的で必要なのかどうか分からないけどとりあえず入れる。今見ると前回インストール時にホームディレクトリに自分でビルドしたらしきものがあるけど、今回はHomebrewでやってみる。

brew install xerces-c

で行けた。ここがこのメモの唯一新しいところかな。homebrewで簡単に入って17 MBしか食わないのでまあ入れておけば。 2015年3月10日時点ではver. 3.1.1が

/usr/local/Cellar/xerces-c/3.1.1

にインストールされたのでこのpathを次のビルドのときに使う。

3. Build

ビルドも~/Downloads内で行うことにする。

mkdir ~/Downloads/g4-build; cd ~/Downloads/g4-build

まずCMakeでビルドのための準備。CMakeは使い慣れると便利なのかもしれないけどGeant4以外ではほとんど使ったことがない。なおうちのCMakeはHomebrewで入れたもの。cmakeが入っていない場合は

brew install cmake

で。それでcmakeのコマンドは

cmake -DCMAKE_INSTALL_PREFIX=~/geant4/geant4.10.01 -DXERCESC_ROOT_DIR=/usr/local/Cellar/xerces-c/3.1.1 -DGEANT4_USE_OPENGL_X11=ON -DGEANT4_USE_RAYTRACER_X11=ON -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_GDML=ON -DGEANT4_BUILD_MULTITHREADED=ON -DGEANT4_USE_QT=ON -DQT_QMAKE_EXECUTABLE=/usr/local/Cellar/qt/4.8.6/bin/qmake ~/Downloads/geant4.10.01

古いログが下に載せてある。

前のversionのlibraryを上書きしたくないのでCMAKE_INSTALL_PREFIXはversion名つきにした。あと個人的にROOTとかGeant4はホームディレクトリに置いとくのが好きなので~/geant4/geant4.10.01以下にインストール。 XERCESC_ROOT_DIRはさっきHomebrewで入れた場所。OpenGL、Ray tracerは普通使うのでON。データも入れるのでON。GDMLは分からないけどせっかくxercesを入れたのでON。あとQtを使うためのオプションDGEANT4_USE_QTQT_QMAKE_EXECUTABLEとマルチスレッド化のためのオプションDGEANT4_BUILD_MULTITHREADEDを入れた。QT_QMAKE_EXECUTABLEを場所はbrew install Qtして入った場所。

できたらビルド。2コアのMacBookAirなのでj2オプション。

time make -j2

timeで時間も測ってみた。 最初、なんかエラー出て止まった(以下)けど単にダウンロードに失敗しただけみたいでもう一度makeしたら行けた。というわけでデータベースをダウンロードするためにネット接続が必要。

一応止まったところまでの時間は以下。この時点で81%でうちのMacBookAir (mid 2012) でだいたい40分くらい。

real  37m29.877s
user  34m50.489s
sys    4m12.055s

makeしたら

make install

してインストール完了。

databaseはversionによらずほとんど共通だと思うのでversion新しくするごとに上書きしないと邪魔になるかなと思ったけど、インストール後の~/geant4/geant4.10.01を見たら800 MB以下なので全然余裕。

4. pathとかの設定

インストールは以上で終了だけど実際にプログラムを動かすための設定。

cd ~/geant4/geant4.10.01/bin
source geant4.sh
cd -

~/.bashrcに書いておけばこのversionのlibraryなどのpathが設定される。

printenv | grep G4

で確認。

なお、僕の環境ではこれらの環境変数を設定していてもCMakeを使った場合find_packageしてくれなかった。cmakeを実行するときのオプションに-DGeant4_DIR=~/geant4/Geant4-10.1.0を入れると読み込んでくれた。違うversionでビルドしたときはこのオプションを変えればいいはず。CMakeFiles.txtfind_package(Geant4 REQUIRED)より前にset(Geant4_DIR ~/geant4/Geant4-10.1.0)を書いてもいけるはず。versionを変えた場合、実行時にlibraryを読む必要があるので上でやったようにlibraryのpathも合わせて変える必要があることに注意。

5. 要らないファイルを消す

ダウンロードしたソースとビルドしたやつを消す。ビルドしたディレクトリは1.3 GBもあってソースファイルや中間ファイルを含むためインストールした場所よりもでかいのだけど、要らないはず。多分。やっぱりmulti-threading要らないや、とかでインストールし直す可能性もあるので、その場合は残しておいたほうがよい。

rm -r ~/Downloads/g4-build ~/Downloads/geant4.10.01

けっきょくG4ApplicationManagerのNtupleにvectorに入れる方法はうまく動かなかった。よくわかんない。

おまけ。

僕が使い始めた頃の最新版は9.3だった。そのときに見た奥村さんのページはこっち。

あと学部4回生のときに同期にやりかたを教えてもらったときの記録はこれ。Linuxだけど。

あとそれ以前にやってみたのはこれ。

懐かしい。

ログ

CMakeのログ(古い)

cmake -DCMAKE_INSTALL_PREFIX=~/geant4/geant4.10.01 -DXERCESC_ROOT_DIR=/usr/local/Cellar/xerces-c/3.1.1 -DGEANT4_USE_OPENGL_X11=ON -DGEANT4_USE_RAYTRACER_X11=ON -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_GDML=ON ~/Downloads/geant4.10.01
-- The C compiler identification is AppleClang 6.0.0.6000056
-- The CXX compiler identification is AppleClang 6.0.0.6000056
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Clang version : 3.5
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found EXPAT: /usr/lib/libexpat.dylib (found version "2.0.1") 
-- Found XercesC: /usr/local/Cellar/xerces-c/3.1.1/lib/libxerces-c.dylib  
-- Looking for XOpenDisplay in /usr/X11R6/lib/libX11.dylib;/usr/X11R6/lib/libXext.dylib
-- Looking for XOpenDisplay in /usr/X11R6/lib/libX11.dylib;/usr/X11R6/lib/libXext.dylib - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found X11: /usr/X11R6/lib/libX11.dylib
-- Found OpenGL: /System/Library/Frameworks/OpenGL.framework  
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - failed
-- Looking for fseeko
-- Looking for fseeko - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Configuring download of missing dataset G4NDL (4.5)
-- Configuring download of missing dataset G4EMLOW (6.41)
-- Configuring download of missing dataset PhotonEvaporation (3.1)
-- Configuring download of missing dataset RadioactiveDecay (4.2)
-- Configuring download of missing dataset G4NEUTRONXS (1.4)
-- Configuring download of missing dataset G4PII (1.3)
-- Configuring download of missing dataset RealSurface (1.0)
-- Configuring download of missing dataset G4SAIDDATA (1.1)
-- Configuring download of missing dataset G4ABLA (3.0)
-- Configuring download of missing dataset G4ENSDFSTATE (1.0)
-- The following Geant4 features are enabled:
GEANT4_BUILD_CXXSTD: Compiling against C++ Standard 'c++98'
GEANT4_USE_SYSTEM_EXPAT: Using system EXPAT library
GEANT4_USE_GDML: Building Geant4 with GDML support
GEANT4_USE_RAYTRACER_X11: Build RayTracer driver with X11 support
GEANT4_USE_OPENGL_X11: Build Geant4 OpenGL driver with X11 support

-- Configuring done
-- Generating done
-- Build files have been written to: /Users/oka/Downloads/g4-build
@pn11
Copy link
Author

pn11 commented Mar 12, 2015

To do:
Qtを使いたい。

@pn11
Copy link
Author

pn11 commented Mar 13, 2015

To do:
次からはCMake optionに GEANT4_BUILD_MULTITHREADED=ON を入れる
http://geant4.cern.ch/support/ReleaseNotes4.10.0.html#3.

@pn11
Copy link
Author

pn11 commented Mar 14, 2015

@pn11
Copy link
Author

pn11 commented Mar 16, 2015

GEANT4_BUILD_MULTITHREADED=ON と GEANT4_USE_QT=ON を入れた。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment