11.1. Introduction to GPS
Table of Contents
`G4GeneralParticleSource`
Geant4 provides a flexible primary particle generator class called G4GeneralParticleSource (usually abbreviated as GPS). It is designed to define complex particle sources using commands in macro files, instead of hard-coding all source properties in C++.
G4GeneralParticleSource is a concrete C++ class that you can use in your PrimaryGeneratorAction. Internally, it manages one or more configurable sources, each with its own particle type, energy distribution, spatial distribution, and angular distribution. You do not need to write separate C++ code for each of these cases, because GPS is driven almost entirely by built-in UI commands.
GPS is especially useful when you need any of the following in a beginner project. You may want an extended or non-trivial energy spectrum, such as a Gaussian distribution or a spectrum read from a file. You may need a source that occupies a surface or volume, for example a plane source, a cylindrical volume, or a spherical shell. You may require a non-uniform angular distribution, such as a cone around a given direction, a cosine law, or an isotropic distribution. You may want to combine several sources, for instance multiple radioactive spots or a background plus a signal source. You may also wish to tune and reconfigure the source with macro commands without recompiling.
In your PrimaryGeneratorAction::GeneratePrimaries method, using GPS usually means creating a G4GeneralParticleSource object as a data member, then calling its GeneratePrimaryVertex method for each event. The details of the source, including particle type, energy, position, and direction, are then controlled by macro commands such as /gps/particle, /gps/energy, /gps/position, and many others. Later sections of this course explain these commands and the available distributions in more detail.
Important GPS Idea: G4GeneralParticleSource separates how you configure the source (through macro commands) from how events are generated (a single call to GeneratePrimaryVertex in C++). This makes the source powerful and easy to modify without changing and recompiling your code.
GPS vs particle gun
Geant4 also provides a simpler primary generator called G4ParticleGun. Both GPS and the particle gun serve the same basic purpose, which is to create primary particles for each event. The crucial difference lies in how flexible and configurable they are.
The particle gun is a lightweight tool for simple, mostly fixed sources. In code, you typically choose one particle type, a single starting position, a fixed momentum direction, and a single energy, such as a 1 MeV gamma at the origin flying along the z axis. Changes to these properties generally require editing C++ code and recompiling, unless you add your own command interface around the gun.
G4GeneralParticleSource, in contrast, is designed for complex and changeable sources. GPS can handle multiple particles, multiple sources, and a large variety of distributions for position, angle, and energy. Everything is set through built-in macro commands, so you can adjust the source during a session or between runs without touching the code. For studies that involve scanning energies, changing source shapes, or trying different angular profiles, GPS is usually the better choice.
A useful way to think about them is this. Use G4ParticleGun when you are learning the basics or you only need a single, simple, monoenergetic beam or point source. Use G4GeneralParticleSource when you need realism, such as extended radioactive sources, complex spectra, or multiple configurable sources that you want to control from macro files.
Rule of thumb:
Use G4ParticleGun for simple, fixed test beams.
Use G4GeneralParticleSource when you need configurable or realistic sources with non-trivial spatial, angular, or energy distributions.
Views: 8
KAHIBARO