Export image in batch mode

Dear Geant4 experts,

I am a student new to Geant4, I developed a stand-alone application (C++ with Qt5) that needs to run a Geant4 simulation showing the results.

The application starts an external process (QProcess) that is a Geant4 application very similar to the example “testEm7” passing a properly prepared macro in batch mode. When the simulation is completed, my program parses the output of the Geant4 application that is on disk. (The .root file)

It works nicely, but I need to include some kind of visualization of the Geant4 geometry and particle tracks and I cannot find a way to export an image from Geant4 when running in batch mode, since there is not an OpenGL viewer on the screen… The error message is the following:

ERROR: G4VisCommandSceneHandlerCreate::SetNewValue: "OGLSQt" is not compatible with your chosen session, and no fallback system found.
Candidates are: ATree DAWNFILE HepRepFile HepRepXML OGL OGLI OGLIQt OGLS OGLSQt RayTracer VRML1FILE VRML2FILE gMocrenFile
***** Illegal parameter (1) </vis/open OGL 600x600-0+0> *****

Please note that if I run the simulation interactively with the Geant4 GUI (Qt-based) everything works fine and I can export png images using /vis/ogl/export.

Is there a simple way to write an image of the simulation on disk when running Geant4 in batch mode?

I know that I can, for example, export a DAWN file and then convert it to an image in a second step, but this process cannot be “automated” using calls to scripts or C++ code, so I cannot display the image in my C++ application.

I thank you very much in advance for your help.
Best Regards,
Valerio Pagliarino

Hi Valerio

The only driver that can produce an image file that can be viewed without a browser is RayTracer. It produces a jpg file. It cannot render trajectories.

As you point out, there are ways of producing files, e.g., DAWNFILE, VRMLFILE, HepRepFile, that can be viewed with appropriate browsers. I think there might be ways to “automate” the process - have a look at the manual for DAWNFILE and DAWN - I’ll dig out the links if you can’t find them, but have to go right now.

We are aware of this requirement and are working on an “off-screen” driver for the next release.


1 Like

Thank you very much, I will look at the DAWN documentation.
Best regards,


in the following lines is reported a partial solution, as @allison said, the conversion process from DAWNFILE to image (.eps) is quite simple to automate. In my first post I was wrong when thinking the opposite, because I did not know that DAWN can work non-interactively from terminal.
I configured the Geant4 macro to create a .prim (DAWN) file:

/vis/open DAWNFILE 
/vis/viewer/zoom 3.4
/vis/scene/add/trajectories smooth
/vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true
/vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 1
/vis/scene/endOfEventAction accumulate
#other lines...
/run/beamOn 10000

then I ran

/usr/local/bin/dawn -d /path/to/the/output/g4_0000.prim

and in the same directory of g4_0000.prim, a file called g4_0000.eps appeared. A this point it was quite simple opening the .eps in my stand-alone Qt application using ImageMagick to convert the vector to png.

To get this process working, I had to download DAWN 3.91a source from here and then run ./configure, make and make install.

Best regards,

Valerio Pagliarino

OK. Great! Thank you for that feedback. :+1: