diff --git a/Tests/UnitTests/Examples/Algorithms/CMakeLists.txt b/Tests/UnitTests/Examples/Algorithms/CMakeLists.txt new file mode 100644 index 00000000000..68400c2d538 --- /dev/null +++ b/Tests/UnitTests/Examples/Algorithms/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Digitization) diff --git a/Tests/UnitTests/Examples/Algorithms/Digitization/CMakeLists.txt b/Tests/UnitTests/Examples/Algorithms/Digitization/CMakeLists.txt new file mode 100644 index 00000000000..651996e51d1 --- /dev/null +++ b/Tests/UnitTests/Examples/Algorithms/Digitization/CMakeLists.txt @@ -0,0 +1,3 @@ +set(unittest_extra_libraries ActsExamplesDigitization) + +add_unittest(ModuleClusters ModuleClustersTests.cpp) diff --git a/Tests/UnitTests/Examples/Algorithms/Digitization/ModuleClustersTests.cpp b/Tests/UnitTests/Examples/Algorithms/Digitization/ModuleClustersTests.cpp new file mode 100644 index 00000000000..5503d2d466c --- /dev/null +++ b/Tests/UnitTests/Examples/Algorithms/Digitization/ModuleClustersTests.cpp @@ -0,0 +1,92 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include "Acts/Utilities/BinningData.hpp" +#include "ActsExamples/Digitization/ModuleClusters.hpp" +#include "ActsFatras/Digitization/Channelizer.hpp" + +using namespace Acts; +using namespace ActsFatras; +using namespace ActsExamples; + +namespace { + +DigitizedParameters makeDigitizationParameters(const Vector2 &position, + const Vector2 &variance, + const BinUtility &binUtility) { + auto [binX, binY, _] = + binUtility.binTriple((Vector3() << position, 0).finished()); + Channelizer::Bin2D bin = {(Channelizer::Bin2D::value_type)binX, + (Channelizer::Bin2D::value_type)binY}; + Channelizer::Segment2D segment = {position, position}; + double activation = 1; + Cluster::Cell cell = {bin, segment, activation}; + + Cluster cluster; + cluster.sizeLoc0 = 1; + cluster.sizeLoc1 = 1; + cluster.channels = {cell}; + + DigitizedParameters params; + params.indices = {eBoundLoc0, eBoundLoc1}; + params.values = {position.x(), position.y()}; + params.variances = {variance.x(), variance.y()}; + params.cluster = {cluster}; + + return params; +} + +auto testDigitizedParametersWithTwoClusters(bool merge, const Vector2 &firstHit, + const Vector2 &secondHit) { + BinUtility binUtility; + binUtility += + BinningData(BinningOption::open, BinningValue::binX, 20, -10.0f, 10.0f); + binUtility += + BinningData(BinningOption::open, BinningValue::binY, 20, -10.0f, 10.0f); + std::vector boundIndices = {eBoundLoc0, eBoundLoc1}; + double nsigma = 1; + bool commonCorner = true; + + ModuleClusters moduleClusters(binUtility, boundIndices, merge, nsigma, + commonCorner); + + moduleClusters.add(makeDigitizationParameters(firstHit, {1, 1}, binUtility), + 0); + moduleClusters.add(makeDigitizationParameters(secondHit, {1, 1}, binUtility), + 1); + + return moduleClusters.digitizedParameters(); +} + +} // namespace + +BOOST_AUTO_TEST_SUITE(DigitizationModuleClustersTests) + +BOOST_AUTO_TEST_CASE(digitizedParameters_merging) { + // overlapping hits are expected to be merged if turned on + { + auto result = testDigitizedParametersWithTwoClusters(true, {0, 0}, {0, 0}); + BOOST_CHECK_EQUAL(result.size(), 1); + + result = testDigitizedParametersWithTwoClusters(false, {0, 0}, {0, 0}); + BOOST_CHECK_EQUAL(result.size(), 2); + } + + // non overlapping hits are not expected to be merged + { + auto result = testDigitizedParametersWithTwoClusters(true, {0, 0}, {5, 0}); + BOOST_CHECK_EQUAL(result.size(), 2); + + result = testDigitizedParametersWithTwoClusters(false, {0, 0}, {5, 0}); + BOOST_CHECK_EQUAL(result.size(), 2); + } +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/Tests/UnitTests/Examples/CMakeLists.txt b/Tests/UnitTests/Examples/CMakeLists.txt index fd13a837780..e275a2da86a 100644 --- a/Tests/UnitTests/Examples/CMakeLists.txt +++ b/Tests/UnitTests/Examples/CMakeLists.txt @@ -1 +1,2 @@ -add_subdirectory_if(Json ACTS_BUILD_PLUGIN_JSON) +add_subdirectory(Algorithms) +add_subdirectory(Io) diff --git a/Tests/UnitTests/Examples/Io/CMakeLists.txt b/Tests/UnitTests/Examples/Io/CMakeLists.txt new file mode 100644 index 00000000000..fd13a837780 --- /dev/null +++ b/Tests/UnitTests/Examples/Io/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory_if(Json ACTS_BUILD_PLUGIN_JSON) diff --git a/Tests/UnitTests/Examples/Json/CMakeLists.txt b/Tests/UnitTests/Examples/Io/Json/CMakeLists.txt similarity index 100% rename from Tests/UnitTests/Examples/Json/CMakeLists.txt rename to Tests/UnitTests/Examples/Io/Json/CMakeLists.txt diff --git a/Tests/UnitTests/Examples/Json/JsonDigitizationConfigTests.cpp b/Tests/UnitTests/Examples/Io/Json/JsonDigitizationConfigTests.cpp similarity index 100% rename from Tests/UnitTests/Examples/Json/JsonDigitizationConfigTests.cpp rename to Tests/UnitTests/Examples/Io/Json/JsonDigitizationConfigTests.cpp