File indexing completed on 2025-01-18 09:13:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010 #include <boost/test/unit_test_suite.hpp>
0011
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Definitions/TrackParametrization.hpp"
0014 #include "Acts/Definitions/Units.hpp"
0015 #include "Acts/EventData/MultiTrajectory.hpp"
0016 #include "Acts/EventData/ParticleHypothesis.hpp"
0017 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0018 #include "Acts/EventData/VectorTrackContainer.hpp"
0019 #include "Acts/Geometry/GeometryContext.hpp"
0020 #include "Acts/Plugins/Podio/PodioTrackContainer.hpp"
0021 #include "Acts/Plugins/Podio/PodioTrackStateContainer.hpp"
0022 #include "Acts/Plugins/Podio/PodioUtil.hpp"
0023 #include "Acts/Surfaces/AnnulusBounds.hpp"
0024 #include "Acts/Surfaces/ConeSurface.hpp"
0025 #include "Acts/Surfaces/ConvexPolygonBounds.hpp"
0026 #include "Acts/Surfaces/CylinderBounds.hpp"
0027 #include "Acts/Surfaces/CylinderSurface.hpp"
0028 #include "Acts/Surfaces/DiamondBounds.hpp"
0029 #include "Acts/Surfaces/DiscBounds.hpp"
0030 #include "Acts/Surfaces/DiscSurface.hpp"
0031 #include "Acts/Surfaces/DiscTrapezoidBounds.hpp"
0032 #include "Acts/Surfaces/EllipseBounds.hpp"
0033 #include "Acts/Surfaces/PerigeeSurface.hpp"
0034 #include "Acts/Surfaces/PlanarBounds.hpp"
0035 #include "Acts/Surfaces/PlaneSurface.hpp"
0036 #include "Acts/Surfaces/RadialBounds.hpp"
0037 #include "Acts/Surfaces/RectangleBounds.hpp"
0038 #include "Acts/Surfaces/StrawSurface.hpp"
0039 #include "Acts/Surfaces/SurfaceBounds.hpp"
0040 #include "Acts/Utilities/Helpers.hpp"
0041 #include "Acts/Utilities/Zip.hpp"
0042 #include "ActsPodioEdm/Surface.h"
0043 #include <ActsPodioEdm/TrackCollection.h>
0044
0045 #include <algorithm>
0046 #include <iterator>
0047 #include <memory>
0048 #include <random>
0049 #include <stdexcept>
0050
0051 using namespace Acts;
0052 using namespace Acts::UnitLiterals;
0053 using namespace Acts::HashedStringLiteral;
0054 BOOST_AUTO_TEST_SUITE(PodioTrackContainerTest)
0055
0056 class NullHelper : public PodioUtil::ConversionHelper {
0057 public:
0058 std::optional<PodioUtil::Identifier> surfaceToIdentifier(
0059 const Surface& ) const override {
0060 return {};
0061 }
0062 const Surface* identifierToSurface(
0063 PodioUtil::Identifier ) const override {
0064 return nullptr;
0065 }
0066
0067 SourceLink identifierToSourceLink(
0068 PodioUtil::Identifier ) const override {
0069 return SourceLink{0};
0070 }
0071
0072 PodioUtil::Identifier sourceLinkToIdentifier(
0073 const SourceLink& ) override {
0074 return 0;
0075 }
0076 };
0077
0078 struct MapHelper : public NullHelper {
0079 std::optional<PodioUtil::Identifier> surfaceToIdentifier(
0080 const Surface& surface) const override {
0081 for (auto&& [id, srf] : surfaces) {
0082 if (srf == &surface) {
0083 return id;
0084 }
0085 }
0086 return {};
0087 }
0088 const Surface* identifierToSurface(PodioUtil::Identifier id) const override {
0089 auto it = surfaces.find(id);
0090 if (it == surfaces.end()) {
0091 return nullptr;
0092 }
0093
0094 return it->second;
0095 }
0096
0097 std::unordered_map<PodioUtil::Identifier, const Surface*> surfaces;
0098 };
0099
0100 BOOST_AUTO_TEST_CASE(ConvertSurface) {
0101 auto rBounds = std::make_shared<RectangleBounds>(15, 20);
0102
0103 auto trf = Transform3::Identity();
0104 trf.translation().setRandom();
0105
0106 auto free = Acts::Surface::makeShared<PlaneSurface>(trf, rBounds);
0107
0108 NullHelper helper;
0109 auto surface = PodioUtil::convertSurfaceToPodio(helper, *free);
0110
0111 auto free2 = PodioUtil::convertSurfaceFromPodio(helper, surface);
0112
0113 Acts::GeometryContext gctx;
0114
0115 BOOST_REQUIRE(free2);
0116 BOOST_CHECK_EQUAL(free->type(), free2->type());
0117 BOOST_CHECK_EQUAL(free->bounds().type(), free2->bounds().type());
0118 BOOST_CHECK_EQUAL(free->center(gctx), free2->center(gctx));
0119
0120 const auto* rBounds2 = dynamic_cast<const RectangleBounds*>(&free2->bounds());
0121 BOOST_REQUIRE_NE(rBounds2, nullptr);
0122
0123 BOOST_CHECK_EQUAL(rBounds2->halfLengthX(), rBounds->halfLengthX());
0124 BOOST_CHECK_EQUAL(rBounds2->halfLengthY(), rBounds->halfLengthY());
0125
0126
0127 }
0128
0129 BOOST_AUTO_TEST_CASE(ConvertTrack) {
0130 auto rBounds = std::make_shared<RectangleBounds>(15, 20);
0131 auto trf = Transform3::Identity();
0132 trf.translation().setRandom();
0133 auto free = Acts::Surface::makeShared<PlaneSurface>(trf, rBounds);
0134
0135 MapHelper helper;
0136
0137 auto refCov = BoundMatrix::Random().eval();
0138
0139 podio::Frame frame;
0140
0141 ParticleHypothesis pHypo = ParticleHypothesis::pion();
0142
0143 {
0144 Acts::MutablePodioTrackStateContainer tsc{helper};
0145 Acts::MutablePodioTrackContainer ptc{helper};
0146 ActsPodioEdm::TrackCollection& tracks = ptc.trackCollection();
0147
0148 Acts::TrackContainer tc{ptc, tsc};
0149
0150 BOOST_CHECK(!tc.hasColumn("int_column"_hash));
0151 BOOST_CHECK(!tc.hasColumn("float_column"_hash));
0152 tc.addColumn<std::int32_t>("int_column");
0153 tc.addColumn<float>("float_column");
0154 BOOST_CHECK(tc.hasColumn("int_column"_hash));
0155 BOOST_CHECK(tc.hasColumn("float_column"_hash));
0156
0157 BOOST_CHECK_EQUAL(tc.size(), 0);
0158
0159 auto t = tc.makeTrack();
0160 BOOST_CHECK_EQUAL(t.tipIndex(), MultiTrajectoryTraits::kInvalid);
0161
0162 t.setParticleHypothesis(pHypo);
0163 BOOST_CHECK_EQUAL(t.particleHypothesis(), pHypo);
0164
0165 BOOST_CHECK_EQUAL(tsc.size(), 0);
0166 auto ts1 = t.appendTrackState();
0167 auto ts2 = t.appendTrackState();
0168 auto ts3 = t.appendTrackState();
0169 BOOST_CHECK_EQUAL(tsc.size(), 3);
0170 BOOST_CHECK_EQUAL(ts1.index(), 0);
0171 BOOST_CHECK_EQUAL(ts2.index(), 1);
0172 BOOST_CHECK_EQUAL(ts3.index(), 2);
0173
0174 BOOST_CHECK_EQUAL(t.nTrackStates(), 3);
0175 BOOST_CHECK_EQUAL(t.tipIndex(), 2);
0176
0177 BOOST_CHECK_EQUAL(tc.size(), 1);
0178
0179 auto pTrack = tracks.at(0);
0180 BOOST_CHECK_EQUAL(pTrack.getData().tipIndex, 2);
0181
0182 t.parameters() << 1, 2, 3, 4, 5, 6;
0183 Eigen::Map<const BoundVector> pars{pTrack.getData().parameters.data()};
0184 BoundVector bv;
0185 bv << 1, 2, 3, 4, 5, 6;
0186 BOOST_CHECK_EQUAL(pars, bv);
0187
0188 t.covariance() = refCov;
0189
0190 Eigen::Map<const BoundMatrix> cov{pTrack.getData().covariance.data()};
0191 BOOST_CHECK_EQUAL(refCov, cov);
0192
0193 t.nMeasurements() = 17;
0194 BOOST_CHECK_EQUAL(pTrack.getData().nMeasurements, 17);
0195
0196 t.nHoles() = 34;
0197 BOOST_CHECK_EQUAL(pTrack.getData().nHoles, 34);
0198
0199 t.chi2() = 882.3f;
0200 BOOST_CHECK_EQUAL(pTrack.getData().chi2, 882.3f);
0201
0202 t.nDoF() = 9;
0203 BOOST_CHECK_EQUAL(pTrack.getData().ndf, 9);
0204
0205 t.nOutliers() = 77;
0206 BOOST_CHECK_EQUAL(pTrack.getData().nOutliers, 77);
0207
0208 t.nSharedHits() = 99;
0209 BOOST_CHECK_EQUAL(pTrack.getData().nSharedHits, 99);
0210
0211 Acts::GeometryContext gctx;
0212 t.setReferenceSurface(free);
0213 const auto& free2 = t.referenceSurface();
0214 BOOST_CHECK_EQUAL(free->center(gctx), free2.center(gctx));
0215
0216 const auto* rBounds2 =
0217 dynamic_cast<const RectangleBounds*>(&free2.bounds());
0218 BOOST_REQUIRE_NE(rBounds2, nullptr);
0219
0220 BOOST_CHECK_EQUAL(rBounds2->halfLengthX(), rBounds->halfLengthX());
0221 BOOST_CHECK_EQUAL(rBounds2->halfLengthY(), rBounds->halfLengthY());
0222
0223 BOOST_CHECK_EQUAL(pTrack.getReferenceSurface().identifier,
0224 PodioUtil::kNoIdentifier);
0225
0226 auto t2 = tc.makeTrack();
0227 auto t3 = tc.makeTrack();
0228 BOOST_CHECK_EQUAL(tc.size(), 3);
0229
0230
0231 helper.surfaces[666] = free.get();
0232 t2.setReferenceSurface(free);
0233 auto pTrack2 = tracks.at(1);
0234 BOOST_CHECK_EQUAL(pTrack2.getReferenceSurface().identifier, 666);
0235
0236 t.component<std::int32_t, "int_column"_hash>() = -11;
0237 t2.component<std::int32_t, "int_column"_hash>() = 42;
0238 t3.component<std::int32_t, "int_column"_hash>() = -98;
0239
0240 t.component<float, "float_column"_hash>() = -11.2f;
0241 t2.component<float, "float_column"_hash>() = 42.4f;
0242 t3.component<float, "float_column"_hash>() = -98.9f;
0243
0244 ptc.releaseInto(frame);
0245 tsc.releaseInto(frame);
0246
0247 BOOST_REQUIRE_NE(frame.get("tracks"), nullptr);
0248 BOOST_CHECK_EQUAL(frame.get("tracks")->size(), 3);
0249 BOOST_REQUIRE_NE(frame.get("tracks_extra__int_column"), nullptr);
0250 BOOST_REQUIRE_NE(frame.get("tracks_extra__float_column"), nullptr);
0251
0252 BOOST_REQUIRE_NE(frame.get("trackStates"), nullptr);
0253 BOOST_CHECK_EQUAL(frame.get("trackStates")->size(), 3);
0254 }
0255
0256 {
0257 Acts::ConstPodioTrackStateContainer tsc{helper, frame};
0258 Acts::ConstPodioTrackContainer ptc{helper, frame};
0259
0260
0261 Acts::TrackContainer tc{ptc, tsc};
0262
0263 BOOST_CHECK(tc.hasColumn("int_column"_hash));
0264 BOOST_CHECK(tc.hasColumn("float_column"_hash));
0265
0266 BOOST_CHECK_EQUAL(tc.size(), 3);
0267
0268 auto t = tc.getTrack(0);
0269 const auto& freeRecreated = t.referenceSurface();
0270
0271 BOOST_CHECK_NE(free.get(), &freeRecreated);
0272
0273 BOOST_CHECK_EQUAL(t.particleHypothesis(), pHypo);
0274
0275 BOOST_CHECK_EQUAL(t.nMeasurements(), 17);
0276
0277 BOOST_CHECK_EQUAL(t.nHoles(), 34);
0278
0279 BOOST_CHECK_EQUAL(t.chi2(), 882.3f);
0280
0281 BOOST_CHECK_EQUAL(t.nDoF(), 9);
0282
0283 BOOST_CHECK_EQUAL(t.nOutliers(), 77);
0284
0285 BOOST_CHECK_EQUAL(t.nSharedHits(), 99);
0286
0287 BOOST_CHECK_EQUAL(t.tipIndex(), 2);
0288 BOOST_CHECK_EQUAL(t.nTrackStates(), 3);
0289
0290 auto t2 = tc.getTrack(1);
0291
0292 BOOST_CHECK_EQUAL(free.get(), &t2.referenceSurface());
0293 BoundVector bv;
0294 bv << 1, 2, 3, 4, 5, 6;
0295 BOOST_CHECK_EQUAL(t.parameters(), bv);
0296
0297 BOOST_CHECK_EQUAL(t.covariance(), refCov);
0298
0299 auto t3 = tc.getTrack(2);
0300 BOOST_CHECK(!t3.hasReferenceSurface());
0301
0302 BOOST_CHECK_EQUAL((t.component<std::int32_t, "int_column"_hash>()), -11);
0303 BOOST_CHECK_EQUAL((t2.component<std::int32_t, "int_column"_hash>()), 42);
0304 BOOST_CHECK_EQUAL((t3.component<std::int32_t, "int_column"_hash>()), -98);
0305
0306 BOOST_CHECK_EQUAL((t.component<float, "float_column"_hash>()), -11.2f);
0307 BOOST_CHECK_EQUAL((t2.component<float, "float_column"_hash>()), 42.4f);
0308 BOOST_CHECK_EQUAL((t3.component<float, "float_column"_hash>()), -98.9f);
0309 }
0310 }
0311
0312 BOOST_AUTO_TEST_CASE(CopyTracksIncludingDynamicColumnsDifferentBackends) {
0313 MapHelper helper;
0314
0315 podio::Frame frame;
0316
0317
0318 VectorTrackContainer vtc{};
0319 VectorMultiTrajectory mtj{};
0320 TrackContainer tc{vtc, mtj};
0321 tc.addColumn<std::uint64_t>("counter");
0322 tc.addColumn<std::uint8_t>("odd");
0323 mtj.addColumn<std::uint64_t>("ts_counter");
0324 mtj.addColumn<std::uint8_t>("ts_odd");
0325
0326 Acts::MutablePodioTrackStateContainer tsc2{helper};
0327 Acts::MutablePodioTrackContainer ptc2{helper};
0328 Acts::TrackContainer tc2{ptc2, tsc2};
0329
0330
0331 Acts::MutablePodioTrackStateContainer tsc3{helper};
0332 Acts::MutablePodioTrackContainer ptc3{helper};
0333 Acts::TrackContainer tc3{ptc3, tsc3};
0334
0335 tc3.addColumn<std::uint64_t>("counter");
0336 tc3.addColumn<std::uint8_t>("odd");
0337 tsc3.addColumn<std::uint64_t>("ts_counter");
0338 tsc3.addColumn<std::uint8_t>("ts_odd");
0339
0340 for (std::size_t i = 0; i < 10; i++) {
0341 auto t = tc.makeTrack();
0342 auto ts = t.appendTrackState();
0343 ts.predicted() = BoundVector::Ones();
0344 ts.component<std::uint64_t, "ts_counter"_hash>() = i;
0345
0346 ts = t.appendTrackState();
0347 ts.predicted().setOnes();
0348 ts.predicted() *= 2;
0349 ts.component<std::uint64_t, "ts_counter"_hash>() = i + 1;
0350
0351 ts = t.appendTrackState();
0352 ts.predicted().setOnes();
0353 ts.predicted() *= 3;
0354 ts.component<std::uint64_t, "ts_counter"_hash>() = i + 2;
0355
0356 t.template component<std::uint64_t>("counter") = i;
0357 t.template component<std::uint8_t>("odd") =
0358 static_cast<std::uint8_t>(i % 2 == 0);
0359
0360 auto t2 = tc2.makeTrack();
0361 BOOST_CHECK_THROW(t2.copyFrom(t),
0362 std::invalid_argument);
0363
0364 auto t3 = tc3.makeTrack();
0365 t3.copyFrom(t);
0366
0367 BOOST_CHECK_NE(t3.tipIndex(), MultiTrajectoryTraits::kInvalid);
0368 BOOST_CHECK_GT(t3.nTrackStates(), 0);
0369 BOOST_REQUIRE_EQUAL(t.nTrackStates(), t3.nTrackStates());
0370
0371 for (auto [tsa, tsb] :
0372 zip(t.trackStatesReversed(), t3.trackStatesReversed())) {
0373 BOOST_CHECK_EQUAL(tsa.predicted(), tsb.predicted());
0374
0375 BOOST_CHECK_EQUAL(
0376 (tsa.template component<std::uint64_t, "ts_counter"_hash>()),
0377 (tsb.template component<std::uint64_t, "ts_counter"_hash>()));
0378
0379 BOOST_CHECK_EQUAL(
0380 (tsa.template component<std::uint8_t, "ts_odd"_hash>()),
0381 (tsb.template component<std::uint8_t, "ts_odd"_hash>()));
0382 }
0383
0384 BOOST_CHECK_EQUAL(t.template component<std::uint64_t>("counter"),
0385 t3.template component<std::uint64_t>("counter"));
0386 BOOST_CHECK_EQUAL(t.template component<std::uint8_t>("odd"),
0387 t3.template component<std::uint8_t>("odd"));
0388 }
0389 }
0390
0391 BOOST_AUTO_TEST_SUITE_END()