File indexing completed on 2025-10-30 07:55:32
0001
0002
0003
0004
0005
0006
0007
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/TrackFinding/TrackParamsLookupAccumulator.hpp"
0021 #include "Acts/Utilities/AxisDefinitions.hpp"
0022 #include "Acts/Utilities/Grid.hpp"
0023 #include "Acts/Utilities/GridAxisGenerators.hpp"
0024 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0025
0026 #include <cmath>
0027 #include <cstddef>
0028 #include <numbers>
0029 #include <optional>
0030 #include <stdexcept>
0031 #include <vector>
0032
0033 using namespace Acts;
0034
0035 namespace ActsTests {
0036
0037 GeometryContext gctx;
0038
0039 BOOST_AUTO_TEST_SUITE(TrackFindingSuite)
0040
0041 using Axis = Axis<AxisType::Equidistant, AxisBoundaryType::Open>;
0042 using AxisGen = GridAxisGenerators::EqOpenEqOpen;
0043
0044 using CellBound = std::pair<std::shared_ptr<BoundTrackParameters>,
0045 std::shared_ptr<BoundTrackParameters>>;
0046
0047 using GridBound = Grid<CellBound, Axis, Axis>;
0048 using AccBound = TrackParamsLookupAccumulator<GridBound>;
0049
0050 using CellFree = std::pair<std::shared_ptr<FreeTrackParameters>,
0051 std::shared_ptr<FreeTrackParameters>>;
0052
0053 using GridFree = Grid<CellFree, Axis, Axis>;
0054 using AccFree = TrackParamsLookupAccumulator<GridFree>;
0055
0056 AxisGen axisGen{{-1, 1}, 2, {-1, 1}, 2};
0057
0058 BOOST_AUTO_TEST_CASE(Exceptions) {
0059
0060 GridBound grid(axisGen());
0061 AccBound acc(grid);
0062
0063
0064 auto transform = Transform3::Identity();
0065 auto bounds1 = std::make_shared<RectangleBounds>(1, 1);
0066 auto bounds2 = std::make_shared<RectangleBounds>(2, 2);
0067
0068 auto surf1 = Surface::makeShared<PlaneSurface>(transform, bounds1);
0069
0070 auto surf2 = Surface::makeShared<PlaneSurface>(transform, bounds2);
0071
0072
0073 Vector4 pos{1, 2, 0, 4};
0074 Vector3 dir{1, 0, 0};
0075 double P = 1.;
0076
0077 auto hypothesis1 = ParticleHypothesis::electron();
0078 auto hypothesis2 = ParticleHypothesis::muon();
0079
0080 auto pars1 = BoundTrackParameters::create(gctx, surf1, pos, dir, 1. / P,
0081 std::nullopt, hypothesis1)
0082 .value();
0083
0084 auto pars2 = BoundTrackParameters::create(gctx, surf2, pos, dir, 1. / P,
0085 std::nullopt, hypothesis1)
0086 .value();
0087
0088 auto pars3 = BoundTrackParameters::create(gctx, surf1, pos, dir, 1. / P,
0089 std::nullopt, hypothesis2)
0090 .value();
0091
0092 auto pars4 = BoundTrackParameters::create(gctx, surf1, pos, dir, -1. / P,
0093 std::nullopt, hypothesis2)
0094 .value();
0095
0096
0097 auto bin = grid.localBinsFromGlobalBin(2);
0098 auto center = grid.binCenter(bin);
0099 Vector2 loc{center.at(0), center.at(1)};
0100
0101
0102 acc.addTrack(pars1, pars1, loc);
0103
0104
0105 BOOST_CHECK_THROW(acc.addTrack(pars2, pars2, loc), std::invalid_argument);
0106
0107
0108 BOOST_CHECK_THROW(acc.addTrack(pars3, pars3, loc), std::invalid_argument);
0109
0110
0111 BOOST_CHECK_THROW(acc.addTrack(pars4, pars4, loc), std::invalid_argument);
0112 }
0113
0114 BOOST_AUTO_TEST_CASE(Accumulation) {
0115
0116 GridBound gridBound(axisGen());
0117 AccBound accBound(gridBound);
0118
0119 GridFree gridFree(axisGen());
0120 AccFree accFree(gridFree);
0121
0122
0123 auto transform = Transform3::Identity();
0124 auto bounds = std::make_shared<RectangleBounds>(1, 1);
0125 auto surf = Surface::makeShared<PlaneSurface>(transform, bounds);
0126
0127 auto hypothesis = ParticleHypothesis::electron();
0128
0129 std::vector<Vector4> avgPoss;
0130 std::vector<Vector3> avgMoms;
0131 Vector4 pos{1, 2, 0, 4};
0132 for (std::size_t i = 0; i < gridBound.size(); i++) {
0133
0134 std::array<Vector4, 4> fourPositions = {pos * (i + 1), pos * (i + 2),
0135 pos * (i + 3), pos * (i + 4)};
0136
0137 std::array<double, 4> thetas = {
0138 std::numbers::pi / (i + 1), std::numbers::pi / (i + 2),
0139 std::numbers::pi / (i + 3), std::numbers::pi / (i + 4)};
0140
0141 std::array<double, 4> phis = {
0142 2 * std::numbers::pi / (i + 1), 2 * std::numbers::pi / (i + 2),
0143 2 * std::numbers::pi / (i + 3), 2 * std::numbers::pi / (i + 4)};
0144
0145 double P = 1.5 * (i + 1);
0146
0147
0148 auto bin = gridBound.localBinsFromGlobalBin(i);
0149 auto center = gridBound.binCenter(bin);
0150 Vector2 loc{center.at(0), center.at(1)};
0151
0152
0153 Vector4 avgPos{0, 0, 0, 0};
0154 Vector3 avgMom{0, 0, 0};
0155 for (std::size_t j = 0; j < 4; j++) {
0156 Vector3 direction{std::sin(thetas.at(j)) * std::cos(phis.at(j)),
0157 std::sin(thetas.at(j)) * std::sin(phis.at(j)),
0158 std::cos(thetas.at(j))};
0159
0160 avgPos += fourPositions.at(j);
0161 avgMom += P * direction;
0162
0163
0164 auto parsBound = BoundTrackParameters::create(
0165 gctx, surf, fourPositions.at(j), direction, 1. / P,
0166 std::nullopt, hypothesis)
0167 .value();
0168
0169 auto parsFree = FreeTrackParameters(fourPositions.at(j), direction,
0170 1. / P, std::nullopt, hypothesis);
0171
0172 accBound.addTrack(parsBound, parsBound, loc);
0173 accFree.addTrack(parsFree, parsFree, loc);
0174 }
0175 avgPoss.push_back(avgPos / fourPositions.size());
0176 avgMoms.push_back(avgMom / fourPositions.size());
0177 }
0178
0179
0180 GridBound avgGridBound = accBound.finalizeLookup();
0181 GridFree avgGridFree = accFree.finalizeLookup();
0182 for (std::size_t i = 0; i < avgGridBound.size(); i++) {
0183 auto [ipBound, refBound] = avgGridBound.at(i);
0184 auto [ipFree, refFree] = avgGridFree.at(i);
0185
0186 Vector4 avgPos = avgPoss.at(i);
0187
0188 Vector3 avgMom = avgMoms.at(i);
0189 Vector3 avgDir = avgMom.normalized();
0190 double avgP = avgMom.norm();
0191
0192 CHECK_CLOSE_ABS(ipBound->fourPosition(gctx), avgPos, 1e-3);
0193 CHECK_CLOSE_ABS(ipBound->direction(), avgDir, 1e-3);
0194 CHECK_CLOSE_ABS(ipBound->absoluteMomentum(), avgP, 1e-3);
0195
0196 CHECK_CLOSE_ABS(ipFree->fourPosition(), avgPos, 1e-3);
0197 CHECK_CLOSE_ABS(ipFree->direction(), avgDir, 1e-3);
0198 CHECK_CLOSE_ABS(ipFree->absoluteMomentum(), avgP, 1e-3);
0199 }
0200 }
0201
0202 BOOST_AUTO_TEST_SUITE_END()
0203
0204 }