From cc47d8b82ec36628a73e3c93eb1c0f493b380527 Mon Sep 17 00:00:00 2001 From: Piotr Date: Thu, 23 Dec 2021 22:18:29 +0100 Subject: [PATCH 1/2] add function to calculate csda range in bulk --- examples/dedx_use_wrappers.c | 14 +++++++++++--- libdedx/dedx_wrappers.c | 26 ++++++++++++++++++++++++-- libdedx/dedx_wrappers.h | 2 ++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/examples/dedx_use_wrappers.c b/examples/dedx_use_wrappers.c index 6d223f3..1c00eb8 100644 --- a/examples/dedx_use_wrappers.c +++ b/examples/dedx_use_wrappers.c @@ -6,7 +6,8 @@ int main() { int err = 0; float energies[10]; - float results[10]; + float stps[10]; + double csdas[10]; const int program = DEDX_PSTAR; const int ion = DEDX_HYDROGEN; const int target = DEDX_WATER_LIQUID; @@ -29,12 +30,19 @@ int main() { energies[i] = 1.f + i * 1.1f; } - err = dedx_get_stp_table(program, ion, target, no_of_points, energies, results); + err = dedx_get_stp_table(program, ion, target, no_of_points, energies, stps); if (err != 0) printf("Encountered error no. %d", err); else for (int i = 0; i < no_of_points; i++) - printf("%f \n", results[i]); + printf("%f \n", stps[i]); + + err = dedx_get_csda_table(program, ion, target, no_of_points, energies, csdas); + if (err != 0) + printf("Encountered error no. %d", err); + else + for (int i = 0; i < no_of_points; i++) + printf("%f \n", csdas[i]); float result = dedx_get_simple_stp_for_program(program, ion, target, energies[0], &err); if (err != 0) diff --git a/libdedx/dedx_wrappers.c b/libdedx/dedx_wrappers.c index 6753460..d31cb57 100644 --- a/libdedx/dedx_wrappers.c +++ b/libdedx/dedx_wrappers.c @@ -16,6 +16,7 @@ */ #include "dedx_wrappers.h" +#include "dedx_tools.h" void dedx_fill_program_list(int *program_list) { /* fill list of available programs, terminated with -1 */ @@ -121,8 +122,7 @@ int dedx_get_stp_table_size(const int program, const int ion, const int target) return result; }; -int -dedx_fill_default_energy_stp_table(const int program, const int ion, const int target, float *energies, float *stps) { +int dedx_fill_default_energy_stp_table(const int program, const int ion, const int target, float *energies, float *stps) { int err = 0; int i; @@ -155,3 +155,25 @@ dedx_fill_default_energy_stp_table(const int program, const int ion, const int t return 0; }; + +int dedx_get_csda_table(const int program, const int ion, const int target, const int no_of_points, + const float *energies, double *csda_ranges) { + int err = 0; + dedx_config *config = (dedx_config *) calloc(1, sizeof(dedx_config)); + config->target = target; + config->ion = ion; + config->program = program; + config->ion_a = ion; + dedx_workspace *ws = dedx_allocate_workspace(1, &err); + + if (err != 0) return err; + dedx_load_config(ws, config, &err); + + for (int i = 0; i < no_of_points; i++) { + csda_ranges[i] = dedx_get_csda(ws, config, energies[i], &err); + } + dedx_free_config(config, &err); + dedx_free_workspace(ws, &err); + + return err; +} \ No newline at end of file diff --git a/libdedx/dedx_wrappers.h b/libdedx/dedx_wrappers.h index 91d3f2f..bb095d2 100644 --- a/libdedx/dedx_wrappers.h +++ b/libdedx/dedx_wrappers.h @@ -20,4 +20,6 @@ int dedx_get_stp_table_size(const int program, const int ion, const int target); int dedx_fill_default_energy_stp_table(const int program, const int ion, const int target, float *energies, float *stps); +int dedx_get_csda_table(const int program, const int ion, const int target, const int no_of_points, + const float *energies, double *csda_ranges); #endif //DEDX_WRAPPERS_INCLUDED From ffd2e5ebd313db75a2c3116f0d5b45b1e129b8cd Mon Sep 17 00:00:00 2001 From: Piotr Date: Thu, 23 Dec 2021 23:00:49 +0100 Subject: [PATCH 2/2] apply suggestions from code review --- examples/dedx_use_wrappers.c | 8 ++++---- libdedx/dedx_wrappers.c | 2 +- libdedx/dedx_wrappers.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/dedx_use_wrappers.c b/examples/dedx_use_wrappers.c index 1c00eb8..0c86009 100644 --- a/examples/dedx_use_wrappers.c +++ b/examples/dedx_use_wrappers.c @@ -7,7 +7,7 @@ int main() { int err = 0; float energies[10]; float stps[10]; - double csdas[10]; + double csda_ranges[10]; const int program = DEDX_PSTAR; const int ion = DEDX_HYDROGEN; const int target = DEDX_WATER_LIQUID; @@ -35,14 +35,14 @@ int main() { printf("Encountered error no. %d", err); else for (int i = 0; i < no_of_points; i++) - printf("%f \n", stps[i]); + printf("E = %f MeV/nucl stop pow. = %f MeV cm2 / g \n", energies[i], stps[i]); - err = dedx_get_csda_table(program, ion, target, no_of_points, energies, csdas); + err = dedx_get_csda_range_table(program, ion, target, no_of_points, energies, csda_ranges); if (err != 0) printf("Encountered error no. %d", err); else for (int i = 0; i < no_of_points; i++) - printf("%f \n", csdas[i]); + printf("E = %f MeV/nucl CSDA range = %f g/cm2\n", energies[i], csda_ranges[i]); float result = dedx_get_simple_stp_for_program(program, ion, target, energies[0], &err); if (err != 0) diff --git a/libdedx/dedx_wrappers.c b/libdedx/dedx_wrappers.c index d31cb57..1334164 100644 --- a/libdedx/dedx_wrappers.c +++ b/libdedx/dedx_wrappers.c @@ -156,7 +156,7 @@ int dedx_fill_default_energy_stp_table(const int program, const int ion, const i }; -int dedx_get_csda_table(const int program, const int ion, const int target, const int no_of_points, +int dedx_get_csda_range_table(const int program, const int ion, const int target, const int no_of_points, const float *energies, double *csda_ranges) { int err = 0; dedx_config *config = (dedx_config *) calloc(1, sizeof(dedx_config)); diff --git a/libdedx/dedx_wrappers.h b/libdedx/dedx_wrappers.h index bb095d2..8cf708c 100644 --- a/libdedx/dedx_wrappers.h +++ b/libdedx/dedx_wrappers.h @@ -20,6 +20,6 @@ int dedx_get_stp_table_size(const int program, const int ion, const int target); int dedx_fill_default_energy_stp_table(const int program, const int ion, const int target, float *energies, float *stps); -int dedx_get_csda_table(const int program, const int ion, const int target, const int no_of_points, +int dedx_get_csda_range_table(const int program, const int ion, const int target, const int no_of_points, const float *energies, double *csda_ranges); #endif //DEDX_WRAPPERS_INCLUDED