It is possible to write a Geant4 geometry with the VRML2 visualisation driver and view the resulting file with Paraview. The result allows visualisation of the complete scene, but it is a bit of a mess. The user has no control over individual elements and the outer “World” box is problematic.
By using “/vis/drawVolume Part1”, where Part1 is a physical volume of the detector being described, a VRML file will be produced containing only Part1. By producing multiple files, one for each physical volume, and displaying them simultaneously in Paraview, the previous limitations are avoided. This macro automates the procedure and renames the files produced.
# vrml output
/control/shell rm *.wrl
#
/vis/open VRML2FILE
/vis/viewer/reset
/vis/drawVolume Part1
/vis/viewer/flush
/control/shell mv g4_00.wrl Part1.wrl
#
/vis/open VRML2FILE
/vis/viewer/reset
/vis/drawVolume Part2
/vis/viewer/flush
/control/shell mv g4_00.wrl Part2.wrl
#
# etc. for all constituent parts of the detector, excluding World.
# Part1, Part2... need replacing with names from your own system
These VRML files can be read in by Paraview. The easiest way to do this is to drag and drop them onto the Pipeline Browser. For some reason this must be done one file at a time. After that, the result is rather good. By clicking on the eyeball next to the file, the specific physical volume can be added to the overall 3D scene or removed again. By selecting Properties, the colours of the individual physical volumes can be changed, as can their transparency. The scene can be viewed from any angle, rotation or zoom and the resulting 2D graphic exported in a wide range of formats.
Visualisation of tracks using the same approach is possible. No method could be found of adding trajectories before /vis/drawVolume was called, which adds a World box which screens the tracks. A solution was found by deleting the unwanted box using sed. It’s a bit ugly, but it works.
/vis/open VRML2FILE
/vis/viewer/reset
/vis/drawVolume
/vis/scene/add/trajectories
/vis/scene/endOfEventAction accumulate
/run/beamOn 50
/control/shell mv g4_00.wrl Tracks.wrl
/control/shell sed -i '/SOLID/,/POLYLINE/d' Tracks.wrl
The above macros were developed with Geant4.10.07 on Xubuntu and will probably run on most Linux and MacOS. Windows users can expect to have to make major modifications. The macros are admittedly somewhat makeshift, requiring hand editing for each particular case. Perhaps somebody might like to write a more general version using parameters.