Contents Previous Next Geant4 User's Guide
For Application Developers
Visualization
8.7 Enhanced Trajectory Drawing



8.7.1 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.


PropertyDefault Setting
Line colour grey
Line visibility true
Draw linetrue
Draw auxiliary points false
Auxiliary point typesquares
Auxiliary point size0
Auxiliary point fill stylefilled
Auxiliary point colourmagenta
Auxiliary point visibilitytrue
Draw step pointfalse
Step point type circles
Step point size 0
Step point fill style filled
Step point colouryellow
Step point visibilitytrue
Time slice interval0


Points to note:

8.7.2 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:
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. By default, all trajectories are coloured grey. Chosen particle types can be highlighted with specified colours.

G4TrajectoryDrawByOriginVolume

This model colours trajectory lines according to the trajectories 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.

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.

8.7.3 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.

8.7.3.1 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

8.7.4 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. 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());

8.7.5 Drawing by time

To draw by time, you need to use a trajectory that records the track time at the beginning and end of each step. To do this, write a tracking action that sets G4RichTrajectory, for example:
#include "G4UserTrackingAction.hh"
class G4Track;
class MyTrackingAction : public G4UserTrackingAction
{
   public:
   virtual void PreUserTrackingAction(const G4Track* aTrack);
};
#include "G4RichTrajectory.hh"
#include "G4TrackingManager.hh"
#include "G4IdentityTrajectoryFilter.hh"
#include "G4TransportationManager.hh"
#include "G4PropagatorInField.hh"
void MyTrackingAction::PreUserTrackingAction(const G4Track* aTrack)
{
  // Require rich trajectory...
  fpTrackingManager->SetTrajectory(new G4RichTrajectory(aTrack));

  // Activate storing of auxiliary points for smoother trajectory...
  static G4IdentityTrajectoryFilter curvedFilter;
  G4TransportationManager::GetTransportationManager()->
    GetPropagatorInField()->SetTrajectoryFilter(&curvedFilter);
}
and register an instance of this with the run manager (this can be done once and for all as soon as the run manager is instantiated, probably in your main program):
#include "MyTrackingAction.hh"
...
  runManager -> SetUserAction (new MyTrackingAction);
When you run, you need to create a trajectory model and set the time slice interval (remembering that paticles 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 OGLSX
/vis/drawVolume
/vis/scene/add/trajectories
/vis/ogl/set/startTime 0.5 ns
/vis/ogl/set/endTime 0.8 ns
/run/beamOn
/vis/viewer/refresh
A good way to see the particles moving through the detector is:
/vis/ogl/set/fade 1
/vis/ogl/set/displayHeadTime true
/control/alias timeRange 1
/control/loop movie.loop -{timeRange} 40 0.1
where fade gives a vapour-trail effect, displayHeadTime displays the time of the leading edge as 2D text, and movie.loop is a macro file:
/vis/ogl/set/startTime {startTime} ns {timeRange} ns
From there, it's straightforward to make a movie.


Next section
Back to contents