More documentation on the example can be found in this file

S. Larsson, May 2004

Acknowledgments to GEANT4 people, in particular to J. Apostolakis, J Generowicz, G. Folger, Vladimir Ivanchenko, M.G.Pia and S. Guatelli.


This example simulates electrons traveling through a 3D magnetic field. The Purging Magnet example is an application of Geant4 in a medical environment. It simulates a strong purging magnet in a treatment head. The geometry is very simplified. The major idea of this example is to implement an external magnetic field grid and test if the deviation of electrons are as expected in this particular field. The data (position, energy and momentum) are collected in a measurement volume.The data is stored in a HBOOK file if the user has set up the AIDA 3.0 environment and Anaphe is available.

How to run the example

- Run the PurgMag" executable.
- File PurgMag.TABLE needs to be available in the current directory in order to run correctly.
- For visualisation use vis.mac.

Default visualization is with OpenGL
- Interactive or batch modes possible.

Default: Interactive mode.

To run a certain number of events in interactive mode, type the following at the "idle>" prompt:

idle> run/beamOn NumberOfEvents
idle> exit
- Simulation histogram output is stored in purgmag.hbk
  • Ntuple with position, energy and momentum for electrons
  • Ntuple with position, energy and momentum for photons (not needed in this example, will be used in further development)
  • Ntuple with position, energy and momentum for positrons (not needed in this example, will be used in further development)
A default vizualisation macro (vis.mac) is pre-loaded before interactive runs.
Executing it
% $G4WORKDIR/bin/Linux-g++/PurgMag
runs vis.mac before giving you an interactive prompt.

Detector description

Simply a measurement volume. All particles entering the volume are scored.

Physics processes

This example uses the standard Electromagnetic processes.

Particle Generator

The PurgMagPrimaryGeneratorAction sets the initial state of tracks to
  • electrons 50MeV
  • Start position (0, 0, 15cm)
  • Momentum direction (0, 0, -1)

Geometry and materials

The world consists of Vacuum to minimize interactions of the electrons with the medium. The purging magnet is implemented as a 3D field grid of field values and geometerically as a pole gap made of iron. The measurement volume also contains vacuum. The field is interpolated using a simple linear interpolation in two dimensions (z and rho).


The design of the magnetic field was made with the OPERA 3D package which is an electromagnetic finite element and finite difference analysis software. The deviation in the y-direction (ey in Ntuple 1) has also been calculated in the OPERA 3D module TOSCA for comparison.
TOSCA: deviation y-direction: 35.112 cm
GEANT4: deviation y-direction: 35.170 cm (updated after PurgMag.pdf)

-- LucianoPandola - 21 Oct 2014

Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2014-10-21 - LucianoPandola
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Geant4 All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback