How to Use ROOT with Monte Carlo Programs
This text is an attempt to summarize known approaches to put
together Monte Carlo simulations and ROOT.
It tries to describe what are the gains a user gets with each approach,
and their caveats.
1. Linking Geant4 and ROOT libraries with your application
We recommend you to configure Geant4 to use shared libraries
by specifying this option when running Configure or
by setting the G4LIB_BUILD_SHARED environment variable
before building libraries. This will save you time when linking
your application program and enable dynamical loading of Geant4
libraries. In order to avoid long list of Geant4 include paths,
you can also choose an option to copy all its header files into
one include directory.
Note that both these options are not set by default by the Configure
script but they are required by all three tools below.
Installation of Geant4 requires CLHEP library.
Instructions how to build CLHEP-1.8
shared library (not installed by default,
but required by the tools below) can be found in the
CLHEP-1.8
Installation Guide , in the paragraph Examples of building
shared library . In case of CLHEP-1.9
and 2.0, shared libraries are built by default. Also in the binary
distribution kits (CLHEP-1.8,
CLHEP-1.9
and 2.0), the shared libraries are included together with the
static ones, by default.
Users, who configured and built ROOT with the "--enable-thread" option,
which is the default on Linux and Darwin (MacOS), should carefully read
this README.
When defining your own ROOT based
classes (for your data) be careful not to include
Geant4 classes in such a way that would require
ROOT to make dictionaries for Geant4
classes (the actual problem is that rootcint cannot parse many of the
Geant4 include files, i.e. for many Geant4
classes no ROOT dictionaries can be generated).
Besides the above notes there is nothing special - you can follow
ROOT tutorials on how to define your own
classes for your data and then use them in your
Geant4 based classes (sensitive detector etc.).
When linking your application program, with both
ROOT and Geant4 libraries, you should exclude
ROOT New library.
A fairly complete, yet still simple to understand, Geant4 + ROOT
example can be found in the
IcaG4.tar.gz
file.
TinyG4 gives you a simple tool which enables you to set up your own
Geant4 application (like, for example, the
Geant4 examples) and run it interactively from the ROOT
UI (you won't need to build any Geant4 application
executables, just the shared libraries).
It will not give you the standard ROOT access (via the ROOT dictionary)
to the Geant4 and Geant4 application classes (due to the reasons
described above). However, all ROOT based classes (such as TH*,
TNtuple, TTree, ...) defined and used within the Geant4 application
will certainly not suffer from this limitation.
(By the standard ROOT access one means class/object inspection via the
ROOT browser (Dump, Inspect, ...) .)
Most of the interactivity is arranged by wrapping the
Geant4 commands with the G4::ApplyCommand()
method. This wrapping disables the automatic completion of the
Geant4 commands using the TAB key. In case you want to keep the full
Geant4 UI functionality, then using TinyG4 together with the
G4UIRoot is recommended.
This tool is provided as an independent package using shared libraries
of Geant4 and ROOT as external ones.
G4UIRoot is a graphical user interface based on the
Geant4 interfaces category and the ROOT GUI classes. It
simultaneously provides :
- a standard ROOT command line UI (terminal)
- a GUI to the Geant4 commands via a graphic tree of commands with
full command help
- Geant4 command line UI (within the GUI)
It doesn't provide the standard ROOT access (via a dictionary) to any
Geant4 objects, however, it does not limit the access to the ROOT based
classes defined and used within the Geant4 application.
This tool is provided as an unofficial part of the Geant4
package. Its installation requires very few modifications
of Geant4 GNUmakefiles, it builds a single library which is placed
in the standard Geant4 library path.
ROOT libraries are used as external ones.
Virtual Monte Carlo provides an abstract interface to Monte Carlo
programs. It enables the user to build a virtual
Monte Carlo application independent of any actual underlying Monte
Carlo
implementation itself.
A user has to implement a class derived from the abstract
Monte Carlo application class, and to provide functions like
ConstructGeometry(), BeginEvent(), FinishEvent(), ... .
The concrete Monte Carlo implementation (Geant3,
Geant4) is selected at
run time - when processing a ROOT
macro where the concrete Monte Carlo is instantiated.
The user's Monte Carlo application is based on the
ROOT framework; a user will have the standard ROOT access to the
application class.
In the implementation of VirtualMC, Geant3 is favoured with respect
to Geant4, as the Virtual MC class was designed as a generalization of
the Geant3 functions.
The interface classes are provided in ROOT, within the directory mc
and the library libMC.so residing in the ROOT lib directory. The
concrete Virtual Monte Carlo implementations (Geant3 VMC, Geant4 VMC)
and examples of VMC usage can be downloaded from the Virtual Monte Carlo
Web page.
The implementation of Virtual Monte Carlo for
Fluka is now under development
by
the ALICE collaboration.
Summary
These tools are not necessarily competitive (in fact they are rather
complementary) and can be used together.
Who could be interested in which tool ?
- TinyG4
- the user who is interested in Geant4 only and wants to stay
all the time in the ROOT UI (or in the ROOT UI + G4UIRoot)
- G4UIRoot
- can be used in a standard Geant4 application as the GUI (or
in any other framework)
- can be embedded in a framework based on ROOT as well
- VirtualMC
- a user who already has a Geant3 application and wants to
move to C++
- a user who wants to feed both Geant3 and Geant4 from the
same source
- not recommended for a user who is interested in Geant4 only
(and for example wants to compare simulated and experimental data)
Rene Brun,
Last update 2005.03.14 by Jacek M. Holeczek