Skip to content

Commit e34dc1f

Browse files
committed
Add README and build scripts
1 parent d569527 commit e34dc1f

File tree

6 files changed

+91
-0
lines changed

6 files changed

+91
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
*This README is about a version of Geant4 enabled for operator-overloading
2+
algorithmic differentiation; see [README_ORIGINAL.rst](README_ORIGINAL.rst)
3+
for information about Geant4.*
4+
5+
# Differentiated Geant4
6+
7+
The [Geant4](https://geant4.web.cern.ch/) toolkit for the simulation of the passage
8+
of particles through matter is widely used in high energy physics and many other
9+
areas. Being able to compute derivatives of user-defined outputs of Geant4 applications
10+
with respect to user-defined inputs would facilitate many interesting application, like
11+
gradient-based design optimization studies of particles detectors. To this end, we created
12+
this **early-stage prototype of a version of Geant4 enabled for forward-mode algorithmic differentiation (AD)**, based on Geant4 version 11.0.4.
13+
14+
## Build instructions
15+
1. Make sure that your system is able to build the original Geant4. According to their [documentation of prerequisites](https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/html/gettingstarted.html), this basically means that you need a recent C++ compiler and CMake. It might also be advisable to have expat installed.
16+
Things are more robust if you do not already have Geant4 installed to system directories or into your present anaconda environment or anything, because this version might later conflict with our AD-differentiated version.
17+
2. You will need to download the [AD tool](https://gitlab.rhrk.uni-kl.de/aehle/easyAD), and to download, configure and build the differentiated versions of CLHEP, Geant4, and ideally also the G4HepEm toolkit and example application. To that end, you may create an empty directory, download [build.sh](setup/build.sh), [download.sh](setup/download.sh), [env-build.sh](setup/env-build.sh), [env-run.sh](setup/env-run.sh) into some empty directory and then run the following commands in that directory:
18+
```bash
19+
export ROOTDIR=$PWD
20+
./download.sh
21+
source env-build.sh
22+
./build.sh
23+
```
24+
3. To run the example application `g4hepem/src/apps/examples/TestEm3/build/TestEm3` or whenever you want to use the differentiated version of Geant4, `source env-build.sh` and `source env-run.sh`.
25+
26+
**Comments**:
27+
- We have mainly tested this with GCC on Ubuntu. Compilation on MacOS with the LLVM implementation of the C++ standard library (libc++) led to compiler errors, partly because we are using `std::complex` beyond what is guaranteed by the C++ language standard.
28+
- On some systems, the `lib` directory in installation directories must be replaced by `lib64` in the build scripts.
29+
- This is an **early-stage work-in-progress prototype** and we expect to improve the user experience in the future. You are nevertheless encouraged to try this out already now, if you like, and let us know about your observations. We are happy to collaborate on applications of differentiated Geant4.
30+
File renamed without changes.

setup/build.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cd $ROOTDIR/clhep/build/
2+
cmake -DCMAKE_INSTALL_PREFIX=$PWD/../install -DCMAKE_BUILD_TYPE=Release ../src -DCMAKE_CXX_STANDARD=17
3+
4+
cd $ROOTDIR/clhep/build/
5+
make install -j80
6+
7+
cd $ROOTDIR/geant4/build/
8+
cmake -DCMAKE_INSTALL_PREFIX=$PWD/../install ../src -DCMAKE_BUILD_TYPE=Release -DGEANT4_INSTALL_DATA=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCLHEP_ROOT_DIR=$PWD/../../clhep/install
9+
10+
cd $ROOTDIR/geant4/build/
11+
make install -j80
12+
13+
cd $ROOTDIR/g4hepem/build/
14+
cmake ../src -DGeant4_DIR=$PWD/../../geant4/install/lib/Geant4-11.0.4 -DCMAKE_INSTALL_PREFIX=$PWD/../install -DCMAKE_BUILD_TYPE=Release -DEASYAD_FORWARD=yes
15+
16+
cd $ROOTDIR/g4hepem/build/
17+
make install -j80
18+
19+
cd $ROOTDIR/g4hepem/src/apps/examples/TestEm3/build
20+
cmake ../ -DGeant4_DIR=$ROOTDIR/geant4/install/lib/Geant4-11.0.4 -DG4HepEm_DIR=$ROOTDIR/g4hepem/install/lib/cmake/G4HepEm/ -DCMAKE_BUILD_TYPE=Release
21+
22+
cd $ROOTDIR/g4hepem/src/apps/examples/TestEm3/build
23+
make -j80
24+
25+

setup/download.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cd $ROOTDIR
2+
git clone https://gitlab.rhrk.uni-kl.de/aehle/easyAD.git
3+
cd easyAD
4+
git checkout work
5+
6+
cd $ROOTDIR
7+
mkdir clhep clhep/build clhep/install
8+
cd clhep
9+
git clone https://gitlab.rhrk.uni-kl.de/aehle/clhep.git src
10+
cd src
11+
git checkout ad
12+
13+
cd $ROOTDIR
14+
mkdir geant4 geant4/build geant4/install
15+
cd geant4
16+
git clone https://gitlab.rhrk.uni-kl.de/aehle/geant4.git src
17+
cd src
18+
git checkout fix_types_2
19+
20+
cd $ROOTDIR
21+
mkdir g4hepem g4hepem/build g4hepem/install
22+
cd g4hepem
23+
git clone https://gitlab.rhrk.uni-kl.de/aehle/g4hepem.git src
24+
cd src
25+
git checkout easyAD_geant4
26+
27+
cd $ROOTDIR/g4hepem/src/apps/examples/TestEm3
28+
mkdir build
29+

setup/env-build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export CPATH=$CPATH:$ROOTDIR/easyAD
2+
export CPATH=$CPATH:$ROOTDIR/clhep/src
3+
export CPATH=$CPATH:$ROOTDIR/geant4/src
4+

setup/env-run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source $ROOTDIR/geant4/install/bin/geant4.sh
2+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTDIR/g4hepem/install/lib
3+

0 commit comments

Comments
 (0)