This paper presents a novel method for the calculation of three-dimensional (3D) Bragg-Gray water-to-detector stopping power ratio (s w,det ) distributions for proton and carbon ion beams. Methods: Contrary to previously published fluence-based calculations of the stopping power ratio, the s w,det calculation method used in this work is based on the specific way GATE/Geant4 scores the energy deposition. It only requires the use of the so-called DoseActor, as available in GATE, for the calculation of the s w,det at any point of a 3D dose distribution. The simulations are performed using GATE-RTion v1.0, a dedicated GATE release that was validated for the clinical use in light ion beam therapy. Results: The Bragg-Gray water-to-air stopping power ratio (s w,air ) was calculated for monoenergetic proton and carbon ion beams with the default stopping power data in GATE-RTion v1.0 and the new ICRU90 recommendation. The s w,air differences between the use of the default and the ICRU90 configuration were 0.6% and 5.4% at the physical range (R 80 -80% dose level in the distal dose falloff) for a 70 MeV proton beam and a 120 MeV/u carbon ion beam, respectively. For protons, the s w, det results for lithium fluoride, silicon, gadolinium oxysulfide, and the active layer material of EBT2 (radiochromic film) were compared with the literature and a reasonable agreement was found. For a real patient treatment plan, the 3D distributions of s w,det in proton beams were calculated. Conclusions: Our method was validated by comparison with available literature data. Its equivalence with Bragg-Gray cavity theory was demonstrated mathematically. The capability of GATE-RTion v1.0 for the s w,det calculation at any point of a 3D dose distribution for simple and complex proton and carbon ion plans was presented.