File indexing completed on 2025-01-18 09:12:28
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/EventData/SubspaceHelpers.hpp"
0010 #include "Acts/EventData/TrackContainer.hpp"
0011 #include "Acts/EventData/TrackStatePropMask.hpp"
0012 #include "Acts/EventData/TrackStateType.hpp"
0013 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0014 #include "Acts/EventData/VectorTrackContainer.hpp"
0015 #include "Acts/EventData/detail/GenerateParameters.hpp"
0016 #include "Acts/Geometry/GeometryIdentifier.hpp"
0017 #include "Acts/Surfaces/PerigeeSurface.hpp"
0018 #include "Acts/Surfaces/PlaneSurface.hpp"
0019 #include "Acts/Surfaces/RectangleBounds.hpp"
0020 #include "Acts/Utilities/TrackHelpers.hpp"
0021
0022 #include <iostream>
0023 #include <numeric>
0024 #include <random>
0025 #include <type_traits>
0026
0027 using namespace Acts;
0028
0029 class BenchmarkSourceLink final {
0030 public:
0031 using Index = std::uint32_t;
0032
0033
0034 constexpr BenchmarkSourceLink(Acts::GeometryIdentifier gid, Index idx)
0035 : m_geometryId(gid), m_index(idx) {}
0036
0037 BenchmarkSourceLink() = default;
0038 BenchmarkSourceLink(const BenchmarkSourceLink&) = default;
0039 BenchmarkSourceLink(BenchmarkSourceLink&&) = default;
0040 BenchmarkSourceLink& operator=(const BenchmarkSourceLink&) = default;
0041 BenchmarkSourceLink& operator=(BenchmarkSourceLink&&) = default;
0042
0043
0044 constexpr Index index() const { return m_index; }
0045
0046 Acts::GeometryIdentifier geometryId() const { return m_geometryId; }
0047
0048 private:
0049 Acts::GeometryIdentifier m_geometryId;
0050 Index m_index = 0;
0051
0052 friend bool operator==(const BenchmarkSourceLink& lhs,
0053 const BenchmarkSourceLink& rhs) {
0054 return (lhs.geometryId() == rhs.geometryId()) &&
0055 (lhs.m_index == rhs.m_index);
0056 }
0057 };
0058
0059 int main(int , char** ) {
0060 std::size_t runs = 1000000;
0061 std::size_t nTracks = 10000;
0062
0063 VectorMultiTrajectory mtj;
0064 VectorTrackContainer vtc;
0065 TrackContainer tc{vtc, mtj};
0066
0067 VectorMultiTrajectory mtjOut;
0068 VectorTrackContainer vtcOut;
0069 TrackContainer output{vtcOut, mtjOut};
0070
0071 GeometryIdentifier gid;
0072 gid.setVolume(5);
0073 gid.setLayer(3);
0074 gid.setSensitive(1);
0075
0076 static_assert(sizeof(BenchmarkSourceLink) <= ACTS_SOURCELINK_SBO_SIZE);
0077
0078 static_assert(std::is_trivially_move_constructible_v<BenchmarkSourceLink>);
0079
0080 std::uniform_int_distribution<> nStatesDist(1, 20);
0081 std::uniform_int_distribution<> measDimDist(1, 3);
0082 std::uniform_real_distribution<> typeDist(0, 1);
0083 std::uniform_real_distribution<> copyDist(0, 1);
0084 std::mt19937 rng{42};
0085
0086 std::vector<std::shared_ptr<Surface>> surfaces;
0087 std::vector<std::pair<BoundVector, BoundMatrix>> parametersVector;
0088 for (std::size_t s = 0; s < 50; ++s) {
0089 surfaces.push_back(Surface::makeShared<PlaneSurface>(
0090 Transform3::Identity(), std::make_shared<RectangleBounds>(50, 50)));
0091
0092 parametersVector.push_back(
0093 detail::Test::generateBoundParametersCovariance(rng, {}));
0094 }
0095
0096 std::size_t nSurface = 0;
0097 auto surface = [&]() {
0098 nSurface++;
0099 return surfaces.at(nSurface % surfaces.size());
0100 };
0101
0102 std::size_t nParams = 0;
0103 auto parameters = [&]() -> const std::pair<BoundVector, BoundMatrix>& {
0104 nParams++;
0105 return parametersVector.at(nParams % parametersVector.size());
0106 };
0107
0108 auto perigee = Surface::makeShared<PerigeeSurface>(Vector3::Zero());
0109
0110 std::cout << "Creating " << nTracks << " tracks x " << runs << " runs"
0111 << std::endl;
0112 for (std::size_t r = 0; r < runs; ++r) {
0113 tc.clear();
0114 output.clear();
0115
0116 for (std::size_t i = 0; i < nTracks; ++i) {
0117 auto track = tc.makeTrack();
0118
0119 std::size_t nStates = nStatesDist(rng);
0120
0121 for (std::size_t j = 0; j < nStates; ++j) {
0122 auto trackState = track.appendTrackState(TrackStatePropMask::All);
0123 trackState.setReferenceSurface(surface());
0124
0125 trackState.jacobian().setZero();
0126 trackState.jacobian().row(j % eBoundSize).setOnes();
0127
0128 double crit = typeDist(rng);
0129
0130 if (crit < 0.1) {
0131
0132 trackState.typeFlags().set(TrackStateFlag::HoleFlag);
0133 } else if (crit < 0.2) {
0134
0135 trackState.typeFlags().set(TrackStateFlag::MaterialFlag);
0136 } else {
0137 BenchmarkSourceLink bsl{gid, 123};
0138 std::size_t measdim = measDimDist(rng);
0139
0140 const auto& [predicted, covariance] = parameters();
0141 trackState.predicted() = predicted;
0142 trackState.predictedCovariance() = covariance;
0143
0144 visit_measurement(
0145 measdim,
0146 [&]<std::size_t N>(std::integral_constant<std::size_t, N> ) {
0147 trackState.allocateCalibrated(ActsVector<N>::Ones(),
0148 ActsSquareMatrix<N>::Identity());
0149
0150 std::array<std::uint8_t, eBoundSize> indices{0};
0151 std::iota(indices.begin(), indices.end(), 0);
0152 trackState.setProjectorSubspaceIndices(indices);
0153 });
0154
0155 trackState.typeFlags().set(TrackStateFlag::MeasurementFlag);
0156 if (crit < 0.4) {
0157
0158 trackState.typeFlags().set(TrackStateFlag::OutlierFlag);
0159 }
0160 }
0161 }
0162
0163 track.setReferenceSurface(perigee);
0164
0165 const auto& [ref, cov] = parameters();
0166 track.parameters() = ref;
0167 track.covariance() = cov;
0168
0169 track.linkForward();
0170
0171 calculateTrackQuantities(track);
0172 }
0173
0174 for (const auto& track : tc) {
0175 if (copyDist(rng) > 0.1) {
0176
0177 continue;
0178 }
0179
0180 auto target = output.makeTrack();
0181 target.copyFrom(track);
0182 }
0183 }
0184
0185 return 0;
0186 }