KAHIBARO
Discord Login Register

10.1. Generic Sources

Creating a source

In GATE, a generic source represents a user-controlled particle generator. It does not include radioactive decay or complex time behavior by itself. Instead, you explicitly set which particle is generated, its position, direction, energy, and intensity. For a beginner, this is the simplest way to start injecting particles into a geometry and to understand how a simulation behaves before moving to radioactive sources.

In Python GATE (OpenGATE), you normally work with a simulation object, for example created earlier in your script. To create a new source, you add an entry to the simulation sources container. A typical pattern looks like this:

python
import opengate as gate
from opengate.util import world_size_from_cm
sim = gate.Simulation()
# world etc. defined earlier ...
source = sim.add_source("my_source", "GenericSource")

The first argument is the name of the source, which you choose. The second argument selects the type of source. Here you use "GenericSource" for a non-radioactive, user-defined source. Each source name must be unique in the simulation.

Once created, you configure the source properties through its attributes. The most basic ones you will always set are:

python
source.position = [0, 0, 0]
source.direction = [0, 0, 1]
source.energy = 511 * gate.g4_units.keV
source.n = 10000

The position is given in the coordinate system of the simulation, usually in millimeters. The direction is a 3-component vector. GATE will normalize this vector internally, so you only need to ensure it points in the desired direction. The energy is defined with appropriate units. The attribute source.n controls how many primary particles this source will generate during the simulation when you use a fixed number of events.

Many simulations involve more than one source. You can add multiple generic sources, each with its own name and configuration:

python
s1 = sim.add_source("left_beam", "GenericSource")
s2 = sim.add_source("right_beam", "GenericSource")

Each source can be positioned differently, have a different energy, or even a different particle type, which you define in the next section.

For time control, generic sources support configuration based on activity or on a fixed number of particles. A simple way for beginners is to specify the number of particles per run through n. Later, when you introduce simulation time and radioactivity units, you can use an activity-based configuration instead and relate the generated particles to a physical duration.

If you want to verify that your source exists and is correctly configured before running, you can print its parameters:

python
print(source)

GATE will show you the name of the source and all its main attributes, which is useful for debugging.

A generic source does not perform radioactive decay. It generates particles directly with the properties you define. If you need realistic decay chains or emission lines, use radioactive sources instead, not a generic source.

Particle definition

The key characteristic of any generic source is the particle it produces. GATE relies on Geant4 particle names, so you must use valid Geant4 identifiers. Common examples include "gamma", "e-", "e+", "proton", "neutron", and various ion definitions that you will see later.

After you have created a generic source, you specify its particle using the particle attribute:

python
source = sim.add_source("my_source", "GenericSource")
source.particle = "gamma"

This tells GATE that every primary generated by this source will be a gamma photon. To change the type, assign another valid name:

python
source.particle = "e-"

or

python
source.particle = "proton"

The typical names for basic particles are summarized in the following table:

Particle typeGATE / Geant4 name
Gamma photongamma
Electrone-
Positrone+
Protonproton
Neutronneutron
Optical photonopticalphoton

The choice of particle must be consistent with the physics list you use later in your simulation. If you choose a particle that is not covered by your physics configuration, it may be transported in a trivial way or produce no meaningful interactions.

You can define several sources with different particles in the same simulation. For instance, you might simulate a gamma source and a separate proton beam:

python
gamma_source = sim.add_source("gamma_source", "GenericSource")
gamma_source.particle = "gamma"
proton_source = sim.add_source("proton_beam", "GenericSource")
proton_source.particle = "proton"

Both sources will be active unless you explicitly disable one. This is helpful for studies that compare different radiation types under identical geometry and scoring conditions.

If you specify an invalid particle name, GATE will produce an error when you initialize or start the simulation. This is one of the first things to check if your simulation stops before running any events.

Always use valid Geant4 particle names in source.particle. A wrong name will prevent the simulation from running. Changing source.particle is the only way to change the particle type for a generic source; geometry, energy, and activity settings do not modify the particle species.

Views: 12

Comments

Please login to add a comment.

Don't have an account? Register now!