How to Make Environments for
Geant4 Visualization

October 19, 2000 (version 10)
October 13, 2000 (version 09)
June 03, 2000 (version 08)
May 31, 2000 (version 07)
May 10, 2000 (version 06)
January 26, 2000 (version 05)
November 02,1999 (version 04)
September 30,1999 (version 03)
September 07,1999 (version 02)
September 02,1999 (version 01)
August 31, 1999 (version 00)

Satoshi Tanaka (Fukui University)

@

1. Introduction

This document describes how to make environments for Geant4 visualization on Linux with the following setup: (1) CLHEP library version 1.5, STL library, and Mesa-3.X are used for compiling Geant4 libraries and executables. (2) The DAWNFILE, OpenGL-Xlib and VRMLFILE drivers are used for Geant4 visualization. The description below is checked with RedHat Linux 6.2, and expected to be valid for many other Linux (and Unix) platforms.

How to obtain (and install) graphics packages Mesa (a free OpenGL), DAWN (a PostScript processor), OPACS (a graphics library for HEP), Hepvis (a graphics library for HEP), SoFree (a free OpenInventor), LessTif (a free Motif), and VRMLview (a VRML 1.0/2.0 viewer), which are available for Geant4 Visualization, is also described below. See also the following link page:
http://geant4.kek.jp/~tanaka/GEANT4/g4_vis_gui_linkpage.html

Note: For the above-mentioned setup (1) and (2), you only need to install Mesa and DAWN.
(Also VRMLview if you want to perform on-line visualization with the VRMLFILE driver.)

2. Required C++ compiler

In order to compile Geant4 and CLHEP 1.5, you need the g++ compiler version 1.1 or after. Linux packages based on RedHat 6.X include the right one. If you are using another package of Linux or an older version of RedHat Linux, you may have to update the g++ compiler. You may also have to update related libraries. You can know a version of the g++ compiler with the command "g++ -v". For more details, see the Web page of Naruto University of Education:
http://erpc1.naruto-u.ac.jp/~geant4 .
The STL library is included in the g++ compiler version 1.X.

In compiling Geant4 with g++ on Linux, the environmental variable G4SYSTEM
should be set to "Linux-g++".

@

3. Installation of CLHEP 1.5

You should obtain the CLHEP 1.5 source codes first. Detailed information on CLHEP is described at http://wwwinfo.cern.ch/asd/lhc++/clhep/index.html .

The installation of CLHEP is very easy:

% gtar xvzf clhep-1.5.0.0.tar.gz
% cd ./CLHEP
% autoconf
% ./configure
% gmake
% su
# gmake install
# cd /usr/local/lib
# ln -s libCLHEP-g++.a libCLHEP.a

In this default way of installation, CLHEP 1.5 is installed under "/usr/local/",
i.e. "/usr/local/lib/" and "/usr/local/include/CLHEP/".
In this case the environmental variable CLHEP_BASE_DIR should be set to
"/usr/local" .

@

4. Installation of Mesa (a free OpenGL)

You need Mesa (a free OpenGL) to use the OpenGL visualization drivers.
(WARNING: Do not use Mesa 3.1 with the OpenGL visualization driver.)

You can obtain source codes of Mesa-3.2 from the following Web site: http://www.mesa3d.org .
The installation is quite easy. If you want to install Mesa-3.2 under, for example, "/usr/local/Mesa-3.2/", do the following:

% gtar xvzf MesaLib-3.2.tar.gz
% cd Mesa-3.2
% ./configure --prefix=/usr/local/Mesa-3.2
% gmake
% gmake strip
% su
# gmake install

For more details, read Mesa-3.2/docs/INSTALL.

IF you install Mesa under "/usr/local/Mesa-3.2", set the environmental variable
OGLHOME to "/usr/local/Mesa-3.2" in order to use the Geant4 OpenGL driver.

If you have the RPM package of Mesa, you can install it easily as follows:

% su
# rpm -i Mesa-devel-3.2-X.i386.rpm


NOTE
: In RedHatLinux 6.2, Mesa 3.2 is already installed under "/usr/X11R6/lib"
and "/usr/X11R6/include". In this case the environmental variable OGLHOME should
be set to "/usr/X11R6" in order to use the Geant4 OpenGL driver.
You can confirm if Mesa is already installed as follows:
% rpm -q Mesa

5. Installation of Fukui Renderer DAWN
(a technical-high-quality PostScript processor)

You need Fukui Renderer DAWN (a technical-high-quality PostScript processor) to use the Geant4 DAWNFILE visualization driver. You can obtain source codes of DAWN from the following Web site: http://geant4.kek.jp/~tanaka . The installation is quite easy. Do as follows:

(Case 1) In case you want to use OpenGL mode of DAWN:
% gtar xvzf dawn_VERSION.tar.gz
% cd dawn_VERSION
% gmake clean
% gmake guiclean
% configure
(* Answer all questions properly.)
% gmake
% su
# gmake install

(Case 2) In case you do NOT want to use OpenGL mode of DAWN,
and only want to use X-Window and PostScript-file-generation modes:
% gtar xvzf dawn_VERSION.tar.gz
% cd dawn_VERSION
% gmake clean
% gmake guiclean
% configure_xwin
(* Answer all questions properly.)
% gmake
% su
# gmake install

In both of the cases, the final step "gmake install" installs DAWN to the directory specified in running the configure script.

Note: Tcl/Tk, Ghostscript, and gv, which are required to execute DAWN,
are included in all major Linux packages.

6. Installation of LessTif (a free Motif)

Installation of LessTif (a free Motif) is not mandatory for the setup (1),(2) mentioned in "1.Introduction". But you need it if you want to use the OpenGL-X-Motif visualization driver. For details on LessTif, see the following Web page: http://www.lesstif.org .

7. Installation of OPACS (a graphics library for HEP)

Installation of OPACS (a graphics library for HEP) is not mandatory for the setup (1),(2) mentioned in "1.Introduction". But you need it if you want to use the OPACS visualization driver. For details on OPACS, see the following Web page: http://www.lal.in2p3.fr/OPACS

8. Installation of Hepvis (a graphics library for HEP) and SoFree (a free OpenInventor)

Installation of Hepvis (a graphics library for HEP) and SoFree (a free OpenInventor) is not mandatory for the setup (1),(2) mentioned in "1.Introduction". But you need them if you want to use the OpenInventor visualization driver. For details on Hepvis and SoFree, see the following Web pages:
http://cactus.phyast.pitt.edu/~joe/hepvis/hepvis.html
http://www.lal.in2p3.fr/Inventor

9. Installation of VRMLview (a VRML 1.0/2.0 viewer)

Installation of VRMLview, a VRML 1.0/2.0 viewer is not mandatory for the setup (1),(2) mentioned in "1.Introduction". But you need it if you want to visualize the VRML 1.0/2.0 files generated with Geant4 VRMLFILE visualization driver. The Linux binary of VRMLview is obtainable at the following place: http://www.sim.no/downloads.html .

Note that shared libraries of Mesa 3.0/3.2 should be installed beforehand in order to execute the distributed VRMLview binary.  You may also have to set the environmental variable LD_LIBRARY_PATH, e.g.,
 % setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/usr/X11R6/lib

The menu gViewh in the VRMLview menu bar enables you to customize various visualization attributes interactively.  For example, Wireframe: on/off of edges, Filled: on/off of surfaces, Vertices: on/off of polygon vertices, Normals: on/off of surface normals.  You can skip visualization of detector geometry by making all the aboves goffh, such that only trajectories are visualized. 

10a. Setting environmental variables (1)

In order to compile Geant4 for visualization, you have to set several environmental variables beforehand. (Equivalently, you can also edit macros of GNUmakefile's in the directory "geant4/config/".).

Adding the following to your ".cshrc" allows you to perform Geant4 visualization with the DAWNFILE, OpenGL, and VRMLFILE drivers:
(You may have to do some customization for your own environment, of course.)

#####################################################
# Sample .cshrc for Geant4 visualization on Linux
#####################################################

###### 1. General setting
setenv G4SYSTEM Linux-g++
#setenv G4SYSTEM SUN-CC
setenv CLHEP_BASE_DIR /usr/local

###### 2. UI

############ 2-1. Selection of (G)UI in installation of libraries
setenv G4UI_BUILD_TERMINAL_SESSION 1
#setenv G4UI_BUILD_GAG_SESSION 1

############ 2-2. Selection of (G)UI in compiling executables
setenv G4UI_USE_TERMINAL 1
#setenv G4UI_USE_GAG 1

###### 3. Visualization

############ 3-1. Home directory of Mesa
setenv OGLHOME /usr/X11R6

############ 3-2. Selection of visualization drivers
# in installation of libraries
setenv G4VIS_BUILD_DAWNFILE_DRIVER 1
setenv G4VIS_BUILD_OPENGLX_DRIVER 1
setenv G4VIS_BUILD_VRMLFILE_DRIVER 1
# setenv G4VIS_BUILD_DAWN_DRIVER 1
# setenv G4VIS_BUILD_OPACS_DRIVER 1
# setenv G4VIS_BUILD_OPENGLXM_DRIVER 1
# setenv G4VIS_BUILD_OPENINVENTOR_DRIVER 1
# setenv G4VIS_BUILD_RAYTRACER_DRIVER 1
# setenv G4VIS_BUILD_VRML_DRIVER 1

############ 3-3. Selection of visualization drivers
# in compiling executables
setenv G4VIS_USE_DAWNFILE 1
setenv G4VIS_USE_OPENGLX 1
setenv G4VIS_USE_VRMLFILE 1
# setenv G4VIS_USE_DAWN 1
# setenv G4VIS_USE_OPACS 1
# setenv G4VIS_USE_OPENGLXM 1
# setenv G4VIS_USE_OPENINVENTOR 1
# setenv G4VIS_USE_RAYTRACER 1
# setenv G4VIS_USE_VRML 1

####################################### END

10b. Setting environmental variables (2)

The followings are templates for customizing the Geant4 DAWNFILE visualization driver.

Note: As for environmental variables to customize Fukui Renderer DAWN, see
the following page:
http://geant4.kek.jp/~tanaka/DAWN/DAWN_ENV.html

############################################################
# Customization of the Geant4 DAWNFILE visualization driver
############################################################

###### 4. Customization of the DAWNFILE driver and renderer DAWN
# Note: For renderer DAWN, "dawn -H" displays all available
# environmental variables.

############ 4.1 On-line use of DAVID (a volume-overlapping debugger)
#
# setenv G4DAWNFILE_VIEWER david

############ 4.2 PostScript file generation with of renderer DAWN
#                using its batch mode
#
# 1: batch mode
# a: batch-append mode (multi-page g4.eps file)
#
# setenv DAWN_BATCH a

############ 4.3 Selection of a PostScript viewer
#
# Note: In some Linux platforms the PostScript viewer "gv" visualizes
#       PostScript files with "anti-aliases" effects.
#       In this case, the figures may look too bright.
#       You can switch off the anti-aliases effects with -noantialias
#       option of gv. You can write a simple shell script with one-line
#       command, e.g, ggv -noantialias $1h. Below we assume that the script
#       is described in a file named ggvnaah.
#
# Selection of a PostScript viewer in on-line Geant4 visualization
# (The default is "gv").
#
# setenv G4DAWNFILE_PS_VIEWER gvnaa
#
# Selection of a PostScript viewer in off-line visualization of
# a generated DAWN-format file "g4_XXX.prim".
#
# setenv DAWN_PS_PREVIEWER gvnaa
#

############ 4.4 Making the multiple X-window mode default
# 0: PostScript file generation mode(default)
# 1: multiple X-windows mode
#
# setenv G4DAWNFILE_MULTI_WINDOW 1

############ 4.5 Output directory of "g4_XX.prim" and
# "g4_XX.eps" files
# Note 1: The default is the current directory.
# Note 2: Do not forget to append "/" at the end.
#
# setenv G4DAWNFILE_DEST_DIR /home/username/tmp/

############ 4.6 Automatic increment of output file names
# USAGE: setenv G4DAWNFILE_MAX_FILE_NUM n
# (n: a positive integer)
# DAWN-format files: g4_00.prim, g4_01.prim, g4_02.prim,
# c, g4_(n-1).prim
# EPS files : g4_00.eps , g4_01.eps , g4_02.eps,
# c, g4_(n-1).eps
# Note: The default value of n is 100.
#
# setenv G4DAWNFILE_MAX_FILE_NUM 100

####################################### END

10c. Setting environmental variables (3)

The followings are templates for customizing the Geant4 VRMLFILE visualization driver.

###### 5. Customization of the VRMLFILE driver

############ 5.1 Selection of a VRML viewer
# The default value is "NONE", which means only generation of
# VRML files.
#
# setenv G4VRMLFILE_VIEWER vrmlview

############ 5.2 Output directory of "g4_XX.wrl"
# Note 1: The default is the current directory.
# Note 2: Do not forget to append "/" at the end.
#
# setenv G4VRMLFILE_DEST_DIR /home/username/tmp/

############ 5.3 Automatic increment of output file names
# USAGE: setenv G4VRMLFILE_MAX_FILE_NUM n
# (n: a positive integer)
#
# Generated VRML files: g4.wrl, g4_1.wrl, g4_2.wrl,
# c, g4_(n-1).wrl
#
# The default value of n is 1, which means the file name
# is fixed to gg4.wrlh.
#
# setenv G4VRMLFILE_MAX_FILE_NUM  1

####################################### END

11. Installation, compilation, and execution of Geant4

You can install Geant4 libraries, compile the official example placed under geant4/examples/novice/N03, and perform Geant4 visualization as follows:

Installation of Geant4 libraries:
% cd geant4/source
% gmake

Compilation of the official example:
% cd geant4/examples/novice/N03
% gmake

Execution of Geant4 visualization:
(Edit "prerunN03.mac" beforehand to choose a default visualization driver, if necessary.)
% ../../../bin/Linux-g++/exampleN03
Idle> /control/execute exN03Vis0.mac

Sample macros for visualization:
Macro files exN03VisX.mac (X = 0,1,2,c) are sample macro files for Geant4 visualization. Most of frequently-used visualization commands are described there. Please read and try to execute them. You can execute each macro file as follows:

% ../../../bin/Linux-g++/exampleN03
Idle> /control/execute exN03VisX.mac

----------------------- End of document ----------------------------