Geant4 Version: 11.4.2
Operating System: MacOS26 / Debian Linux
Compiler/Version: clang21 / gcc14
CMake Version: 4.3.1
Hello,
I’m simulating the mu+ → e+ decay for μSR (muon spin rotation) under the magnetic field.
I found what appears to be a thread-safety issue in the spin-dependent muon decay.
In a μSR simulation using G4DecayWithSpin, the decay positron asymmetry (A) is significantly reduced in multi-threaded mode compared to sequential mode. For example,
Sequential: A = 0.327 (almost equivalent to the theoretical value of 1/3)
Multi-threaded (32 threads): A = 0.107
I verified the problem in two independent ways:
- by comparing the distribution of the dot product between the muon polarization at decay and the decay positron momentum direction.
- by fitting the oscillation amplitude of the decay-positron time spectrum in a transverse magnetic field.
Both methods give consistent results.
This only happens when spin precession in a magnetic field is enabled. In zero magnetic field, sequential and multi-threaded runs give consistent results.
After some debugging with the help of AI-assistant, I found that all worker threads appear to share the same G4MuonDecayChannelWithSpin instance. The pointer address printed in every worker thread is identical.
G4DecayWithSpin::AtRestDoIt() calls
decaytable->GetDecayChannel(ip)->SetPolarization(parent_polarization);
and later G4MuonDecayChannelWithSpin::DecayIt() uses the member variable parent_polarization.
Since the decay channel object seems to be shared between threads, it looks possible that one thread overwrites parent_polarization before another thread executes DecayIt().
Is this expected behavior, or could this be a thread-safety issue?