Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions examples/dedx_use_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
int main() {
int err = 0;
float energies[10];
float results[10];
float stps[10];
double csda_ranges[10];
const int program = DEDX_PSTAR;
const int ion = DEDX_HYDROGEN;
const int target = DEDX_WATER_LIQUID;
Expand All @@ -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("E = %f MeV/nucl stop pow. = %f MeV cm2 / g \n", energies[i], stps[i]);

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("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)
Expand Down
26 changes: 24 additions & 2 deletions libdedx/dedx_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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_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));
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;
}
2 changes: 2 additions & 0 deletions libdedx/dedx_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_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