janpipek / g4application

A simple modular application for Geant 4.
MIT License
2 stars 0 forks source link
geant4

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.

g4application

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.

Main features

Component system

Components

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.

Built-in components

Add them using:

/component/builtin GPS    
/component/builtin DefaultWorld

Composite user actions

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:

Plug-ins

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.

Example plugins

There are a few example plug-ins that use most features of G4Application in the examples subdirectory.

Configuration

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

How to build

You will need:

After building, you will obtain:

Environment variables (alternatively can be set as CMake variables):

Building tested on Linux (Fedora Core 18, 20, 22, Scientific Linux 6.4, Ubuntu 14.04), tests on other platforms are welcome.

Included 3rd-party code

g4application includes code from the following projects:

Thanks to the original authors!

Running the app

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].

History & motivation

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).

Known issues

Related projects

Contact

I'd be happy to accept feature requests, cooperation, questions, bug reports... Please write to jan.pipek AT gmail.com