generate jacobians for multiple sources and detecors

14 views
Skip to first unread message

IRENE

unread,
Sep 10, 2025, 2:45:35 PM (12 days ago) Sep 10
to mcx-users
Dear Dr.Fang, 

I am doing simulations with two source and detectors. I want to know if we can generate jacobians for different pairs of source detectors. For example, both ssrcs and det1, both srcs and det2. 

I tried to generate the jacobians for both sources and 1st detector, but it does show anything. can you please help me solve this error? My mcxlab should be the newest. 

Here is my code: 
%% preparing the input data
% set seed to make the simulation repeatible
cfg.seed=hex2dec('623F9A9E');
%cfg.nphoton=1e6;
cfg.nphoton=1e9;
cfg.maxdetphoton =1e8;
% define homogeneous structure
cfg.vol=ones(95,70,45);
cfg.vol=uint8(cfg.vol);
% define the source position
% cfg.srcpos=[15,35,0];
% cfg.srcdir=[0 0 1];
cfg.srcpos=[15,35,0;70,35,0];
cfg.srcdir=[0 0 1;0 0 1];
cfg.issrcfrom0=1;
% Define detector position,radius: 2mm
cfg.detpos=[40,35,0,2;45,35,0,2];
% Define optical properties, format: [mua(1/mm) mus(1/mm) g n]
cfg.prop=[0 0 1 1 % medium 0: the environment
0.01 10 0.9 1.4]; % medium 5: white matter
% time-domain simulation parameters
cfg.tstart=0;
cfg.tend = 10e-9;%10ns
cfg.tstep=5e-12;%5ps
% GPU thread configuration
cfg.autopilot=1;
cfg.gpuid=2;
% Output options:
cfg.savedetflag = 'dpm'; %save detector ID , pathlength and momentum
%% preview phantom, sources and detectors
figure
mcxpreview(cfg);% Invert the Z-axis
set(gca, 'ZDir','reverse');
title('domain preview');
%% running simulation with boundary reflection enabled
cfg.isreflect=1; % enable reflection at exterior boundary
cfg.isrefint=1; % enable reflection at interior boundary too
[flux, detp, vol, seeds] = mcxlab(cfg);
%% view flux distribution
figure(1)
cwflux=sum(flux.data,4);
imagesc(log(squeeze(cwflux(:,35,:))'));
%% generate Jacobians with replay method
% for the left source and close detecor
cfg.replaydet = 1; % for the first detector: SDS=25mm
cfgA = cfg;
cfgA.seed = seeds.data;
cfgA.outputtype = 'jacobian'; % weighted pathlength
cfgA.detphotons = detp.data;
[fluxA, detpA, volA, seedsA] = mcxlab(cfgA);
jacA = sum(fluxA.data, 4);
%%
figure('Name','JacA(25mm)')
imagesc(log10(abs(squeeze(jacA(:, 35, :))')));
colorbar
axis image
colormap('jet')

Thanks and best wishes,
Xingmin

Reply all
Reply to author
Forward
0 new messages