aboutsummaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test.c')
-rw-r--r--test.c33
1 files changed, 32 insertions, 1 deletions
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)