Contents Previous Next Geant4 User's Guide
For Application Developers
Visualization
8.3 The Visualization Drivers



As explained in the Introduction to Visualization, Geant4 provides many different choices of visualization systems. Features and notes on each driver are briefly described here along with links to detailed web pages for the various drivers.

Details are given below for:

8.3.1 Availability of drivers on the supported systems

Table 8.3.1 lists required graphics systems and supported platforms for the various visualization drivers

DriverRequired Graphics SystemPlatform
OpenGL-XlibOpenGLLinux, Unix, Mac with Xlib
OpenGL-MotifOpenGLLinux, UNIX, Mac with Motif
OpenGL-Win32OpenGLWindows
OpenInventor-XOpenInventor, OpenGLLinux, UNIX, Mac with Xlib or Motif
OpenInventor-Win32OpenInventor, OpenGLWindows
HepRepWIRED or FRED HepRep BrowserLinux, UNIX, Mac, Windows
DAWNFILE Fukui Renderer DAWNLinux, Unix, Mac, Windows
DAWN-NetworkFukui Renderer DAWNLinux, UNIX
VRMLFILEany VRML viewerLinux, UNIX, Mac, Windows
VRML-Networkany network-enabled VRML viewerLinux, UNIX
RayTracerany JPEG viewerLinux, UNIX, Mac, Windows
ASCIITreenoneLinux, UNIX, Mac, Windows
GAGTreeGAGLinux, UNIX, Mac, Windows
XMLTreeany XML viewerLinux, UNIX, Mac, Windows

8.3.2 OpenGL

These drivers have been developed by John Allison and Andrew Walkden (University of Manchester). It is an interface to the de facto standard 3D graphics library, OpenGL. It is well suited for real-time fast visualization and demonstration. Fast visualization is realized with hardware acceleration, reuse of shapes stored in a display list, etc. NURBS visualization is also supported.

Several versions of the OpenGL drivers are prepared. Versions for Xlib, Motif and Win32 platforms are available by default. For each version, there are two modes: immediate mode and stored mode. The former has no limitation on data size, and the latter is fast for visualizing large data repetitively, and so is suitable for animation.

If you don't have Motif, all control is done from Geant4 commands:

     /vis/open OGLIX
     /vis/viewer/set/viewpointThetaPhi 70 20
     /vis/viewer/zoom 2
     etc.
But if you have Motif libraries, you can control Geant4 from Motif widgets:
     /vis/open OGLIXm

The OpenGL driver added Smooth shading and Transparency since Geant4 release 8.0.

Further information (OpenGL and Mesa):

8.3.3 OpenInventor

These drivers were developed by Jeff Kallenbach (FNAL) and Guy Barrand (IN2P3) based on the Hepvis class library originated by Joe Boudreau (Pittsburgh University). The OpenInventor drivers and the Hepvis class library are based on the well-established OpenInventor technology for scientific visualization. They have high extendibility. They support high interactivity, e.g., attribute e diting of picked objects. Some OpenInventor viewers support "stereoscopic" effects.

It is also possible to save a visualized 3D scene as an OpenInventor-formatted file, and re-visualize the scene afterwards.

Because it is connected directly to the Geant4 kernel, using same language as that kernel (C++), OpenInventor systems can have direct access to Geant4 data (geometry, trajectories, etc.).

Because OpenInventor uses OpenGL for rendering, it supports lighting and transparency.

OpenInventor provides thumbwheel control to rotate and zoom.

OpenInventor supports picking to ask about data. [Control Clicking] on a volume turns on rendering of that volume's daughters. [Shift Clicking] a daughter turns that rendering off: If modeling opaque solid, effect is like opening a box to look inside.

Further information (HEPVis and OpenScientist):

Further information (OpenInventor):

8.3.4 HepRepFile

The HepRepFile driver creates a HepRep XML file in the HepRep1 format suitable for viewing with the WIRED3 HepRep Browser.

The HepRep graphics format is further described at http://www.slac.stanford.edu/~perl/heprep.

To write just the detector geometry to this file, use the command:

     /vis/viewer/flush

Or, to also include trajectories and hits (after the appropriate /vis/viewer/add/trajectories or /vis/viewer/add/hits commands), just issue:

     /run/beamOn 1

HepRepFile will write a file called G4Data0.heprep to the current directory. Each subsequent file will have a file name like G4Data1.heprep, G4Data2.heprep, etc.

View the file using the WIRED3 HepRep Browser, available from: http://www.slac.stanford.edu/BFROOT/www/Computing/Graphics/Wired/.

WIRED3 allows you to pick on volumes, trajectories and hits to find out their associated HepRep Attributes, such as volume name, particle ID, momentum, etc. These same attributes can be displayed as labels on the relevant objects, and you can make visibility cuts based on these attributes ("show me only the photons", or "omit any volumes made of iron").

WIRED3 can read heprep files in zipped format as well as unzipped, so you can save space by applying gzip to the heprep file. This will reduce the file to about five percent of its original size.

Several environment variables are available to override some of HepRepFile's defaults

Further information:

8.3.5 HepRepXML

The HepRepXML driver creates a HepRep file in the HepRep2 format suitable for viewing with the WIRED4 Plugin to the JAS3 Analysis System or the FRED event display.

This driver can write both Binary HepRep (.bheprep) and XML HepRep (.heprep) files. Binary HepRep files are a one-to-one translation of XML HepRep files, but they are considerably shorter and faster to parse by a HepRepViewer such as WIRED 4.

Both Binary HepRep and XML HepRep can be compressed using the standard zlib library if linked into Geant4 using G4LIB_USE_ZLIB. If a standard zlib is not available (WIN32-VC for instance) you should also set G4LIB_BUILD_ZLIB to build G4zlib included with Geant4.

HepRep files (Binary and XML) can contain multiple HepRep events/geometries. If the file contains more than one HepRep it is not strictly XML anymore. Files can be written in .heprep.zip, .heprep.gz or .heprep format and their binary versions .bheprep.zip, .bheprep.gz or .bheprep.

The .heprep.zip is the default for file output, the .heprep is the default for stdout and stderr.

(Optional) To set the filename with a particular extension such as: .heprep.zip, .heprep.gz, .heprep, .bheprep.zip, .bheprep.gz or .bheprep use for instance:

     /vis/scene/create filename.bheprep.zip

(Optional) To create separate files for each event, you can set a suffix such as "-0001" to start writing files from filename-0001.bheprep.zip to filename-9999.bheprep.zip (or up), while "-55-sub" will start write files filename-55-sub.bheprep.zip to filename-99-sub.bheprep.zip (or up).

     /vis/heprep/setEventNumberSuffix -0001
(Note: suffix has to contain at least one digit)

(Optional) To route the HepRep XML output to stdout (or stderr), by default uncompressed, use:

     /vis/scene/create stdout

(Optional) To add attributes to each point on a trajectory, use:

     /vis/heprep/addPointAttributes 1

Be aware that this may increase the size of the output dramatically.

(Optional) You may use the commands:

     /vis/viewer/zoom                            to set an initial zoom factor
     /vis/viewer/set/viewpointThetaPhi           to set an initial view point
     /vis/heprep/setCoordinateSystem uvw         to change the coordinate system, where uvw can be "xyz", "zxy", ...

(Optional) You may decide to write .zip files with events and geometry separated (but linked). This results in a smaller zip file, as the geometry is only written once. Use the command:

     /vis/heprep/appendGeometry false

(Optional) To close the file, remove the SceneHandler, use:

     /vis/sceneHandler/remove scene-handler-0

Limitations: Only one SceneHandler can exist at any time, connected to a single Viewer. Since the HepRep format is a model rather than a view this is not a real limitation. In WIRED 4 you can create as many views (SceneHandlers) as you like.

Further information:

8.3.6 DAWN

The DAWN drivers are interfaces to Fukui Renderer DAWN, which has been developed by Satoshi Tanaka, Minato Kawaguti et al (Fukui University). It is a vectorized 3D PostScript processor, and so well suited to prepare technical high quality outputs for presentation and/or documentation. It is also useful for precise debugging of detector geometry. Remote visualization, off-line re-visualization, cut view, and many other useful functions of detector simulation are supported. A DAWN process is automatically invoked as a co-process of Geant4 when visualization is performed, and 3D data are passed with inter-process communication, via a file, or the TCP/IP socket.

When Geant4 Visualization is performed with the DAWN driver, the visualized view is automatically saved to a file named g4.eps in the current directory, which describes a vectorized (Encapsulated) PostScript data of the view.

There are two kinds of DAWN drivers, the DAWNFILE driver and the DAWN-Network driver. The DAWNFILE driver is usually recommended, since it is faster and safer in the sense that it is not affected by network conditions.

The DAWNFILE driver sends 3D data to DAWN via an intermediate file, named g4.prim in the current directory. The file g4.prim can be re-visualized later without the help of Geant4. This is done by invoking DAWN by hand:

     % dawn g4.prim 

DAWN files can also serve as input to two additional programs:

The DAWN-Network driver is almost the same as the DAWNFILE driver except that

If you have not set up network configurations of your host machine, set the environment variable G4DAWN_NAMED_PIPE to "1", e.g., % setenv G4DAWN_NAMED_PIPE 1. This setting switches the default socket connection to the named-pipe connection within the same host machine. The DAWN-Network driver also saves the 3D data to the file g4.prim in the current directory.

Remote Visualization with the DAWN-Network Driver

Visualization in Geant4 is considered to be "remote" when it is performed on a machine other than the Geant4 host. Some of the visualization drivers support this feature.

Usually, the visualization host is your local host, while the Geant4 host is a remote host where you log in, for example, with the telnet command. This enables distributed processing of Geant4 visualization, avoiding the transfer of large amounts of visualization data to your terminal display via the network. This section describes how to perform remote Geant4 visualization with the DAWN-Network driver. In order to do it, you must install the Fukui Renderer DAWN on your local host beforehand.

The following steps realize remote Geant4 visualization viewed by DAWN.

  1. Invoke DAWN with "-G" option on your local host:
           Local_Host> dawn -G
    This invokes DAWN with the network connection mode.

  2. Login to the remote host where a Geant4 executable is placed.

  3. Set an environment variable on the remote host as follows:
           Remote_Host> setenv G4DAWN_HOST_NAME local_host_name
    For example, if you are working in the local host named "arkoop.kek.jp", set this environment variable as follows:
           Remote_Host> setenv G4DAWN_HOST_NAME arkoop.kek.jp
    This tells a Geant4 process running on the remote host where Geant4 Visualization should be performed, i.e., where the visualized views should be displayed.

  4. Invoke a Geant4 process and perform visualization with the DAWN-Network driver. For example:
      
           Idle> /vis/open DAWN
           Idle> /vis/drawVolume 
           Idle> /vis/viewer/flush
          

In step 4, 3D scene data are sent from the remote host to the local host as DAWN-formatted data, and the local DAWN will visualize the data. The transferred data are saved as a file named g4.prim in the current directory of the local host.

Further information:

Further information:

8.3.7 VRML

These drivers were developed by Satoshi Tanaka and Yasuhide Sawada (Fukui University). They generate VRML files, which describe 3D scenes to be visualized with a proper VRML viewer, at either a local or a remote host. It realizes virtual-reality visualization with your WWW browser. There are many excellent VRML viewers, which enable one to perform interactive spinning of detectors, walking and/or flying inside detectors or particle showers, interactive investigation of detailed detector geometry etc.

There are two kinds of VRML drivers: the VRMLFILE driver, and the VRML-Network driver. The VRMLFILE driver is usually recommended, since it is faster and safer in the sense that it is not affected by network conditions.

The VRMLFILE driver sends 3D data to your VRML viewer, which is running on the same host machine as Geant4, via an intermediate file named g4.wrl created in the current directory. This file can be re-visualization afterwards. In visualization, the name of the VRML viewer should be specified by setting the environment variable G4VRML_VIEWER beforehand. For example,

     % setenv G4VRML_VIEWER  "netscape"

Its default value is NONE, which means that no viewer is invoked and only the file g4.wrl is generated.

Remote Visualization with the VRML-Network Driver

Visualization in Geant4 is considered to be "remote" when it is performed on a machine other than the Geant4 host. Some of the visualization drivers support this feature.

Usually, the visualization host is your local host, while the Geant4 host is a remote host where you log in, for example, with the telnet command. This enables distributed processing of Geant4 visualization, avoiding the transfer of large amounts of visualization data to your terminal display via the network.

In order to perform remote visualization with the VRML-Network driver, the following must be installed on your local host beforehand:

  1. a VRML viewer
  2. the Java application g4vrmlview.
The Java application g4vrmlview is included as part of the Geant4 package and is located at:
     source/visualization/VRML/g4vrmlview/
. Installation instructions for g4vrmlview can be found in the README file there, or on the WWW page below.

The following steps realize remote Geant4 visualization displayed with your local VRML browser:

  1. Invoke the g4vrmlview on your local host, giving a VRML viewer name as its argument:
           Local_Host> java g4vrmlview  VRML_viewer_name
    For example, if you want to use the Netscape browser as your VRML viewer, execute g4vrmlview as follows:
           Local_Host> java g4vrmlview  netscape
    Of course, the command path to the VRML viewer should be properly set.

  2. Log in to the remote host where a Geant4 executable is placed.

  3. Set an environment variable on the remote host as follows:
           Remote_Host> setenv G4VRML_HOST_NAME local_host_name
    For example, if you are working on the local host named "arkoop.kek.jp", set this environment variable as follows:
           Remote_Host> setenv G4VRML_HOST_NAME arkoop.kek.jp
    This tells a Geant4 process running on the remote host where Geant4 Visualization should be performed, i.e., where the visualized views should be displayed.

  4. Invoke a Geant4 process and perform visualization with the VRML-Network driver. For example:
           
           Idle> /vis/open VRML2
           Idle> /vis/drawVolume 
           Idle> /vis/viewer/update
           

In step 4, 3D scene data are sent from the remote host to the local host as VRML-formatted data, and the VRML viewer specified in step 3 is invoked by the g4vrmlview process to visualize the VRML data. The transferred VRML data are saved as a file named g4.wrl in the current directory of the local host.

Further information:

Further information (VRML drivers):

Sample VRML files:

Further information (VRML language and browsers):

8.3.8 RayTracer

This driver was developed by Makoto Asai and Minamimoto (Hirosihma Instutute of Technology). It performs ray-tracing visualization using the tracking routines of Geant4. It is, therefore, available for every kinds of shapes/solids which Geant4 can handle. It is also utilized for debugging the user's geometry for the tracking routines of Geant4. It is well suited for photo-realistic high quality output for presentation, and for intuitive debugging of detector geometry. It produces a JPEG file. This driver is by default listed in the available visualization drivers of user's application.

Some pieces of geometries may fail to show up in other visualization drivers (due to algorithms those drivers use to compute visualizable shapes and polygons), but RayTracer can handle any geometry that the Geant4 navigator can handle.

Because RayTracer in essence takes over Geant4's tracking routines for its own use, RayTracer cannot be used to visualize Trajectories or hits.

An X-Window version, called RayTracerX, can be selected by setting G4VIS_BUILD_RATRACERX_DRIVER at Geant4 library build time and G4VIS_USE_RAYTRACERX at application (user code) build time (assuming you use the standard visualization manager, G4VisExecutive, or an equally smart vis manager). RayTracerX builds the same jpeg file as RayTracer, but simultaneously renders to screen so you can watch as rendering grows progressively smoother.

RayTracer has its own built-in commands - /vis/rayTracer/.... Alternatively, you can treat it as a normal vis system and use /vis/viewer/... commands, e.g:

  /vis/open RayTracerX
  /vis/drawVolume
  /vis/viewer/set/viewpointThetaPhi 30 30
  /vis/viewer/refresh
The view parameters are translated into the necessary RayTracer parameters.

RayTracer is compute intensive. If you are unsure of a good viewing angle or zoom factor, you might be advised to choose them with a faster renderer, such as OpenGL, and transfer the view parameters with /vis/viewer/set/all:

  /vis/open OGLSXm  # or any of the OGL options.  Opens, say, viewer-0.
  /vis/drawVolume
  /vis/viewer/zoom  # plus any /vis/viewer/commands that get you the view you want.
  /vis/open RayTracerX
  /vis/viewer/set/all viewer-0
  /vis/viewer/refresh

8.3.9 Visualization of detector geometry tree

ASCIITREE is a visualization driver that is not actually graphical but that dumps the volume hierarchy as a simple text tree.

Each call to /vis/viewer/flush or /vis/drawTree will dump the tree.

ASCIITree has command to control its verbosity, /vis/ASCIITree/verbose. The verbosity value controls the amount of information available, e.g., physical volume name alone, or also logical volume and solid names. If the volume is "sensitive" and/or has a "readout geometry", this may also be indicated. Also, the mass of the physical volume tree(s) can be printed (but beware - higher verbosity levels can be computationally intensive).

At verbosity level 4, ASCIITree calculates the mass of the complete geometry tree taking into account daughters up to the depth specified for each physical volume. The calculation involves subtracting the mass of that part of the mother that is occupied by each daughter and then adding the mass of the daughter, and so on down the hierarchy.

     /vis/ASCIITree/Verbose 4
     /vis/viewer/flush
     "HadCalorimeterPhysical":0 / "HadCalorimeterLogical" / "HadCalorimeterBox"(G4Box), 1.8 m3 , 11.35 g/cm3
     "HadCalColumnPhysical":-1 (10 replicas) / "HadCalColumnLogical" / "HadCalColumnBox"(G4Box), 180000 cm3, 11.35 g/cm3
     "HadCalCellPhysical":-1 (2 replicas) / "HadCalCellLogical" / "HadCalCellBox"(G4Box), 90000 cm3, 11.35 g/cm3
     "HadCalLayerPhysical":-1 (20 replicas) / "HadCalLayerLogical" / "HadCalLayerBox"(G4Box), 4500 cm3, 11.35 g/cm3
     "HadCalScintiPhysical":0 / "HadCalScintiLogical" / "HadCalScintiBox"(G4Box), 900 cm3, 1.032 g/cm3
     
     Calculating mass(es)...
     Overall volume of "worldPhysical":0, is 2400 m3
     Mass of tree to unlimited depth is 22260.5 kg

Some more examples of ASCIITree in action:

     Idle> /vis/ASCIITree/verbose 1
     Idle> /vis/drawTree
     #  Set verbosity with "/vis/ASCIITree/verbose ":
     #    <  10: - does not print daughters of repeated placements, does not repeat replicas.
     #    >= 10: prints all physical volumes.
     #  The level of detail is given by verbosity%10:
     #  for each volume:
     #    >=  0: physical volume name.
     #    >=  1: logical volume name (and names of sensitive detector and readout geometry, if any).
     #    >=  2: solid name and type.
     #    >=  3: volume and density.
     #    >=  5: daughter-subtracted volume and mass.
     #  and in the summary at the end of printing:
     #    >=  4: daughter-included mass of top physical volume(s) in scene to depth specified.
     .....
     "Calorimeter", copy no. 0, belongs to logical volume "Calorimeter"
       "Layer", copy no. -1, belongs to logical volume "Layer" (10 replicas)
         "Absorber", copy no. 0, belongs to logical volume "Absorber"
           "Gap", copy no. 0, belongs to logical volume "Gap"
     .....
     Idle> /vis/ASCIITree/verbose 15
     Idle> /vis/drawTree
     ....
      "tube_phys":0 / "tube_L" / "tube"(G4Tubs), 395841 cm3, 1.782 mg/cm3, 9.6539e-08 mm3, 1.72032e-10 mg
        "divided_tube_phys":0 / "divided_tube_L" / "divided_tube"(G4Tubs), 65973.4 cm3, 1.782 mg/cm3, 7587.54 cm3, 13.521 g 
          "divided_tube_inset_phys":0 / "divided_tube_inset_L" / "divided_tube_inset"(G4Tubs), 58385.9 cm3, 1.782 mg/cm3, 6.03369e-09 mm3, 1.0752e-11 mg
            "sub_divided_tube_phys":0 / "sub_divided_tube_L" / "sub_divided_tube"(G4Tubs), 14596.5 cm3, 1.782 mg/cm3, 12196.5 cm3, 21.7341 g 
     .....
     Calculating mass(es)...
     Overall volume of "expHall_P":0, is 8000 m3  and the daughter-included mass to unlimited depth is 78414 kg
     .....

For the complete list of commands and options, see the Control...UICommands section of this user guide.

8.3.10 GAG Tree

The GAGTree driver provides a listing of the detector geometry tree within GAG, the Geant Adaptive GUI, (http://erpc1.naruto-u.ac.jp/~geant4). GAG allows "folding/un-folding" a part of the geometry tree, using the Tree Widget in Java:

8.3.11 XML Tree

The XML description of the geometry tree can be created in Geant4 by the XML Tree driver. The XML source can also be edited on the fly. The created XML files are visualizable with any XML browser (in Windows, a good XML viewer is XML Notepad).


Next section
Back to contents