From a752ad53b2712fb58bed611ef9297cb822e1bb20 Mon Sep 17 00:00:00 2001 From: tlatorre Date: Thu, 5 Jul 2018 16:43:24 -0400 Subject: add a function to compute the energy along a muon track --- test.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'test.c') diff --git a/test.c b/test.c index 1491711..3448565 100644 --- a/test.c +++ b/test.c @@ -109,6 +109,36 @@ int isclose(double a, double b, double rel_tol, double abs_tol) return fabs(a-b) <= fmax(rel_tol*fmax(fabs(a),fabs(b)),abs_tol); } +int test_muon_get_E(char *err) +{ + /* A very simple test to make sure the energy as a function of distance + * along the track makes sense. Should include more detailed tests later. */ + double T, E, range; + + /* Assume initial kinetic energy is 1 GeV. */ + T = 1000.0; + E = get_E(T,1e-9,1.0); + + /* At the beginning of the track we should have roughly the same energy. */ + if (!isclose(E, T, 1e-5, 0)) { + sprintf(err, "KE = %.5f, but expected %.5f", E, T); + return 1; + } + + /* Assume initial kinetic energy is 1 GeV. */ + T = 1000.0; + range = get_range(T,1.0); + E = get_E(T,range,1.0); + + /* At the end of the track we should have roughly the same energy. */ + if (!isclose(E, 0, 1e-5, 1e-5)) { + sprintf(err, "KE = %.5f, but expected %.5f", E, 0.0); + return 1; + } + + return 0; +} + int test_muon_get_range(char *err) { /* A very simple test to make sure we read in the PDG table correctly. */ @@ -198,7 +228,8 @@ struct tests { {test_solid_angle, "test_solid_angle"}, {test_refractive_index, "test_refractive_index"}, {test_muon_get_dEdx, "test_muon_get_dEdx"}, - {test_muon_get_range, "test_muon_get_range"} + {test_muon_get_range, "test_muon_get_range"}, + {test_muon_get_E, "test_muon_get_E"} }; int main(int argc, char **argv) -- cgit