SLIDE 1 An introduction to Monte Carlo methods in XRF analysis
Tom Schoonjans Joint ICTP-IAEA school, Trieste
SLIDE 2 Outline
- 1. Introduction to Monte Carlo methods
- 2. Monte Carlo simulation of energy
dispersive X-ray fluorescence (ED-XRF) spectrometers
- 3. Overview of available codes
SLIDE 3
Monte Carlo method: definition
Refers to any technique of statistical sampling, employed to approximate solutions to quantitative problems which may be too complex to solve analytically
SLIDE 4 Origins of the Monte Carlo method
Developed twice independently
- 1. Enrico Fermi: moderation
- f neutrons
- 2. Metropolis, Ulam and
Von Neumann: Manhattan project and ENIAC
The beginning of the Monte Carlo method by N. Metropolis, 1987
SLIDE 5 Monte Carlo simulation method
- Widespread statistical simulation tool
based on the use of random numbers
- A given problem is converted to its
probabilistic analogue
- Used in mathematics, physics, engineering,
biology, artificial intelligence, economy etc.
SLIDE 6 Monte Carlo simulation method
- Phenomena occurring in the examined system
must be characterized by probability density function (pdfs)
- Perform simulations by random sampling from the
pdfs
- Desired result is taken as an average over a
number of observations
- Engine is most often a pseudo random number
generator
SLIDE 7 Generating random variables with a specified distribution
- Continuous random variable: xmin ≤ X ≤ xmax
- Probability density function: f(x) ≥0
with:
- Cumulative distribution function:
- Monotonously increasing, F(xmin) = 0, F(xmax) = 1
x = F-1(R) inverse cdf, with 0 ≤ R ≤1 The values selected using the inverse cdf will reproduce the distribution f(x) in the interval [xmin, xmax]
f
xmin xmax
∫
(x)dx =1
F(x) = f
xmin x
∫
(u)du
SLIDE 8 Generating random variables with a specified distribution
- Discrete random variables: X = {x1,...,xn}
- Corresponding probabilities of events
{x1,...,xn}: {P1,...,Pn}
- R: uniform random number in [0,1]
- Select event for index k={1,...,n}:
Pi
i=1 n
∑
=1
Pi
i=1 k−1
∑
< R ≤ Pi
i=1 k
∑
SLIDE 9 Random number generators
- Critical component of all Monte Carlo
simulations!
- Initially performed using lists of “true”
random numbers
- Von Neumann: first pseudo random number
generator (middle-square method)
- Properties: speed, period length, uniformity,
coverage
A Million Random Digits with 100,000 Normal Deviates by the RAND corporation
SLIDE 10 Pseudo random number generators
- 1. Linear congruential generators
- Short period: maximum 232 or 264
- Easily implemented
- 2. Mersenne twister
- Most commonly used PRNG nowadays
- Period: 219937-1
- Passes the Diehard test package
- GPU implementation available (MTGP)
Xn+1 = (aXn + b) mod m
SLIDE 11 Pseudo random number generators
- 3. /dev/random
- special device file on Unix(-like) operating systems
- very high quality randomness (for cryptographic
applications!)
- entropy pool fed with noise produced by device
drivers, network interfaces etc.
- blocks → slow!
- non-blocking version: /dev/urandom (Linux only)
- Windows alternative: CryptGenRandom and rand_s
SLIDE 12 Example: estimation of π
Random selection of points within a square of 2a x 2a = 4a2 area
x y a a
π = 4 a2π 4a2 ⎛ ⎝ ⎜ ⎞ ⎠ ⎟ = 4 Acircle Asquare ⎛ ⎝ ⎜ ⎞ ⎠ ⎟ ≈ 4 Ncircle Ntotal ⎛ ⎝ ⎜ ⎞ ⎠ ⎟
SLIDE 13 Example: estimation of π
Random selection of points within a square of 2a x 2a = 4a2 area
x y a a
π = 4 a2π 4a2 ⎛ ⎝ ⎜ ⎞ ⎠ ⎟ = 4 Acircle Asquare ⎛ ⎝ ⎜ ⎞ ⎠ ⎟ ≈ 4 Ncircle Ntotal ⎛ ⎝ ⎜ ⎞ ⎠ ⎟
SLIDE 14 Monte Carlo simulation
spectrometers
SLIDE 15
Brute force algorithm
SLIDE 16
- Basic idea: predict the response of X-ray
imaging and spectroscopy experiments
- Optimize and design experimental setups in
silico
- Dose calculation
- Estimation of detection limits
- Quantification
A general Monte Carlo simulation
SLIDE 17 A general Monte Carlo simulation
- f ED-XRF spectrometers
- Simulates the fate of individual photons
- Trajectories are modeled as consisting of a
number of straight steps.
- At the end of each step, an interaction will
- ccur, leading to a change in direction and
energy
SLIDE 18
SLIDE 19 Initial photon properties:
- Energy
- Degree of linear polarization
- Intensity (weight)
- Point or Gaussian source
- Discrete or continuous
SLIDE 20 Sample properties:
- position and orientation
- n parallel layers
- Thickness
- Density
- Composition
SLIDE 21 Detector properties:
- position and orientation
- crystal
- window
- zero/gain
- Collimator (optional)
SLIDE 22
Stepsize? Atom type? Interaction type? New direction?
SLIDE 23 Selection of the step length
- Determined by the density, thickness and
the absorption coefficients of the sample layers
- Inverse cdf is based on the Bouguer-
Lambert-Beer equation:
f (x) = µρ exp(−µρx) F(x) = µ
x
∫
ρ exp(−µρt)dt =1− exp(−µρx) ≡ R ⇒ x = − 1 µρ ln(1− R) ⇔ x = − 1 µρ ln(R)
SLIDE 24 Selection of atom type
Current layer contains ne different elements, each element present with a weight fraction wi
wi
i=0 k
∑
mi ≤ R < wi
i=0 k+1
∑
mi with mi = µi wi
i=0 ne
∑
µi
SLIDE 25 Selection of interaction type
Three possibilities:
- 1. Rayleigh scattering:
- 2. Compton scattering
- 3. Photoelectric effect
0 ≤ R ≤ σ RZ µZ
σ RZ µZ < R ≤ σ RZ + σ CZ µZ
σ RZ + σ CZ µZ < R ≤1
SLIDE 26 Rayleigh scattering
unchanged
azimuthal angle φi must be selected in accordance with the appropriate differential Rayleigh cross section.
calculated numerically
SLIDE 27 Compton scattering
Compton formula:
azimuthal angle φi must be selected in accordance with the appropriate differential Compton cross section.
influence of the momentum pz of the scattering electron
Ei+1 = Ei 1+ Ei mec2 (1− cosθi) − 2pz mec sinθi 2 ⎛ ⎝ ⎜ ⎞ ⎠ ⎟
−1
SLIDE 28 Photoelectric effect
Which shell experienced effect?
shell = K shell: 0 ≤ R < τ K τ L1 shell: τ K τ ≤ R < τ K + τ L1 τ L2 shell: τ K + τ L1 τ ≤ R < τ K + τ L1 + τ L2 τ L3 shell: τ K + τ L1 + τ L2 τ ≤ R < τ K + τ L1 + τ L2 + τ L3 τ ... ⎧ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪
SLIDE 29 Photoelectric effect
Fluorescence yield: fluorescence or Auger effect? Using yields for primary vacancies! Fluorescence if: Take into account Coster-Kronig transitions!
0 ≤ R < ωshell
SLIDE 30 Is Y = 3?
YES
Get from rng: 0 < R < 1
NO
Is Y = 2? Is R < f23 L?
YES NO YES
Is R < f12 L?
NO Y = 1 YES Y = 2
Is R < f12 L+f13 L?
NO YES
Shell = L3 Shell = L2 Shell = L1
NO
Shell LY
Definitive selection of L-shell to be involved in transition
SLIDE 31 Definitive selection of M-shell to be involved in transition
Is Y = 5? Shell MY Get from rng: 0 < R < 1
NO
Shell = M5
YES
Is Y = 4? Is R < f45 M?
YES
Shell = M4
YES NO
Is Y = 3?
NO
Is R < f34 M?
YES Y = 4 YES
Is R < f34 M+ f35 M?
NO YES
Shell = M3
NO
Is Y = 2? Is R < f23 M?
YES YES Y = 3
Is R < f23 M+ f24 M?
NO YES Y = 4
Is R < f23 M+ f24 M + f25 M?
NO YES
Shell = M2
NO
Is R < f12 M?
NO NO Y = 1 YES Y = 2
Is R < f12 M+ f13 M?
NO YES Y = 3
Is R < f12 M+ f13 M + f14 M?
NO YES Y = 4
Is R < f12 M+ f13 M + f14 M + f15 M?
NO
Shell = M1
YES NO
SLIDE 32 Photoelectric effect
Which fluorescence line? Determine using the shell’s radiative rates: Scattering angle θi and azimuthal angle φi are chosen random:
line = KL2line: 0 ≤ R < pKL2 KL3line: pKL2 ≤ R < pKL2 + pKL3 KM2line: pKL2 + pKL3 ≤ R < pKL2 + pKL3 + pKM2 KM3line: pKL2 + pKL3 + pKM2 ≤ R < pKL2 + pKL3 + pKM2 + pKM3 ... ⎧ ⎨ ⎪ ⎪ ⎪ ⎪ ⎩ ⎪ ⎪ ⎪ ⎪
cosθi = (2R −1) ϕi = 2πR
SLIDE 33 K L3 L2 L1 M1 M2 M3 M4 M5
SLIDE 34 K L3 L2 L1 M1 M2 M3 M4 M5
Photoelectric effect: K shell
SLIDE 35 K L3 L2 L1 M1 M2 M3 M4 M5
Photoelectric effect: K shell Fluorescence yield: 0 < ωK(Z)< 1 Photon emission or Auger effect?
SLIDE 36 K L3 L2 L1 M1 M2 M3 M4 M5
Photoelectric effect: K shell
SLIDE 37 K L3 L2 L1 M1 M2 M3 M4 M5
Photoelectric effect: K shell
SLIDE 38 K L3 L2 L1 M1 M2 M3 M4 M5
Photoelectric effect: K shell
SLIDE 39 K L3 L2 L1 M1 M2 M3 M4 M5
Photoelectric effect: K shell
SLIDE 40 K L3 L2 L1 M1 M2 M3 M4 M5
Photoelectric effect: K shell
Fluorescence yield: 0 < ωLX(Z)< 1 Photon emission or Auger effect? Coster-Kronig transitions?
SLIDE 41 K L3 L2 L1 M1 M2 M3 M4 M5
Photoelectric effect: K shell
Fluorescence yield: 0 < ωLX(Z)< 1 Photon emission or Auger effect? Coster-Kronig transitions?
SLIDE 42 XRF cross sections: cascade effect
- Occurs whenever multiple shells of a particular
element can be excited
- Two components: radiative and non-radiative
- Leads to considerable boost in the observed intensity
- f L- and M-lines: several times larger than intensity
through primary excitations
- Very obvious when using monochromatic excitations
- Very often neglected in quantification and simulations
- Complex implementation
- Many fundamental parameters involved → accuracy?
SLIDE 43 New photon coordinates
Photon direction: Photon coordinates:
sinΘi+1cosΦi+1 sinΘi+1sinΦi+1 cosΘi+1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = cosΘi cosΦi − sinΦi sinΘi cosΦi cosΘi sinΦi cosΦi sinΘi sinΦi − sinΘi cosΘi ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ sinθi cosφi sinθi sinφi cosθi ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥
xi+1 = xi + Si sinΘi+1cosΦi+1 yi+1 = yi + Si sinΘi+1sinΦi+1 xi+1 = xi + Si cosΦi+1
ri ri+1 φi θi ri-1 (Θi,Φi) (Θi+1,Φi+1)
SLIDE 44 Photon termination
- After each interaction, a new step length
will be calculated and so on...
- The procedure stops when either the
photon is absorbed by the sample or leaves it.
- Upon leaving the sample, a check is
performed to determine whether or not the photon hits the detector
SLIDE 45 Brute force algorithm: inefficient
- Very large number of photons must be
simulated
- Possible loss of photons due to thin, low
absorbent samples, low fluorescence yields, and detector geometry
- Usually requires supercomputer
SLIDE 46
Code optimizations: variance reduction
SLIDE 47 Selection of the step length
- Force photons to stay within the system
- Largest index m is found according to:
- Step length calculated as:
- Photon weight multiplied with Pabs
SLIDE 48 Forced detection
- For each photon at each interaction point
- Calculate the probabilities of all possible
pathways of the photon to reach a random point on the detector
- Fractional photons added to virtual MCA
SLIDE 49 Fluorescence yield
- Multiply photon weight with fluorescence
yield of selected sub-shell
- Avoids the loss of simulated photons to
low energy cascade photons
- Cascade effect simulation taken into
account by variance reduction through corrected XRF production cross sections
SLIDE 50
Detector response function
SLIDE 51 Case study: NIST SRM 1155
- Stainless steel Cr18Ni12
- HASYLAB Beamline L
- Excitation energy: 16 keV
- Exposure: 300 s RT
- Degree of polarization
∼ 92 %
Cr 18.37% Ni 12.35% Mo 2.386% Mn 1.619% Cu 0.1734% Co 0.1052% V 0.0508% C 0.0445% S 0.0175%
SLIDE 52
Experimental data
SLIDE 53
Raw simulation result
SLIDE 54 Semiconductor detectors
- Incident X-rays will ionize the
semiconductor material, leading to the production of electron-hole pairs
- The number of pairs is proportional the
energy of the incoming photon
- Influenced by an electric field, the electrons
and holes migrate to the electrodes
- Results in a pulse that will be measured in
the outer circuit
- Dead time leads to some photons not being
counted
SLIDE 55 Spectral artifacts: peak broadening
- XRF lines experience Gaussian peak-broadening,
due to the statistical nature of the photon-charge conversions and to electronic noise
- Incoming lines are not discrete, but have a
Lorentzian profile
Voigt profile, a convolution
- f a Gaussian and a Lorentzian distribution
- Usually approximated as Gaussians or pseudo-Voigt
functions
SLIDE 56
After Gaussian convolution
SLIDE 57
After Gaussian convolution
SLIDE 58 20 40 60 80 100 Incident photon energy (keV) 0.00 0.02 0.04 0.06 0.08 Fluorescence escape ratio Si−KL
3
Ge−KL
3
Ge−KM
3
Ge−L
3M5
Detector escape peaks
detector crystal through XRF or Compton scattering may leave detector
- Results in detection of a
pulse with energy lower than expected
calculated based on crystal composition and thickness
- Calculated analytically or
with Monte Carlo simulation
SLIDE 59 Detector escape peaks
Compton escape ratios in Si drift detector 20 40 60 80 100 Incident photon energy (keV) 20 40 60 80 100 Compton photon energy (keV) 0.0000 0.0036 0.0071 Compton escape ratios in Ge detector 20 40 60 80 100 Incident photon energy (keV) 20 40 60 80 100 Compton photon energy (keV) 2.04× 10
−4
4.08× 10
−4
SLIDE 60
With escape peaks
SLIDE 61
With escape peaks
SLIDE 62 Detector pulse pile-up simulation
- Emergence of peaks at energy values
corresponding to the sum of XRF peaks
- Due to the limitations of the electronics
connected to the detector
- Magnitude strongly correlated to beam
intensity
- Monte Carlo simulation using exponential
pulse interval distribution
SLIDE 63 Cu−KL
3
(esc) Cu−KM
3
Scatter
Pulse pile−up peaks
10 20 30 40 50 Energy (keV) 10 10
2
10
4
10
6
Intensity (counts/channel)
Detector pulse pile-up simulation
SLIDE 64
With pulse pile-up...
SLIDE 65
...and some Poisson noise
SLIDE 66
Higher order interactions
SLIDE 67
Higher order interactions
SLIDE 68 Individual interaction contributions to intensity
@16 keV: 8.3116287 @Ni-KL23: 70.221933 @Fe-KL23: 109.02429!!
@16 keV: 12.699491 @Ni-KL23: 97.242868
@16 keV: 18.460541 Expressed in cm2/g
# Cr-KL23 Fe-KL23 Ni-KL23 1
655007 3084620 482088
2
406554 194120 3066
3
29652 2558 28
4
706 27 < 1
SLIDE 69
Overview of available codes
SLIDE 70 Geant4
- Low energy electromagnetic package
- Support for cascade effect
- Toolkit, not a finalized program
- Allows for very complex geometries
- Electron-matter interactions
- Open source
SLIDE 71 MCSHAPE
- Dedicated XRF code
- Advanced modeling of electrons produced
by Compton, Auger and photoelectric effect
- University of Bologna: Jorge Fernandez and
Viviana Scot
- Source code not distributed, binaries only
SLIDE 72 XRMC
- X-ray spectroscopy and imaging
experiments
- Complex sample geometries using quadrics
- Highly extensible
- University of Sassari
- Open source: GPLv3
SLIDE 73 References
Vincze et al. Spectrochim. Acta Part B, 48(4): 553–573, 1993.
Vincze et al. Spectrochim. Acta Part B, 50(2): 127–147, 1995.
- T. Schoonjans et al. Spectrochim. Acta Part B,
70:10–23, 2012.
SLIDE 74 Acknowledgements
Vincze
- Claudio Ferrero
- Manuel Sanchez del Rio
- Armando Solé
- Geert Silversmit
- Philip Brondeel
- Karen Appel
- Jan Garrevoet
- Beta testers
- Everyone that ever
contributed code or reported bugs!
SLIDE 75 Acknowledgements
Vincze
- Claudio Ferrero
- Manuel Sanchez del Rio
- Armando Solé
- Geert Silversmit
- Philip Brondeel
- Karen Appel
- Jan Garrevoet
- Beta testers
- Everyone that ever
contributed code or reported bugs!
Thank you!