From Wiki OpenGATE
Revision as of 08:40, 21 June 2016 by Albertine.Dubois (Talk | contribs) (Created page with "== Introduction == This page will give an overview on how to include new physics processes into Gate. Keep in mind, that Gate is basically a very advanced interface to Geant4...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


This page will give an overview on how to include new physics processes into Gate. Keep in mind, that Gate is basically a very advanced interface to Geant4. It is not the scope of this document to explain how to implement a new physics effect into a Monte Carol simulation. If you want to do so, we would recommend to add such a new process into Geant4 following this guideline [1].

Here we will describe how to make physics processes already included in Geant4 available in GATE.

Basic Layout

To add a process into GATE you will need to create two classes.

  • Messenger class: This will provide the user interface, e.g. the commands in the mac script [2]
  • Wrapper class: This will wrap the Geant4 process to be compatible with GATE [3]

For the following tutorial, let us assume you want to incorporate the Cerenkov process into GATE.

First Step

You need to create four files. The *.hh files must be put into sources/physics/include, the *.cc files into sources/physics/src GateCerenkovMessenger.hh GateCerenkovPB.hh

Second Step

Write the wrapper code in and GateCerenkovPB.hh.


Include GateVProcess.hh as it provides the necessary wrapper functions. MAKE_PROCESS_AUTO_CREATOR will magically insert the process into gate without having to change source code elsewhere. The file should finally look like [4]


#include "GateVProcess.hh"


Include the Cerenkov code from Geant4 and the GATE Cerenkov messenger. You will now need to write for class functions

  • GateCerenkovPB::GateCerenkovPB():GateVProcess("Cerenkov")

Define the default particles for which this process is applied. Initialize the GateCerenkovMessenger

  • G4VProcess* GateCerenkovPB::CreateProcess(G4ParticleDefinition *)

Create the Geant4 process and configure it. Configuration values are provided by the Messenger class.

  • void GateCerenkovPB::ConstructProcess(G4ProcessManager * manager)

Add the process to the simulation and determine the order in which this effect will take place.

  • bool GateCerenkovPB::IsApplicable(G4ParticleDefinition * par)

Determine if the process is applicable for passed particle. Returns true or false

The file will look like [5]

Third step

Write the user interface command.

You need to fill the basic functions:

  • GateCerenkovMessenger::GateCerenkovMessenger(GateVProcess *pb):GateVProcessMessenger(pb)

Set initialization values and initialize user interface commands.

  • GateCerenkovMessenger::~GateCerenkovMessenger()


  • void GateCerenkovMessenger::BuildCommands(G4String base)

Define the UI commands, their description, default values and parameter ranges

  • void GateCerenkovMessenger::SetNewValue(G4UIcommand* command, G4String param)

Query the UI and set the values The complete files can be found here.[6] [7]

Third step - Details

The Geant4 Cerenkov process has three configuration options. The number of photons which can be created per step, the max velocity change of the particle due to the effect and whether to track second particles first.

Let us just consider the first one, the number of photons per step. This parameter is an integer, so lets create a protected variable

G4UIcmdWithAnInteger* pSetMaxNumPhotonsPerStep;
  • In void GateCerenkovMessenger::BuildCommands(G4String base) we connect it with the GUI
pSetMaxNumPhotonsPerStep = new G4UIcmdWithAnInteger((mPrefix+base+"/setMaxNumPhotonsPerStep").c_str(),this);

Define its name

pSetMaxNumPhotonsPerStep->SetParameterName("maxNumPhotonsPerStep", false);

Define the parameter range

pSetMaxNumPhotonsPerStep->SetRange("maxNumPhotonsPerStep >= 0");

A default value


And a description for the gui

pSetMaxNumPhotonsPerStep->SetGuidance("Set maximum number of photons created per step");
  • In GateCerenkovMessenger::SetNewValue(G4UIcommand* command, G4String param) we query the gui and set the content to a variable
if (command == pSetMaxNumPhotonsPerStep) { maxNumPhotonsPerStep = pSetMaxNumPhotonsPerStep->GetNewIntValue(param); }
  • Now we only need to create a function which enables the wrapper to query the configuration setting
inline int GetMaxNumPhotonsPerStep() const { return maxNumPhotonsPerStep; }

In the wrapper we can now access the value using messenger->GetMaxNumPhotonsPerStep()

Step 4

After you have created your files, copy them to the respective directories (sources/physics/include for *.hh, sources/physics/src for *.cc)[8] configure and compile Gate. The process should now be available. If you want to share this process with coleagues, you only need to provide this four files. Of course we would be very happy if you could provide the GATE community access to your physics process in order to steadily improve GATE.