# 2023 Laboratory C: Monte Carlo Simulations: Error Analysis and Spatial and Angular Distributions

##### GOALS: Gain familiarity with the error characteristics of Monte Carlo simulations

Open VTS_MATLAB folder and click on file short_course_monte_carlo_lab.m.

#### I. Dependence of Fluence Predictions on Number of Photons Simulated

##### Goal: This exercise explores how fluence estimates change with the number of photons simulated.
1. Go to the section Example 1a. This example sets up a Monte Carlo simulation for a system with a collimated source impinging on a slab of tissue. The tissue optical properties are specified in the "tissueInput.LayerRegions" struct under "RegionOP".
```tissueInput.LayerRegions = struct(...
'ZRange', ...
{...
[-Inf, 0], ... % air "z" range
[0, 100], ... % tissue "z" range
[100, +Inf] ... % air "z" range
}, ...
'RegionOP', ...
{...
[0.0, 1e-10, 1.0, 1.0], ... % air optical properties
[0.01, 1.0, 0.8, 1.4], ... % tissue OPs [ua, us', g, n]
[0.0, 1e-10, 1.0, 1.0] ... % air optical properties
} ...
);
```

The vector with comment "tissue OPs" specifies μa mm-1, μs' mm-1, g and n of the tissue slab. Fluence is calculated in a cylindrical coordinate system (ρ, z) for increasing number of photons launched from the source, N = 10, 100, 1000, 10000.

2. Configure an Analog simulation by setting "options.AbsorptionWeightingType" to 'Analog' (Line 17).
```  options.AbsorptionWeightingType = 'Analog';
```
3. Set the tissue absorption to μa=0.01 mm-1 (Line 46).
4. Execute Example 1a by right clicking on the cell so that it turns a pale yellow color and selecting "Evaluate Current Cell" or typing Ctrl+Enter.
5. How do the fluence results change as N is increased?
6. The relative error (RE) for the fluence is determined by dividing the standard deviation by the mean. For N=10,000, why does the relative error increase with distance from the source?
7. Change the Monte Carlo estimator to Discrete Absorption Weighting (DAW) by setting "options.AbsorptionWeightingType" to 'Discrete'.
```  options.AbsorptionWeightingType = 'Discrete';
```

Execute the Example 1a cell with this new setting.

8. How do the results using Analog and DAW compare for a given number of launched photons N?
9. For N=10000 which estimator provides fluence results with the least RE?
10. Now move down to Example 1b. This cell plots the difference in the relative error (RE) between Analog and DAW estimators.
11. Execute this cell. In what spatial regions does DAW show smaller RE than Analog? Can you explain why?

#### II. Spatially-Resolved Reflectance Predictions for Analog versus CAW Simulations

##### Goal:This exercise compares error estimates of spatially-resolved reflectance using Analog versus Continuous Absorption Weighting (CAW) simulations.
1. Example 2 sets up two Monte Carlo simulations using: 1) Analog, and 2) Continuous Absorption Weighting (CAW). The source is collimated and the tissue has optical properties [μa, μ's, g, n] = [0.01, 1.0, 0.8, 1.4]. Spatially-resolved reflectance is calculated in ρ bins. The number of photons launched for each simulation is N=10,000.
2. Set the tissue absorption to μa=0.01 mm-1 1 (Line 181).
```   [0.01, 1.0, 0.8, 1.4], ... % tissue OPs [ua, us', g, n]
```

and execute this cell.

3. What span of source-detector separations (ρ) does Analog have smaller standard deviations (SDs) than CAW? Where does CAW have smaller SDs? Can you explain why?
4. Note the time each took to execute in the MATLAB command window. Why does Analog run so much faster?
5. Determine the Analog relative error (RE) in the last ρ bin (ρ=9.9 mm) by typing "d1SD(100)/d1.Mean(100)" in the MATLAB command window. Do the same for CAW "d2SD(100)/d2.Mean(100)". Which method, Analog or CAW, has the smaller relative error?
6. The efficiency of an estimator is calculated as Efficiency =1/(RE^2 T) where RE is the relative error and T is the time it took for the simulation to execute. Which estimator has the larger efficiency for detector estimates at ρ=9.9 mm?
7. Set the tissue absorption to μa=0.1 mm-1
```   [0.1, 1.0, 0.8, 1.4], ... % tissue OPs [ua, us', g, n]
```

and execute the cell again.

8. Looking at the results for μa=0.01 mm-1 with μa=0.1 mm-1, how do the two methods RE compare as absorption is increased? How does the efficiency compare?
##### GOALS:Gain familiarity with the use of Monte Carlo Simulations to provide fluence and radiance predictions

Bring up the Vts.Gui.Wpf GUI

#### III. Monte Carlo Simulations of Narrow Collimated Beam Irradiation

##### Goal: This portion of the lab is to examine the impact of optical properties on the amplitude and axial/lateral dispersion of the light in turbid tissues.
1. Select the Monte Carlo Solver Panel.
3. In the Input File Specification, click the Load Input File button. Select the file: infile_one_layer_ROfRho_FluenceOfRhoAndZ.txt. This is a Monte Carlo simulation input file that specifies a Discrete Absorption Weighting (DAW) simulation to produce reflectance as a function of source-detector (ρ) separation, R(ρ) and fluence in cylindrical coordinates (ρ,z).
4. Set the begin and end of the tissue layer (Layer 1) thickness to be 0 and 100mm and the optical properties to be μa = 0.01mm-1, μ's = 1mm-1, g=0.8.
5. Set Number of Photons to 1000.
6. Click the Run Simulation button.
7. On the Map View plot, note the Mean Depth magnitude, axial and lateral penetration depths of the fluence distribution. On the map border, the z_max is based on the infile FluenceOfRhoAndZ detector definition for Z Stop which is set to 10 mm and the rho_max is based on the Rho Stop which is set to 10 mm.
8. Increase the absorption coefficient to μa = 0.1mm-1, keeping all other properties constant.
9. Click the Run Monte Carlo Simulation button.
10. Note the magnitude of the Mean Depth, axial and lateral penetration depths of the fluence distribution.
11. Fix μa = 0.1mm-1 and repeat this exercise for μ's = 0, 0.1 and 1.0 mm-1. Note the mean depth of penetration.
##### Questions:
1. How does increasing absorption change the magnitude, axial and lateral penetration depths?
2. How does increasing scattering change the magnitude, axial and lateral penetration depths?

#### IV. Visualizing Radiance versus Fluence distributions using the Monte Carlo CommandLine Application

##### Goal: This portion of the lab exercise is to examine the directional aspect of radiance in turbid tissues.
1. On the Desktop, holding down the shift key, right click the MCCL folder and select Open PowerShell window here.
2. Execute the Monte Carlo Command Line Application using the command is ./mc.exe infile=infile_one_layer_FluenceOfRhoAndZ_RadianceOfRhoAndZAndAngle.txt. This infile specifies a perpendicular point source impinging on the tissue at (0,0,0). The tissue is homogeneous with optical properties μa = 0.01mm-1, μ's = 1mm-1, g=0.8 and n = 1.4. N=10,000 photons are launched. Executing this command creates a folder called "one_layer_FluenceOfRhoAndZ_RadianceOfRhoAndZAndAngle" in the MCCL directory with fluence and radiance detector results.
3. Go into the MCCL folder.
4. Click on load_results_script. This will bring up MATLAB and also a window to edit load_results_script.m. Change datanames to be one_layer_FluenceOfRhoAndZ_RadianceOfRhoAndZAndAngle. Click "Run" or enter load_results_script and execute at the MATLAB prompt.
5. Four figures should appear, one plot of Fluence, two plots of radiance in the lower and upper hemispheres, and one plot of lower and upper hemisphere ratios. Note that the lower hemisphere is notated as [0-π/2] and the upper hemisphere as [π/2-π]. These angles are with reference to the positive z-axis which is into the tissue.
##### Questions:
1. In what way can the angular information shown in the radiance plots be useful?
2. Which plot of radiance looks most like Fluence and why?
##### Additional Questions:Consider the situation where you using a laser-based therapy to treat an embedded tumor. For this application, it is critical that you maximize the axial penetration of the light field. However during the treatment, the tissue absorption may increase due to increased blood flow and scattering may decrease due to morphological changes in the tissue. In this context comment on the following:
1. How does an increase in absorption impact (a) the axial penetration of the light field and (b) the lateral dispersion of the light field?
2. How does a decrease in scattering impact (a) the axial penetration of the light field and (b) the lateral dispersion of the light field?
3. Would increasing the beam diameter improve (a) the axial penetration of the light field and/or (b) the lateral dispersion of the light field? Is this impact the same regardless of the optical properties? (Hint: Select the Fluence/Interrogation Solver panel. Select "Standard Diffusion (Analytic distributed Gaussian Source)" in the Forward Solver dropdown menu and select Φ(Fluence) in the Map Type. Use different Gaussian Beam Diameters (0.1mm and 10mm) and generate fluence maps.)