diff --git a/CMakeLists.txt b/CMakeLists.txt index df41ae8..0ab1e73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -419,6 +419,7 @@ if(AARE_TESTS) ${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterFinder.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterVector.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Cluster.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/CalculateEta.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterFile.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Pedestal.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyFile.test.cpp diff --git a/include/aare/CalculateEta.hpp b/include/aare/CalculateEta.hpp index 088b4e8..86871c9 100644 --- a/include/aare/CalculateEta.hpp +++ b/include/aare/CalculateEta.hpp @@ -25,12 +25,11 @@ typedef enum { pTopRight = 8 } pixel; -// TODO: maybe template this!!!!!! why int32_t???? -struct Eta2 { +template struct Eta2 { double x; double y; int c; - int32_t sum; + T sum; }; /** @@ -56,9 +55,9 @@ NDArray calculate_eta2(const ClusterVector &clusters) { */ template -Eta2 calculate_eta2( - const Cluster &cl) { - Eta2 eta{}; +Eta2 +calculate_eta2(const Cluster &cl) { + Eta2 eta{}; auto max_sum = cl.max_sum_2x2(); eta.sum = max_sum.first; @@ -67,7 +66,7 @@ Eta2 calculate_eta2( size_t index_bottom_left_max_2x2_subcluster = (int(c / (ClusterSizeX - 1))) * ClusterSizeX + c % (ClusterSizeX - 1); - if ((cl.data[index_bottom_left_max_2x2_subcluster] +s + if ((cl.data[index_bottom_left_max_2x2_subcluster] + cl.data[index_bottom_left_max_2x2_subcluster + 1]) != 0) eta.x = static_cast( cl.data[index_bottom_left_max_2x2_subcluster + 1]) / @@ -89,9 +88,9 @@ Eta2 calculate_eta2( // calculates Eta3 for 3x3 cluster based on code from analyze_cluster // TODO only supported for 3x3 Clusters -template Eta2 calculate_eta3(const Cluster &cl) { +template Eta2 calculate_eta3(const Cluster &cl) { - Eta2 eta{}; + Eta2 eta{}; T sum = 0; diff --git a/src/CalculateEta.test.cpp b/src/CalculateEta.test.cpp new file mode 100644 index 0000000..2bdf387 --- /dev/null +++ b/src/CalculateEta.test.cpp @@ -0,0 +1,62 @@ +/************************************************ + * @file CalculateEta.test.cpp + * @short test case to calculate_eta2 + ***********************************************/ + +#include "aare/CalculateEta.hpp" +#include "aare/Cluster.hpp" +#include "aare/ClusterFile.hpp" + +// #include "catch.hpp" +#include +#include +#include + +using namespace aare; + +using ClusterTypes = + std::variant, Cluster, Cluster, + Cluster, Cluster>; + +auto get_test_parameters() { + return GENERATE( + std::make_tuple(ClusterTypes{Cluster{0, 0, {1, 2, 3, 1}}}, + Eta2{2. / 3, 3. / 4, corner::cBottomLeft, 7}), + std::make_tuple( + ClusterTypes{Cluster{0, 0, {1, 2, 3, 4, 5, 6, 1, 2, 7}}}, + Eta2{6. / 11, 2. / 7, corner::cTopRight, 20}), + std::make_tuple(ClusterTypes{Cluster{ + 0, 0, {1, 6, 7, 6, 5, 4, 3, 2, 1, 8, 8, 9, 2, + 1, 4, 5, 6, 7, 8, 4, 1, 1, 1, 1, 1}}}, + Eta2{9. / 17, 5. / 13, 8, 28}), + std::make_tuple( + ClusterTypes{Cluster{0, 0, {1, 4, 7, 2, 5, 6, 4, 3}}}, + Eta2{7. / 11, 6. / 10, 1, 21}), + std::make_tuple( + ClusterTypes{Cluster{0, 0, {1, 3, 2, 3, 4, 2}}}, + Eta2{3. / 5, 4. / 6, 1, 11})); +} + +TEST_CASE("compute_largest_2x2_subcluster", "[.eta_calculation]") { + auto [cluster, expected_eta] = get_test_parameters(); + + auto [sum, index] = std::visit( + [](const auto &clustertype) { return clustertype.max_sum_2x2(); }, + cluster); + CHECK(expected_eta.c == index); + CHECK(expected_eta.sum == sum); +} + +TEST_CASE("calculate_eta2", "[.eta_calculation]") { + + auto [cluster, expected_eta] = get_test_parameters(); + + auto eta = std::visit( + [](const auto &clustertype) { return calculate_eta2(clustertype); }, + cluster); + + CHECK(eta.x == expected_eta.x); + CHECK(eta.y == expected_eta.y); + CHECK(eta.c == expected_eta.c); + CHECK(eta.sum == expected_eta.sum); +} diff --git a/src/Cluster.test.cpp b/src/Cluster.test.cpp index 7918d72..e502012 100644 --- a/src/Cluster.test.cpp +++ b/src/Cluster.test.cpp @@ -26,36 +26,3 @@ TEST_CASE("Correct Instantiation of Cluster and ClusterVector", CHECK(not is_cluster_v); CHECK(is_cluster_v>); } - -using ClusterTypes = - std::variant, Cluster, Cluster, - Cluster, Cluster>; - -TEST_CASE("calculate_eta2", "[.cluster][.eta_calculation]") { - - auto [cluster, expected_eta] = GENERATE( - std::make_tuple(ClusterTypes{Cluster{0, 0, {1, 2, 3, 1}}}, - Eta2{2. / 3, 3. / 4, corner::cBottomLeft, 7}), - std::make_tuple( - ClusterTypes{Cluster{0, 0, {1, 2, 3, 4, 5, 6, 1, 2, 7}}}, - Eta2{6. / 11, 2. / 7, corner::cTopRight, 20}), - std::make_tuple(ClusterTypes{Cluster{ - 0, 0, {1, 6, 7, 6, 5, 4, 3, 2, 1, 8, 8, 9, 2, - 1, 4, 5, 6, 7, 8, 4, 1, 1, 1, 1, 1}}}, - Eta2{9. / 17, 5. / 13, 8, 28}), - std::make_tuple( - ClusterTypes{Cluster{0, 0, {1, 4, 7, 2, 5, 6, 4, 3}}}, - Eta2{7. / 11, 6. / 10, 1, 21}), - std::make_tuple( - ClusterTypes{Cluster{0, 0, {1, 3, 2, 3, 4, 2}}}, - Eta2{3. / 5, 4. / 6, 1, 11})); - - Eta2 eta = std::visit( - [](const auto &clustertype) { return calculate_eta2(clustertype); }, - cluster); - - CHECK(eta.x == expected_eta.x); - CHECK(eta.y == expected_eta.y); - CHECK(eta.c == expected_eta.c); - CHECK(eta.sum == expected_eta.sum); -} diff --git a/src/Interpolator.cpp b/src/Interpolator.cpp index e434231..e4f8e5c 100644 --- a/src/Interpolator.cpp +++ b/src/Interpolator.cpp @@ -68,7 +68,7 @@ Interpolator::interpolate(const ClusterVector &clusters) { for (size_t i = 0; i < clusters.size(); i++) { auto cluster = clusters.at(i); - Eta2 eta = calculate_eta2(cluster); + auto eta = calculate_eta2(cluster); Photon photon; photon.x = cluster.x; @@ -118,7 +118,7 @@ Interpolator::interpolate(const ClusterVector &clusters) { clusters.cluster_size_y() == 2) { for (size_t i = 0; i < clusters.size(); i++) { auto cluster = clusters.at(i); - Eta2 eta = calculate_eta2(cluster); + auto eta = calculate_eta2(cluster); Photon photon; photon.x = cluster.x;