Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-04 08:10:43

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Utilities/AxisDefinitions.hpp"
0012 #include "Acts/Utilities/IAxis.hpp"
0013 #include "Acts/Utilities/IMultiAxis.hpp"
0014 #include "ActsExamples/Digitization/MeasurementCreation.hpp"
0015 #include "ActsExamples/Digitization/ModuleClusters.hpp"
0016 #include "ActsFatras/Digitization/Segmentizer.hpp"
0017 
0018 #include <algorithm>
0019 #include <iterator>
0020 #include <memory>
0021 
0022 using namespace Acts;
0023 using namespace ActsFatras;
0024 using namespace ActsExamples;
0025 
0026 namespace ActsTests {
0027 
0028 std::shared_ptr<const IMultiAxis> makeSegmentation() {
0029   const auto axisX = IAxis::createEquidistant(AxisBoundaryType::Bound, -10.0,
0030                                               10.0, 20, AxisDirection::AxisX);
0031   const auto axisY = IAxis::createEquidistant(AxisBoundaryType::Bound, -10.0,
0032                                               10.0, 20, AxisDirection::AxisY);
0033   return IMultiAxis::create(*axisX, *axisY);
0034 }
0035 
0036 DigitizedParameters makeDigitizationParameters(const Vector2 &position,
0037                                                const Vector2 &variance,
0038                                                const IMultiAxis &segmentation) {
0039   // Cell bins are zero-based while the axis bin indices start at one
0040   const std::size_t binX = segmentation.getAxis(0).getBin(position.x()) - 1;
0041   const std::size_t binY = segmentation.getAxis(1).getBin(position.y()) - 1;
0042   const Segmentizer::Bin2D bin = {
0043       static_cast<Segmentizer::Bin2D::value_type>(binX),
0044       static_cast<Segmentizer::Bin2D::value_type>(binY)};
0045   const Segmentizer::Segment2D segment = {position, position};
0046   const double activation = 1;
0047   const Cluster::Cell cell = {bin, segment, activation};
0048 
0049   Cluster cluster;
0050   cluster.sizeLoc0 = 1;
0051   cluster.sizeLoc1 = 1;
0052   cluster.channels = {cell};
0053 
0054   DigitizedParameters params;
0055   params.indices = {eBoundLoc0, eBoundLoc1};
0056   params.values = {position.x(), position.y()};
0057   params.variances = {variance.x(), variance.y()};
0058   params.cluster = {cluster};
0059 
0060   return params;
0061 }
0062 
0063 DigitizedParameters makeDigitizationParametersWithTime(
0064     const Vector2 &position, const Vector2 &variance, double time,
0065     double timeVariance, const IMultiAxis &segmentation) {
0066   DigitizedParameters params =
0067       makeDigitizationParameters(position, variance, segmentation);
0068   params.indices.push_back(eBoundTime);
0069   params.values.push_back(time);
0070   params.variances.push_back(timeVariance);
0071   return params;
0072 }
0073 
0074 auto testDigitizedParametersWithTwoClusters(bool merge, const Vector2 &firstHit,
0075                                             const Vector2 &secondHit) {
0076   std::shared_ptr<const IMultiAxis> segmentation = makeSegmentation();
0077   std::vector<Acts::BoundIndices> boundIndices = {eBoundLoc0, eBoundLoc1};
0078   double nsigma = 1;
0079   bool commonCorner = true;
0080 
0081   ModuleClusters moduleClusters(segmentation, boundIndices, merge, nsigma,
0082                                 commonCorner);
0083 
0084   moduleClusters.add(
0085       makeDigitizationParameters(firstHit, {1, 1}, *segmentation), 0);
0086   moduleClusters.add(
0087       makeDigitizationParameters(secondHit, {1, 1}, *segmentation), 1);
0088 
0089   return moduleClusters.digitizedParameters();
0090 }
0091 
0092 auto testDigitizedParametersWithTwoTimedClusters(bool merge,
0093                                                  const Vector2 &firstHit,
0094                                                  double firstTime,
0095                                                  const Vector2 &secondHit,
0096                                                  double secondTime) {
0097   std::shared_ptr<const IMultiAxis> segmentation = makeSegmentation();
0098   std::vector<Acts::BoundIndices> boundIndices = {eBoundLoc0, eBoundLoc1};
0099   double nsigma = 1;
0100   bool commonCorner = true;
0101 
0102   ModuleClusters moduleClusters(segmentation, boundIndices, merge, nsigma,
0103                                 commonCorner);
0104 
0105   moduleClusters.add(makeDigitizationParametersWithTime(
0106                          firstHit, {1, 1}, firstTime, 1, *segmentation),
0107                      0);
0108   moduleClusters.add(makeDigitizationParametersWithTime(
0109                          secondHit, {1, 1}, secondTime, 1, *segmentation),
0110                      1);
0111 
0112   return moduleClusters.digitizedParameters();
0113 }
0114 
0115 BOOST_AUTO_TEST_SUITE(DigitizationSuite)
0116 
0117 BOOST_AUTO_TEST_CASE(digitizedParameters_merging) {
0118   // overlapping hits are expected to be merged if turned on
0119   {
0120     auto result = testDigitizedParametersWithTwoClusters(true, {0, 0}, {0, 0});
0121     BOOST_CHECK_EQUAL(result.size(), 1);
0122 
0123     result = testDigitizedParametersWithTwoClusters(false, {0, 0}, {0, 0});
0124     BOOST_CHECK_EQUAL(result.size(), 2);
0125   }
0126 
0127   // non overlapping hits are not expected to be merged
0128   {
0129     auto result = testDigitizedParametersWithTwoClusters(true, {0, 0}, {5, 0});
0130     BOOST_CHECK_EQUAL(result.size(), 2);
0131 
0132     result = testDigitizedParametersWithTwoClusters(false, {0, 0}, {5, 0});
0133     BOOST_CHECK_EQUAL(result.size(), 2);
0134   }
0135 }
0136 
0137 BOOST_AUTO_TEST_CASE(digitizedParameters_merging_with_smeared_time) {
0138   // hits with geometric (loc0, loc1) and smeared (time) parameters in
0139   // adjacent cells: compatible times are expected to be merged
0140   {
0141     auto result = testDigitizedParametersWithTwoTimedClusters(true, {0, 0}, 1.0,
0142                                                               {1.05, 0}, 2.0);
0143     BOOST_REQUIRE_EQUAL(result.size(), 1);
0144 
0145     const auto &[params, simHits] = result.front();
0146     auto it = std::ranges::find(params.indices, eBoundTime);
0147     BOOST_REQUIRE(it != params.indices.end());
0148     auto slot = std::distance(params.indices.begin(), it);
0149     BOOST_CHECK_CLOSE(params.values.at(slot), 1.5, 1e-6);
0150     BOOST_CHECK_EQUAL(simHits.size(), 2);
0151   }
0152 
0153   // incompatible times prevent merging
0154   {
0155     auto result = testDigitizedParametersWithTwoTimedClusters(true, {0, 0}, 0.0,
0156                                                               {1.05, 0}, 10.0);
0157     BOOST_CHECK_EQUAL(result.size(), 2);
0158   }
0159 }
0160 
0161 BOOST_AUTO_TEST_SUITE_END()
0162 
0163 }  // namespace ActsTests