This tutorial can be used on its own, but gives the most comprehensive introduction to Geant4 visualization when used as part of the following full set of documents:
While some Geant4 visualization drivers are always included by default in your Geant4 build (because they require no external libraries), OpenGL is not part of the default set. You have to specifically ask to include OpenGL.
If you followed the Geant4 Installation Guides referenced above, you used the Geant4 Configuration script and said "yes" to including OpenGL.
If you are following some other set of build instructions, refer to them for how to include OpenGL. This may involve explicitly setting environment variables.
The Installation Guides listed above already showed you how to start Geant4 with OpenGL included. They then showed you how to use a few simple commands to do the most minimal visualization of some detector geometry and some event data. This guide will show you some additional commands.
/vis/open OGLAn empty graphics windows should appear
/vis/drawVolumeThe graphics window should redraw to show the detector geometry:
/vis/viewer/set/viewpointThetaPhi 70 20
/vis/viewer/zoom 2
/vis/viewer/reset
Command directory path : / Sub-directories : 1) /control/ UI control commands. 2) /units/ Available units. 3) /geometry/ Geometry control commands. 4) /tracking/ TrackingManager and SteppingManager control commands. 5) /event/ EventManager control commands. 6) /run/ Run control commands. 7) /random/ Random number status control commands. 8) /particle/ Particle control commands. 9) /process/ Process Table control commands. 10) /vis/ Visualization commands. 11) /mydet/ A01 detector setup control commands. 12) /hits/ Sensitive detectors and Hits 13) /gun/ Particle Gun control commands. Commands : Type the number ( 0:end, -n:n level back ) :
Guidance : Operations on Geant4 viewers. Sub-directories : 1) /vis/viewer/set/ Set view parameters of current viewer. Commands : 2) clear * /vis/viewer/clear [] 3) create * /vis/viewer/create [ ] [ ] [ ] 4) dolly * /vis/viewer/dolly [ ] [ ] 5) dollyTo * /vis/viewer/dollyTo [ ] [ ] 6) flush * /vis/viewer/flush [ ] 7) lightsThetaPhi * /vis/viewer/lightsThetaPhi [ ] [ ] [deg|rad] 8) lightsVector * /vis/viewer/lightsVector [ ] [ ] [ ] 9) list * /vis/viewer/list [ ] [ ] 10) pan * /vis/viewer/pan [ ] [ ] [ ] 11) panTo * /vis/viewer/panTo [ ] [ ] [ ] 12) refresh * /vis/viewer/refresh [ ] 13) remove * /vis/viewer/remove 14) reset * /vis/viewer/reset [ ] 15) select * /vis/viewer/select 16) update * /vis/viewer/update [ ] 17) show * Synonym for "/vis/viewer/update" - see that command for guidance. 18) viewpointThetaPhi * /vis/viewer/viewpointThetaPhi [ ] [ ] [deg|r ad] 19) viewpointVector * /vis/viewer/viewpointVector [ ] [ ] [ ] 20) zoom * /vis/viewer/zoom [ ] 21) zoomTo * /vis/viewer/zoomTo [ ]
/vis/viewer/set/viewpointThetaPhi 40 40
/vis/viewer/panTo -5 -1 /vis/viewer/zoom 4.
/vis/scene/add/trajectories /vis/scene/add/hits
/run/beamOn 1
/vis/viewer/set/style surface /run/beamOn 1The detector will then appear as a solid (though it is somewhat transparent, allowing you to still seee the tracks passing within).
/vis/viewer/set/style wireframe /run/beamOn 1Notice that the style command does not affect the hits. They are always drawn as surfaces because of code in the relevant c++ classes (which override any style commands issued at run time):
src/A01EmCalorimeterHit.cc: attribs.SetForceSolid(true); src/A01HadCalorimeterHit.cc: attribs.SetForceSolid(true); src/A01HodoscopeHit.cc: attribs.SetForceSolid(true);
By default, hidden line removal is disabled:
/vis/viewer/set/hiddenEdge 1This hides edges of geometry, but lets trajectories through:
/vis/viewer/set/hiddenMarker 1
/vis/viewer/reset
/vis/open OGL /vis/drawVolume /vis/viewer/set/viewpointThetaPhi 70 20 /vis/viewer/zoom 2 /vis/viewer/reset /vis/viewer/set/viewpointThetaPhi 40 40 /vis/viewer/panTo -5 -1 /vis/viewer/zoom 4. /vis/scene/add/trajectories /vis/scene/add/hits /run/beamOn 1 /vis/viewer/set/style surface /run/beamOn 1 /vis/viewer/set/style wireframe /run/beamOn 1
Other Resources: