Skip to content

Commit

Permalink
test: Unit test geometric digitization hit merging (#2213)
Browse files Browse the repository at this point in the history
This adds a unit test to the geometric digitization. For now I just added a quick check if that hit merging does something if you provide the same hit twice.
  • Loading branch information
andiwand committed Jun 23, 2023
1 parent 9c50e11 commit 360b24f
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 1 deletion.
1 change: 1 addition & 0 deletions Tests/UnitTests/Examples/Algorithms/CMakeLists.txt
@@ -0,0 +1 @@
add_subdirectory(Digitization)
@@ -0,0 +1,3 @@
set(unittest_extra_libraries ActsExamplesDigitization)

add_unittest(ModuleClusters 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 <boost/test/unit_test.hpp>

#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<Acts::BoundIndices> 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()
3 changes: 2 additions & 1 deletion Tests/UnitTests/Examples/CMakeLists.txt
@@ -1 +1,2 @@
add_subdirectory_if(Json ACTS_BUILD_PLUGIN_JSON)
add_subdirectory(Algorithms)
add_subdirectory(Io)
1 change: 1 addition & 0 deletions Tests/UnitTests/Examples/Io/CMakeLists.txt
@@ -0,0 +1 @@
add_subdirectory_if(Json ACTS_BUILD_PLUGIN_JSON)

0 comments on commit 360b24f

Please sign in to comment.