Introduction to Visualization¶
The Geant4 visualization system was developed in response to a diverse set of requirements:
Quick response to study geometries, trajectories and hits
High-quality output for publications
Flexible camera control to debug complex geometries
Tools to show volume overlap errors in detector geometries
Interactive picking to get more information on visualized objects
No one graphics system is ideal for all of these requirements, and many of the large software frameworks into which Geant4 has been incorporated already have their own visualization systems, so Geant4 visualization was designed around an abstract interface that supports a diverse family of graphics systems. Some of these graphics systems use a graphics library compiled with Geant4, such as OpenGL, Qt, while others involve a separate application, such as HepRApp or DAWN.
Most examples include a vis.mac to perform typical visualization for that example. The macro includes optional code which you can uncomment to activate additional visualization features.
What Can be Visualized¶
Simulation data can be visualized:
Detector components
A hierarchical structure of physical volumes
A piece of physical volume, logical volume, and solid
Particle trajectories and tracking steps
Hits of particles in detector components
Scoring data
Plots
Other user defined objects can be visualized:
Polylines, such as coordinate axes
3D Markers, such as eye guides
Text, descriptive character strings, comments or titles
Scales
Logos
You have a Choice of Visualization Drivers¶
The many graphics systems that Geant4 supports are complementary to each other.
OpenGL
View directly from Geant4
Requires addition of GL libraries that are freely available for all operating systems (and pre-installed on many)
Rendered, photorealistic image with some interactive features
zoom, rotate, translate
Fast response (can usually exploit full potential of graphics hardware)
Print to EPS (vector and pixel graphics)
Qt
View directly from Geant4
Requires addition of Qt and GL libraries that are freely available on most operating systems
Rendered, photorealistic image
Many interactive features
zoom, rotate, translate
Fast response (can usually exploit full potential of graphics hardware)
Expanded printing ability (vector and pixel graphics)
Easy interface to make movies
Open Inventor
View directly from Geant4
Requires addition of Coin3d libraries (freely available for most Linux systems).
Rendered, photorealistic image
Many interactive features
zoom, rotate, translate
click to “see inside” opaque volumes
Fast response (can usually exploit full potential of graphics hardware)
Expanded printing ability: vector graphics (with transparency in PDF) and pixel graphics
Qt3D
View directly from Geant4
Requires addition of Qt libraries that are freely available on most operating systems
Rendered, photorealistic image
Many interactive features
zoom, rotate, translate
Fast response (can usually exploit full potential of graphics hardware)
TSG
View directly from Geant4
Based on the ToolsSG library distributed with Geant4.
Rendered, photorealistic image
Many interactive features
zoom, rotate, translate
Fast response (can usually exploit full potential of graphics hardware)
Can also view plots of histograms, etc., accumulated in your application
Vtk
View directly from Geant4
Requires installation of Vtk (vtk.org)
Rendered, photorealistic image
Many interactive features
zoom, rotate, translate
Fast response (can usually exploit full potential of graphics hardware)
HepRepFile
Create a file to view in a HepRep browser such as HepRApp or FRED
Requires a HepRep browser (above options work on any operating system)
Wireframe or simple area fills (not photorealistic)
Many interactive features
zoom, rotate, translate
click to show attributes (momentum, etc.)
special projections (FishEye, etc.)
control visibility from hierarchical (tree) view of data
Hierarchical view of the geometry
Export to many vector graphic formats (PostScript, PDF, etc.)
DAWN
Create a file to view in the DAWN Renderer
Requires DAWN, available for all Linux and Windows systems
Rendered, photorealistic image
No interactive features
Highest quality technical rendering - output to vector PostScript
VRML
Create a file with VRML2FILE to view in any VRML browser (many different choices for different browsers and operating systems).
Rendered, photorealistic image with some interactive features
zoom, rotate, translate
Limited printing ability (pixel graphics, not vector graphics)
RayTracer
Create a jpeg file
Forms image by using Geant4‘s own tracking to follow photons through the detector
Can show geometry but not trajectories
Can render any geometry that Geant4 can handle (such as Boolean solids)
Supports shadows, transparency and mirrored surfaces
gMocren
Create a gMocren file suitable for viewing in the gMocren volume data visualization application
Represents three dimensional volume data such as radiation therapy dose
Can also include geometry and trajectory information
ASCIITree
Text dump of the geometry hierarchy
Not graphical
Control over level of detail to be dumped
Can calculate mass and volume of any hierarchy of volumes
Choose the Driver that Meets Your Needs¶
If you want very responsive photorealistic graphics (and have the OpenGL libraries installed)
OpenGL is a good solution (if you have the Motif extensions, this also gives GUI control)
If you want to have the User Interface and all Visualization windows in the same window
Only Qt can do that
If you want very responsive photorealistic graphics plus more interactivity (and have the OpenInventor or Qt libraries installed)
OpenInventor with or without Qt are good solutions
Qt3D, TSG and Vtk are also candidates
If you want GUI control, very responsive photorealistic graphics plus more interactivity (and have the Qt libraries installed).
Qt is a good solution
If you want GUI control, want to be able to pick on items to inquire about them (identity, momentum, etc.), perhaps want to render to vector formats, and a wireframe look will do
HepRepFile will meet your needs
If you want to render highest quality photorealistic images for use in a poster or a technical design report, and you can live without quick rotate and zoom
DAWN is the way to go
If you want to render to a 3D format that others can view in a variety of commodity browsers (including some web browser plug-ins)
VRML is the way to go
If you want to visualize a geometry that the other visualization drivers can’t handle, or you need transparency or mirrors, and you don’t need to visualize trajectories
RayTracer will do it
If you want to visualization volume data, such as radiation therapy dose distributions
gMocren will meet your needs
If you just want to quickly check the geometry hierarchy, or if you want to calculate the volume or mass of any geometry hierarchy
ASCIITree will meet your needs
You can also add your own visualization driver.
Geant4‘s visualization system is modular. By creating just three new classes, you can direct Geant4 information to your own visualization system.
Controlling Visualization¶
Your Geant4 code stays basically the same no matter which driver you use.
Visualization is performed either with commands or from C++ code.
Some visualization drivers work directly from Geant4
OpenGL
Qt
Qt3D
Vtk
TSG
OpenInventor
RayTracer
ASCIITree
For other visualization drivers, you first have Geant4 produce a file, and then you have that file rendered by another application (which may have GUI control)
HepRepFile
DAWN
VRML2FILE
gMocren
Visualization Details¶
The following sections of this guide cover the details of Geant4 visualization:
Adding Visualization to Your Executable
The Visualization Drivers
Controlling Visualization from Commands
Controlling Visualization from Compiled Code
Visualization Attributes
Enhanced Trajectory Drawing
Polylines, Markers and Text
Making a Movie
Other useful references for Geant4 visualization outside of this user guide:
Macro files
vis.mac
distributed in Geant4 source in basic examples.