diff options
author | tlatorre <tlatorre@uchicago.edu> | 2019-01-10 09:17:09 -0600 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2019-01-10 09:17:09 -0600 |
commit | 1df2bedf516d5fd9c305ba065bf4cf1007967e41 (patch) | |
tree | a2f84efe2c6a579d8d781fd773cde9b359d28d8d /src/test.c | |
parent | 29f4c9d95b20b0e39b39bf7cee868a132768ccb6 (diff) | |
download | sddm-1df2bedf516d5fd9c305ba065bf4cf1007967e41.tar.gz sddm-1df2bedf516d5fd9c305ba065bf4cf1007967e41.tar.bz2 sddm-1df2bedf516d5fd9c305ba065bf4cf1007967e41.zip |
update find_peaks algorithm
Previously, the algorithm used to find peaks was to search for all peaks in the
Hough transform above some constant fraction of the highest peak. This
algorithm could have issues finding smaller peaks away from the highest peak.
The new algorithm instead finds the highest peak in the Hough transform and
then recomputes the Hough transform ignoring all PMT hits within the Cerenkov
cone of the first peak. The next peak is found from this transform and the
process is iteratively repeated until a certain number of peaks are found.
One disadvantage of this new system is that it will *always* find the same
number of peaks and this will usually be greater than the actual number of
rings in the event. This is not a problem though since when fitting the event
we loop over all possible peaks and do a quick fit to determine the starting
point and so false positives are OK because the real peaks will fit better
during this quick fit.
Another potential issue with this new method is that by rejecting all PMT hits
within the Cerenkov cone of the first peak we could miss a second peak very
close to the first peak. This is partially mitigated by the fact that when we
loop over all possible combinations of the particle ids and directions we allow
each peak to be used more than once. For example, when fitting for the
hypothesis that an event is caused by two electrons and one muon and given two
possible directions 1 and 2, we will fit for the following possible direction
combinations:
1 1 1
1 1 2
1 2 1
1 2 2
2 2 1
2 2 2
Therefore if there is a second ring close to the first it is possible to fit it
correctly since we will seed the quick fit with two particles pointing in the
same direction.
This commit also adds a few tests for new functions and changes the energy step
size during the quick fit to 10% of the starting energy value.
Diffstat (limited to 'src/test.c')
-rw-r--r-- | src/test.c | 86 |
1 files changed, 86 insertions, 0 deletions
@@ -25,6 +25,7 @@ #include "sno.h" #include "quad.h" #include "find_peaks.h" +#include <gsl/gsl_sort.h> typedef int testFunction(char *err); @@ -1893,6 +1894,88 @@ int test_combinations_with_replacement(char *err) return 0; } +int test_get_dir(char *err) +{ + /* Tests the get_dir() function. */ + size_t i, j; + double dir[3], expected_dir[3]; + double theta, phi; + + init_genrand(0); + + for (i = 0; i < 100; i++) { + theta = genrand_real2()*M_PI; + phi = genrand_real2()*2*M_PI; + + get_dir(dir,theta,phi); + + expected_dir[0] = sin(theta)*cos(phi); + expected_dir[1] = sin(theta)*sin(phi); + expected_dir[2] = cos(theta); + + for (j = 0; j < 3; j++) { + if (!isclose(dir[j],expected_dir[j],0,1e-9)) { + sprintf(err, "dir[%zu] returned %.2f but expected %.2f", j, dir[j], expected_dir[j]); + return 1; + } + } + } + + return 0; +} + +int test_argmax(char *err) +{ + /* Tests the argmax() function. */ + size_t i, j; + double a[100]; + size_t max, p; + + init_genrand(0); + + for (i = 0; i < 100; i++) { + for (j = 0; j < 100; j++) + a[j] = genrand_real2(); + + max = argmax(a,LEN(a)); + + gsl_sort_largest_index(&p,1,a,1,LEN(a)); + + if (max != p) { + sprintf(err, "argmax() returned %zu but expected %zu", max, p); + return 1; + } + } + + return 0; +} + +int test_argmin(char *err) +{ + /* Tests the argmin() function. */ + size_t i, j; + double a[100]; + size_t min, p; + + init_genrand(0); + + for (i = 0; i < 100; i++) { + for (j = 0; j < 100; j++) + a[j] = genrand_real2(); + + min = argmin(a,LEN(a)); + + gsl_sort_smallest_index(&p,1,a,1,LEN(a)); + + if (min != p) { + sprintf(err, "argmin() returned %zu but expected %zu", min, p); + return 1; + } + } + + return 0; +} + struct tests { testFunction *test; char *name; @@ -1940,6 +2023,9 @@ struct tests { {test_find_peaks_highest, "test_find_peaks_highest"}, {test_find_peaks_sorted, "test_find_peaks_sorted"}, {test_combinations_with_replacement, "test_combinations_with_replacement"}, + {test_get_dir, "test_get_dir"}, + {test_argmax, "test_argmax"}, + {test_argmin, "test_argmin"}, }; int main(int argc, char **argv) |