9.2. Starting the Visualization System
Table of Contents
`/vis/open`
To see your geometry you must first start a visualization driver. In Geant4 this is always done with the macro command /vis/open. You usually type it in an interactive session or put it in a macro file that runs at the beginning of your job.
The general form is:
Rule:
Use /vis/open <driverName> to start a visualization driver.
Only one main viewer can be active at a time.
The <driverName> selects which visualization backend you use. Common interactive drivers are OGL based. Typical examples are:
| Command | Meaning | Notes |
|---|---|---|
/vis/open OGL | Open a basic OpenGL viewer | Simple, suitable for most tutorials |
/vis/open OGLQt | Open an OpenGL viewer inside a Qt window | Needs Geant4 built with Qt support |
/vis/open OGLX | Open an OpenGL viewer using X11 | Linux with X11 only |
/vis/open OGLSX | Open a specialized OpenGL X viewer | Platform dependent |
If you are not sure which drivers are available, you can use the command:
/vis/open ?
Geant4 will list all visualization drivers that were compiled into your installation. On different systems or build options, the list will differ. If you try to open a driver that is not available, Geant4 prints an error and does not create a viewer.
You should create the visualization system only after the run manager has initialized the geometry. A very common sequence of commands in a macro looks like:
/run/initializeto build the geometry and physics./vis/open OGLor another driver.- Visualization commands such as
/vis/drawVolume.
If you call /vis/open before the run is properly initialized, the viewer may open but have no geometry to display, or some features may not be available.
Once the driver is open, it usually creates a main window. For OpenGL Qt, this is a window with toolbars, menus, and a 3D view. For simpler drivers you may see only a drawing window. You can open multiple viewers by calling /vis/open again with another driver, but for beginners it is easier to work with one viewer and one driver until you become familiar with the system.
When you quit your Geant4 application, the visualization windows close automatically. In long sessions, if you want to close a viewer without stopping the application, you can close the window using the window manager controls. The underlying driver remains initialized and you can reopen a viewer with /vis/open again if needed.
`/vis/drawVolume`
Once a visualization driver is open, you still have to tell Geant4 what to draw. The command /vis/drawVolume is the basic way to display your detector geometry in the viewer.
The simple form without arguments,
/vis/drawVolume
tells Geant4 to draw the world volume and everything placed inside it. This is the most common case for beginners and usually what you want when you first check your geometry.
Rule:
Use /vis/drawVolume after /run/initialize and /vis/open to display the geometry hierarchy starting from the world volume.
If the window is empty, verify this order of commands.
If you want to draw a specific volume instead of the whole world, you can give the logical or physical volume name as an argument, for example:
/vis/drawVolume myDetectorLogical
This draws only that volume and its daughters. This is useful for complex setups where the world is large and you want to focus on one detector component. The names you use must be exactly the names you gave to the volumes in your C++ code.
A typical minimal visualization macro used in many examples is:
/run/initialize
/vis/open OGL
/vis/drawVolume
After these commands, the viewer shows your geometry, usually with a default viewpoint and style. If nothing appears, you can force a redraw with commands such as /vis/viewer/refresh or by interacting with the viewer window. In most interactive viewers, rotating or zooming triggers a refresh automatically.
The /vis/drawVolume command works together with other visualization commands that you will see later, such as changing colors or switching between wireframe and solid rendering. You can call /vis/drawVolume again after you modify the geometry or visualization attributes to update the display.
For debugging geometry, it is common to first draw the world with /vis/drawVolume, then zoom in to regions of interest and, if necessary, redraw only a particular volume by name. This makes it easier to inspect overlaps or incorrect placements without clutter from the full detector.
Views: 7
KAHIBARO