A GLAST Geant4 Visualization Howto (Windows based)
In order to clarify the step I've followed to enable visualization
drivers on Geant4 for the beamtest06 package on my windows box I've decided to setup this small
howto page; I hope it can be of some use for GLAST. Please for any
comments and/or requests contact me. Please note that these
instructions are for Geant4 6.2.2;
I expect that some changes will occur for the new 8.0 version (for
example Francesco told me that in the new version you don't need
anymore to register individual drivers, you just setup a visualization
manager and have at your disposal all the possible visualization
output).
Please note also that almost the same thing can be done for our standard G4Generator package;
we just need to register a visualization manager using our customized
RunManager and than pass, with the use of the standard jobOptions file,
to Geant4 some UI macros like the one I show down in the section 3 of
this page. I've not tried it, but it should be trivia. In this way we
could have G4Generator generates HepRep files (or VRML, or DAWN, or
what you want) directly. Consider that the output of Geant4 is quite
different, as volumes hierarchy, from the one we are used in
GlastDetSvc. For example the HepRep file that Geant4 generates contains
only polygons; so any box is splitted in 6 polygons and the
InstanceTree in the generated HepRep file will be quite big (and
different from the HepRep file generated by HepRepSvc).
1. Building the proper Geant4 external library
First of all we need a proper Geant4 library. In our standard
distribution of Geant4 we have left out the visualization modules .. to
reintroduce them on windows I've just got the really useful Geant4build package by Tracy and modified the requirements it in the following way:
- in the include_dirs definition I've added
"$(G4srcdir)/visualization/management/include" \
"$(G4srcdir)/visualization/FukuiRenderer/include" \
"$(G4srcdir)/visualization/HepRep/include" \
"$(G4srcdir)/visualization/HepRep/include/zlib" \
"$(G4srcdir)/visualization/HepRep/include/zipios++" \
"$(G4srcdir)/visualization/HepRep/include/ref" \
"$(G4srcdir)/visualization/HepRep/include/HEPREP" \
"$(G4srcdir)/visualization/RayTracer/include" \
"$(G4srcdir)/visualization/VRML/include" \
"$(G4srcdir)/visualization/Tree/include" \
"$(G4srcdir)/visualization/XXX/include" \
"$(G4srcdir)/visualization/modeling/include"
- I've added the following library in the constituents
library libG4visualization -no_share \
-s=$(G4srcdir)/visualization/modeling $(source) \
-s=$(G4srcdir)/visualization/management $(source) \
-s=$(G4srcdir)/visualization/FukuiRenderer $(source) \
-s=$(G4srcdir)/visualization/HepRep $(source) \
-s=$(G4srcdir)/visualization/RayTracer $(source) \
-s=$(G4srcdir)/visualization/VRML $(source) \
-s=$(G4srcdir)/visualization/Tree $(source) \
-s=$(G4srcdir)/visualization/XXX $(source)
With these changes I've managed to build the Geant4 library with all the standard libraries plus the libG4visualization one .. if you need it I've just put a precompiled version here.
2. Changes to IExternal/Geant4 package
At this point you need to change the IExternal/Geant4 package by adding in the requirements file to the macro_append Geant4_linkopts the new libG4visualization library.
3. Changes to the beam test package
In the end you need some changes to the beamtest06 package. For example, if you want to add the HepRep visualization driver
- Add to the requirements file the flag /D G4VIS_USE to the cpp_flags for the package
- Add to the VisManager.cxx file something like
#include "G4HepRepFile.hh"
#include "G4HepRep.hh"
- Add to the constructor of the VisManager class something like
RegisterGraphicsSystem (new G4HepRep);
At this point you can use a standard Geant4 visualization macro like this one
/vis/open HepRepFile
/vis/viewer/reset
/vis/viewer/set/viewpointThetaPhi 0 0 deg
/vis/viewer/zoom 1.3
/vis/scene/add/axes 0 0 0 50 mm
/vis/scene/endOfEventAction accumulate
/tracking/storeTrajectory 1
/vis/drawVolume
/vis/scene/add/trajectories
to setup the proper generation of an HepRep file that you can than visualize with Wired or FRED.