Advanced Example xray_fluorescence

X-ray Fluorescence

XrayFluo is an advanced Geant4 example reproducing various setups for PIXE or XRF experiments.

A sample macro, livermore.mac, is provided.

The detector is a monolithic Si(Li) or HPGe detector, with real response functions stored in response.dat and SILIresponse.dat.

The sample is a simple box whose material can be selected. It can be irradiated with different particles, using different incident-energy spectra and different primary-generator shapes.

Two diaphragms reproducing those used to collimate the incident beam on the sample and detector during the test beam are also simulated.

The aim of this advanced example is to illustrate the generation and analysis of de-excitation products available in Geant4.

Particle generation is performed using G4ParticleGun. The example shows how to use it to obtain either a beam with a circular cross-section or a particle source that is isotropic in space.

The example also includes the possibility of generating particles according to a specified energy spectrum:

  • B_flare.dat, C_Flare.dat, and M_flare.dat contain photon spectra during solar flares.
  • mercury2_flx_solmax.dat and mercury_flx_solmin.dat contain proton spectra during solar maximum and solar minimum conditions, respectively.
  • merc2_flx_alp_max.dat and merc_flx_alp_min.dat contain alpha-particle spectra during solar maximum and solar minimum conditions, respectively.

These features are available by changing hard-coded values in XrayFluoRunAction.cc.

Histogramming facilities are provided using the built-in Geant4 g4analysis tools.

To use the visualisation features, the environment must first be configured as described in the Geant4 manual.

Path to the low-energy database:

setenv G4LEDATA /your/path/to/geant4/data/G4EMLOWXX.XX

Path to the X-ray fluorescence data files. If this variable is not set, the current working directory is assumed:

setenv XRAYDATA /path/to/detector/and/input/spctra/files

1. Run

After compiling the program, execute a sample simulation by typing, for example:

$G4WORKDIR/bin/Linux-g++/XrayFluo

The program then gives the user four options:

Please Select Simulation Geometrical Set-Up:
1 - Test Beam
2 - Infinite Plane
3 - Planet and Sun
4 - Phase-Space Production

The first three options select different experimental setups: a test beam, an infinite plane, and a planetary geometry. The fourth is a simplified version of the first, without a detector, intended only to generate a tuple containing particles generated in or exiting the sample.

To run a macro, type:

idle> execute command "/control/execute xxxxx.mac"

If the analysis options are enabled, histograms are automatically stored in the corresponding files. ROOT is the default format.

To launch the application in batch mode, specify the macro filename and the option number after the executable filename:

$G4WORKDIR/bin/Linux-g++/XrayFluo xxxxx.mac 1

2. Detector Description

The telescope and detector geometry is defined in XrayFluoDetectorConstruction.cc and related files.

3. Detector Properties

Detector-specific properties are described in XrayFluoSiLiDetectorType and XrayFluoHPGeDetectorType, both derived from XrayFluoVDetectorType.

Additional detector types can be added by creating other implementations of XrayFluoVDetectorType. Detector-type selection is made in XrayFluoDetectorConstruction and can be modified through the following UI command:

/apparate/detector

Other commands are available to simulate sample granularity:

/apparate/sample
/apparate/sampleGranularity
/apparate/GrainDiameter

The grains are spheres arranged in a compact cubic structure, corresponding to a superposition of maximum-density planes with an ABC ABC stacking sequence. The fundamental cell is face-centred cubic.

4. Physics Processes

The user can select a preferred pre-built physics list that produces atomic de-excitation products:

  • Livermore
  • Standard, options 0, 1, 2, or 3
  • Penelope

5. Event Generation

Event generation is performed using G4ParticleGun with some modifications. See XrayFluoParticleGeneratorAction.cc.

Event generation is controlled by commands in the /gun/ category. Consult the help documentation for further details. Two commands are highlighted here:

  • /gun/loadGunData <filename>: used with setup 1. It loads the ntuple created in setup 4. All loaded particles are generated and directed toward the detector, which can improve the efficiency of detector studies.
  • /gun/loadRayleighFlag <true/false>: allows the user to decide whether backscattered primary particles should be loaded and directed toward the detector. To be effective, this command must be used before /gun/loadGunData.

Last updated: 24/11/2026 by M. A. Cortes-Giraldo