From c8bff440e7848a33f369dff1ce11f726cecbbe20 Mon Sep 17 00:00:00 2001 From: tlatorre Date: Mon, 10 Sep 2018 11:16:41 -0500 Subject: add a fast likelihood function This commit adds a fast function to calculate the expected number of PE at a PMT without numerically integrating over the track. This calculation is *much* faster than integrating over the track (~30 ms compared to several seconds) and so we use it during the "quick" minimization phase of the fit to quickly find the best position. --- src/test.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/test.c') diff --git a/src/test.c b/src/test.c index fb788ba..fa4256f 100644 --- a/src/test.c +++ b/src/test.c @@ -467,6 +467,28 @@ err: return 1; } +int test_lnfact(char *err) +{ + /* Tests the lnfact() function. */ + size_t i; + double x, expected; + + for (i = 0; i < 1000; i++) { + x = lnfact(i); + expected = gsl_sf_lnfact(i); + + if (!isclose(x, expected, 1e-9, 1e-9)) { + sprintf(err, "lnfact(%zu) returned %.5g, but expected %.5g", i, x, expected); + goto err; + } + } + + return 0; + +err: + return 1; +} + struct tests { testFunction *test; char *name; @@ -482,6 +504,7 @@ struct tests { {test_path, "test_path"}, {test_interp1d, "test_interp1d"}, {test_kahan_sum, "test_kahan_sum"}, + {test_lnfact, "test_lnfact"}, }; int main(int argc, char **argv) -- cgit