Scoring and geometrical importance sampling in Geant4

Michael Dressel

Table of Contents

1. Preface
2. Introduction
3. Geometries
4. Sampler classes
5. Scoring
6. Importance sampling
7. Importance weight window sampling
8. Example B06

1. Preface

This document gives short descriptions of the basic concepts of the implementation of scoring and importance sampling (or geometrical splitting and Russian roulette) in Geant4. The reader is expected to be familiar with both Geant4 and the concept of importance sampling.

2. Introduction

The scoring implemented intends to appraise particle quantities related to special regions or surfaces. The scoring is aimed to apply to all "cells" (physical volumes or replicas) of a given geometry. The scoring is designed to be customised. Nevertheless it is aimed to provide standard scoring for quantities such as: tracks entering a cell, average weight of entering tracks, energy of entering tracks, collisions inside the cell.

The purpose of importance sampling is to save computing time by sampling particle histories entering important regions more often and histories entering less important regions less often. Comparing the result of an importance sampled to an analogue sampled simulation the mean value must be equal while the variance should be reduced in the same amount of computing time.

The implementation of scoring is independent from the implementation of importance sampling. However both share common concepts. Scoring and importance sampling apply to particle types chosen by the user.

Examples on how to use scoring and importance sampling may be found in examples/extended/biasing.

3. Geometries

The kind of scoring referred to in this note and the importance sampling apply to spatial cells given by the user.


A cell is a physical volume further specified by it's replica number (if the volume is a replica).

The cells may be defined in two kinds of geometries:

mass geometry:

The one geometry of the experiment to be simulated. Physics processes apply to this geometry.

parallel geometry:

A parallel geometry may be constructed to define the physical volumes according to which scoring and/or importance sampling is applied.

The user has the choice to score and/or sample by importance the particles of the chosen type, according to the mass geometry or to a parallel geometry. It is possible to utilise several parallel geometries in addition to the mass geometry. This provides the user with a lot of flexibility to define separate geometries for different particle types in order to apply scoring or/and importance sampling.

3.1. Limitations of "parallel" geometries

  • A special kind of "transportation" inside the "parallel" geometry has been developed. In the current implementation, this does not take into account fields. Therefore "parallel" geometries can only be used in field free simulations.

    The world volume of the parallel geometry must overlap the world volume of the mass geometry.

    Particles croosing a boundary in the parallel geometry where there is vakuum in the mass geometry are also biased. This may be optimized in later versions.

  • Mass and parallel geometry boundaries are not concident in the current implementation.

4. Sampler classes

Seven classes are provided for scoring, importance and weight window sampling in the mass and a parallel geometry respectively:

All the sampler classes derive form the interface G4VSampler. This way a common type for the samplers is defined. The interface G4VSampler declares one abstract function: Initalize().

Table 1. Sampler classes

 mass geometry"parallel" geometry
biasing and scoringG4MassImportanceScoreSamplerG4ParallelImportanceScoreSampler -- G4PImportanceWWindowScoreSampler

At least one object of at lest one of the above classes has to be created. One object is required for every particle type to be scored or/and importance sampled.


The samplers have to be initialised after the G4RunManager has been initialised.

4.1. Responsibilities of the different sampler classes

all sampler classes:

Each object of a sampler class is responsible for one particle type. The particle type is given to the constructor of the sampler classes via the particle type name e.g. "neutron".

score sampler classes:

G4MassScoreSampler, G4ParallelScoreSampler, G4MassImportanceScoreSampler, G4ParallelImportanceScoreSampler serve a "scorer" (see Scoring). The constructors have to be given a reference to a "scorer".

importance sampler classes:

G4MassImportanceSampler, G4ParallelImportanceSampler, G4MassImportanceScoreSampler, G4ParallelImportanceScoreSampler apply importance sampling according to importance values related to "cells" provided by an "importance store" (see Importance sampling). The constructors have to be given a reference to a "importance store".

mass geometry sampler classes:

G4MassScoreSampler, G4MassImportanceSampler, G4MassImportanceScoreSampler deal with the mass geometry.

parallel geometry sampler classes:

G4ParallelScoreSampler, G4ParallelImportanceSampler, G4ParallelImportanceScoreSampler deal with a "parallel" geometry. A reference to the world volume of the "parallel" geometry is given directly to G4ParallelScoreSampler and via the "importance store" (see Importance sampling) to G4ParallelImportanceSampler and G4ParallelImportanceScoreSampler.

parallel importance weight window score sampler:

G4PImportanceWWindowScoreSampler applies importance sampling and weight window sampling in a parallel geometry. It also does scoring.

In addition to the references given to G4ParallelImportanceScoreSampler a reference to a weight window algorithm derived from G4VWeightWindowAlgorithma has to be given to the constructor.

5. Scoring

Scoring may be applied to the mass or a parallel geometry. Scoring is done with an object generically called "scorer". The "scorer" receives the information about every step a particle of chosen type takes. The information consists of an object of the Geant4 kernel class G4Step and an object of the class G4GeometryCellStep provided in particular for the purpose of scoring and importance sampling. G4GeometryCellStep provides information about the previous and current "cell" of the particles track.

A "scorer" class derives from the interface G4VScorer. Users may create customised "scorers" or use the classes G4Scorer for standard scoring. A class G4ScoreTable exists which may be used to print a table of scores from the scores created by G4Scorer. For detailed information about the standard scoring see: Standard scoring in Geant4

The scoring "samplers" (score sampler classes:) take one reference to a class ("scorer") derived from G4VScorer. To score different particle types with one scorer the reference to that scorer has to be given to the different samplers of the particle types to be scored.

Classes involved:

  • G4VScorer:
    class G4VScorer {
      virtual ~G4VScorer(){}
      virtual void Score(const G4Step &step, const G4GeometryCellStep &pstep) = 0;

    The member function Score(const G4Step &step, const G4GeometryCellStep &pstep) is invoked for every "PostStep" of a chosen particle before the "PostStepDoIt"-functions of the physical processes are invoked.

  • G4GeometryCellStep:
    class G4GeometryCellStep {
      G4GeometryCellStep(const G4GeometryCell &preKey, const G4GeometryCell &postKey):
      G4GeometryCell fPreTouchableKey;
      G4GeometryCell fPostTouchableKey;  
      G4bool fCrossBoundary;
    The classes used in G4GeometryCellStep:
    • G4GeometryCell identifys a "cell" as a physical volume with a replica number. The "cell" is in the "parallel" geometry if a sampler for "parallel" geometries is used else it is in the mass geometry.
    • fPreTouchableKey refers to the previous "cell" the particle touched, or it is equal to fPostTouchableKey if the track has not crossed a boundary.
    • fPostTouchableKey refers to the current "cell".
    • fCrossBoundary is set "true" in case the particle crosses a boundary in the parallel or mass geometry with respect to the sampler used.


When scoring is done in a "parallel" geometry special action has to be taken to prevent counting of "collisions" with boundaries of the mass geometry as interactions. This is differently handled when scoring is done in the mass geometry.

6. Importance sampling

The importance sampling acts on particles crossing boundaries between "importance cells". The action taken depends on the importance values assigned to the "cells". In general a particle history is splitted or Russian roulette is played if the importance increases or decreases respectively. A weight assigned to the history is changed according to the action taken.

The tools provided for importance sampling (or geometrical splitting and Russian roulette) require the user to have a good understanding of the physics in the problem. This is because the user has to decide which particle types have to be biased, define the regions (physical volumes, replicas) and assign importances to that regions. If this is not done properly it can not be expected that the results describe a real experiment.

An "importance store" with the interface G4VIStore is used to store importance values related to "cells" (physical volumes or replicas). In order to do importance sampling the user has to create an object (e.g. of class G4IStore) of type G4VIStore. The constructors of the importance sampler (importance sampler classes:) take a reference to a G4VIStore. The user fills the store with cells and theirimportance values.

6.1. Interpretation of importance values

The different cases:

  • Cell is not in store

    Not filling a certain cell into the store means that no importance biasing is done for tracks at boundaries between the cell unknown by the store and it's neighboring cells.

  • Importance value = zero

    Importance = 0, will be interpreted in the same way as above.

  • importance values > 0

    Normal allowed values

  • Importance value smaller zero

    Not allowed!

The interface G4VIStore:

class  G4VIStore {
  G4VIStore(G4VPhysicalVolume &worldVolume){}
  virtual  ~G4VIStore(){}
  virtual void AddImportanceRegion(G4double importance,
                                   const G4VPhysicalVolume &,
                                   G4int aRepNum = 0) = 0;
  virtual void ChangeImportance(G4double importance,
                                const G4VPhysicalVolume &,
                                G4int aRepNum = 0) = 0;
  virtual G4double GetImportance(const G4VPhysicalVolume &,
                                 G4int aRepNum = 0) const = 0;
  virtual G4double GetImportance(const G4GeometryCell &gCell) const = 0;
  virtual G4bool IsKnown(const G4GeometryCell &gCell) const = 0;
  virtual G4VPhysicalVolume &GetWorldVolume() = 0;

A "importance store" has to be constructed with a reference to the world volume of the geometry used for importance sampling. This may be the world volume of the mass or of a parallel geometry. The member function AddImportanceRegion adds a "cell" together with a importance value to the "importance store". The importance values may be returned either according to a physical volume and a replica number or according to a G4GeometryCell. The user has to make be aware of the interpretation Section 6.1 of assigning importance values to a cell and filling a cell into the store.


In Geant4 the world volume has the replica number -1.

7. Importance weight window sampling

In this release weight window sampling only aims for one purpose: to reduce large weight differences that might occur if secondary particles that are not importance sampled create a particle that is importance sampled. In principle this situation should be avoided by sampling all the relevant particles.

Weight window sampling is more important if other non analogue sampling techniques are applied together with importance sampling.

The weight window sampling so far applies only in the initial step of a track.

8. Example B06

The examples are distributed in Geant4 in the directory: examples/extended/biasing.