Trajectories disappear at end of run

Hello,
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.
Chris



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
{material}{energy}.dat
/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
{material}{energy}.dat
##/detectors/PlaneR/detHistFilename {directory}/Hist
{material}.dat
/control/execute init_vis.mac

Macro file for the initialization of example B1

in interactive session

Set some default verbose

/control/verbose 2
/control/saveHistory
/run/verbose 2

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

#/run/numberOfThreads 4

Initialize kernel

/run/initialize

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/sceneHandler/attach
/vis/viewer/create ! ! 600x600-0+0
/vis/viewer/refresh

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/drawVolume
/vis/scene/create
/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 -------

/vis/sceneHandler/attach

set extents

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

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
/vis/scene/add/trajectories
/tracking/storeTrajectory 1
Attributes available for modeling and filtering with
“/vis/modeling/trajectories/create/drawByAttribute” and
“/vis/filtering/trajectories/create/attributeFilter” commands:
G4TrajectoriesModel:
Event ID (EventID): G4int
Run ID (RunID): G4int
G4Trajectory:
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
G4TrajectoryPoint:
Position (Pos): G4BestUnit (G4ThreeVector)
/vis/scene/notifyHandlers
/vis/modeling/trajectories/create/drawByCharge
/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:

#/vis/scene/add/hits

To draw only gammas:

#/vis/filtering/trajectories/create/particleFilter
#/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/create/drawByParticleID
#/vis/modeling/trajectories/drawByParticleID-0/default/setDrawStepPts true

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

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

To superimpose all of the events from a given run:

/vis/scene/endOfEventAction accumulate

Decorations

Name

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

or, if your system does not support right-adjustment

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

Axes, scale, etc.

/vis/scene/add/scale
/vis/scene/notifyHandlers
/vis/scene/add/axes
/vis/scene/notifyHandlers
/vis/scene/add/eventID
/vis/scene/notifyHandlers
/vis/scene/add/date
/vis/scene/notifyHandlers
/vis/scene/add/logo2D
/vis/scene/notifyHandlers
/vis/scene/add/logo
/vis/scene/notifyHandlers

Frame

/vis/set/colour red
/vis/set/lineWidth 2
/vis/scene/add/frame
/vis/scene/notifyHandlers
/vis/set/colour
/vis/set/lineWidth

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

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

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

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

To get nice view

Make the “World” box invisible

/vis/geometry/set/visibility samplecontainer 0 false
/vis/scene/notifyHandlers

“Envelope” is transparent blue to represent water

/vis/geometry/set/colour LogSample 0 0 0 1 .3
/vis/scene/notifyHandlers
#/vis/scene/create
#/vis/scene/add/extent -3 3 -3 3 -3 3 cm
#/vis/sceneHandler/attach
/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/viewer/refresh
/vis/verbose warnings
Visualization verbosity changed to warnings (3)

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

#/vis/viewer/flush

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
John

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.

Thanks
Chris

Best Wishes
Chris

// SEMVisExecutive.hh

#ifndef SEMVISEXECUTIVE_HH
#define SEMVISEXECUTIVE_HH

#include “G4VisExecutive.hh”

class SEMVisExecutive: public G4VisExecutive {

public: // With description

SEMVisExecutive ();

private:

void RegisterGraphicsSystems ();

};

#include “SEMVisExecutive.icc”

#endif

// SEMVisExecutive.icc

// Supported drivers…

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

// Needing external packages or libraries…

#ifdef G4VIS_USE_DAWN
#include “G4FukuiRenderer.hh”
#endif

#ifdef G4VIS_USE_OPENGLX
#include “G4OpenGLImmediateX.hh”
#include “G4OpenGLStoredX.hh”
#endif

#ifdef G4VIS_USE_OPENGLWIN32
#include “G4OpenGLImmediateWin32.hh”
#include “G4OpenGLStoredWin32.hh”
#endif

#ifdef G4VIS_USE_OPENGLXM
#include “G4OpenGLImmediateXm.hh”
#include “G4OpenGLStoredXm.hh”
#endif

#ifdef G4VIS_USE_OIX
#include “G4OpenInventorX.hh”
#endif

#ifdef G4VIS_USE_OIWIN32
#include “G4OpenInventorWin32.hh”
#endif

#ifdef G4VIS_USE_VRML
#include “G4VRML1.hh”
#include “G4VRML2.hh”
#endif

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);
#endif
RegisterGraphicsSystem (new G4RayTracer);
RegisterGraphicsSystem (new G4VRML1File);
RegisterGraphicsSystem (new SEMVRML2File);

// Graphics systems needing external packages or libraries…

#ifdef G4VIS_USE_DAWN
RegisterGraphicsSystem (new G4FukuiRenderer);
#endif

#ifdef G4VIS_USE_OPENGLX
RegisterGraphicsSystem (new G4OpenGLImmediateX);
RegisterGraphicsSystem (new G4OpenGLStoredX);
#endif

#ifdef G4VIS_USE_OPENGLWIN32
RegisterGraphicsSystem (new G4OpenGLImmediateWin32);
RegisterGraphicsSystem (new G4OpenGLStoredWin32);
#endif

#ifdef G4VIS_USE_OPENGLXM
RegisterGraphicsSystem (new G4OpenGLImmediateXm);
RegisterGraphicsSystem (new G4OpenGLStoredXm);
#endif

#ifdef G4VIS_USE_OIX
RegisterGraphicsSystem (new G4OpenInventorX);
#endif

#ifdef G4VIS_USE_OIWIN32
RegisterGraphicsSystem (new G4OpenInventorWin32);
#endif

#ifdef G4VIS_USE_VRML
RegisterGraphicsSystem (new G4VRML1);
RegisterGraphicsSystem (new G4VRML2);
#endif

}

Hi Chris

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

Cheers
John

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

Cheers
Chris

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
Chris

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.

Sincerely,
Micah

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
Chris

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.

Cheers,
Micah