Note: This application was developed for a historic version of Geant4. It is not developed anymore. If anyone wants to continue the work, I will be most happy to pass it over.
A library and a simple generic application for Geant4. It works as a universal executable for geant4 tasks. It provides a component and plug-in API to plug in specific behaviour (in one or more plug-ins in parallel).
Apart from this, g4application offers features that are not tightly connected to plugin system but can make your life with Geant4 easier.
A component is a class (set of classes) that can be turned on (and perhaps off) by a single method call / user macro command. Each of the components can define:
By default, the component is empty. The user has to override methods they are interested in.
G4PhysListFactory
specified by its nameG4GeneralParticleSource
) to be configured using its commandsAdd them using:
/component/builtin GPS
/component/builtin DefaultWorld
By default, it is not possible to include more the one for each G4User...Action classes in one Geant4 application. This limitation is even more pressing when different part of the application are developed separately. So g4application includes a composite user action class that can contain more instances of the respective action type and executes them in the FIFO order. These are:
CompositeEventAction
CompositeRunAction
CompositeStackingAction
CompositeSteppingAction
CompositeTrackingAction
Plug-ins of g4application are separate dynamic libraries that are loaded at runtime. Each plug-in can contain one or more components.
The plug-in project has to include a class inheriting from g4::Plugin
and export it using MAKE_G4_PLUGIN
macro. See examples for details.
Loading a plugin:
/plugin/open <somePlugin.so> # Opens the DLL
/plugin/loadAll somePlugin # Use all components from the plug in
/plugin/load somePlugin someComponent # Use a single component
/plugin/listComponents somePlugin # Print all component names from the plugin
The plugin DLL is searched for using standard Unix lookup mechanism.
There are a few example plug-ins that use most features of G4Application in the
examples
subdirectory.
The application holds one map of string key / (string/int/float) pairs in a static class Configuration
.
The classes that want to listen to configuration updates, have to inherit from ConfigurationObserver
.
User commands:
/conf/setInt
/conf/setDouble
/conf/setString
/conf/print # Print all configurations
You will need:
After building, you will obtain:
Environment variables (alternatively can be set as CMake variables):
G4APP_PATH
- when you set this, the built libraries and executable will be copied there (optional).G4APP_SOURCE_PATH
- if you use the provided FindG4Application.cmake (when building your modules),
this path is used for searching libraries and include directories of g4application (required in plugins).Building tested on Linux (Fedora Core 18, 20, 22, Scientific Linux 6.4, Ubuntu 14.04), tests on other platforms are welcome.
g4application includes code from the following projects:
Thanks to the original authors!
Usage: g4 [options] <macro1> <macro2> ...
Options:
-h, --help Print usage and exit.
-v, --version Print version info and exit.
-i, --interactive Start interactive mode [optional parameter: qt*/tcsh].
2010-2012: I was developing two similar models of Leksell Gamma Knife at a same time and I wanted them to share a lot of code. In the end, I made the application call the plug-ins instead of two application using the same library.
2013: I hope that the application is universal enough to be used in other environments.
2014: All my simulations for Ph.D. thesis (successfully defended ;-)) were based on g4application.
2015: Complete API redesign, only Geant4 10.1+ is supported (see branch geant9 for older version).
g4application-dicom: voxel geometries built from DICOM data. Implemented as a plug-in. https://github.com/janpipek/g4application-dicom
pyg4app: Python scripts to dynamically generate macro files in a somewhat structured manner (currently out of sync). https://github.com/janpipek/pyg4app
g4application-gammaknife: not yet published model of Leksell Gamma Knife Perfexion.
I'd be happy to accept feature requests, cooperation, questions, bug reports... Please write to jan.pipek AT gmail.com