GH2ROOT
Geant kinematics/hits/digits to ROOT conversion tool
René Brun
CERN/IT
Fons Rademakers
GSI/Darmstadt and Hewlett-Packard
Abstract
A tool to automatically generate the C++ code for a Geant3 based application.
The classes generated include code to read Geant3 data (Kine, Hits,Digi) stored
in Zebra files or equivalent and to convert this data into a ROOT Tree.
The code to browse and display the data is also generated.
A detailed information can be found at http://root.cern.ch/root/gh2root.html.
1. Program invokation
gh2root is a Fortran program that generates automatically C++
code corresponding to the Geant3 structures JSET, JVERTX, JKINE, JHITS
and JDIGI.
gh2root.f is the Fortran file that must be compiled to generate
the gh2root executable module. gh2root requires the Zebra package only,
not Geant3 itself. The following command illustrates how to compile
and link on an hpux system.
f77 -o gh2root -g +ppu gh2root.f /cern/pro/lib/libpacklib.a
The input to gh2root can be a Geant3/RZ file containing the
detector definition data structures generated at initialisation
time of Geant or a Zebra/FZ file with these data structures.
Instead of using gh2root as a program, one can
also call directly the subroutine Convert in a program using Geant
at the end of the initialisation phase.
When using gh2root as a program, the invokation is:
gh2root geantfile.geom [prefix] [lrecl]
where geantfile.geom is the Geant3/RZ or FZfile. If the file is an FZ file,
the parameters prefix and lrecl are mandatory. In this case,
lrecl is the record length in machine words (eg 900) of the FZ file.
gh2root generates C++ classes (both header files and implementation).
All generated classes start by the chain of characters specified in
the optional argument prefix. By default prefix is 'X'.
The following classes are generated (assuming X is the prefix):
- XRun: This class controls all the other classes
- GParticle: A combined vertex/particle handling class. This class
will be used to convert a JVERTX/JKINE Zebra structure
into a TClonesArray of GParticle objects pointed by
the data member fParticles in the class XGRun.
- XMaker: This is the base class for all Makers. This class provides
the basic functions to convert the Geant3 JHITS structures.
- A Maker class is generated for each set/detector.
The name of the Maker class is XSetDetMaker where Set/Det are the names
of the Geant set and det (created via GSDET).
The XSetDetMaker class is the manager for hits/digits produced by a given
Geant3 set and det. All hits are stored in a TClonesArray pointed
by the member fHits. All digits are stored in a TClonesArray pointed
by fDigits.
- A hit class named XSetDethit. A hit object has data members
corresponding to the information specified by the Geant routines
GSDET and GSDETH. (track number, volumes numbers and hits).
- A digit class named XSetDetdigit. A digit object has data members
corresponding to the information specified by the Geant routines
GSDET and GSDETD. (track numbers, volumes numbers and digits).

2. Compiling the generated code
The generated classes can be compiled into a shared library.
gh2root generates the Makefile to compile and make the library
for several machines (see later).
Once the library called libghlib.so has been generated, it can be
dynamically linked to a running ROOT program.
gh2root generates also ROOT macros to invoke these classes
- fake.C : to generate random particles and hits.
- run.C : to convert a Geant FZ file into a ROOT Tree.
- browse.C : to browse a ROOT file with hits.
- analyze.C : example of analysis code to loop on
generated events and make histograms.
The macros above typically invoke service functions from the XGRun class to:
- Initialize ROOT and all detector makers.
- Control the processing of one event.
- Simulate random tracks and hits.
- Import a Zebra KINE,HITS and DIGI structures from FZ.
- Create and Fill the ROOT Trees with particles/hits/digits.
- Browse the generated ROOT file.
- Control functions for graphics (DistancetoPrimitive and Paint)
3. Using the generated Makefiles
The following makefiles are generated:
- Makefile.aix for AIX with the xlC compiler
- Makefile.alpha for Dec/Alpha with the CXX compiler
- Makefile.hpux for hp-ux10.20 with the CC compiler
- Makefile.hpuxacc for hpux10.20 withe the aCC compiler
- Makefile.linux for Intel/Linux with g++
- Makefile.sgi for SGI/Irix with the CC compiler
- Makefile.solaris for Sun/Solaris with the CC compiler
- Makefile.win for WindowsNT with VisualC++
- Make-macros common to all systems. This file specifies rules
and dependencies.
When you install gh2root on your system, create a link to the
Makefile corresponding to your system (eg on hpux):
ln -s Makefile.hpux makefile
To compile and generate the libghlib.so library, do:
gmake depend
gmake
gmake groot
4. Examples
We use the Geant3 RZ file from the STAR experiment at RHIC.
gh2root star.geom Star
This generates the STAR classes:

5. Using the generated macros
The generated classes can be tested without any Geant3 input file
using the kine/hits/digits simulator in the macro
fake.C.
In an interactive ROOT session, do:
root > .x fake.C
You can edit this macro to change the number of tracks and hits
per track.
An existing Geant3 Zebra/FZ file containing kinematics, hits and digits
can be automatically converted to a ROOT Tree with the macro
run.C.
root > .x run.C
Edit this macro to specify the right file name (input and output).
Probably, you will have to specify a value for lrecl.
The generated file contains 3 ROOT Trees:
- TK: with the kinematics.
- TH: with the hits.
- TD: with the digits.
You can browse through the generated ROOT file using the macro
browse.C.
The following picture shows the browser pointing to a hit.

You can click in the browser on the hit with the right mouse button
and select the Inspect item. This will open the ROOT inspector
to display the internal structure of this hit as shown in the picture below.

The macro analyze.C
is an example of analysis code, looping on all
generated events and tracks. An histogram is created, filled
with some track parameters and displayed.
6. Viewing Hits
You can now use the standard ROOT utilities to naviguate
inside the event objects. For example, the macro
stardisp.C
produces the following picture:

Acknowledgements
The authors would like to thank Pavel Nevski from the STAR collaboration,
Patrice Lebrun and Claude Charlot from the CMS collaboration for providing
the most recent Geant geometry and hits description files as well as
Geant output files with kinematics and hits.