Trajectories disappear at end of run

I am running Geant4 version 10.7.p01 on Windows 10.
I am trying to view electron trajectories with electrons flying in an electric field. I can see the electron trajectories while the program runs (see screenshots), but when the program reaches the end of the run, the trajectories disappear.
I had tried this before on Linux and I found the trajectories disappeared rapidly, but now they disappear only at the end of the run. The difference could be due to me now running on Windows (as opposed to Linux before) or using the latest release of Geant4.
I had previously solved my problems by simulating electron trajectories in vacuum using COMSOL and in a material using Geant4 and pass the trajectory information between them. This works fine (albeit rather slow) for simple geometries (e.g. a flat plane), but becomes difficult for complex geometries. Hence, my return to trying to see if I can get this to work solely within Geant4.

I find that if I set the electric field to zero, the electron trajectories do not disappear at the end of the run.

Previously, the problems appeared to have something to do with my use of GDML input files. I am back to using the GDML input again as it is needed for the complex geometries.

Any help appreciated.

Output to screen (after all the trajectory information is output to screen) is below.
Run terminated.
Run Summary
Number of events processed : 200
User=1.328000s Real=4.138877s Sys=0.703000s
Energy deposited in detector Sample = 1.7358114275e+05 eV
100 events have been kept for refreshing and/or reviewing.
“/vis/reviewKeptEvents” to review them one by one.
“/vis/enable”, then “/vis/viewer/flush” or “/vis/viewer/rebuild” to see them accumulated.
WARNING: G4VisManager::EndOfRun: Automatic event keeping was suspended.
The number of events in the run exceeded the maximum, 100, that may be
kept by the vis manager.
The number of events kept by the vis manager can be changed with
"/vis/scene/endOfEventAction accumulate ", where N is the
maximum number you wish to allow. N < 0 means “unlimited”.
/detectors/PlaneR/outputCounts results/YieldR_Silicon.dat
Detector counts written to file results/YieldR_Silicon.dat
/detectors/PlaneT/outputCounts results/YieldT_Silicon.dat
Detector counts written to file results/YieldT_Silicon.dat
#/detectors/PlaneR/outputEnergyPDF {directory}/EnergyPDF_{material}{energy}.dat
#/detectors/PlaneR/outputEnergyHistogram {directory}/EnergyHistogram
/detectors/PlaneR/outputHits results/EmissionR_Silicon_1000eV.dat
Detector hits written to file results/EmissionR_Silicon_1000eV.dat
/detectors/PlaneT/outputHits results/EmissionT_Silicon_1000eV.dat
Detector hits written to file results/EmissionT_Silicon_1000eV.dat
/detectors/Sample/outputHits results/EmissionSample_Silicon_1000.dat
Detector hits written to file results/EmissionSample_Silicon_1000.dat
##/detectors/PlaneR/PDFFilename {directory}/PlanePDF
##/detectors/PlaneR/detHistFilename {directory}/Hist
/control/execute init_vis.mac

Macro file for the initialization of example B1

in interactive session

Set some default verbose

/control/verbose 2
/run/verbose 2

Change the default number of threads (in multi-threaded mode)

#/run/numberOfThreads 4

Initialize kernel


Visualization setting

/control/execute vis.mac

Macro file for the visualization setting in the initialization phase

of the B1 example when running in interactive mode

Use these open statements to open selected visualization

Use this open statement to create an OpenGL view:

#/vis/open OGL 600x600-0+0
/vis/open OGLIWin32 600x600-0+0
/vis/sceneHandler/create OGLIWin32
/vis/viewer/create ! ! 600x600-0+0

Use this open statement to create an OpenInventor view:

#/vis/open OI

Use this open statement to create a .prim file suitable for

viewing in DAWN:

#/vis/open DAWNFILE

Use this open statement to create a .heprep file suitable for

viewing in HepRApp:

#/vis/open HepRepFile

Use this open statement to create a .wrl file suitable for

viewing in a VRML viewer:

#/vis/open VRML2FILE

Disable auto refresh and quieten vis messages whilst scene and

trajectories are established:

/vis/viewer/set/autoRefresh false
/vis/verbose errors
Visualization verbosity changed to errors (2)

Draw geometry:

/vis/scene/add/volume world -1 -1 none m 0 0 0 0 0 0

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : visman0202
issued by : G4Scene::CalculateExtent
Scene has no extent. Please activate or add something.
The camera needs to have something to point at!
Add a volume. (You may need “/run/initialize”.)
Or use “/vis/scene/add/extent”.
“/vis/scene/list” to see list of models.
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------


set extents

/vis/scene/add/extent -3 3 -3 3 -3 3 cm

Specify view angle:

/vis/viewer/set/viewpointVector -1 0 0
/vis/viewer/set/lightsVector -1 0 0

Specify style (surface, wireframe, auxiliary edges,…)

/vis/viewer/set/style wireframe
/vis/viewer/set/auxiliaryEdge true
/vis/viewer/set/lineSegmentsPerCircle 100

Draw smooth trajectories at end of event, showing trajectory points

as markers 2 pixels wide:

#/vis/scene/add/trajectories smooth
/tracking/storeTrajectory 1
Attributes available for modeling and filtering with
“/vis/modeling/trajectories/create/drawByAttribute” and
“/vis/filtering/trajectories/create/attributeFilter” commands:
Event ID (EventID): G4int
Run ID (RunID): G4int
Charge (Ch): unit: e+ (G4double)
Track ID (ID): G4int
Initial kinetic energy (IKE): G4BestUnit (G4double)
Initial momentum magnitude (IMag): G4BestUnit (G4double)
Initial momentum (IMom): G4BestUnit (G4ThreeVector)
No. of points (NTP): G4int
PDG Encoding (PDG): G4int
Parent ID (PID): G4int
Particle Name (PN): G4String
Position (Pos): G4BestUnit (G4ThreeVector)
/vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true
/vis/scene/notifyHandlers scene-0
/vis/scene/notifyHandlers scene-1
/vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 2
/vis/scene/notifyHandlers scene-0
/vis/scene/notifyHandlers scene-1

(if too many tracks cause core dump => /tracking/storeTrajectory 0)

Draw hits at end of event:


To draw only gammas:

#/vis/filtering/trajectories/particleFilter-0/add gamma

To invert the above, drawing all particles except gammas,

keep the above two lines but also add:

#/vis/filtering/trajectories/particleFilter-0/invert true

Many other options are available with /vis/modeling and /vis/filtering.

For example, to select colour by particle ID:

#/vis/modeling/trajectories/drawByParticleID-0/default/setDrawStepPts true

To select or override default colours (note: e+ is blue by default):

#/vis/modeling/trajectories/drawByParticleID-0/set e+ yellow

To superimpose all of the events from a given run:

/vis/scene/endOfEventAction accumulate



/vis/set/textColour green
/vis/set/textLayout right
/vis/scene/add/text2D 0.9 -.9 24 ! ! exampleB1

or, if your system does not support right-adjustment

#/vis/scene/add/text2D 0 -.9 24 ! ! exampleB1

Axes, scale, etc.



/vis/set/colour red
/vis/set/lineWidth 2

Attach text to one edge of Shape1, with a small, fixed offset

/vis/scene/add/text 0 6 -4 cm 18 4 4 Shape1

Attach text to one corner of Shape2, with a small, fixed offset

/vis/scene/add/text 6 7 10 cm 18 4 4 Shape2

To get nice view

Make the “World” box invisible

/vis/geometry/set/visibility samplecontainer 0 false

“Envelope” is transparent blue to represent water

/vis/geometry/set/colour LogSample 0 0 0 1 .3
#/vis/scene/add/extent -3 3 -3 3 -3 3 cm
/vis/viewer/set/style surface
/vis/viewer/set/hiddenMarker true
/vis/viewer/set/viewpointThetaPhi 120 150

Re-establish auto refreshing and verbosity:

/vis/viewer/set/autoRefresh true
/vis/verbose warnings
Visualization verbosity changed to warnings (3)

For file-based drivers, use this to create an empty detector view:


Hi Chris

This is strange. Even if you exceed the number of events that may be kept, the trajectories that have been drawn should not disappear.

Stranger than strange! I can’t imagine why this should affect drawing. Do you try to draw the field? Even so, it should not matter.

It looks like G4 tries to “rebuild” the view at the end of run. Normally, the view would not be touched until the start off the next run. Are you doing anything that might cause a rebuild?

It’s just a warning, but you might want to increase the number to be kept. In fact, this might be a workaround for you. Keep as many events as you generate in the run, then even on rebuild they will be drawn.

Have you made everything invisible? But it’s just a warning and things seem to display OK.

Hope this helps

Hi John,
Thanks for the prompt reply. I think the problem probably lies in the fact that although I have updated the code to work under the latest release, there is something in the visualisation aspect that I have missed and is causing problems. For instance, there is a class G4VisExecutive which appears to have been overridden and a new class SEMVisExecutive added. I add the code for the .hh and .icc files below in case you spot anything. I might just try putting back the G4VisExecutive class to see what happens, but before I will examine the code in G4VisExecutive.hh and .icc.


Best Wishes

// SEMVisExecutive.hh


#include “G4VisExecutive.hh”

class SEMVisExecutive: public G4VisExecutive {

public: // With description

SEMVisExecutive ();


void RegisterGraphicsSystems ();


#include “SEMVisExecutive.icc”


// SEMVisExecutive.icc

// Supported drivers…

// Not needing external packages or libraries…
#include “G4ASCIITree.hh”
#include “G4DAWNFILE.hh”
#ifndef WIN32
#include “G4HepRep.hh”
#include “G4HepRepFile.hh”
#include “G4RayTracer.hh”
#include “G4VRML1File.hh”
#include “SEMVRML2File.hh”

// Needing external packages or libraries…

#include “G4FukuiRenderer.hh”

#include “G4OpenGLImmediateX.hh”
#include “G4OpenGLStoredX.hh”

#include “G4OpenGLImmediateWin32.hh”
#include “G4OpenGLStoredWin32.hh”

#include “G4OpenGLImmediateXm.hh”
#include “G4OpenGLStoredXm.hh”

#ifdef G4VIS_USE_OIX
#include “G4OpenInventorX.hh”

#ifdef G4VIS_USE_OIWIN32
#include “G4OpenInventorWin32.hh”

#include “G4VRML1.hh”
#include “G4VRML2.hh”

SEMVisExecutive::SEMVisExecutive () {}

void SEMVisExecutive::RegisterGraphicsSystems () {

// Graphics Systems not needing external packages or libraries…
RegisterGraphicsSystem (new G4ASCIITree);
RegisterGraphicsSystem (new G4DAWNFILE);
#ifndef WIN32
RegisterGraphicsSystem (new G4HepRep);
RegisterGraphicsSystem (new G4HepRepFile);
RegisterGraphicsSystem (new G4RayTracer);
RegisterGraphicsSystem (new G4VRML1File);
RegisterGraphicsSystem (new SEMVRML2File);

// Graphics systems needing external packages or libraries…

RegisterGraphicsSystem (new G4FukuiRenderer);

RegisterGraphicsSystem (new G4OpenGLImmediateX);
RegisterGraphicsSystem (new G4OpenGLStoredX);

RegisterGraphicsSystem (new G4OpenGLImmediateWin32);
RegisterGraphicsSystem (new G4OpenGLStoredWin32);

RegisterGraphicsSystem (new G4OpenGLImmediateXm);
RegisterGraphicsSystem (new G4OpenGLStoredXm);

#ifdef G4VIS_USE_OIX
RegisterGraphicsSystem (new G4OpenInventorX);

#ifdef G4VIS_USE_OIWIN32
RegisterGraphicsSystem (new G4OpenInventorWin32);

RegisterGraphicsSystem (new G4VRML1);
RegisterGraphicsSystem (new G4VRML2);


Hi Chris

SEMVisExecutive is not a supported class. You’re on your own with that. So, yes, please try the canonical build.


Hi John,
Thanks again. I’ll have a go. It might take a while…


Hi John,
I replaced the SEMVisExecutive class with G4VisExecutive, but I still have the same problems. However, I do have a class which definitely needs updating. The class inherits from G4eLowEnergyLoss, but this class seems to have been discontinued from version 9.5. The problem is which class should I inherit from now? Since this is not a graphics or visualisation issue, I guess I should repost the question in the appropriate subgroup.

Best Wishes

Hi Chris,
Did you ever resolve this? I am running into something similar, where my trajectories or saved events are either disappearing or not being drawn at all. I’m working with John to resolve my issues and was curious if our cases are more similar.


1 Like

Hi Micah,
Its been quite a while since I worked on this. The problem seemed to come down to the fact that the package I was using had rewritten the G4Transportation class. It worked OK as long as there were no electric or magnetic fields. As soon as such fields were introduced, I hit problems and I never worked out how to update the G4Transportation class to the latest release. I was working with COMSOL to generate the electric fields. In the end, I used Geant4 to simulate electrons in the material and COMSOL to simulate the electrons in the vacuum and passed information between the two when the electrons crossed the surface.
I may well return to the problem at some future stage as some other researchers are interested in my work, but they can’t afford the full COMSOL package…

Let me know how you get on.
Best Wishes

Thanks Chris,
I am importing the COMSOL data and it works fine for that project; although I am not trying to draw the fields. However, my issue really comes on another project and the EndOfEventAction. It seems to ignore anything I want it to do for drawing.