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

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

The macros above typically invoke service functions from the XGRun class to:

3. Using the generated Makefiles

The following makefiles are generated:

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:

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.