Enhanced Trajectory Drawing

Default Configuration

Trajectory drawing styles are specified through trajectory drawing models. Each drawing model has a default configuration provided through a G4VisTrajContext object. The default context settings are shown below.

Table 24 Default context settings for trajectory drawing models.

Property

Default Setting

Line colour

grey

Line visibility

true

Draw line

true

Draw auxiliary points

false

Auxiliary point type

squares

Auxiliary point size

2 pixels or mm*

Auxiliary point size type

screen

Auxiliary point fill style

filled

Auxiliary point colour

magenta

Auxiliary point visibility

true

Draw step point

false

Step point type

circles

Step point size

2 pixels or mm*

Step point size type

screen

Step point fill style

filled

Step point colour

yellow

Step point visibility

true

Time slice interval

0

* Depending on size type. If size type == screen, pixels are assumed and no unit need be supplied. If size type == world, a unit must be supplied, e.g., 10 cm.

Note

Different visualisation drivers handle trajectory configuration in different ways, so trajectories may not necessarily get displayed as you have configured them.

Trajectory Drawing Models

A trajectory drawing model can override the default context according to the properties of a given trajectory. The following models are supplied with the Geant4 distribution:

  • G4TrajectoryGenericDrawer (generic)

  • G4TrajectoryDrawByCharge (drawByCharge)

  • G4TrajectoryDrawByParticleID (drawByParticleID)

  • G4TrajectoryDrawByOriginVolume (drawByOriginVolume)

  • G4TrajectoryDrawByTouchedVolume (drawByTouchedVolume)

  • G4TrajectoryDrawByAttribute (drawByAttribute)

Both the context and model properties can be configured by the user. The models are described briefly below, followed by some example configuration commands.

G4TrajectoryGenericDrawer

This model simply draws all trajectories in the same style, with the properties provided by the context.

G4TrajectoryDrawByCharge

This is the default model - if no model is specified by the user, this model will be constructed automatically. The trajectory lines are coloured according to charge, with all other configuration parameters provided by the default context. The default colouring scheme is shown below.

Charge

Colour

1

blue

-1

red

0

green

G4TrajectoryDrawByParticleID

This model colours trajectory lines according to particle type. All other configuration parameters are provided by the default context. Chosen particle types can be highlighted with specified colours. By default, trajectories are coloured according to the scheme below and any other particle in the default colour (grey). (All may be overridden by the set command.)

Particle

Colour

gamma

green

e-

red

e+

blue

pi+

magenta

pi-

magenta

proton

cyan

neutron

yellow

G4TrajectoryDrawByOriginVolume

This model colours trajectory lines according to the trajectory’s originating volume name. The volume can be either a logical or physical volume. Physical volume takes precedence over logical volume. All trajectories are coloured grey by default.

G4TrajectoryDrawByTouchedVolume

This model colours trajectory lines if it touches one or more volumes according to the physical volume name(s). It requires rich trajectories, G4RichTrajectory (/vis/scene/add/trajectories rich). All trajectories are coloured grey by default.

G4TrajectoryDrawByAttribute

This model draws trajectories based on the HepRep style attributes associated with trajectories. Each attribute drawer can be configured with interval and/or single value data. A new context object is created for each interval/single value. This makes it possible to have different step point markers etc, as well as line colour for trajectory attributes falling into different intervals, or matching single values. The single value data should override the interval data, allowing specific values to be highlighted. Units should be specified on the command line if the attribute unit is specified either as a G4BestUnit or if the unit is part of the value string.

Controlling from Commands

Multiple trajectory models can be created and configured using commands in the “/vis/modeling/trajectories/” directory. It is then possible to list available models and select one to be current.

Model configuration commands are generated dynamically when a model is instantiated. These commands apply directly to that instance. This makes it possible to have multiple instances of the drawByCharge model for example, each independently configurable through it’s own set of commands.

See the interactive help for more information on the available commands.

Example commands

  • Create a generic model named generic-0 by default

    /vis/modeling/trajectories/create/generic
    
  • Configure context to colour all trajectories red

    /vis/modeling/trajectories/generic-0/default/setLineColour red
    
  • Create a drawByCharge model named drawCharge-0 by default (Subsequent models will be named drawByCharge-1, drawByCharge-2, etc.)

    /vis/modeling/trajectories/create/drawByCharge
    
  • Create a drawByCharge model named testChargeModel

    /vis/modeling/trajectories/create/drawByCharge testChargeModel
    
  • Configure drawByCharge-0 model

    /vis/modeling/trajectories/drawByCharge-0/set 1 red
    /vis/modeling/trajectories/drawByCharge-0/set -1 red
    /vis/modeling/trajectories/drawByCharge-0/set 0 white
    
  • Configure testCharge model through G4Colour components

    /vis/modeling/trajectories/testChargeModel/setRGBA 1 0 1 1 1
    /vis/modeling/trajectories/testChargeModel/setRGBA -1 0.5 0.5 0.5 1
    /vis/modeling/trajectories/testChargeModel/setRGBA 0 1 1 0 1
    
  • Create a drawByParticleID model named drawByParticleID-0

    /vis/modeling/trajectories/create/drawByParticleID
    
  • Configure drawByParticleID-0 model

    /vis/modeling/trajectories/drawByParticleID-0/set gamma red
    /vis/modeling/trajectories/drawByParticleID-0/setRGBA e+ 1 0 1 1
    
  • List available models

    /vis/modeling/trajectories/list
    
  • select drawByParticleID-0 to be current

    /vis/modeling/trajectories/select drawByParticleID-0
    
  • Create a drawByAttribute model named drawByAttribute-0

    /vis/modeling/trajectories/create/drawByAttribute
    
  • Configure drawByAttribute-0 model

    /vis/modeling/trajectories/drawByAttribute-0/verbose true
    
  • Select attribute “CPN”

    /vis/modeling/trajectories/drawByAttribute-0/setAttribute CPN
    
  • Configure single value data

    /vis/modeling/trajectories/drawByAttribute-0/addValue brem_key  eBrem
    /vis/modeling/trajectories/drawByAttribute-0/addValue annihil_key annihil
    /vis/modeling/trajectories/drawByAttribute-0/addValue decay_key Decay
    /vis/modeling/trajectories/drawByAttribute-0/addValue muIon_key muIoni
    /vis/modeling/trajectories/drawByAttribute-0/addValue eIon_key  eIoni
    
    /vis/modeling/trajectories/drawByAttribute-0/brem_key/setLineColour     red
    /vis/modeling/trajectories/drawByAttribute-0/annihil_key/setLineColour  green
    /vis/modeling/trajectories/drawByAttribute-0/decay_key/setLineColour    cyan
    /vis/modeling/trajectories/drawByAttribute-0/eIon_key/setLineColour     yellow
    /vis/modeling/trajectories/drawByAttribute-0/muIon_key/setLineColour magenta
    
  • Create a drawByAttribute model named drawByAttribute-1

    /vis/modeling/trajectories/create/drawByAttribute
    
  • Select “IMag” attribute

    /vis/modeling/trajectories/drawByAttribute-1/setAttribute IMag
    
  • Configure interval data

    /vis/modeling/trajectories/drawByAttribute-1/addInterval interval1 0.0 keV 2.5MeV
    /vis/modeling/trajectories/drawByAttribute-1/addInterval interval2 2.5 MeV 5 MeV
    /vis/modeling/trajectories/drawByAttribute-1/addInterval interval3 5 MeV 7.5 MeV
    /vis/modeling/trajectories/drawByAttribute-1/addInterval interval4 7.5 MeV 10 MeV
    /vis/modeling/trajectories/drawByAttribute-1/addInterval interval5 10 MeV 12.5 MeV
    /vis/modeling/trajectories/drawByAttribute-1/addInterval interval6 12.5 MeV 10000 MeV
    
    /vis/modeling/trajectories/drawByAttribute-1/interval1/setLineColourRGBA 0.8 0 0.8 1
    /vis/modeling/trajectories/drawByAttribute-1/interval2/setLineColourRGBA 0.23 0.41 1 1
    /vis/modeling/trajectories/drawByAttribute-1/interval3/setLineColourRGBA 0 1 0 1
    /vis/modeling/trajectories/drawByAttribute-1/interval4/setLineColourRGBA 1 1 0 1
    /vis/modeling/trajectories/drawByAttribute-1/interval5/setLineColourRGBA 1 0.3 0 1
    /vis/modeling/trajectories/drawByAttribute-1/interval6/setLineColourRGBA 1 0 0 1
    
  • Create a drawByEncounteredVolume model named drawByEncounteredVolume-0

    /vis/modeling/trajectories/create/drawByEncounteredVolume
    
  • Change the color for a specific encountered shape

    /vis/modeling/trajectories/drawByEncounteredVolume-0/set Shape1 cyan
    

Controlling from Compiled Code

It is possible to use the enhanced trajectory drawing functionality in compiled code as well as from commands. Multiple trajectory models can be instantiated, configured and registered with G4VisManager. Once registered, the models are owned by G4VisManager, and must not be deleted by the user.

Only one model may be current. For example:

G4VisManager* visManager = new G4VisExecutive;
visManager->Initialize();

G4TrajectoryDrawByParticleID* model = new G4TrajectoryDrawByParticleID;
G4TrajectoryDrawByParticleID* model2 = new G4TrajectoryDrawByParticleID("test");

model->SetDefault("cyan");
model->Set("gamma", "green");
model->Set("e+", "magenta");
model->Set("e-", G4Colour(0.3, 0.3, 0.3));

visManager->RegisterModel(model);
visManager->RegisterModel(model2);

visManager->SelectTrajectoryModel(model->Name());

Drawing by time

To draw by time, you need to use G4RichTrajectory, for example:

/vis/scene/add/trajectories rich

or

/vis/scene/add/trajectories rich smooth

When you run, you need to create a trajectory model and set the time slice interval (remembering that particles are often relativistic and travel 30 cm/ns):

/vis/modeling/trajectories/create/drawByCharge
/vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true
/vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 5
/vis/modeling/trajectories/drawByCharge-0/default/setDrawAuxPts true
/vis/modeling/trajectories/drawByCharge-0/default/setAuxPtsSize 5
/vis/modeling/trajectories/drawByCharge-0/default/setTimeSliceInterval 0.1 ns
/vis/modeling/trajectories/list

and use a graphics driver that can display by time:

/vis/open OGL
/vis/drawVolume
/vis/scene/add/trajectories rich
/vis/viewer/set/timeWindow/startTime 0.5 ns
/vis/viewer/set/timeWindow/endTime 0.8 ns
/run/beamOn
/vis/viewer/refresh

For tips on how to see particles “moving through time” see Making a Movie.