nrc-cnrc / EGSnrc

Toolkit for Monte Carlo simulation of ionizing radiation — Trousse d'outils logiciels pour la simulation Monte Carlo du rayonnement ionisant
http://nrc-cnrc.github.io/EGSnrc
GNU Affero General Public License v3.0
242 stars 146 forks source link

Unit conversion 1.602E-10 in DOSRZnrc, DOSXYZnrc etc is off by 0.011% vs current data #676

Open dworogers opened 3 years ago

dworogers commented 3 years ago

Various RZ and other codes need to convert from scored MeV/g to Gy. Using latest codata values the conversion is 1.6021766E-10 rather than 1.602E-10 used in the codes, i.e. 0.011% higher. Not a big deal but might as well have it exact.

ftessier commented 3 years ago

Agreed. Since this value is exact in the SI, I would go all the way and define e = 1.602 176 634 x 10^-19 C.

ftessier commented 3 years ago

Found this in src/EEMF_macros_beamnrc.mortran: REPLACE{$EC_em}WITH{1.60217662E-19}; "electron charge". I suggest we simply make such a constant available throughout, along with conversion factors such as eVToMeV, MeVPerGramToGray, etc., as suggested by @MartinMartinov in #701.

ftessier commented 3 years ago

Something like this, in a new header egs_constants.h:


// Physical constants

const EGS_Float     e_charge = 1.602176634e-19;    // Coulomb, exact, CODATA 2018

// Conversion factors

const EGS_Float     eV_to_MeV           = 1e-6;
const EGS_Float     eV_to_Joule         = e_charge;
const EGS_Float     MeV_to_Joule        = 1e6 * eV_to_Joule;
const EGS_Float     MeVPerGram_to_Gray  = 1e3 * MeV_to_Joule;

// (and more...)
mchamberland commented 3 months ago

Just bumped into something where two codes were using slightly different values for the electron charge, which made it trickier than it should have been to tell if there was any difference between the two codes.

So, what I'm saying is: I hope this gets addressed soon!

ftessier commented 3 months ago

Yes, the EGSnrc rewrite we are considering will use the exact value of $\large e$ as a constant, and perhaps a solid unit conversion library (or at the very least conversion factors as pointed out above). No more hard coded numbers!