Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:09

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/Plugins/ExaTrkX/detail/TensorVectorConversion.hpp"
0013 #include "Acts/Utilities/Helpers.hpp"
0014 
0015 #include <algorithm>
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> edges;
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       edges.push_back(*it - 100);
0038       edges.push_back(*std::next(it) - 100);
0039     }
0040   }
0041 
0042   auto edgeTensor =
0043       Acts::detail::vectorToTensor2D(edges, 2).t().contiguous().clone();
0044   auto dummyWeights = torch::ones(edges.size() / 2, torch::kFloat32);
0045 
0046   // Run Track building
0047   auto logger = Acts::getDefaultLogger("TestLogger", Acts::Logging::ERROR);
0048   Acts::BoostTrackBuilding trackBuilder(std::move(logger));
0049 
0050   auto testTracks = trackBuilder({}, edgeTensor, dummyWeights, spacepointIds);
0051 
0052   // Sort tracks, so we can find them
0053   std::for_each(testTracks.begin(), testTracks.end(),
0054                 [](auto &t) { std::ranges::sort(t); });
0055   std::for_each(refTracks.begin(), refTracks.end(),
0056                 [](auto &t) { std::ranges::sort(t); });
0057 
0058   // Check what we have here
0059   for (const auto &refTrack : refTracks) {
0060     BOOST_CHECK(Acts::rangeContainsValue(testTracks, refTrack));
0061   }
0062 }