It is widely accepted that the Monte Carlo method applied to the simulation of radiation transport is able to compute accurate results in radiotherapy problems [8, 13]. However, general purpose Monte Carlo codes for radiation transport usually require exceedingly long simulation times to reduce the statistical uncertainty to acceptable levels. For clinical applications, several codes—in which approximations to the physical interaction and transport models were introduced—have been developed to overcome this limitation [6, 10, 12, 19, 21]. These codes lead to a gain in simulation speed at the expense of reducing the accuracy of the results or limiting the range of applicability. A further limitation for the implementation in clinical routine has been the difficulty and effort entailed in preparing, executing, and analyzing a simulation.

In this article we shall focus on the simulation of medical linear accelerators (linacs) and on the computation of the absorbed dose distribution in patients. These tasks require coding the linac geometry, which is a tedious and error-prone task, and the careful selection of certain transport parameters, which demands some knowledge of the physics of the Monte Carlo code employed. To surmount these constraints we have developed the PRIMO system. PRIMO generates the necessary input files for simulating a variety of Varian and Elekta linacs with the Monte Carlo code PENELOPE [1, 15, 16] and computes dose distributions in phantoms and computerized tomographies. It can also produce and import phase-space files in the International Atomic Energy Agency (IAEA) format [7]. In order to increase the simulation speed, we developed a set of dedicated variance-reduction techniques [4, 5, 14, 17]. PRIMO combines all these features and functionalities under a friendly graphical user interface, which includes various tools for analyzing and representing the generated data.

The end result is a program that handles the process of preparing, executing and analyzing the simulation of a linac and the computed dose distribution without requiring any previous knowledge from end users about the Monte Carlo method. Nonetheless, advanced users can have access to the details of the simulation by modifying the configuration files that govern the execution.

Code layers

PRIMO is designed as a layered software structure, which is schematized in Fig. 1. The lowermost layer is PENELOPE, formed by a set of subroutines that model the physics of the electromagnetic shower. PENGEOM, in the next layer, allows the description of material objects limited by quadric surfaces, such as those employed in this work for linac geometry modeling. PENGEOMis included in the PENELOPE distribution.

Fig. 1
figure 1

Schematic of the layered structure of the PRIMO simulation system

In PENELOPE, end users are responsible for writing a main program that defines the source of particles, the quantities of interest to be tallied and the variance-reduction techniques to be applied. PRIMO relies on PENEASY [17], a general purpose, modular main program that includes several source models and tallies. PENEASY incorporates PENVOX, a set of routines that handle voxelized geometries, or a combination of voxels and quadrics [2, 3]. Thus, the second layer of our software structure, which is devoted to the geometry, is formed by two parts: PENGEOM and PENVOX. Sitting above it, the PENEASY code provides the steering main program for the Monte Carlo simulation.

The input files required to run the PENELOPE/PENEASY system are created during run time by PENEASYLINAC [17], which forms the fourth layer of the structure. This code accepts as input the linac model and its configuration, which is determined by

  • whether the machine is operated in the electron or photon mode,

  • the nominal beam energy,

  • the position of the jaws, and

  • the configuration of the multileaf collimator (or electron applicator size in electron mode).

Based on these choices, PENEASYLINAC creates a quadric geometry file for PENGEOM and a configuration file for PENEASY. This latter file defines the particle source, the values of PENELOPE’s parameters governing the transport physics, and the values of the parameters for the applied variance-reduction techniques.

The upper code of the scheme is the Graphical Layer for the Automation of the Simulation System, designed for the modeled linacs, which we named Linac-GLASS. This layer is basically an elaborate user interface to operate PENEASYLINAC, to run PENELOPE/PENEASY, and to collect the simulation results and produce graphical plots of the data.

The parts of the system related to Monte Carlo simulation are written in Fortran, while the analysis tools and the graphical user interface are coded in Delphi. Owing to the latter, PRIMO runs only on Windows.

PRIMO work flow

Linac-GLASS is designed to reduce the user’s effort to accomplish the steps of simulation setup, execution, and analysis of the results. Any interface element available in GLASS can be associated to one of these three main categories. A brief description of the scope and functions available is given below.

Simulation setup

Radiation source

Simulation setup windows are used to define the radiation source. To simulate a linac, the accelerator model and the operation mode (photon or electron) must be chosen. The currently available linacs from Varian are Clinacs 600 C, 600 C/D, Unique, the series 18, 21, and 23, and TrueBeam, the latter by means of the phase-space files distributed by Varian in the IAEA format. PRIMO also includes the geometries of the Elekta linacs SL/i and MLCi.

Once the linac model has been chosen, users should specify the nominal energy. For each nominal energy there is a corresponding default set of primary beam simulation parameters. These default values can be modified to adequately reproduce experimental dose profiles. The shape of the radiation field is further defined by positioning the jaws, multileaf collimators, or electron applicators according to the linac model and operation mode chosen.

PRIMO decides the most adequate variance-reduction techniques to be employed and determines the parameters related to them. Notwithstanding, users can modify all parameters that govern the simulation.

The simulation of a linac can be used either to tally a phase-space file in the IAEA format or a dose distribution. Simulations can be started either from the primary electron source of the linac, as it has been already described, or from a previously tallied phase-space file. PRIMO can use imported phase-space files that have been written by other Monte Carlo codes using the IAEA format.

Dose tallying

Dose distributions can be estimated inside a phantom or in a computerized tomography study. For the latter, PRIMO imports DICOM-CT images (Digital Imaging and Communication in Medicine Standard) from which it can construct a voxelized geometry for the estimation of the dose. The importing process requires the conversion of Hounsfield units into mass density values. Additionally, each voxel of the computerized tomography must be associated with a material medium [9]. This is done by using the threshold method [20] interactively aided by the display of a frequency histogram of Hounsfield units and of density maps superimposed to the material maps. There are 40 materials available for the creation of voxelized geometries.

Structures such as planning target volumes or organs at risk can be delineated in the computerized tomography volume and used to calculate dose–volume histograms. Structures can also be imported from an external treatment planning system provided they conform with the DICOM RT-STRUCT standard.

Execution

The simulation can be separated by geometrical segments. Three segments are predefined, namely, the fixed upper components, the movable components of the linac and the dose tallying geometry (binned phantom or voxelized tomography). The current version can distribute a simulation in up to 24 processing cores of a single computer. When all the processes are completed PRIMO combines the corresponding dose distributions into a single dose map. Simulation progress can be tracked in run time.

Analysis

GLASS provides a complete set of tools for analyzing both phase-space files and dose distributions. The analysis of the former includes 2D plots of the spatial distribution of particles and the energy spectrum in the phase-space plane. Phase-space files produced by PRIMO can be filtered by the material medium where the particles were produced. This feature is useful for particle contamination studies or for further optimization of the simulation.

Dose estimation results are presented as 3D dose distributions superimposed to the computerized tomography volume or phantom. Users can navigate these volumes through axial, coronal, and sagittal slices. Lateral dose profiles and the depth curve are shown during navigation. In the case the dose distribution has been estimated in a computerized tomography volume, cumulative and differential dose–volume histograms are plotted for the delineated or imported structures. A useful feature of PRIMO is the possibility of importing experimental data from a dosimetry system. Simulated and experimental data are compared by means of dose profiles, differential plots, and the gamma test [11].

An example: prostate irradiation

In this section we describe the steps involved in creating and simulating a typical radiotherapy treatment plan with PRIMO. In this example a conformal technique is employed to irradiate the prostate with eight radiation fields with equally spaced gantry angles of 45°, starting at 0°. A simulation of the upper part of the linac, a Varian Clinac 2100 C/D, from the primary electron source downstream to a plane located upstream of the jaws was launched. The default set of parameters for the radiation source corresponding to a photon beam with nominal energy of 6 MV was chosen. The default parameters for this beam consist of a primary pencil beam source of 6.26 MeV electrons. A total of 5 × 108 primary electrons were simulated and a phase space was tallied. The splitting-roulette [14] variance-reduction technique was used in this simulation segment. This phase-space file has to be computed only once for all the considered radiation fields and phantoms at a given nominal energy. Therefore, the time devoted to this segment, although reported, is not taken into account to compute the total simulation time.

Prior to field setup, the set of images stored in DICOM-CT format was imported into PRIMO and the corresponding voxelized geometry was generated. The materials selected were air, adipose tissue, soft tissue, and compact bone. The planning target volumes and the organs at risk where delineated with PRIMO, including the prostate gland, and the rectum and bladder, respectively.

A second simulation segment including the jaws and the multileaf collimator was configured and run. Eight fields were defined to irradiate the prostate planning target volume. The field size was of 7.0 cm in the patient long-axis direction and ranged from 6.7–8.1 cm in the orthogonal direction. The shape of the fields were conformed to that of the prostate gland planning target volume by using a high definition Millenium multileaf collimator (MLC 120HD) as shown in Fig. 2. The phase space obtained in the previous simulation segment was used as the source of particles. The movable skins [5] variance-reduction technique applied to the multileaf collimator was used in this simulation segment. This technique consists of considering certain collimating elements of the linac as formed by skin and nonskin zones. Skins are regions where charged particles are likely to emerge and contribute to beam contamination. In the skins the simulation of charged particles is discontinued at relatively low energies so as to ensure that radiation transport is performed to high accuracy. Regions that will absorb nearly all charged particles are defined as nonskins and the absorption energies of these particles are accordingly set higher in order to avoid a waste of computation time. The skin depth depends on the beam energy. PRIMO automatically sets the position of the interfaces dividing both types of regions according to the nominal energy selected by the user. A screenshot of the 3D dose distribution obtained for the simulation of the plan described above is shown in Fig. 3.

Fig. 2
figure 2

Screenshot of PRIMO showing the beam’s eye view of the field with gantry angle of 45° superimposed to the digitally reconstructed radiograph for the example of prostate irradiation

Fig. 3
figure 3

Screenshot of PRIMO showing the dose distribution obtained for prostate irradiation with eight fields. The cumulative dose–volume histogram for the delineated structures is also plotted

Simulation timings

All simulations were run on an eight-core Intel Xeon processor running at 2.67 GHz. The simulations were distributed among the eight cores in all cases. The voxelized geometry had 256 × 100 × 256 voxels of size 1.86 × 3.00 × 1.86 mm3. PRIMO can distribute the simulation of multiple fields among the cores of a computer. The simulation time of segment 1 (from primary electron source down to the upstream face of the jaws) required 3.8 h. The combined simulation time of segments 2 (jaws and multileaf collimator 120HD) and 3 (computerized tomography) was 1.8 h, reaching an overall relative standard uncertainty of 2 %.

In order to put into perspective the simulation time needed for prostate irradiation, we computed the dose distribution in a water phantom for several reference fields. In all cases where the dose was tallied in water, the bin size was set to 2 × 2 × 2 mm3. Also, in all cases, the average standard statistical uncertainty was 2 %.

All simulation times, in hours, are reported in Tab. 1. It is interesting to note that the computation of the dose in the water phantom for the 10 × 10 cm2 reference field with 6 MV photons takes a time (0.9 h) comparable to that (1.8 h) required for the case of the tomographic volume. This fact indicates that the algorithm handling voxelized structures is efficient and that due to usage of movable skins in the multileaf collimator geometry the time employed in the simulation of this complex structure is moderate.

Tab. 1 Simulation times in hours for several reference fields. Columns s1, s2, and s3 correspond to the simulation time required for segments 1 (s1, upper part of the linac), 2 (s2, lower part of the linac), and 3 (s3, water phantom or computerized tomography), respectively. In all cases the standard statistical uncertainty was 2 %. All doses estimated in water phantoms were tallied on 2 × 2 × 2 mm3 bins. The dose estimated on a computerized tomography (8 fields) had voxel size equal to 1.86 × 3.00 × 1.86 mm3. In the case of the TrueBeam simulation we used the phase-space file distributed by Varian for a 6 MV free flattening filter (FFF) beam, which was tallied just above the jaws. Consequently, the time s1 for TrueBeam is not reported. All simulations were run on an eight core Intel Xeon computer at 2.67 GHz. Simulation time for s3 can be further decreased by increasing simulation time on s1. In general, s1 is simulated once and for all

The minimum statistical uncertainty of the absorbed dose that can be reached with a given phase-space file is conditioned by the latent variance [18] associated to this phase-space file. Following Sempau et al. [18], it can be derived that the variance, σ2, of the absorbed dose obtained from a Monte Carlo simulation of a linac can be expressed as

(Equ1)

The quantities c 1 and c 2,3 are independent from the simulation time. They are related to the simulation of segment 1 and segments 2 and 3, respectively. The time devoted to simulate segment 1 is denoted by t 1. Equivalently, t 2,3 corresponds to the simulation time of segments 2 and 3. From the previous equation it follows that the variance can be maintained constant while reducing t 2,3, provided t1 is appropriately increased (Tab. 1). Notice that by increasing t 2,3 up to infinity, the latent variance c 1/t 1 of the phase-space file tallied at segment 1 is asymptotically reached.

Conclusion

PRIMO facilitates the Monte Carlo simulation with PENELOPE of most Varian and Elekta linacs and the estimation of the dose distribution in water phantoms and computerized tomographies. Knowledge of the Monte Carlo method, of programming, of the peculiarities of PENELOPE, and of the physics of radiation transport is not necessary in order to set up, run, and analyze the simulation of a linac and the subsequent dose distribution. Users of other Monte Carlo codes can also benefit from PRIMO thanks to the possibility of importing and simulating external phase-space files written in the IAEA format.

Owing to a number of specifically developed variance-reduction techniques, PRIMO efficiently simulates linac geometries. Most cases can be simulated in the timeframe of 1–2 h using a single desktop computer, obtaining a dose distribution within the routine clinical requirements. Also, the code is capable of computing a dose distribution produced by a multiple-field irradiation. Users with a multiple-core computer can reduce simulation time by automatically distributing the simulation among the available computing cores. PRIMO is free software that can be downloaded from http://www.primoproject.net. In a nutshell, PRIMO is an automated, fully Monte Carlo-based, linac simulator and dose calculator, which is both user-friendly and self-contained.