-
sh <(curl -L https://nixos.org/nix/install) --daemon
-
Clone this repository:
git clone https://github.com/mdcge/double-sipm.git
. -
cd
into it. -
Type
nix develop --extra-experimental-features 'nix-command flakes'
(this may take some time as Geant4 will be downloaded and compiled). -
Type
just
.This will compile and run the example and should take a few seconds. At this point, an image of a small simulated detector should appear.
If all of this works, you now have an environment in which you can execute the Geant4 examples, and develop and run your own Geant4 code.
-
Linux: this is developed and tested on Linux. If the above instructions fail to work for you on Linux, this is considered a bug: please report it.
-
Windows: use WSL2, where it should work just as well as on Linux.
-
MacOS: the support for Geant4 in Nix (on MacOS) was marked as broken in the past. This appears to longer be the case, but we have not verified to what extent it works.
As is stands you have to write nix develop
in order to activate the environment necessary to run and develop this code. What is more, nix develop
places you in a minimal bash shell in which any personal configurations you may be used to will be missing.
Both of these problems can be fixed with direnv which:
- automatically enables the environment when you enter the directory
- places you in your usual shell with all your preset configurations
To use direnv
:
Depending on which shell you are using, this will involve adding one of the following lines to the end of your shell configuration file:
eval "$(direnv hook bash)" # in ~/.bashrc
eval "$(direnv hook zsh)" # in ~/.zshrc
eval `direnv hook tcsh` # in ~/.cshrc
Various configuration options of Geant4 itself can be changed by editing flake.nix
here:
(geant4.override {
enableMultiThreading = false;
enableInventor = false;
enableQt = true;
enableXM = false;
enableOpenGLX11 = true;
enablePython = false;
enableRaytracerX11 = false;
})
If you change the Geant4 configuration (if you are using direnv
, it will notice the change, and automatically switch to the new configuration (recompiling Geant4, if this is a configuration not seen before) at your next shell prompt).
Be sure to expunge any examples you had compiled with a differently-configured Geant4, otherwise you may get mysterious problems.
This repository also allows you to run and edit the standard Geant4 examples. For example,
just G4-examples/run B1
This should copy the sources of the most basic example that is distributed with Geant4, into the local directory, configure it, compile it and execute it.
If all goes well, an image of a detector should appear. Try typing /run/beamOn 10
in the Session
box, and some simulated events should appear on the image.
You should be able to modify the source code (for example increase the value of env_sizeZ
in B1/src/DetectorConstruction.cc
(change it from 30 to 130, to make the change obvious)) and run your modified version by repeating the earlier command just G4-examples/run B1
.
Many of the other examples can be run in the same way: just G4-examples/run <example-name>
.
-
Some of them will fail because necessary libraries have not (yet) been provided in this flake.
-
Others will fail because the internal organization of the example differs from that of the simple ones, which is assumed by
just run
.In many of these cases it should be fairly easy to figure out how to compile and execute the example by hand. The procedure tends to me something like
- Create a
build
subirectory the example's top-level directory cd
into the newly-createdbuild
directorycmake -S . -B build
cmake --build build -j
- Find the executable which was produced by the previous step, and execute it by preceding its name with
./
In the case of the B1 example, this would be./exampleB1
.
- Create a
Fixes to these problems may be provided eventually. Don't hold your breath.