Option of getting the photon exit weight

51 views
Skip to first unread message

Viet Tran Ba

unread,
Apr 16, 2025, 11:17:04 AMApr 16
to mcx-users
Dear Dr. Fang,

is there a way of getting the photon exit weight after a simulation? I need it to compute the total diffuse reflectance which leaves the surface. Using --saveref will not work for me, because I want to filter out photons with certain exit directions.

The only existing solution I have found was to use something similar as the MCXLab function mcxdetweight(). However, implementing it in Python (which I am currently using to analyze the MCX results) gives me the following problems:

a) My tissue volume is 3D, with different mu_a for multiple voxels.
b) Trying to retrieve the partial path length of each photon with --savedetflag P gives me the error: an illegal memory access was encountered in unit mcx_core.cu:3488.

My current command is:

./mcx -f input.json -O F -b 1 -a 1 -F jnii -e 0.0001 --bc mm_mm_000000 -H --savedetflag DXVW --saveref

I am using a detector at z = 0 to detect the exiting photons. I can confirm that I indeed detect many photons.

Please let me know if I should provide further information.

Thank you for your answer in advance.

With kind regards,

Viet

Qianqian Fang

unread,
Apr 16, 2025, 12:46:08 PMApr 16
to mcx-...@googlegroups.com, Viet Tran Ba

as you recognized, the provided function mcx/utils/mcxdetweight.m does this in matlab,

for pmcx, you should use pmcx.detweight()

https://github.com/fangq/mcx/blob/v2025/pmcx/pmcx/utils.py#L100-L115


On 4/16/25 09:46, Viet Tran Ba wrote:

You don't often get email from bowre...@gmail.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/f9970400-6daa-4cbb-8fa5-09e4940598d7n%40googlegroups.com.

Viet Tran Ba

unread,
Apr 25, 2025, 4:47:04 AMApr 25
to mcx-users
Dear Dr. Fang,

thank you for your answer! However, because I did not really understand how to set the inputs of the function pmcx.detweight() with my current evaluation framework, I have decided to save the photon weight p.w together with its position in the photon data instead (in mcx_core.cu in the MCX repository). 
To compute the resulting reflectance, for each surface voxel, I determined all corresponding photon exit positions and summed its weights to get the reflectance. Afterwards, I divided the reflectance by the amount of simulated photons and the voxel size.

However, if I compare the resulting reflectance and the accumulated reflectance from --saveref, I observe that the resulting reflectance is roughly only half as high as the accumulated reflectance.

Did I save the wrong photon weights, or is there anything I forgot to consider?

Thank you very much for your answer in advance.

With kind regards,

Viet

Qianqian Fang

unread,
Apr 30, 2025, 10:33:53 AMApr 30
to mcx-...@googlegroups.com, Viet Tran Ba

hi Viet,

MCX applies normalization by default (-U 1). This not only applies to fluence, but also dref. 

the internally computed value of the normalization factor is printed in the log (normalization factor alpha = ...). the formula differs from your requested output type, see the source code

https://github.com/fangq/mcx/blob/v2025/src/mcx_core.cu#L3744-L3807

please verify that your normalization matches those produced from mcx.

the other thing you should check out is the dref validation script:

https://github.com/fangq/mcx/blob/master/mcxlab/examples/demo_diffuse_reflectance_validation.m

it uses the detected photon to compute dref using a function mcxcwdref() and this output allows it to be directly compared with dref computed from analytical models.

Qianqian

Reply all
Reply to author
Forward
0 new messages