Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 07:54:22

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/Plugins/ExaTrkX/BoostTrackBuilding.hpp"
0012 #include "Acts/Utilities/Helpers.hpp"
0013 
0014 #include <algorithm>
0015 #include <numeric>
0016 
0017 BOOST_AUTO_TEST_CASE(test_track_building) {
0018   // Make some spacepoint IDs
0019   // The spacepoint ids are [100, 101, 102, ...]
0020   // They should not be zero based to check if the thing also works if the
0021   // spacepoint IDs do not match the node IDs used for the edges
0022   std::vector<int> spacepointIds(16);
0023   std::iota(spacepointIds.begin(), spacepointIds.end(), 100);
0024 
0025   // Build 4 tracks with 4 hits
0026   std::vector<std::vector<int>> refTracks;
0027   for (auto t = 0ul; t < 4; ++t) {
0028     refTracks.emplace_back(spacepointIds.begin() + 4 * t,
0029                            spacepointIds.begin() + 4 * (t + 1));
0030   }
0031 
0032   // Make edges
0033   std::vector<std::int64_t> e0, e1;
0034   for (const auto &track : refTracks) {
0035     for (auto it = track.begin(); it != track.end() - 1; ++it) {
0036       // edges must be 0 based, so subtract 100 again
0037       e0.push_back(*it - 100);
0038       e1.push_back(*std::next(it) - 100);
0039     }
0040   }
0041 
0042   Acts::ExecutionContext execCtx{Acts::Device::Cpu(), {}};
0043 
0044   auto edgeTensor = Acts::Tensor<std::int64_t>::Create({2, e0.size()}, execCtx);
0045   std::copy(e0.begin(), e0.end(), edgeTensor.data());
0046   std::copy(e1.begin(), e1.end(), edgeTensor.data() + e0.size());
0047 
0048   auto dummyNodes =
0049       Acts::Tensor<float>::Create({spacepointIds.size(), 16}, execCtx);
0050   auto dummyWeights = Acts::Tensor<float>::Create({e0.size(), 1}, execCtx);
0051   std::fill(dummyWeights.data(), dummyWeights.data() + dummyWeights.size(),
0052             1.f);
0053 
0054   // Run Track building
0055   auto logger = Acts::getDefaultLogger("TestLogger", Acts::Logging::ERROR);
0056   Acts::BoostTrackBuilding trackBuilder({}, std::move(logger));
0057 
0058   auto testTracks = trackBuilder({std::move(dummyNodes), std::move(edgeTensor),
0059                                   std::nullopt, std::move(dummyWeights)},
0060                                  spacepointIds);
0061 
0062   BOOST_CHECK_EQUAL(testTracks.size(), refTracks.size());
0063 
0064   // Sort tracks, so we can find them
0065   std::ranges::for_each(testTracks, [](auto &t) { std::ranges::sort(t); });
0066   std::ranges::sort(testTracks, std::less{}, [](auto &t) { return t.at(0); });
0067 
0068   std::ranges::for_each(refTracks, [](auto &t) { std::ranges::sort(t); });
0069   std::ranges::sort(refTracks, std::less{}, [](auto &t) { return t.at(0); });
0070 
0071   // Check what we have here
0072   for (const auto &refTrack : refTracks) {
0073     BOOST_CHECK(Acts::rangeContainsValue(testTracks, refTrack));
0074   }
0075 }