File indexing completed on 2025-01-18 09:13:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 #include <boost/test/unit_test_suite.hpp>
0012
0013 #include "Acts/Definitions/TrackParametrization.hpp"
0014 #include "Acts/Definitions/Units.hpp"
0015 #include "Acts/EventData/SourceLink.hpp"
0016 #include "Acts/EventData/TrackStatePropMask.hpp"
0017 #include "Acts/EventData/detail/MultiTrajectoryTestsCommon.hpp"
0018 #include "Acts/Geometry/GeometryContext.hpp"
0019 #include "Acts/Plugins/Podio/PodioTrackStateContainer.hpp"
0020 #include "Acts/Plugins/Podio/PodioUtil.hpp"
0021 #include "Acts/Surfaces/PlaneSurface.hpp"
0022 #include "Acts/Surfaces/RectangleBounds.hpp"
0023 #include "ActsPodioEdm/BoundParametersCollection.h"
0024 #include "ActsPodioEdm/JacobianCollection.h"
0025 #include "ActsPodioEdm/TrackStateCollection.h"
0026
0027 #include <filesystem>
0028
0029 #include <podio/UserDataCollection.h>
0030
0031 namespace {
0032
0033 using namespace Acts;
0034 using namespace Acts::UnitLiterals;
0035 using namespace Acts::detail::Test;
0036 namespace bd = boost::unit_test::data;
0037
0038 std::default_random_engine rng(31415);
0039
0040 class NullHelper : public PodioUtil::ConversionHelper {
0041 public:
0042 std::optional<PodioUtil::Identifier> surfaceToIdentifier(
0043 const Surface& ) const override {
0044 return {};
0045 }
0046 const Surface* identifierToSurface(
0047 PodioUtil::Identifier ) const override {
0048 return nullptr;
0049 }
0050
0051 SourceLink identifierToSourceLink(
0052 PodioUtil::Identifier ) const override {
0053 return SourceLink{0};
0054 }
0055
0056 PodioUtil::Identifier sourceLinkToIdentifier(
0057 const SourceLink& ) override {
0058 return 0;
0059 }
0060 };
0061
0062 struct MapHelper : public NullHelper {
0063 std::optional<PodioUtil::Identifier> surfaceToIdentifier(
0064 const Surface& surface) const override {
0065 for (auto&& [id, srf] : surfaces) {
0066 if (srf == &surface) {
0067 return id;
0068 }
0069 }
0070 return {};
0071 }
0072 const Surface* identifierToSurface(PodioUtil::Identifier id) const override {
0073 auto it = surfaces.find(id);
0074 if (it == surfaces.end()) {
0075 return nullptr;
0076 }
0077
0078 return it->second;
0079 }
0080
0081 PodioUtil::Identifier sourceLinkToIdentifier(const SourceLink& sl) override {
0082 sourceLinks.push_back(sl);
0083 return sourceLinks.size() - 1;
0084 }
0085
0086 SourceLink identifierToSourceLink(PodioUtil::Identifier id) const override {
0087 return sourceLinks.at(id);
0088 }
0089
0090 std::unordered_map<PodioUtil::Identifier, const Surface*> surfaces;
0091 std::vector<SourceLink> sourceLinks;
0092 };
0093
0094 struct Factory {
0095 using trajectory_t = MutablePodioTrackStateContainer;
0096 using const_trajectory_t = ConstPodioTrackStateContainer;
0097
0098 MapHelper m_helper;
0099
0100 MutablePodioTrackStateContainer create() { return {m_helper}; }
0101 };
0102
0103 using CommonTests = MultiTrajectoryTestsCommon<Factory>;
0104
0105 }
0106
0107 BOOST_AUTO_TEST_SUITE(PodioTrackStateContainerTest)
0108
0109 BOOST_AUTO_TEST_CASE(Build) {
0110 CommonTests ct;
0111 ct.testBuild();
0112 }
0113
0114 BOOST_AUTO_TEST_CASE(ConstCorrectness) {
0115
0116 }
0117
0118 BOOST_AUTO_TEST_CASE(Clear) {
0119 CommonTests ct;
0120 ct.testClear();
0121 }
0122
0123 BOOST_AUTO_TEST_CASE(ApplyWithAbort) {
0124 CommonTests ct;
0125 ct.testApplyWithAbort();
0126 }
0127
0128 BOOST_AUTO_TEST_CASE(AddTrackStateWithBitMask) {
0129 CommonTests ct;
0130 ct.testAddTrackStateWithBitMask();
0131 }
0132
0133 BOOST_AUTO_TEST_CASE(AddTrackStateComponents) {
0134 CommonTests ct;
0135 ct.testAddTrackStateComponents();
0136 }
0137
0138
0139 BOOST_AUTO_TEST_CASE(TrackStateProxyCrossTalk) {
0140 CommonTests ct;
0141 ct.testTrackStateProxyCrossTalk(rng);
0142 }
0143
0144 BOOST_AUTO_TEST_CASE(TrackStateReassignment) {
0145 CommonTests ct;
0146 ct.testTrackStateReassignment(rng);
0147 }
0148
0149 BOOST_DATA_TEST_CASE(TrackStateProxyStorage, bd::make({1u, 2u}),
0150 nMeasurements) {
0151 CommonTests ct;
0152 ct.testTrackStateProxyStorage(rng, nMeasurements);
0153 }
0154
0155 BOOST_AUTO_TEST_CASE(TrackStateProxyAllocations) {
0156 CommonTests ct;
0157 ct.testTrackStateProxyAllocations(rng);
0158 }
0159
0160 BOOST_AUTO_TEST_CASE(TrackStateProxyGetMask) {
0161 CommonTests ct;
0162 ct.testTrackStateProxyGetMask();
0163 }
0164
0165 BOOST_AUTO_TEST_CASE(TrackStateProxyCopy) {
0166 CommonTests ct;
0167 ct.testTrackStateProxyCopy(rng);
0168 }
0169
0170 BOOST_AUTO_TEST_CASE(TrackStateCopyDynamicColumns) {
0171 CommonTests ct;
0172 ct.testTrackStateCopyDynamicColumns();
0173 }
0174
0175 BOOST_AUTO_TEST_CASE(TrackStateProxyCopyDiffMTJ) {
0176 CommonTests ct;
0177 ct.testTrackStateProxyCopyDiffMTJ();
0178 }
0179
0180 BOOST_AUTO_TEST_CASE(ProxyAssignment) {
0181 CommonTests ct;
0182 ct.testProxyAssignment();
0183 }
0184
0185 BOOST_AUTO_TEST_CASE(CopyFromConst) {
0186 CommonTests ct;
0187 ct.testCopyFromConst();
0188 }
0189
0190 BOOST_AUTO_TEST_CASE(TrackStateProxyShare) {
0191 CommonTests ct;
0192 ct.testTrackStateProxyShare(rng);
0193 }
0194
0195 BOOST_AUTO_TEST_CASE(MultiTrajectoryExtraColumns) {
0196 CommonTests ct;
0197 ct.testMultiTrajectoryExtraColumns();
0198 }
0199
0200 BOOST_AUTO_TEST_CASE(MultiTrajectoryExtraColumnsRuntime) {
0201 CommonTests ct;
0202 ct.testMultiTrajectoryExtraColumnsRuntime();
0203 }
0204
0205 BOOST_AUTO_TEST_CASE(MultiTrajectoryAllocateCalibratedInit) {
0206 CommonTests ct;
0207 ct.testMultiTrajectoryAllocateCalibratedInit(rng);
0208 }
0209
0210 BOOST_AUTO_TEST_CASE(WriteToPodioFrame) {
0211 using namespace HashedStringLiteral;
0212
0213 MapHelper helper;
0214
0215 auto tmp_path = std::filesystem::temp_directory_path();
0216 auto outfile = tmp_path / "trackstates.root";
0217
0218 BoundVector tv1;
0219 tv1 << 1, 1, 1, 1, 1, 1;
0220
0221 BoundVector tv2 = tv1 * 2;
0222 BoundVector tv3 = tv1 * 3;
0223 BoundVector tv4 = tv1 * 4;
0224
0225 BoundMatrix cov1;
0226 cov1.setOnes();
0227
0228 BoundMatrix cov2 = cov1 * 2;
0229 BoundMatrix cov3 = cov1 * 3;
0230 BoundMatrix cov4 = cov1 * 4;
0231
0232 auto rBounds = std::make_shared<RectangleBounds>(15, 20);
0233 auto trf = Transform3::Identity();
0234 trf.translation().setRandom();
0235 auto free = Acts::Surface::makeShared<PlaneSurface>(trf, rBounds);
0236 auto reg = Acts::Surface::makeShared<PlaneSurface>(trf, rBounds);
0237
0238 helper.surfaces[666] = reg.get();
0239
0240 podio::Frame frame;
0241
0242 MutablePodioTrackStateContainer c{helper};
0243 BOOST_CHECK(!c.hasColumn("int_column"_hash));
0244 BOOST_CHECK(!c.hasColumn("float_column"_hash));
0245 c.addColumn<std::int32_t>("int_column");
0246 c.addColumn<float>("float_column");
0247 BOOST_CHECK(c.hasColumn("int_column"_hash));
0248 BOOST_CHECK(c.hasColumn("float_column"_hash));
0249
0250 {
0251 auto t1 = c.makeTrackState(TrackStatePropMask::Predicted);
0252 t1.predicted() = tv1;
0253 t1.predictedCovariance() = cov1;
0254
0255 t1.setReferenceSurface(free);
0256
0257 auto t2 = c.makeTrackState(TrackStatePropMask::All, t1.index());
0258 t2.predicted() = tv2;
0259 t2.predictedCovariance() = cov2;
0260
0261 t2.filtered() = tv3;
0262 t2.filteredCovariance() = cov3;
0263
0264 t2.smoothed() = tv4;
0265 t2.smoothedCovariance() = cov4;
0266
0267 t2.jacobian() = cov2;
0268
0269 auto t3 = c.makeTrackState();
0270 t3.setReferenceSurface(reg);
0271
0272 t1.component<std::int32_t, "int_column"_hash>() = -11;
0273 t2.component<std::int32_t, "int_column"_hash>() = 42;
0274 t3.component<std::int32_t, "int_column"_hash>() = -98;
0275
0276 t1.component<float, "float_column"_hash>() = -11.2f;
0277 t2.component<float, "float_column"_hash>() = 42.4f;
0278 t3.component<float, "float_column"_hash>() = -98.9f;
0279 }
0280
0281 c.releaseInto(frame, "test");
0282
0283 BOOST_CHECK_EQUAL(frame.get("trackStates_test")->size(), 3);
0284 BOOST_CHECK_EQUAL(frame.get("trackStateParameters_test")->size(), 7);
0285 BOOST_CHECK_EQUAL(frame.get("trackStateJacobians_test")->size(), 2);
0286 BOOST_CHECK_NE(frame.get("trackStates_test_extra__int_column"), nullptr);
0287 BOOST_CHECK_NE(frame.get("trackStates_test_extra__float_column"), nullptr);
0288
0289 ConstPodioTrackStateContainer cc{helper, frame, "test"};
0290
0291 BOOST_CHECK_EQUAL(cc.size(), 3);
0292 BOOST_CHECK(cc.hasColumn("int_column"_hash));
0293 BOOST_CHECK(cc.hasColumn("float_column"_hash));
0294
0295 auto t1 = cc.getTrackState(0);
0296 auto t2 = cc.getTrackState(1);
0297 auto t3 = cc.getTrackState(2);
0298
0299 BOOST_CHECK_EQUAL(t2.previous(), 0);
0300
0301 BOOST_CHECK(t1.hasReferenceSurface());
0302 BOOST_CHECK(!t2.hasReferenceSurface());
0303 BOOST_CHECK(t3.hasReferenceSurface());
0304
0305 Acts::GeometryContext gctx;
0306
0307 const auto& ext = t1.referenceSurface();
0308 BOOST_CHECK_NE(&ext, free.get());
0309 BOOST_CHECK_EQUAL(trf.matrix(), ext.transform(gctx).matrix());
0310 BOOST_CHECK_EQUAL(free->bounds().type(), ext.bounds().type());
0311 BOOST_CHECK_EQUAL(free->type(), ext.type());
0312 const auto* rBounds2 = dynamic_cast<const RectangleBounds*>(&ext.bounds());
0313 BOOST_REQUIRE_NE(rBounds2, nullptr);
0314 BOOST_CHECK_EQUAL(rBounds->halfLengthX(), rBounds2->halfLengthX());
0315 BOOST_CHECK_EQUAL(rBounds->halfLengthY(), rBounds2->halfLengthY());
0316
0317 BOOST_CHECK_EQUAL(t1.predicted(), tv1);
0318 BOOST_CHECK_EQUAL(t1.predictedCovariance(), cov1);
0319
0320 BOOST_CHECK_EQUAL(t2.predicted(), tv2);
0321 BOOST_CHECK_EQUAL(t2.predictedCovariance(), cov2);
0322 BOOST_CHECK_EQUAL(t2.filtered(), tv3);
0323 BOOST_CHECK_EQUAL(t2.filteredCovariance(), cov3);
0324 BOOST_CHECK_EQUAL(t2.smoothed(), tv4);
0325 BOOST_CHECK_EQUAL(t2.smoothedCovariance(), cov4);
0326
0327 BOOST_CHECK_EQUAL(t2.jacobian(), cov2);
0328
0329 BOOST_CHECK_EQUAL(&t3.referenceSurface(), reg.get());
0330
0331 BOOST_CHECK_EQUAL((t1.component<std::int32_t, "int_column"_hash>()), -11);
0332 BOOST_CHECK_EQUAL((t2.component<std::int32_t, "int_column"_hash>()), 42);
0333 BOOST_CHECK_EQUAL((t3.component<std::int32_t, "int_column"_hash>()), -98);
0334
0335 BOOST_CHECK_EQUAL((t1.component<float, "float_column"_hash>()), -11.2f);
0336 BOOST_CHECK_EQUAL((t2.component<float, "float_column"_hash>()), 42.4f);
0337 BOOST_CHECK_EQUAL((t3.component<float, "float_column"_hash>()), -98.9f);
0338 }
0339
0340 BOOST_AUTO_TEST_SUITE_END()