diff options
Diffstat (limited to 'src/proton.c')
-rw-r--r-- | src/proton.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/proton.c b/src/proton.c index 922c552..f5a6b61 100644 --- a/src/proton.c +++ b/src/proton.c @@ -18,9 +18,12 @@ static int initialized = 0; -static double *x, *dEdx, *csda_range; +static double *x, *dEdx_rad, *dEdx, *csda_range; static size_t size; +static gsl_interp_accel *acc_dEdx_rad; +static gsl_spline *spline_dEdx_rad; + static gsl_interp_accel *acc_dEdx; static gsl_spline *spline_dEdx; @@ -71,6 +74,7 @@ static int init() } x = malloc(sizeof(double)*n); + dEdx_rad = malloc(sizeof(double)*n); dEdx = malloc(sizeof(double)*n); csda_range = malloc(sizeof(double)*n); size = n; @@ -103,6 +107,9 @@ static int init() case 0: x[n] = value; break; + case 2: + dEdx_rad[n] = value; + break; case 3: dEdx[n] = value; break; @@ -119,6 +126,10 @@ static int init() fclose(f); + acc_dEdx_rad = gsl_interp_accel_alloc(); + spline_dEdx_rad = gsl_spline_alloc(gsl_interp_linear, size); + gsl_spline_init(spline_dEdx_rad, x, dEdx_rad, size); + acc_dEdx = gsl_interp_accel_alloc(); spline_dEdx = gsl_spline_alloc(gsl_interp_linear, size); gsl_spline_init(spline_dEdx, x, dEdx, size); @@ -158,6 +169,27 @@ double proton_get_range(double T, double rho) return gsl_spline_eval(spline_range, T, acc_range)/rho; } +double proton_get_dEdx_rad(double T, double rho) +{ + /* Returns the approximate radiative dE/dx for a proton in water with + * kinetic energy `T`. + * + * `T` should be in MeV and `rho` in g/cm^3. + * + * Return value is in MeV/cm. + * + * See http://pdg.lbl.gov/2018/AtomicNuclearProperties/adndt.pdf. */ + if (!initialized) { + if (init()) { + exit(1); + } + } + + if (T < spline_dEdx_rad->x[0]) return spline_dEdx_rad->y[0]; + + return gsl_spline_eval(spline_dEdx_rad, T, acc_dEdx_rad)*rho; +} + double proton_get_dEdx(double T, double rho) { /* Returns the approximate dE/dx for a proton in water with kinetic energy |