Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:53

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/tools/detail/fwd.hpp>
0010 #include <boost/test/tools/old/interface.hpp>
0011 #include <boost/test/unit_test.hpp>
0012 
0013 #include "Acts/Definitions/Algebra.hpp"
0014 #include "Acts/EventData/ParticleHypothesis.hpp"
0015 #include "Acts/EventData/TrackParameters.hpp"
0016 #include "Acts/Geometry/GeometryContext.hpp"
0017 #include "Acts/Surfaces/PlaneSurface.hpp"
0018 #include "Acts/Surfaces/RectangleBounds.hpp"
0019 #include "Acts/Surfaces/Surface.hpp"
0020 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0021 #include "Acts/TrackFinding/TrackParamsLookupAccumulator.hpp"
0022 #include "Acts/Utilities/AxisDefinitions.hpp"
0023 #include "Acts/Utilities/Grid.hpp"
0024 #include "Acts/Utilities/GridAxisGenerators.hpp"
0025 
0026 #include <cmath>
0027 #include <cstddef>
0028 #include <numbers>
0029 #include <optional>
0030 #include <stdexcept>
0031 #include <vector>
0032 
0033 BOOST_AUTO_TEST_SUITE(TrackParamsLookupAccumulator)
0034 
0035 Acts::GeometryContext gctx;
0036 
0037 using Axis =
0038     Acts::Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Open>;
0039 using AxisGen = Acts::GridAxisGenerators::EqOpenEqOpen;
0040 
0041 using CellBound = std::pair<std::shared_ptr<Acts::BoundTrackParameters>,
0042                             std::shared_ptr<Acts::BoundTrackParameters>>;
0043 
0044 using GridBound = Acts::Grid<CellBound, Axis, Axis>;
0045 using AccBound = Acts::TrackParamsLookupAccumulator<GridBound>;
0046 
0047 using CellCurvilinear =
0048     std::pair<std::shared_ptr<Acts::CurvilinearTrackParameters>,
0049               std::shared_ptr<Acts::CurvilinearTrackParameters>>;
0050 
0051 using GridCurvilinear = Acts::Grid<CellCurvilinear, Axis, Axis>;
0052 using AccCurvilinear = Acts::TrackParamsLookupAccumulator<GridCurvilinear>;
0053 
0054 using CellFree = std::pair<std::shared_ptr<Acts::FreeTrackParameters>,
0055                            std::shared_ptr<Acts::FreeTrackParameters>>;
0056 
0057 using GridFree = Acts::Grid<CellFree, Axis, Axis>;
0058 using AccFree = Acts::TrackParamsLookupAccumulator<GridFree>;
0059 
0060 AxisGen axisGen{{-1, 1}, 2, {-1, 1}, 2};
0061 
0062 BOOST_AUTO_TEST_CASE(Exceptions) {
0063   // Instantiate grid
0064   GridBound grid(axisGen());
0065   AccBound acc(grid);
0066 
0067   // Create a reference surface for bound parameters
0068   auto transform = Acts::Transform3::Identity();
0069   auto bounds1 = std::make_shared<Acts::RectangleBounds>(1, 1);
0070   auto bounds2 = std::make_shared<Acts::RectangleBounds>(2, 2);
0071 
0072   auto surf1 =
0073       Acts::Surface::makeShared<Acts::PlaneSurface>(transform, bounds1);
0074 
0075   auto surf2 =
0076       Acts::Surface::makeShared<Acts::PlaneSurface>(transform, bounds2);
0077 
0078   // Create parameters to accumulate
0079   Acts::Vector4 pos{1, 2, 0, 4};
0080   Acts::Vector3 dir{1, 0, 0};
0081   double P = 1.;
0082 
0083   auto hypothesis1 = Acts::ParticleHypothesis::electron();
0084   auto hypothesis2 = Acts::ParticleHypothesis::muon();
0085 
0086   auto pars1 = Acts::BoundTrackParameters::create(surf1, gctx, pos, dir, 1. / P,
0087                                                   std::nullopt, hypothesis1)
0088                    .value();
0089 
0090   auto pars2 = Acts::BoundTrackParameters::create(surf2, gctx, pos, dir, 1. / P,
0091                                                   std::nullopt, hypothesis1)
0092                    .value();
0093 
0094   auto pars3 = Acts::BoundTrackParameters::create(surf1, gctx, pos, dir, 1. / P,
0095                                                   std::nullopt, hypothesis2)
0096                    .value();
0097 
0098   auto pars4 = Acts::BoundTrackParameters::create(
0099                    surf1, gctx, pos, dir, -1. / P, std::nullopt, hypothesis2)
0100                    .value();
0101 
0102   // Get the point of the grid
0103   auto bin = grid.localBinsFromGlobalBin(2);
0104   auto center = grid.binCenter(bin);
0105   Acts::Vector2 loc{center.at(0), center.at(1)};
0106 
0107   // Fill in grid
0108   acc.addTrack(pars1, pars1, loc);
0109 
0110   // Different reference surfaces
0111   BOOST_CHECK_THROW(acc.addTrack(pars2, pars2, loc), std::invalid_argument);
0112 
0113   // Different particle hypotheses
0114   BOOST_CHECK_THROW(acc.addTrack(pars3, pars3, loc), std::invalid_argument);
0115 
0116   // Different charges
0117   BOOST_CHECK_THROW(acc.addTrack(pars4, pars4, loc), std::invalid_argument);
0118 }
0119 
0120 BOOST_AUTO_TEST_CASE(Accumulation) {
0121   // Instantiate grids
0122   GridBound gridBound(axisGen());
0123   AccBound accBound(gridBound);
0124 
0125   GridCurvilinear gridCurvilinear(axisGen());
0126   AccCurvilinear accCurvilinear(gridCurvilinear);
0127 
0128   GridFree gridFree(axisGen());
0129   AccFree accFree(gridFree);
0130 
0131   // Create a reference surface for bound parameters
0132   auto transform = Acts::Transform3::Identity();
0133   auto bounds = std::make_shared<Acts::RectangleBounds>(1, 1);
0134   auto surf = Acts::Surface::makeShared<Acts::PlaneSurface>(transform, bounds);
0135 
0136   auto hypothesis = Acts::ParticleHypothesis::electron();
0137 
0138   std::vector<Acts::Vector4> avgPoss;
0139   std::vector<Acts::Vector3> avgMoms;
0140   Acts::Vector4 pos{1, 2, 0, 4};
0141   for (std::size_t i = 0; i < gridBound.size(); i++) {
0142     // Create parameters to accumulate
0143     std::array<Acts::Vector4, 4> fourPositions = {pos * (i + 1), pos * (i + 2),
0144                                                   pos * (i + 3), pos * (i + 4)};
0145 
0146     std::array<double, 4> thetas = {
0147         std::numbers::pi / (i + 1), std::numbers::pi / (i + 2),
0148         std::numbers::pi / (i + 3), std::numbers::pi / (i + 4)};
0149 
0150     std::array<double, 4> phis = {
0151         2 * std::numbers::pi / (i + 1), 2 * std::numbers::pi / (i + 2),
0152         2 * std::numbers::pi / (i + 3), 2 * std::numbers::pi / (i + 4)};
0153 
0154     double P = 1.5 * (i + 1);
0155 
0156     // Get the point of the grid
0157     auto bin = gridBound.localBinsFromGlobalBin(i);
0158     auto center = gridBound.binCenter(bin);
0159     Acts::Vector2 loc{center.at(0), center.at(1)};
0160 
0161     // Accumulate
0162     Acts::Vector4 avgPos{0, 0, 0, 0};
0163     Acts::Vector3 avgMom{0, 0, 0};
0164     for (std::size_t j = 0; j < 4; j++) {
0165       Acts::Vector3 direction{std::sin(thetas.at(j)) * std::cos(phis.at(j)),
0166                               std::sin(thetas.at(j)) * std::sin(phis.at(j)),
0167                               std::cos(thetas.at(j))};
0168 
0169       avgPos += fourPositions.at(j);
0170       avgMom += P * direction;
0171 
0172       // Fill in each grid
0173       auto parsBound = Acts::BoundTrackParameters::create(
0174                            surf, gctx, fourPositions.at(j), direction, 1. / P,
0175                            std::nullopt, hypothesis)
0176                            .value();
0177 
0178       auto parsCurvilinear = Acts::CurvilinearTrackParameters(
0179           fourPositions.at(j), direction, 1. / P, std::nullopt, hypothesis);
0180 
0181       auto parsFree = Acts::FreeTrackParameters(
0182           fourPositions.at(j), direction, 1. / P, std::nullopt, hypothesis);
0183 
0184       accBound.addTrack(parsBound, parsBound, loc);
0185       accCurvilinear.addTrack(parsCurvilinear, parsCurvilinear, loc);
0186       accFree.addTrack(parsFree, parsFree, loc);
0187     }
0188     avgPoss.push_back(avgPos / fourPositions.size());
0189     avgMoms.push_back(avgMom / fourPositions.size());
0190   }
0191 
0192   // Finalize and compare
0193   GridBound avgGridBound = accBound.finalizeLookup();
0194   GridCurvilinear avgGridCurvilinear = accCurvilinear.finalizeLookup();
0195   GridFree avgGridFree = accFree.finalizeLookup();
0196   for (std::size_t i = 0; i < avgGridBound.size(); i++) {
0197     auto [ipBound, refBound] = avgGridBound.at(i);
0198     auto [ipCurvilinear, refCurvilinear] = avgGridCurvilinear.at(i);
0199     auto [ipFree, refFree] = avgGridFree.at(i);
0200 
0201     Acts::Vector4 avgPos = avgPoss.at(i);
0202 
0203     Acts::Vector3 avgMom = avgMoms.at(i);
0204     Acts::Vector3 avgDir = avgMom.normalized();
0205     double avgP = avgMom.norm();
0206 
0207     CHECK_CLOSE_ABS(ipBound->fourPosition(gctx), avgPos, 1e-3);
0208     CHECK_CLOSE_ABS(ipBound->direction(), avgDir, 1e-3);
0209     CHECK_CLOSE_ABS(ipBound->absoluteMomentum(), avgP, 1e-3);
0210 
0211     CHECK_CLOSE_ABS(ipCurvilinear->fourPosition(), avgPos, 1e-3);
0212     CHECK_CLOSE_ABS(ipCurvilinear->direction(), avgDir, 1e-3);
0213     CHECK_CLOSE_ABS(ipCurvilinear->absoluteMomentum(), avgP, 1e-3);
0214 
0215     CHECK_CLOSE_ABS(ipFree->fourPosition(), avgPos, 1e-3);
0216     CHECK_CLOSE_ABS(ipFree->direction(), avgDir, 1e-3);
0217     CHECK_CLOSE_ABS(ipFree->absoluteMomentum(), avgP, 1e-3);
0218   }
0219 }
0220 
0221 BOOST_AUTO_TEST_SUITE_END()