generate jacobians for multiple sources and detecors

37 views
Skip to first unread message

IRENE

unread,
Sep 10, 2025, 2:45:35 PMSep 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

Qianqian Fang

unread,
Sep 30, 2025, 1:56:55 PMSep 30
to mcx-...@googlegroups.com, IRENE

hi Irene,

I apologize for the delay. after debugging this issue further, I found several bugs in mcx related to combining replay with multi-source simulation, the issues were documented in this ticket

https://github.com/fangq/mcx/issues/250

I was able to fix it with the two commits linked in the above issue


you may try your sample script again (suggest using lower photon numbers first) - here are the expected results

when using cfg.replaydet=-1 and cfg.srcid=-1, this will produce a Nx * Ny * Nz * Nt * Ndet * Nsrc 6D array to store all combinations of the Jacobians

when cfg.replaydet=1 or 2 and cfg.srcid=-1, the 6th dimension is still Nsrc, but the 5th becomes 1

when cfg.replaydet=-1 and cfg.srcid undefined, the 6th dimension is still 1, the 5th stays 2, each storing the sum of the Jacobians from both sources for each of the detector

when cfg.replaydet=1 or 2 and cfg.srcid=1 or 2, the 5/6 dimensions become 1, producing only one Jacobian for the specified src/det pair

when cfg.replaydet=0 and cfg.srcid undefined, the 5/6 dimensions become 1, producing only one Jacobian summing all src/all detector combinations

Qianqian

On 9/10/25 09:12, IRENE wrote:

You don't often get email from irene...@outlook.com. Learn why this is important

--
You received this message because you are subscribed to the Google Groups "mcx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mcx-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mcx-users/dc9e14e8-4528-476a-a8e4-411f5e7bac26n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages