4.8.  Command-based scoring

4.8.1.  Introduction

Command-based scoring in Geant4 utilizes parallel navigation in a parallel world volume as descibed in the previous sections. Through interactive commands, the user can define :

  • A parallel world for scoring and three-dimensional mesh in it
  • Arbitrary number of physics quantities to be scored and filters

After scoring (i.e. a run), the user can visualize the score and dump scores into a file. All available UI commands are listed in List of built-in commands.

Command-based scoring is an optional functionality and the user has to explicity define its use in the main(). To do this, the method G4ScoringManager::GetScoringManager() must be invoked right after the instantiation of G4RunManager. The scoring manager is a singleton object, and the pointer accessed above should not be deleted by the user.

Example 4.22.  A user main() to use the command-based scoring

#include "G4RunManager.hh"
#include "G4ScoringManager.hh"

int main(int argc,char** argv)
 // Construct the run manager
 G4RunManager * runManager = new G4RunManager;

 // Activate command-based scorer



4.8.2.  Defining a scoring mesh

To define a scoring mesh, the user has to specify the followings.

  • Shape and name of the 3D scoring mesh. Currently, box is the only available shape.
  • Size of the scoring mesh. Mesh size must be specified as "half width" similar to the arguments of G4Box.
  • Number of bins for each axes. Note that too hugh number causes immense memory consumption.
  • Optionally, position and rotation of the mesh. If not specified, the mesh is positioned at the center of the world volume without rotation.

For a scoring mesh the user can have arbitrary number of quantities to be scored for each cell of the mesh. For each scoring quantity, the use can set one filter. Please note that /score/filter affects on the preceding scorer. Names of scorers and filters must be unique for the mesh. It is possible to define more than one scorer of same kind with different names and, likely, with different filters.

Defining a scoring mesh and scores in the mesh should terminate with the /score/close command. The following sample UI commands define a scoring mesh named boxMesh_1, size of which is 2 m * 2 m * 2 m, and sliced into 30 cells along each axes. For each cell energy deposition, number of steps of gamma, number of steps of electron and number of steps of positron are scored.

Example 4.23.  UI commands to define a scoring mesh and scorers

# define scoring mesh
/score/create/boxMesh boxMesh_1
/score/mesh/boxSize 100. 100. 100. cm
/score/mesh/nBin 30 30 30
# define scorers and filters
/score/quantity/energyDeposit eDep
/score/quantity/nOfStep nOfStepGamma
/score/filter/particle gammaFilter gamma
/score/quantity/nOfStep nOfStepEMinus
/score/filter/particle eMinusFilter e-
/score/quantity/nOfStep nOfStepEPlus
/score/filter/particle ePlusFilter e+

4.8.3.  Drawing scores

Once scores are filled, it is possible to visualize the scores. The score is drawn on top of the mass geometry with the current visualization settings.

Drawing scores in slices (left) and projection (right)

Figure 4.9.  Drawing scores in slices (left) and projection (right)

Scored data can be visualized using the commands "/score/drawProjection" and "/score/drawColumn". For details, see examples/extended/runAndEvent/RE03.

By default, entries are linearly mapped to colors (gray - blue - green - red). This color mapping is implemented in G4DefaultLinearColorMap class, and registered to G4ScoringManager with the color map name "defaultLinearColorMap". The user may alternate color map by implementing a customised color map class derived from G4VScoreColorMap and register it to G4ScoringManager. Then, for each draw command, one can specify the preferred color map.

4.8.4.  Writing scores to a file

It is possible to dump a score in a mesh (/score/dumpQuantityToFile command) or all scores in a mesh (/score/dumpAllQuantitiesToFile command) to a file. The default file format is the simple CSV. To alternate the file format, one should overwrite G4VScoreWriter class and register it to G4ScoringManager. The scoring manager takes ownership of the registered writer, and will delete it at the end of the job.

Please refer to /examples/extended/runAndEvent/RE03 for details.