Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:42

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 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 http://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 
0014 #include <algorithm>
0015 
0016 BOOST_AUTO_TEST_CASE(test_track_building) {
0017   // Make some spacepoint IDs
0018   // The spacepoint ids are [100, 101, 102, ...]
0019   // They should not be zero based to check if the thing also works if the
0020   // spacepoint IDs do not match the node IDs used for the edges
0021   std::vector<int> spacepointIds(16);
0022   std::iota(spacepointIds.begin(), spacepointIds.end(), 100);
0023 
0024   // Build 4 tracks with 4 hits
0025   std::vector<std::vector<int>> refTracks;
0026   for (auto t = 0ul; t < 4; ++t) {
0027     refTracks.emplace_back(spacepointIds.begin() + 4 * t,
0028                            spacepointIds.begin() + 4 * (t + 1));
0029   }
0030 
0031   // Make edges
0032   std::vector<int64_t> edges;
0033   for (const auto &track : refTracks) {
0034     for (auto it = track.begin(); it != track.end() - 1; ++it) {
0035       // edges must be 0 based, so subtract 100 again
0036       edges.push_back(*it - 100);
0037       edges.push_back(*std::next(it) - 100);
0038     }
0039   }
0040 
0041   auto edgeTensor =
0042       Acts::detail::vectorToTensor2D(edges, 2).t().contiguous().clone();
0043   auto dummyWeights = torch::ones(edges.size() / 2, torch::kFloat32);
0044 
0045   // Run Track building
0046   auto logger = Acts::getDefaultLogger("TestLogger", Acts::Logging::ERROR);
0047   Acts::BoostTrackBuilding trackBuilder(std::move(logger));
0048 
0049   auto testTracks = trackBuilder({}, edgeTensor, dummyWeights, spacepointIds);
0050 
0051   // Sort tracks, so we can find them
0052   std::for_each(testTracks.begin(), testTracks.end(),
0053                 [](auto &t) { std::sort(t.begin(), t.end()); });
0054   std::for_each(refTracks.begin(), refTracks.end(),
0055                 [](auto &t) { std::sort(t.begin(), t.end()); });
0056 
0057   // Check what we have here
0058   for (const auto &refTrack : refTracks) {
0059     auto found = std::find(testTracks.begin(), testTracks.end(), refTrack);
0060     BOOST_CHECK(found != testTracks.end());
0061   }
0062 }