Monitor unit calculation in electron therapy using Monte Carlo Simulation: a GUI for the phase-space field trimming

Purpose: We developed a graphical user interface (GUI) for electron phase-space field trimming using Monte Carlo simulations. This GUI can be used for monitor unit (MU) calculation in electron therapy. Methods: The GUI and electron field trimming algorithm were developed using MATLAB and C code. Phase-space files for the electron fields were generated using the EGSnrc code based on a Varian 21EX Linac with variables of applicator size, field size and energy. Verification of the alogrithm was carried out by comparing the relative output factor, which was used for MU calculation, predicted by Monte Carlo simulations and from actual measurements. Results: Our electron field trimming algorithm was found to be about five times faster than the original Monte Carlo simulation. Clinically, the GUI performed best when using voxel size ≥ 0.3 × 0.3 × 0.3 cm3, and field size larger than 2 cm in radius based on an acceptable deviation of 2%. Conclusion: A GUI for generating irregular field for MU calculation using Monte Carlo simulations was created as a user-friendly tool in electron therapy.


Introduction
Electron therapy is often used clinically in the treatment of superficial tumours or subcutaneous diseases [1]. Treatments are usually delivered with a single direct electron field at a nominal source-to-surface distance (SSD) equal to 100 cm. When the radiation dose is prescribed by radiation oncologist to the tumour, monitor unit (MU) will be calculated based on variables of field size, applicators, beam energy and treatment distance [2,3]. MU is a measure of output from a linear accelerator (Linac) using an internal ionization chamber to measure the dose delivered to the patient, and is calibrated to give an absorbed dose under specific conditions [4]. The MU can be calculated using a formula with variables of effective SSD (SSD eff ) and relative output factor (ROF) determined using the sector-integration method for an irregular field [2]. The ROF as a function of field size, applicator size and beam energy for an irregular electron field can be determined using the classical sectorintegration method or Monte Carlo simulation, which is used as a benchmark in electron dose calculation [5].
Monte Carlo simulations, as used in this study, determine a numerical result through random sampling [6]. Since the accuracy of the result depends on the number of experiments or histories, hundred millions of histories are often required to produce a phase-space file specifying the particle data of an irregular electron field. Therefore, Monte Carlo methodology is computer time consuming [7]. For example, to determine the ROF from a phase-space file for an irregular electron field, a complete Monte Carlo simulation may easily take several hours which is unacceptable in a clinical setting. Therefore a trimming algorithm is developed to significantly reduce the run time of the overall simulation, by trimming particles in the scoring plane from a phase-space file that lie outside the arbitrary field. These outlier particles do not make a significant contribution to the ROF for large enough fields, if the distance between the dose prescription point and the field edge is larger than the lateral electron scattering path of the beam. Using the trimmed phase-space field for the Monte Carlo simulation will result in large reductions in run times because fewer particles are required for the simulation [8,9]. Any further distribution of this work must maintain attribution to the author(s) and the title of the work, journal citation and DOI.
The aim of this note is to develop a robust and quick algorithm as part of a larger clinical software package that would allow the medical physics and radiotherapy staff to conveniently automate the entire MU calculation process using Monte Carlo simulation. Our graphical user interface (GUI) [10,11] for electron phase-space field trimming has the following features: • A new algorithm to trim the phase-space file generated by the EGSnrc code [12].
• The image of a custom field can be imported into the GUI and used as input to the trimming algorithm.
• The GUI is extremely portable and has been tested to work on both Microsoft Windows and Linux systems.
• The GUI has low system requirements, only requiring MATLAB with the Image Processing Toolbox and EGSnrc system.
• The GUI is robust and can detect the results of past trials and reuse them to increase the speed of future MU calculations.
• The GUI allows modification of certain parameters by the radiotherapy staff including voxel size, phantom size, and the number of times to reuse phase-space histories in the simulation.

Electron MU calculation
The MU for electron treatment delivery can be calculated as follows [10]: In equation (1) In equation (2), D is the dose for a custom field, FS and FS o are the custom and reference field, while d m and app are the depth of maximum dose and applicator size.

Workflow and computer programming
The MU calculation can be divided into three main stages, which deal with completely independent portions of the ROF calculation. There is distinction between the generation of the Monte Carlo phase-space file by the BEAMnrc [13] and the prediction of the dose deposited at d m by the DOSXYZnrc [14]. Figure 1 shows the flowchart depicting the integration of all components in the electron MU calculation using Monte Carlo simulation.
In figure 1, the phase-space file of the electron field with size equal to the applicator (e.g. 10×10 cm 2 ) is generated in Stage 1 using the BEAMnrc code. The phase-space file is a binary file containing particle data (e.g. type, energy, position and direction) scored on the z-plane at SSD=100 cm [13]. Since patient's tumour may vary in shape, an irregular field fitted to conform the shape of tumour is needed in the treatment delivery. The generation of irregular phase-space field requires a trimming from the applicator square field in Stage 2 ( figure 1). Finally, the ROF required in the MU calculation, according to equation (2), is determined by doses predicted using the DOSXYZnrc code in Stage 3, and the MU is therefore calculated by equation (1).

GUI and verification of simulation
The GUI as shown in figure 2, and the trimming algorithm were written in MATLAB, whereas the file manipulation functions were written in C. For verification of simulation, the phase-space files were generated based on the Varian 21EX Linac at SSD=100 cm for electron beam energies of 4, 6 and 9 MeV using a 10×10 cm 2 applicator. The phase-space files are stored in a binary format containing a header followed by a record of all scored particles.
Before trimming can begin, the user supplies the GUI (figure 2) with an image file containing an outline of the electron field needed for the treatment delivery. Image recognition is used to determine the external outline of the field which is then filled in to create a solid shape. The user then scales and orients the field within the  scoring plane of the phase-space file before the field is vectorized to create a 2D logical matrix of the location of each pixel. The pixels are recorded with an accuracy of 0.01 cm. This default accuracy can be increased for finer trimming, which may be necessary for intricate field shapes. Various arbitrary fields were used to test the dexterity of the GUI as shown in figure 3.
The trimming algorithm exploits vector manipulation to quickly determine which particles are inside the field by using the X and Y particle coordinates to index the 2D logical matrix of pixel locations. If the indexed value is zero then the corresponding particle is located outside the field and is therefore trimmed. The remaining particles are written out to another phase-space file in the EGSnrc format. During trimming, particles crossing the scoring plane more than once (i.e. multiple passers) are discarded from the phase-space file, because they would not contribute significantly to the ROF calculation.
The ROF estimates were verified by comparing them with experimental measurement [15]. For clinical use, a percentage error of up to 2% between simulation and measurement is considered acceptable [16]. The ROF measurements were carried out using circular fields with radii of 2-5 cm, and beam energies of 4, 6, and 9 MeV.

Results and discussion
When running the phase-space field trimming, it is found that reading and writing particle data was the most time consuming process, whereas the trimming operation was the least. The run time performance of the reading, writing, and trimming operations scale linearly with the number of histories in the phase-space file and is shown in figure 4. Figure 5 shows the plots of the particle distribution in the scoring plane for the input phase-space files ( figure 3) and for the trimmed phase-space files using each of the four fields. By comparing figures 5 and 3, we can see that the GUI successfully trimmed the phase-space files. However, even if a 10×10 cm 2 field is used in the trimming process, certain particles will be removed because there are particles outside the simulated applicator, and multiple passers are discarded.
As the GUI is very memory intensive, it must process the particles from the phase-space file in batches. The number of particles in each batch is hardware dependent and must be set correctly before use. While increasing the batch size may cause the GUI to run out of memory and crash prematurely, it may also increase the performance of the GUI. This batch processing approach allows the GUI to handle any sizes of phase-space file. Comparing the run time of MU calculation with and without using the trimming algorithm, it is found that the former needs 0.1-0.9 h while the latter needs 5.1-6.3 h. The calculation was done using a PC with an Intel Core i7 desktop processor, 32 GB Ram and a 1TB SATA internal hard disk. Calculation speed can further be increased by employing solid state hard disk or cell processors [7].
The percentage deviations of ROF between measurement and Monte Carlo trimming are shown in table 1 with number of histories equal to 20 million.
In table 1, it is seen that the accuracy of ROF value varies with changing voxel size. It shows that using a voxel size of 0.3×0.3×0.3 cm 3 yields the least amount of percentage error for fields with radii greater than 2 cm.  This is due to a larger voxel size capturing enough dose to yield a meaningful ROF value. However, increasing the voxel size too much may cause the ROF value to drift from its true value at d m . Moreover, it is found that there were very high percentage errors for fields with radii smaller than 2 cm. It shows that the phase-space trimming approach is a poor predictor of ROF for very small fields. This is because trimming the phase-space field will remove particles that scatter at the edge of the field. For large fields with edges far from the central axis, the scattering effect may not be significant. This is because the electron range is not long enough to reach the centre of the field from the edge, and the electron range depends on the energy of the electron beams. For 4, 6 and 9 MeV electron beam energies, the electron ranges are about 2, 3 and 4.5 cm, respectively. However, for small fields (< 2 cm) or even irregular fields that have their edges very close to the central axis, the loss of scattering information will impact the ROF calculation [17,18]. Although clinically used fields tend to be larger than 2 cm in radius, it is still recommended to use voxel size not smaller than 0.3×0.3×0.3 cm 3 on the GUI.

Conclusions
The phase-space trimming GUI is a platform independent tool that can trim any arbitrary field as needed from a bigger phase-space file to an accuracy of 0.01 cm (by default) or more. The run time performance of the trimming algorithm is hardware dependent but has been shown to scale linearly with the number of particles in the input phase-space file. It is concluded that the GUI can help to calculate MU for electron therapy clinically with field size > 2 cm in radius, using voxel size 0.3×0.3×0.3 cm 3 .

Data availability statement
The data that support the findings of this study are available upon reasonable request from the authors.