1. Introduction

The Monte Carlo (MC) method history began two centuries before its computational implementation that happened in the period of World War II (1939–1945). The MC method conception starts in 1733 with the Probléme de l'aiguille (Needle's problem) by Georges-Louis Leclerc, known as the Comte de Buffon [1], which is enunciated as:

Sur un plancher qui n est formé que de planches égales & parallèles, on jette une Baguette d'une certaine longueur, & qu'on suppose sans largeur. Quand tombera-telle franchement íùr une seule planche? Leclerc [1], p. 44

#### or, translated to English:

On the floor formed only of equal boards placed in parallel, one throws a needle of a certain length which and supposed without width. When will this needle fall on one specific board?

The first solution proposed by Leclerc [2], in 1777, is considered one of the oldest geometrical probability solutions. The method basically consists in generating successive random samples N that will be tested in a statistical model representing the statistical probability. To use this method, one needs to satisfy the main condition: the random variable evaluated must be independent, which means that previous events of interest may not have (may have the minimum) an influence on the successive tryings. In the needle case, Leclerc ([2], pp. 100–104), presented a solution considering the distance D of the limits of each wood board and the length l of the needle (l < D) taking the probabilities of crossing zero lines and one line as [3].

"time dependence" and is suitable for a stochastic calculation, which depends on a sequence of random numbers generated during the simulation. It means that a new execution of the solution with a new (different) sequence of random numbers for the same simulation will not give identical results. However, it will return values that agree with the results obtained from the previous sequence within some "sta-

Monte Carlo's Core and Tests for Application Developers: Geant4 and XRMC Comparison…

In a general manner, the problems that are in essence managed by random phenomena can be solved by applying MC [11, 12]. The main idea of MC method is to estimate a quantity, based on systems that use random numbers to simulate random walks [11], with an estimator computed from observed/experimental data [12]. Considering this idea, the core system of a MCCT is based on a randomized algorithm (random number generator) to manage probabilities (libraries of sampling distribution) [12]. A MCCT has other tools implemented, but for an AD, the knowledge of the MC core limitations is essential to estimate the accuracy and

Taking into account the proposition of MCCT for transport radiation, one may define core as the computational random number generator (randomized algorithm) and the cross sections for each possible process of interaction (probabilities, in the case of photons that can be the total attenuation cross sections for each possible process, or the differential cross sections—if applicable—or the energy transfer cross sections or the energy absorption cross sections). Let's think about a traditional MC simulation as is represented in the following scheme (Figure 1). It is important to keep in mind that this is a simplified scheme of transport radiation designed to aid the understanding of the basics of MC processing. Before one starts to run<sup>1</sup> an event<sup>2</sup> in a MCCT, one may define the simulation universe (or world), including the geometry, material composition of the simulated objects, and, if

The run starts always with the generation of a primary particle (emitted by the radiation source), and it finishes when all histories were run. As one may observe in Figure 1, the system starts the run, after the geometry built and physics definition, by initializing the counter of the number of histories (VARnh). This variable is compared to the expected total number of histories (nh), so if the VARnh is equal to nh, then the termination of run is performed, or if VARnh is smaller than nh, then a new history is started by generating a new primary particle. In the generation of primary particle, if the source is defined by an energy distribution and/or position distribution (linear, planar, or volumetric source) and/or momentum direction distribution, the random number generator will be evoked (one to each distribution needed). After the primary particle of the source is generated, the information about this particle is recorded at the beginning of step (pre-step information). Following the step execution, the end of the step information will be generated

a. Is this particle inside the world? In MC simulation, the geometrical limits to follow the transport of radiation are the limits described on the geometry by the larger volume (the world) that will contain the other volumes. Some MCCTs have no world volume defined; usually if they are specific MC using variance reduction techniques that force the radiation to interact with the

<sup>2</sup> EVENT: every interaction that happened to one primary particle or its secondaries until they die or leave the universe of simulation. It is defined as the collections of steps performed by one particle.

necessary, the additional information needed for the interaction.

(post-step information) and tested. The traditional MCCT tests are:

<sup>1</sup> RUN: word used to define the execution of the MC code.

81

tistical error" or in a statistical fluctuation range [11].

DOI: http://dx.doi.org/10.5772/intechopen.88893

precision of the results.

$$p\_0 = \mathbf{1} - 2\mathbf{r}\theta \text{ and } p\_1 = 2\mathbf{r}\theta \text{, where } r = \frac{l}{D} \text{ and } \theta = \frac{1}{\pi}I$$

It seems to be a simple problem, but its solution ensued a sequence of different mathematical methodologies [3]. For example, in 1812, Laplace, using his theory of probability and theoretical calculations based on this methodology to determine an approximation to the π value [3, 4], presented a generalized solution in 3D space [3–5].

Following the main condition of independence for random variable enunciated by Leclerc [2], the MC method was proposed as an alternative solution to analytical mathematics to evaluate the behavior of random samples to predict a statistic sample distribution or a statistic behavior. This behavior can be assessed by empirical processes of drawing sequences of independent random samples and observing its behavior [6]. The strategy is simple in concept, but it is time-consuming, being the first computerized MC simulation developed and implemented by the working team of John and Klara von Neumann and Nick Metropolis with the advent of the computers in 1947–1948 [7].

There are different algorithms [8–10] implemented to apply different MC solutions by using different computational tools. Since the objective of this chapter is to present MC validation and/or reliability for application developers (AD), on a specific study case, we will not detail the different MC algorithms.

There are several characteristics that can be used to classify MC computational tools (MCCT); however, based on the objective of this chapter, the available ones will be classified according to its applicability as general and specific MCCTs. So, in section 2, the general concepts and MCCT code core (cross-sectional libraries and pseudorandom generators), including the specific and general MCCTs characteristics and some codes available nowadays, are going to be presented. In section 3, the validation and reliability of MCCT code concepts and main methods, including its limitations on the implementations of cross-sectional libraries and random generators, are going to be discussed. To illustrate this, a case study of validation for dosimetry in mammography using two MCCT methods for radiation transport (Geant4 and XRMC) is going to be presented. In the last section, the final considerations on choosing a MCCT and important issues on validation or reliability tests will be presented.

### 2. Monte Carlo general concepts and core

The MC method may be used to solve different kinds of problems. It may be used to solve problems that could also be solved by deterministic calculations, but it is usually more time-consuming than those and can increase the complexity of the solution. MC must to be applied, generally, when the change in the model follows a

### Monte Carlo's Core and Tests for Application Developers: Geant4 and XRMC Comparison… DOI: http://dx.doi.org/10.5772/intechopen.88893

"time dependence" and is suitable for a stochastic calculation, which depends on a sequence of random numbers generated during the simulation. It means that a new execution of the solution with a new (different) sequence of random numbers for the same simulation will not give identical results. However, it will return values that agree with the results obtained from the previous sequence within some "statistical error" or in a statistical fluctuation range [11].

In a general manner, the problems that are in essence managed by random phenomena can be solved by applying MC [11, 12]. The main idea of MC method is to estimate a quantity, based on systems that use random numbers to simulate random walks [11], with an estimator computed from observed/experimental data [12]. Considering this idea, the core system of a MCCT is based on a randomized algorithm (random number generator) to manage probabilities (libraries of sampling distribution) [12]. A MCCT has other tools implemented, but for an AD, the knowledge of the MC core limitations is essential to estimate the accuracy and precision of the results.

Taking into account the proposition of MCCT for transport radiation, one may define core as the computational random number generator (randomized algorithm) and the cross sections for each possible process of interaction (probabilities, in the case of photons that can be the total attenuation cross sections for each possible process, or the differential cross sections—if applicable—or the energy transfer cross sections or the energy absorption cross sections). Let's think about a traditional MC simulation as is represented in the following scheme (Figure 1). It is important to keep in mind that this is a simplified scheme of transport radiation designed to aid the understanding of the basics of MC processing. Before one starts to run<sup>1</sup> an event<sup>2</sup> in a MCCT, one may define the simulation universe (or world), including the geometry, material composition of the simulated objects, and, if necessary, the additional information needed for the interaction.

The run starts always with the generation of a primary particle (emitted by the radiation source), and it finishes when all histories were run. As one may observe in Figure 1, the system starts the run, after the geometry built and physics definition, by initializing the counter of the number of histories (VARnh). This variable is compared to the expected total number of histories (nh), so if the VARnh is equal to nh, then the termination of run is performed, or if VARnh is smaller than nh, then a new history is started by generating a new primary particle. In the generation of primary particle, if the source is defined by an energy distribution and/or position distribution (linear, planar, or volumetric source) and/or momentum direction distribution, the random number generator will be evoked (one to each distribution needed). After the primary particle of the source is generated, the information about this particle is recorded at the beginning of step (pre-step information). Following the step execution, the end of the step information will be generated (post-step information) and tested. The traditional MCCT tests are:

a. Is this particle inside the world? In MC simulation, the geometrical limits to follow the transport of radiation are the limits described on the geometry by the larger volume (the world) that will contain the other volumes. Some MCCTs have no world volume defined; usually if they are specific MC using variance reduction techniques that force the radiation to interact with the

The first solution proposed by Leclerc [2], in 1777, is considered one of the oldest geometrical probability solutions. The method basically consists in generating successive random samples N that will be tested in a statistical model representing the statistical probability. To use this method, one needs to satisfy the main condition: the random variable evaluated must be independent, which means that previous events of interest may not have (may have the minimum) an influence on the successive tryings. In the needle case, Leclerc ([2], pp. 100–104), presented a solution considering the distance D of the limits of each wood board and the length l of the needle (l < D) taking the probabilities of crossing zero lines and one

Theory, Application, and Implementation of Monte Carlo Method in Science and Technology

It seems to be a simple problem, but its solution ensued a sequence of different mathematical methodologies [3]. For example, in 1812, Laplace, using his theory of probability and theoretical calculations based on this methodology to determine an approximation to the π value [3, 4], presented a generalized solution in 3D

Following the main condition of independence for random variable enunciated by Leclerc [2], the MC method was proposed as an alternative solution to analytical mathematics to evaluate the behavior of random samples to predict a statistic sample distribution or a statistic behavior. This behavior can be assessed by empirical processes of drawing sequences of independent random samples and observing its behavior [6]. The strategy is simple in concept, but it is time-consuming, being the first computerized MC simulation developed and implemented by the working team of John and Klara von Neumann and Nick Metropolis with the advent of the

There are different algorithms [8–10] implemented to apply different MC solutions by using different computational tools. Since the objective of this chapter is to present MC validation and/or reliability for application developers (AD), on a

There are several characteristics that can be used to classify MC computational tools (MCCT); however, based on the objective of this chapter, the available ones will be classified according to its applicability as general and specific MCCTs. So, in section 2, the general concepts and MCCT code core (cross-sectional libraries and pseudorandom generators), including the specific and general MCCTs characteristics and some codes available nowadays, are going to be presented. In section 3, the validation and reliability of MCCT code concepts and main methods, including its limitations on the implementations of cross-sectional libraries and random generators, are going to be discussed. To illustrate this, a case study of validation for dosimetry in mammography using two MCCT methods for radiation transport (Geant4 and XRMC) is going to be presented. In the last section, the final considerations on choosing a MCCT and important issues on validation or reliability tests

The MC method may be used to solve different kinds of problems. It may be used to solve problems that could also be solved by deterministic calculations, but it is usually more time-consuming than those and can increase the complexity of the solution. MC must to be applied, generally, when the change in the model follows a

specific study case, we will not detail the different MC algorithms.

<sup>D</sup> and <sup>θ</sup> <sup>¼</sup> <sup>1</sup>

π :

<sup>p</sup><sup>0</sup> <sup>¼</sup> <sup>1</sup> � 2r<sup>θ</sup> and <sup>p</sup><sup>1</sup> <sup>¼</sup> 2rθ, where <sup>r</sup> <sup>¼</sup> <sup>l</sup>

line as [3].

space [3–5].

computers in 1947–1948 [7].

will be presented.

80

2. Monte Carlo general concepts and core

<sup>1</sup> RUN: word used to define the execution of the MC code.

<sup>2</sup> EVENT: every interaction that happened to one primary particle or its secondaries until they die or leave the universe of simulation. It is defined as the collections of steps performed by one particle.

defined volumes, then the logic is different than the presented in the scheme in Figure 1.

If the particle is alive and inside the world, then it is important to know if this particle will find a geometrical boundary and/or a different material in its path during the step. If the answer is no to both pre-defined questions, then the code will proceed with the step. If the answer is yes, the code will calculate the length until this boundary and check if the other volume has or does not have a new material, and the step will proceed until the boundary; after that the residual kinetic energy of the particle will be recalculated for the next volume material. At the end of the step, the post-step information is recorded. Then, the VARnh is increased of a unit and is compared to nh. If VARnh is equal to nh, the termination of run is performed. If VARnh is smaller than nh, a new step procedure is started by recording the poststep information of the previous step as initial information of the new one, proceeding with the verifications and implementations for this new step. It is important to note that all secondary particles generated, as product of an interaction, will be transported following the same procedure starting in Record Pré-Step with the exception that VARnh will not be incremented and these particles will be followed

Monte Carlo's Core and Tests for Application Developers: Geant4 and XRMC Comparison…

To illustrate the selection of random number, let's create a hypothesis of a 40 keV photon interacting with a liquid water medium. In this case, the total

Considering the information in Figure 2, one may see that among the three possible processes of interaction a probability of approximately 10.71% for coherent scattering, 68.11% for incoherent scattering, and 21.18% for photoelectric effect. Then, the normalization of the probabilities for each process between 0 and 1 is performed, considering the total attenuation cross section as the normalizing factor,

Scheme of the random generator logic to define a probability of interaction of a 40 keV photon into liquid water

<sup>3</sup> All attenuation cross sections used were from XCOM NIST (https://physics. nist.gov/cgi-bin/Xcom/xc

/g).<sup>3</sup> Figure 2 shows the simplified scheme that defines the process of

/g), incoherent scattering (0.1827 cm2

/g, being composed by coherent scattering

/g), and photoelectric effect

until they die or leave the world.

(0.02874 cm<sup>2</sup>

(0.05680 cm2

interaction.

Figure 2.

medium.

om3\_2).

83

attenuation cross section is 0.2683 cm<sup>2</sup>

DOI: http://dx.doi.org/10.5772/intechopen.88893

b. Is this particle alive? In MCCT for transport radiation, there is a minimum energy to proceed the transportation, so if the particle kinetic energy is smaller than this minimum energy, then this particle will die, which means in MCCT all residual energy will be locally deposited and the particle will stop.

#### Figure 1.

Simplified scheme of a traditional Monte Carlo simulation.

Monte Carlo's Core and Tests for Application Developers: Geant4 and XRMC Comparison… DOI: http://dx.doi.org/10.5772/intechopen.88893

If the particle is alive and inside the world, then it is important to know if this particle will find a geometrical boundary and/or a different material in its path during the step. If the answer is no to both pre-defined questions, then the code will proceed with the step. If the answer is yes, the code will calculate the length until this boundary and check if the other volume has or does not have a new material, and the step will proceed until the boundary; after that the residual kinetic energy of the particle will be recalculated for the next volume material. At the end of the step, the post-step information is recorded. Then, the VARnh is increased of a unit and is compared to nh. If VARnh is equal to nh, the termination of run is performed. If VARnh is smaller than nh, a new step procedure is started by recording the poststep information of the previous step as initial information of the new one, proceeding with the verifications and implementations for this new step. It is important to note that all secondary particles generated, as product of an interaction, will be transported following the same procedure starting in Record Pré-Step with the exception that VARnh will not be incremented and these particles will be followed until they die or leave the world.

To illustrate the selection of random number, let's create a hypothesis of a 40 keV photon interacting with a liquid water medium. In this case, the total attenuation cross section is 0.2683 cm<sup>2</sup> /g, being composed by coherent scattering (0.02874 cm<sup>2</sup> /g), incoherent scattering (0.1827 cm2 /g), and photoelectric effect (0.05680 cm2 /g).<sup>3</sup> Figure 2 shows the simplified scheme that defines the process of interaction.

Considering the information in Figure 2, one may see that among the three possible processes of interaction a probability of approximately 10.71% for coherent scattering, 68.11% for incoherent scattering, and 21.18% for photoelectric effect. Then, the normalization of the probabilities for each process between 0 and 1 is performed, considering the total attenuation cross section as the normalizing factor,

#### Figure 2.

defined volumes, then the logic is different than the presented in the scheme

b. Is this particle alive? In MCCT for transport radiation, there is a minimum energy to proceed the transportation, so if the particle kinetic energy is smaller than this minimum energy, then this particle will die, which means in MCCT all residual energy will be locally deposited and the particle will stop.

Theory, Application, and Implementation of Monte Carlo Method in Science and Technology

in Figure 1.

Figure 1.

82

Simplified scheme of a traditional Monte Carlo simulation.

Scheme of the random generator logic to define a probability of interaction of a 40 keV photon into liquid water medium.

<sup>3</sup> All attenuation cross sections used were from XCOM NIST (https://physics. nist.gov/cgi-bin/Xcom/xc om3\_2).

and these normalized probabilities are organized in a sequence of real values. The possible number of values between 0 and 1 depends on the variable type defined in the MCCT implementation for the random generator number. On the presented example, the random numbers in the intervals [0; 0.10714) identify coherent scattering [0.10714; 0.78824), incoherent scattering, and [0.78824; 1) photoelectric effect. It is important to note that the probability of occurrence is proportional to the quantity of random numbers in the sequence of values. In the case exemplified in Figure 2, the number 0.0053721 is in the range [0; 0.10714) and defines the photon transport by coherent effect. If the random number were 0.78824, the photoelectric effect would be simulated since this value is in the range [0.78824; 1).

disadvantage on developing TRNG is that it is implemented in hardware, which limits the flexibility of this random number generator and since additional verification of randomness is required with every change of environment [16]. Because of the hardware implementation of TRNG, computers without a hardware random number generator will require a peripheral that will generate a TRNG seed to be

Monte Carlo's Core and Tests for Application Developers: Geant4 and XRMC Comparison…

Sometimes, an association of random number generators (PRNG-PRNG and PRNG-TRNG) is implemented to increase the period of a random generator, but the randomness of the number generated must be tested and verified. Special care must to be taken attention on running MCCT in computational grids or clusters to ensure that every processor will have an independent random seed to start the process. If this requirement is not kept, inconsistencies in the results may happen turning them unrealistic and carrying with them statistical tendencies that do not represent the expected probabilities. Therefore, to guarantee the reliability of results of a MCCT, the AD must understand the random number generator and its period and limitations. Considering the reliability of the MCCT in the example described above, when it is applied to low-energy radiation transport, the probabilities (e.g., cross-sectional libraries—total and differential—for photons), the distribution functions, and the transport models for particles, such as electrons, are indispensable. As a general rule, it is important to know the processes simulated and if there are one or more models to be evoked. To validate these characteristics, the MCCT requires a microscopic validation<sup>4</sup> that in turn requires experimental data of the cross sections or distribution functions for different material and energy range. The microscopic validation is hard work to be performed by an AD; however, one may find the validation of the data libraries in the literature and/or online libraries [17–27] and on

independent validations published for specific MC codes [21, 28–30].

2.1 General versus specific Monte Carlo toolkit for radiation transport

The MCCT may be classified according to its applicability as general purpose (GP) [31–33] or specific purpose (SP) [33–35]. It is important to understand that this classification refers to the possibility of using MCCT in different applications and not the kind of solution generated by the MCCT. All MCCTs present a general solution to the study case, when applied to the same particle types, degrees of freedom, and simulated quantities, taking into account the limitations of the

Some MCCTs are developed considering the simulation of a wide range of particles and/or quantities. Usually these MCCTs simulate detailedly the radiation transport of primary and secondary particles using minimal approximations as possible. These MCCTs are called general purpose Monte Carlo toolkit (GPMCT), and they may be applied to solve a wide range of radiation transport problems: large energy range, different particle types, different geometries, and a large range of simulated processes. As examples, one may cite Geant4, MCNP, or FLUKA. The geometry and tracking (Geant4) [36–38] is a MCCT that has a complete range of functionalities including tracking, geometry, physics models, and hits [36]. It was developed based on object-oriented technology and implemented in C++ programming language. The physics processes available cover a comprehensive range, including electromagnetic, hadronic, and optical ones with a large set of

<sup>4</sup> Microscopic validation: refers to the detailed validation of microscopic quantities (usually the libraries)

used by the MC code to generate the quantitative results. See more information on Section 3.

Verification, validation, comparison, and reliability of Monte Carlo toolkit.

used as incoming data for PRNG [16].

DOI: http://dx.doi.org/10.5772/intechopen.88893

implemented code and libraries.

85

During the simulation several processes may need to have a random number generated such as process of interaction (used in the above example), momentum direction of the particle, secondary particle momentum and kinetic energy, atomic effect (if considered in the simulation), probability of Auger effect, and momentum direction of the Auger electron or auto-absorption of the Auger electron, among others. After the random definition of some of the abovementioned characteristics, deterministic equations are applied to keep the Principle of Energy and Momentum Conservation. Regarding the core of MCCT, it is important to know, as an AD, the main validity and limitations of the random number generator and the cross-sectional libraries.

The random number generator may be classified as pseudorandom number generator (PRNG) or true random number generator (TRNG) [13]. The so-called PRNG uses a deterministic process to generate a series of outputs from an initial seed state which means that for the same input "seed" one may have the same output number [13–15]. As an example one may cite the <cstdlib> head of C++ rand() function. In this case, usually the random number generated is an integer, and to know the range of possible numbers, it helps the AD to understand the limitations of the number of histories that can be run without compromising the randomicity of the simulation [13, 14], the so-called period of random number generator [16]. Table 1 presents the different range of values generated among the possible integer variables according to [14].

Based on the value range presented in Table 1, one may see that different possible variable definitions of the random generator can affect the resolution of the simulation, which means that there is a limit of histories with a proper random behavior for a PRNG. The PRNG is used in several applications [15], and one advantage of using it on MCCT is the capability of reproducing the same sequence of pseudorandom numbers [14] that can be used to validate an application and/or to validate and test different installations of a MCCT under different environments (evaluating the accuracy and precision of the simulation in different conditions) [16].

The TRNG uses a non-deterministic source to produce randomness [13], and its advantage is that TRNG is unpredictable, unbiased, and independent [16]. The


#### Table 1.

Type of integers, storage size, and range of possible values in C++ programming language.

### Monte Carlo's Core and Tests for Application Developers: Geant4 and XRMC Comparison… DOI: http://dx.doi.org/10.5772/intechopen.88893

disadvantage on developing TRNG is that it is implemented in hardware, which limits the flexibility of this random number generator and since additional verification of randomness is required with every change of environment [16]. Because of the hardware implementation of TRNG, computers without a hardware random number generator will require a peripheral that will generate a TRNG seed to be used as incoming data for PRNG [16].

Sometimes, an association of random number generators (PRNG-PRNG and PRNG-TRNG) is implemented to increase the period of a random generator, but the randomness of the number generated must be tested and verified. Special care must to be taken attention on running MCCT in computational grids or clusters to ensure that every processor will have an independent random seed to start the process. If this requirement is not kept, inconsistencies in the results may happen turning them unrealistic and carrying with them statistical tendencies that do not represent the expected probabilities. Therefore, to guarantee the reliability of results of a MCCT, the AD must understand the random number generator and its period and limitations.

Considering the reliability of the MCCT in the example described above, when it is applied to low-energy radiation transport, the probabilities (e.g., cross-sectional libraries—total and differential—for photons), the distribution functions, and the transport models for particles, such as electrons, are indispensable. As a general rule, it is important to know the processes simulated and if there are one or more models to be evoked. To validate these characteristics, the MCCT requires a microscopic validation<sup>4</sup> that in turn requires experimental data of the cross sections or distribution functions for different material and energy range. The microscopic validation is hard work to be performed by an AD; however, one may find the validation of the data libraries in the literature and/or online libraries [17–27] and on independent validations published for specific MC codes [21, 28–30].

#### 2.1 General versus specific Monte Carlo toolkit for radiation transport

The MCCT may be classified according to its applicability as general purpose (GP) [31–33] or specific purpose (SP) [33–35]. It is important to understand that this classification refers to the possibility of using MCCT in different applications and not the kind of solution generated by the MCCT. All MCCTs present a general solution to the study case, when applied to the same particle types, degrees of freedom, and simulated quantities, taking into account the limitations of the implemented code and libraries.

Some MCCTs are developed considering the simulation of a wide range of particles and/or quantities. Usually these MCCTs simulate detailedly the radiation transport of primary and secondary particles using minimal approximations as possible. These MCCTs are called general purpose Monte Carlo toolkit (GPMCT), and they may be applied to solve a wide range of radiation transport problems: large energy range, different particle types, different geometries, and a large range of simulated processes. As examples, one may cite Geant4, MCNP, or FLUKA.

The geometry and tracking (Geant4) [36–38] is a MCCT that has a complete range of functionalities including tracking, geometry, physics models, and hits [36]. It was developed based on object-oriented technology and implemented in C++ programming language. The physics processes available cover a comprehensive range, including electromagnetic, hadronic, and optical ones with a large set of

and these normalized probabilities are organized in a sequence of real values. The possible number of values between 0 and 1 depends on the variable type defined in the MCCT implementation for the random generator number. On the presented example, the random numbers in the intervals [0; 0.10714) identify coherent scattering [0.10714; 0.78824), incoherent scattering, and [0.78824; 1) photoelectric effect. It is important to note that the probability of occurrence is proportional to the quantity of random numbers in the sequence of values. In the case exemplified in Figure 2, the number 0.0053721 is in the range [0; 0.10714) and defines the photon transport by coherent effect. If the random number were 0.78824, the photoelectric effect would be simulated since this value is in the range [0.78824; 1). During the simulation several processes may need to have a random number generated such as process of interaction (used in the above example), momentum direction of the particle, secondary particle momentum and kinetic energy, atomic effect (if considered in the simulation), probability of Auger effect, and momentum direction of the Auger electron or auto-absorption of the Auger electron, among others. After the random definition of some of the abovementioned characteristics, deterministic equations are applied to keep the Principle of Energy and Momentum Conservation. Regarding the core of MCCT, it is important to know, as an AD, the main validity and limitations of the random number generator and the cross-sectional libraries. The random number generator may be classified as pseudorandom number generator (PRNG) or true random number generator (TRNG) [13]. The so-called PRNG uses a deterministic process to generate a series of outputs from an initial seed state which means that for the same input "seed" one may have the same output number [13–15]. As an example one may cite the <cstdlib> head of C++ rand() function. In this case, usually the random number generated is an integer, and to know the range of possible numbers, it helps the AD to understand the limitations of the number of histories that can be run without compromising the randomicity of the simulation [13, 14], the so-called period of random number generator [16]. Table 1 presents the different range of values generated among the

Theory, Application, and Implementation of Monte Carlo Method in Science and Technology

Based on the value range presented in Table 1, one may see that different possible variable definitions of the random generator can affect the resolution of the simulation, which means that there is a limit of histories with a proper random behavior for a PRNG. The PRNG is used in several applications [15], and one advantage of using it on MCCT is the capability of reproducing the same sequence of pseudorandom numbers [14] that can be used to validate an application and/or to validate and test different installations of a MCCT under different environments (evaluating the

The TRNG uses a non-deterministic source to produce randomness [13], and its

Int 2 bytes or 4 bytes 32,768 to 32,767 or 2,147,483,648 to 2,147,483,647

Long 4 bytes 2,147,483,648 to 2,147,483,647

Unsigned integer 2 bytes or 4 bytes 0 to 65,535 or 0 to 4,294,967,295 Unsigned long 4 bytes 0 to 4,294,967,295

advantage is that TRNG is unpredictable, unbiased, and independent [16]. The

accuracy and precision of the simulation in different conditions) [16].

Type Storage size Values range Short 2 bytes 32,768 to 32,767

Unsigned short 2 bytes 0 to 65,535

Type of integers, storage size, and range of possible values in C++ programming language.

possible integer variables according to [14].

Table 1.

<sup>4</sup> Microscopic validation: refers to the detailed validation of microscopic quantities (usually the libraries) used by the MC code to generate the quantitative results. See more information on Section 3. Verification, validation, comparison, and reliability of Monte Carlo toolkit.

materials, chemical elements, and long-lived particles, over a wide energy range starting from 250 or 990 eV and extending to a few TeV. The extended package Geant4-DNA adds processes for the modeling of induced biological damage by ionizing radiation at DNA scale, which transports all particles using a discrete model [39–42] extending the possibility of transport particles down to a few eV (the range is different to each particle and process). On Geant4, the AD may access a large cross-sectional library database, making possible to choose different radiation processes and, to each process, to select different transport models. On Geant4, the AD may implement different variance reduction methods and set different parameters to transport primary and secondary particles [43] among the more than 35 particles<sup>5</sup> allowed [43]. AD may use Geant4 classes to create collections of interactions, named hits (G4VHit or G4THitsCollection), and/or evoke sensitive detector counters (G4MultiFunctionalDetector or G4VPrimitiveScorer) and/or implement his/ her own personal class (a new sensitive detector or hit file) [44].

output files. Generally, the AD may choose between formatted and unformatted output and may generate a personalized routine for additional outputs [53].

Monte Carlo's Core and Tests for Application Developers: Geant4 and XRMC Comparison…

DOI: http://dx.doi.org/10.5772/intechopen.88893

matter interactions generally used for XRF applications.

electrons using the Livermore database is under development [58].

87

The penetration and energy loss of positrons and electron (PENELOPE) [60], version 2014, MCCT simulates the coupled electron-photon transport as well as photons, electrons, and positrons. The PENELOPE simulation algorithm is based on a scattering model combining numerical databases with analytical cross-sectional models for the different interaction mechanisms being applicable to energies from few hundred eV up to approximately 1 GeV. Photon transport is simulated by means of the standard, detailed simulation method. Electron and positron transports are simulated based on a mixed procedure, which combines a detailed simulation with a condensed one [60–63]. The implementation of the cross-sectional

The integrated tiger series (ITS) [57–59], version 6, allows solutions of linear time-independent coupled electron/photon radiation transport problems. This MCCT employs accurate cross sections, sampling distributions, and physical models to describe the production and transport of the electron/photon cascade from 1.0 keV to 1.0 GeV [58, 59]. The ITS, version 6, was converted to Fortran 90 [59] with C++ links to CAD software. The availability of the source code allows the AD to tailor this MCCT to specific applications and to extend its capabilities to more complex applications. Overlaps in CAD geometry may be evaluated and reported in an output file [58]. The AD may set different parameters by command line like to define the cross section for different data sets, to deactivate the coherent photon scattering, to include (or not) binding effects in incoherent photon scattering, and/or to apply (or not) energy-loss straggling to electrons [59]. The AD may set different output information such as the energy and charge deposited in every subzone, the detailed energy and charge deposited in every subzone, and the geometry-dependent input settings [58]. ITS' cross-sectional [58] suite of codes includes a multigroup version along with the multigroup cross-sectional generator CEPXS and a continuous-energy (XGEN) cross sections [58, 59]. In ITS, photons below 1 keV are locally absorbed, an alternative algorithm to electron transport was implemented named Generalized Boltzmann Fokker-Planck (GBFP), and the full transport capability for photons and

However, some MCCTs are developed to solve problems considering specific particles or specific geometrical conditions or specific simulated quantities. These MCCTs are called specific purpose Monte Carlo toolkit (SPMCT) and are usually optimized to use several approximations and variance reduction techniques. They are developed considering restrictions on applications, and very specific quantities are simulated. In general, the SPMCTs are faster than the GPMCTs to solve the same problem. As examples, one may cite XRMC, ITS TIGER series, PENELOPE, EGS, and ETRAN. The X-Ray Monte Carlo (XRMC) [54] simulates accurately X-ray imaging and spectroscopy experiments of heterogeneous samples. This MCCT is implemented in C++ and is capable of simulating, in detail, complex experiments on generic samples using different variance reduction techniques by default. It was developed initially to simulate X-ray fluorescence and photon imaging. XRMC simulates the transport of photons only and makes it possible to simulate the following quantities: total fluence and fluence with energy binding and total energy fluence and energy fluence with energy binning. As output, it may generate a raw file with the transmission image [55], and if energy binning is evoked, the AD may define the bin size. On transport possibilities, the AD may define maximum scattering order number, maximum scattering order as transmission, first-order scattering or fluorescence emission, and second-order scattering or fluorescence emission or higher order. It also has the flexibility of activating or inactivating fluorescence [54, 55] process. The cross-sectional library evoked by XRMC is the xraylib [56], a library for X-ray

The Monte Carlo N-particle (MCNP6) [45–49] MCCT includes a powerful general source, a criticality source, and a surface source. In addition to that, this MCCT includes both geometry and output counter (named tally) plotters. MCNP is implemented on GNU Fortran and C/C++ compilers [49] being a continuousenergy, generalized-geometry, time-dependent, MC radiation-transport code designed to track many particle types over broad ranges of energies. This MCCT may simulate neutron, photon, electron, or coupled neutron/photon/electron transport and heavy ions [49]. It simulates different energy ranges for different particles: neutron energy range from 10<sup>11</sup> to 20 MeV for most of isotopes and up to 150 MeV for some others, photon energy range from 1 keV up to 100 GeV, and electron energy range from 1 keV to 1 GeV [50]. It has a rich collection of variance reduction techniques with an extensive collection of cross-sectional data. In addition, MCNP contains numerous tallies: surface current and flux, volume flux (track length), point or ring detectors, particle heating, fission heating, pulse height tally for energy or charge deposition, mesh tallies, and radiography tallies [46, 49]. This MCCT makes it possible to change transport parameters by command lines [46, 50].

The Fluktuierende Kaskade (FLUKA) [51–53] MCCT was implemented and presents a number of ADs interface routines in Fortran 77. It simulates accurately the interaction and propagation of radiation in matter of about 60 different particles,<sup>6</sup> including photons and electrons from 100 eV or 1 keV to thousands of TeV, neutrinos, muons of any energy, hadrons of energies up to 20 TeV and all the corresponding antiparticles, neutrons down to thermal energies, and heavy ions. Efficiency on radiation transport has been achieved using a frequent access table look-up sampling, and accuracy is maximized by systematic use of double precision variables. It is provided with a large number of available options for an AD and has been completely restructured introducing dynamical dimensioning. It has the double capability to be used in a biased mode as well as a fully analogue code which means that while it can be used to predict fluctuations, signal coincidences, and other correlated events, a wide choice of statistical techniques is also available to investigate punch through or other rare events in connection with attenuations by many orders of magnitude [52]. FLUKA can generate several output cards: a main (standard) output file, two scratch files, a file with the last random number seeds, an error messages file (if any), and any number (including zero) of estimator

<sup>5</sup> The Geant4 list of particles and its identifications number may be found at https://www.star.bnl.gov/ public/comp/simu/newsite/gstar/Manual/particle\_id.html).

<sup>6</sup> The FLUKA list of particles and its identifications number may be found at http://www.fluka.org/c ontent/manuals/online/5.1.html.

#### Monte Carlo's Core and Tests for Application Developers: Geant4 and XRMC Comparison… DOI: http://dx.doi.org/10.5772/intechopen.88893

output files. Generally, the AD may choose between formatted and unformatted output and may generate a personalized routine for additional outputs [53].

However, some MCCTs are developed to solve problems considering specific particles or specific geometrical conditions or specific simulated quantities. These MCCTs are called specific purpose Monte Carlo toolkit (SPMCT) and are usually optimized to use several approximations and variance reduction techniques. They are developed considering restrictions on applications, and very specific quantities are simulated. In general, the SPMCTs are faster than the GPMCTs to solve the same problem. As examples, one may cite XRMC, ITS TIGER series, PENELOPE, EGS, and ETRAN.

The X-Ray Monte Carlo (XRMC) [54] simulates accurately X-ray imaging and spectroscopy experiments of heterogeneous samples. This MCCT is implemented in C++ and is capable of simulating, in detail, complex experiments on generic samples using different variance reduction techniques by default. It was developed initially to simulate X-ray fluorescence and photon imaging. XRMC simulates the transport of photons only and makes it possible to simulate the following quantities: total fluence and fluence with energy binding and total energy fluence and energy fluence with energy binning. As output, it may generate a raw file with the transmission image [55], and if energy binning is evoked, the AD may define the bin size. On transport possibilities, the AD may define maximum scattering order number, maximum scattering order as transmission, first-order scattering or fluorescence emission, and second-order scattering or fluorescence emission or higher order. It also has the flexibility of activating or inactivating fluorescence [54, 55] process. The cross-sectional library evoked by XRMC is the xraylib [56], a library for X-ray matter interactions generally used for XRF applications.

The integrated tiger series (ITS) [57–59], version 6, allows solutions of linear time-independent coupled electron/photon radiation transport problems. This MCCT employs accurate cross sections, sampling distributions, and physical models to describe the production and transport of the electron/photon cascade from 1.0 keV to 1.0 GeV [58, 59]. The ITS, version 6, was converted to Fortran 90 [59] with C++ links to CAD software. The availability of the source code allows the AD to tailor this MCCT to specific applications and to extend its capabilities to more complex applications. Overlaps in CAD geometry may be evaluated and reported in an output file [58]. The AD may set different parameters by command line like to define the cross section for different data sets, to deactivate the coherent photon scattering, to include (or not) binding effects in incoherent photon scattering, and/or to apply (or not) energy-loss straggling to electrons [59]. The AD may set different output information such as the energy and charge deposited in every subzone, the detailed energy and charge deposited in every subzone, and the geometry-dependent input settings [58]. ITS' cross-sectional [58] suite of codes includes a multigroup version along with the multigroup cross-sectional generator CEPXS and a continuous-energy (XGEN) cross sections [58, 59]. In ITS, photons below 1 keV are locally absorbed, an alternative algorithm to electron transport was implemented named Generalized Boltzmann Fokker-Planck (GBFP), and the full transport capability for photons and electrons using the Livermore database is under development [58].

The penetration and energy loss of positrons and electron (PENELOPE) [60], version 2014, MCCT simulates the coupled electron-photon transport as well as photons, electrons, and positrons. The PENELOPE simulation algorithm is based on a scattering model combining numerical databases with analytical cross-sectional models for the different interaction mechanisms being applicable to energies from few hundred eV up to approximately 1 GeV. Photon transport is simulated by means of the standard, detailed simulation method. Electron and positron transports are simulated based on a mixed procedure, which combines a detailed simulation with a condensed one [60–63]. The implementation of the cross-sectional

materials, chemical elements, and long-lived particles, over a wide energy range starting from 250 or 990 eV and extending to a few TeV. The extended package Geant4-DNA adds processes for the modeling of induced biological damage by ionizing radiation at DNA scale, which transports all particles using a discrete model [39–42] extending the possibility of transport particles down to a few eV (the range is different to each particle and process). On Geant4, the AD may access a large cross-sectional library database, making possible to choose different radiation processes and, to each process, to select different transport models. On Geant4, the AD may implement different variance reduction methods and set different parameters to transport primary and secondary particles [43] among the more than 35 particles<sup>5</sup> allowed [43]. AD may use Geant4 classes to create collections of interactions, named hits (G4VHit or G4THitsCollection), and/or evoke sensitive detector counters (G4MultiFunctionalDetector or G4VPrimitiveScorer) and/or implement his/

Theory, Application, and Implementation of Monte Carlo Method in Science and Technology

The Monte Carlo N-particle (MCNP6) [45–49] MCCT includes a powerful general source, a criticality source, and a surface source. In addition to that, this MCCT includes both geometry and output counter (named tally) plotters. MCNP is implemented on GNU Fortran and C/C++ compilers [49] being a continuousenergy, generalized-geometry, time-dependent, MC radiation-transport code designed to track many particle types over broad ranges of energies. This MCCT may simulate neutron, photon, electron, or coupled neutron/photon/electron transport and heavy ions [49]. It simulates different energy ranges for different particles: neutron energy range from 10<sup>11</sup> to 20 MeV for most of isotopes and up to 150 MeV for some others, photon energy range from 1 keV up to 100 GeV, and electron energy range from 1 keV to 1 GeV [50]. It has a rich collection of variance reduction techniques with an extensive collection of cross-sectional data. In addition, MCNP contains numerous tallies: surface current and flux, volume flux (track length), point or ring detectors, particle heating, fission heating, pulse height tally for energy or charge deposition, mesh tallies, and radiography tallies [46, 49]. This MCCT makes it possible to change transport parameters by command lines [46, 50]. The Fluktuierende Kaskade (FLUKA) [51–53] MCCT was implemented and presents a number of ADs interface routines in Fortran 77. It simulates accurately the interaction and propagation of radiation in matter of about 60 different particles,<sup>6</sup> including photons and electrons from 100 eV or 1 keV to thousands of TeV, neutrinos, muons of any energy, hadrons of energies up to 20 TeV and all the corresponding antiparticles, neutrons down to thermal energies, and heavy ions. Efficiency on radiation transport has been achieved using a frequent access table look-up sampling, and accuracy is maximized by systematic use of double precision variables. It is provided with a large number of available options for an AD and has been completely restructured introducing dynamical dimensioning. It has the double capability to be used in a biased mode as well as a fully analogue code which means that while it can be used to predict fluctuations, signal coincidences, and other correlated events, a wide choice of statistical techniques is also available to investigate punch through or other rare events in connection with attenuations by many orders of magnitude [52]. FLUKA can generate several output cards: a main (standard) output file, two scratch files, a file with the last random number seeds, an error messages file (if any), and any number (including zero) of estimator

<sup>5</sup> The Geant4 list of particles and its identifications number may be found at https://www.star.bnl.gov/

<sup>6</sup> The FLUKA list of particles and its identifications number may be found at http://www.fluka.org/c

public/comp/simu/newsite/gstar/Manual/particle\_id.html).

ontent/manuals/online/5.1.html.

86

her own personal class (a new sensitive detector or hit file) [44].

libraries considers EPDL<sup>7</sup> total cross sections for photoelectric absorption and Rayleigh scattering, XCOM8 cross sections for pair production, and SUMGA<sup>9</sup> function for total atomic cross sections and Compton scattering. PENELOPE can simulate the emission of characteristic X-rays and Auger electrons resulting from vacancies produced in K, L, M, and N shells by photoelectric absorption, Compton scattering, triplet production, and electron/positron impact. In PENELOPE 2014, the elastic collisions of electrons and positrons are simulated, using numerical partial-wave cross sections for free neutral atoms by elastic scattering of electrons and positrons by atoms (ELSEPA) program that is a database distributed by ICRU Report 77 (2007) [60]. The output may be defined using Fortran subroutines, where the AD may get different quantities such as number of materials that were loaded, mass density of specific materials, characteristics of the slowing down for charged particles, energy of the particle at the beginning of the track segment, effective stopping power of soft energy-loss interactions, and energy lost along the step, among others [61].

as Sandia's older SANDYL code and their more current series of the TIGER, CYLTRAN, and ACCEPT codes, together have been called ETRAN model too.

Monte Carlo's Core and Tests for Application Developers: Geant4 and XRMC Comparison…

a. The characteristics of the application: type of primary and secondary particles and their energy range, quantities to be simulated, geometry and material

b. The capabilities of the MC code: if the code can handle properly the transport of primary and (if necessary) secondary particles in the energy range of interest, if it is possible to simulate the necessary quantities, and if it can handle the transport simulation in all material compositions expected and

c. The limitations of the MC code: transport processes and models simulated in the energy range of interest (search for microscopic validation of the crosssectional libraries published) and how accurate the MCCT is on simulating the dosimetric quantities and the particle fluxes (search for macroscopic validation published), being recommended that the AD proceeds his/her own

d. The computational performance: verifying the running time to get an

acceptable statistical fluctuation in the results for the cases of interest and, in some cases, checking the RAM memory used to build the virtual universe and

Considering those minimal guidelines on choosing a MCCT, there is a good chance for the AD to not have unresolvable problems during the development of an application. Now, if you, as an AD, still have questions about the proper MCCT to choose, keep in mind the best one is the MCCT able to solve your "problem" (accuracy of the results) with an adequate statistical fluctuation (precision of the results). In addition to that, an AD at least should be able to install and to use the MCCT interface, being aware of the common limitation of it. All these characteristics may be found, usually,

3. Verification, validation, comparison, and reliability of Monte Carlo

To guarantee that one application is realistic, it is important to test it (computational code) in different ways. There are several known ways to test a computational code and its parts; however, in this section, the focus is to present the concepts applied on developed applications for MCCTs such as verification, valida-

When one is working in an application for MCCT, it is important to understand the concepts that may guarantee its internal consistency and accuracy. The IEEE 1012–2016 gives a general description of software verification and validation, and the IEEE 24765–2017 gives a detailed description of these concepts defining these terms. Verification is defined as a "confirmation by examination and provisions of objective evidence that specified requirements have been fulfilled" (IEEE 1012– 2016), and lately this concept was detailed as "the process of evaluating a system or component to determine whether the products of a given development phase satisfy the conditions imposed at the start of that phase" (IEEE 24765–2017). Validation is

When an AD chooses a MCCT, it is important to consider:

composition of the simulated universe;

DOI: http://dx.doi.org/10.5772/intechopen.88893

how it simulates the geometry of interest;

the memory used to save the output files;

in the manual (user manual and physics process manual).

macroscopic validation;

toolkits

89

tion, comparison, and reliability.

The electron gamma shower (EGS) MCCT may be found on different main versions, EGS5 and EGSnrc. Both versions of EGS are implemented in Mortran3 language, which is a preprocessor for Fortran [64, 65]. The origins of EGS MCCT are documented in NRC-PIRS-0436 report [66]. The EGS5 simulates the coupled transport of electrons and photons in an arbitrary geometry for particles with energies from a few keV up to a several hundred GeV [64] depending on the atomic numbers of the target materials. The EGSnrc<sup>10</sup> (Electron Gamma Shower from National Research Council) is an extended and improved version of the EGS MCCT, having specific modeling implementations to electron and photon transport through matter. It includes the BEAMnrc software component that models beams traveling through consecutive material components, ranging from a simple slab to the full treatment head of a radiotherapy linear particle accelerator (linac). EGSnrc is particularly well-suited for medical physics applications (research and devices development) being used for medical radiation detection, medical image based on x-radiation, and dosimetry for a specific volume. However, due to the flexibility of this MCCT, the AD may use it for different applications such as in industrial linac beams, X-ray emitters, radiation shielding, and more. The EGSnrc simulates the radiation transport in homogeneous materials for photons, electrons, and positrons with energies between 1 keV and 10 GeV. It incorporates significant refinements in charged particle transport and better low energy cross sections and makes it possible to define elaborated geometries and particle sources [65].

The electron transport (ETRAN) MCCT transports electrons and photons through extended media being developed by the National Bureau of Standards. This MCCT has various versions representing mainly refinements, embellishments, and different geometrical treatments that share the same basic simulation algorithm based on random sampling the path of electrons and photons as they travel through matter. The algorithms and computational tools written at other laboratories, such

<sup>7</sup> EPDL: Photon and Electron Interaction Data is available at https://www-nds.iaea.org/epdl97.

<sup>8</sup> XCOM: Photon Cross-sectional Database is available at https://www.nist.gov/pml/xcom-photon-crosssections-database.

<sup>9</sup> Additional information about SUGMA function access SectionB.2 in Appendix B of the PENELOPE-2014: A Code System for Monte Carlo Simulation of Electron and Photon Transport at https:// www.oecd-nea.org/science/docs/2015/nsc-doc2015-3.pdf

<sup>10</sup> The EGSnrc has its official page associate to National Research Council Canada at https://nrc.canada. ca/en/research-development/products-services/software-applications/egsnrc-software-tool-model-radia tion-transport.

Monte Carlo's Core and Tests for Application Developers: Geant4 and XRMC Comparison… DOI: http://dx.doi.org/10.5772/intechopen.88893

as Sandia's older SANDYL code and their more current series of the TIGER, CYLTRAN, and ACCEPT codes, together have been called ETRAN model too. When an AD chooses a MCCT, it is important to consider:


Considering those minimal guidelines on choosing a MCCT, there is a good chance for the AD to not have unresolvable problems during the development of an application. Now, if you, as an AD, still have questions about the proper MCCT to choose, keep in mind the best one is the MCCT able to solve your "problem" (accuracy of the results) with an adequate statistical fluctuation (precision of the results). In addition to that, an AD at least should be able to install and to use the MCCT interface, being aware of the common limitation of it. All these characteristics may be found, usually, in the manual (user manual and physics process manual).
