Here's my script:
clear; clc;
n = 1.4;
g = 0.9;
% length of voxel in mm
cfg.unitinmm = 0.25;
nR = 20/cfg.unitinmm;
nz = 7/cfg.unitinmm;
% volume
cfg.vol = uint8(ones(nR,nR,nz));
% source parameters
probe_NA = 0.22;
probe_r = 0.5; % mm
cfg.srctype = 'disk';
cfg.srcpos = [nR/2 nR/2 nz];
cfg.srcparam1 = [probe_r/cfg.unitinmm 0 0 0];
cfg.srcparam2 = [0 0 0 0];
f = -probe_r/tan(asin(probe_NA/n))./cfg.unitinmm; % focal length
cfg.srcdir = [0 0 -1 f];
cfg.issrcfrom0 = 1;
% other simulation inputs
cfg.prop = [5 0 1 1.5; 0 0 g n];
cfg.nphoton = 1e7;
cfg.bc = 'rrrrra';
cfg.savedetflag = 'dpxvw';
cfg.gpuid = 1;
cfg.autopilot = 1;
cfg.tstart = 0;
cfg.tend = 5e-9;
cfg.tstep = 5e-9;
cfg.debuglevel = 'P';
cfg.isnormalized = 0;
% start the comparison
num_points = 30;
% choose opt props
min_ua = 0.0025;
max_ua = 0.0055;
ua = linspace(min_ua,max_ua,num_points);
us = 25;
Freal = zeros(1,num_points);
Fcheck = zeros(1,num_points);
Ereal = zeros(1,num_points);
Echeck = zeros(1,num_points);
h = waitbar(0, 'Starting');
cfg.prop(2,2) = us;
for i = 1:num_points
cfg.outputtype = 'flux';
cfg.prop(2,1) = ua(i);
[flux_em, ~, ~, ~] = mcxlab(cfg);
Freal(i) = sum(flux_em.data./cfg.nphoton,'all');
Echeck(i) = sum(flux_em.data./cfg.nphoton.*ua(i).*cfg.unitinmm,'all');
cfg.outputtype = 'energy';
[energy_em, ~, ~, ~] = mcxlab(cfg);
Ereal(i) = sum(energy_em.data./cfg.nphoton,'all');
Fcheck(i) = sum(energy_em.data./cfg.nphoton./(ua(i).*cfg.unitinmm),'all');
waitbar(i/num_points,h, sprintf('Percent completed: %0.3f %%', i/num_points*100));
end
delete(h)
%%
figure; plot(ua,Ereal); ylabel('energy'); xlabel('ua (mm^{-1})');
hold on; plot(ua,Echeck,LineStyle='--');
legend("outputtype='energy'", "outputtype='flux'")
grid on
figure; plot(ua,Freal); ylabel('flux'); xlabel('ua (mm^{-1})');
hold on; plot(ua,Fcheck,LineStyle='--');
legend("outputtype='flux'", "outputtype='energy'")
grid on