9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/tools/old/interface.hpp>
11 #include <boost/test/unit_test.hpp>
12 #include <boost/test/unit_test_suite.hpp>
41 #include "ActsPodioEdm/Surface.h"
42 #include <ActsPodioEdm/TrackCollection.h>
51 using namespace Acts::UnitLiterals;
52 using namespace Acts::HashedStringLiteral;
53 BOOST_AUTO_TEST_SUITE(PodioTrackConversion)
55 class NullHelper : public PodioUtil::ConversionHelper {
57 std::optional<PodioUtil::Identifier> surfaceToIdentifier(
58 const Surface& )
const override {
77 struct MapHelper :
public NullHelper {
78 std::optional<PodioUtil::Identifier> surfaceToIdentifier(
80 for (
auto&& [
id, srf] : surfaces) {
81 if (srf == &surface) {
88 auto it = surfaces.find(
id);
89 if (
it == surfaces.end()) {
96 std::unordered_map<PodioUtil::Identifier, const Surface*>
surfaces;
100 auto rBounds = std::make_shared<RectangleBounds>(15, 20);
102 auto trf = Transform3::Identity();
103 trf.translation().setRandom();
105 auto free = Acts::Surface::makeShared<PlaneSurface>(trf,
rBounds);
114 BOOST_REQUIRE(free2);
115 BOOST_CHECK_EQUAL(free->type(), free2->type());
116 BOOST_CHECK_EQUAL(free->bounds().type(), free2->bounds().type());
117 BOOST_CHECK_EQUAL(free->center(gctx), free2->center(gctx));
119 const auto* rBounds2 =
dynamic_cast<const RectangleBounds*
>(&free2->bounds());
120 BOOST_REQUIRE_NE(rBounds2,
nullptr);
122 BOOST_CHECK_EQUAL(rBounds2->halfLengthX(),
rBounds->halfLengthX());
123 BOOST_CHECK_EQUAL(rBounds2->halfLengthY(),
rBounds->halfLengthY());
129 auto rBounds = std::make_shared<RectangleBounds>(15, 20);
130 auto trf = Transform3::Identity();
131 trf.translation().setRandom();
132 auto free = Acts::Surface::makeShared<PlaneSurface>(trf,
rBounds);
136 auto refCov = BoundMatrix::Random().eval();
143 ActsPodioEdm::TrackCollection&
tracks = ptc.trackCollection();
147 BOOST_CHECK(!
tc.hasColumn(
"int_column"_hash));
148 BOOST_CHECK(!
tc.hasColumn(
"float_column"_hash));
149 tc.addColumn<int32_t>(
"int_column");
150 tc.addColumn<
float>(
"float_column");
151 BOOST_CHECK(
tc.hasColumn(
"int_column"_hash));
152 BOOST_CHECK(
tc.hasColumn(
"float_column"_hash));
154 BOOST_CHECK_EQUAL(
tc.size(), 0);
156 auto t =
tc.getTrack(
tc.addTrack());
159 BOOST_CHECK_EQUAL(tsc.size(), 0);
160 auto ts1 = t.appendTrackState();
161 auto ts2 = t.appendTrackState();
162 auto ts3 = t.appendTrackState();
163 BOOST_CHECK_EQUAL(tsc.size(), 3);
164 BOOST_CHECK_EQUAL(ts1.index(), 0);
165 BOOST_CHECK_EQUAL(ts2.index(), 1);
166 BOOST_CHECK_EQUAL(ts3.index(), 2);
168 BOOST_CHECK_EQUAL(t.nTrackStates(), 3);
169 BOOST_CHECK_EQUAL(t.tipIndex(), 2);
171 BOOST_CHECK_EQUAL(
tc.size(), 1);
173 auto pTrack = tracks.at(0);
174 BOOST_CHECK_EQUAL(pTrack.data().tipIndex, 2);
176 t.parameters() << 1, 2, 3, 4, 5, 6;
177 Eigen::Map<BoundVector>
pars{pTrack.data().parameters.data()};
179 bv << 1, 2, 3, 4, 5, 6;
180 BOOST_CHECK_EQUAL(
pars, bv);
182 t.covariance() = refCov;
184 Eigen::Map<const BoundMatrix>
cov{pTrack.data().covariance.data()};
185 BOOST_CHECK_EQUAL(refCov,
cov);
187 t.nMeasurements() = 17;
188 BOOST_CHECK_EQUAL(pTrack.data().nMeasurements, 17);
191 BOOST_CHECK_EQUAL(pTrack.data().nHoles, 34);
194 BOOST_CHECK_EQUAL(pTrack.data().chi2, 882.3f);
197 BOOST_CHECK_EQUAL(pTrack.data().ndf, 9);
200 BOOST_CHECK_EQUAL(pTrack.data().nOutliers, 77);
202 t.nSharedHits() = 99;
203 BOOST_CHECK_EQUAL(pTrack.data().nSharedHits, 99);
206 t.setReferenceSurface(free);
207 const auto& free2 = t.referenceSurface();
208 BOOST_CHECK_EQUAL(free->center(gctx), free2.center(gctx));
210 const auto* rBounds2 =
212 BOOST_REQUIRE_NE(rBounds2,
nullptr);
214 BOOST_CHECK_EQUAL(rBounds2->halfLengthX(),
rBounds->halfLengthX());
215 BOOST_CHECK_EQUAL(rBounds2->halfLengthY(),
rBounds->halfLengthY());
217 BOOST_CHECK_EQUAL(pTrack.getReferenceSurface().identifier,
220 auto t2 =
tc.getTrack(
tc.addTrack());
221 auto t3 =
tc.getTrack(
tc.addTrack());
222 BOOST_CHECK_EQUAL(
tc.size(), 3);
225 helper.surfaces[666] = free.get();
226 t2.setReferenceSurface(free);
227 auto pTrack2 = tracks.at(1);
228 BOOST_CHECK_EQUAL(pTrack2.getReferenceSurface().identifier, 666);
230 t.component<int32_t,
"int_column"_hash>() = -11;
231 t2.component<int32_t,
"int_column"_hash>() = 42;
232 t3.component<int32_t,
"int_column"_hash>() = -98;
234 t.component<float,
"float_column"_hash>() = -11.2
f;
235 t2.component<float,
"float_column"_hash>() = 42.4
f;
236 t3.component<float,
"float_column"_hash>() = -98.9
f;
238 ptc.releaseInto(frame);
239 tsc.releaseInto(frame);
241 BOOST_REQUIRE_NE(frame.get(
"tracks"),
nullptr);
242 BOOST_CHECK_EQUAL(frame.get(
"tracks")->size(), 3);
243 BOOST_REQUIRE_NE(frame.get(
"tracks_extra__int_column"),
nullptr);
244 BOOST_REQUIRE_NE(frame.get(
"tracks_extra__float_column"),
nullptr);
246 BOOST_REQUIRE_NE(frame.get(
"trackStates"),
nullptr);
247 BOOST_CHECK_EQUAL(frame.get(
"trackStates")->size(), 3);
257 BOOST_CHECK(
tc.hasColumn(
"int_column"_hash));
258 BOOST_CHECK(
tc.hasColumn(
"float_column"_hash));
260 BOOST_CHECK_EQUAL(
tc.size(), 3);
262 auto t =
tc.getTrack(0);
263 const auto& freeRecreated = t.referenceSurface();
265 BOOST_CHECK_NE(free.get(), &freeRecreated);
267 BOOST_CHECK_EQUAL(t.nMeasurements(), 17);
269 BOOST_CHECK_EQUAL(t.nHoles(), 34);
271 BOOST_CHECK_EQUAL(t.chi2(), 882.3f);
273 BOOST_CHECK_EQUAL(t.nDoF(), 9);
275 BOOST_CHECK_EQUAL(t.nOutliers(), 77);
277 BOOST_CHECK_EQUAL(t.nSharedHits(), 99);
279 BOOST_CHECK_EQUAL(t.tipIndex(), 2);
280 BOOST_CHECK_EQUAL(t.nTrackStates(), 3);
282 auto t2 =
tc.getTrack(1);
284 BOOST_CHECK_EQUAL(free.get(), &t2.referenceSurface());
286 bv << 1, 2, 3, 4, 5, 6;
287 BOOST_CHECK_EQUAL(t.parameters(), bv);
289 BOOST_CHECK_EQUAL(t.covariance(), refCov);
291 auto t3 =
tc.getTrack(2);
292 BOOST_CHECK(!t3.hasReferenceSurface());
294 BOOST_CHECK_EQUAL((t.component<int32_t,
"int_column"_hash>()), -11);
295 BOOST_CHECK_EQUAL((t2.component<int32_t,
"int_column"_hash>()), 42);
296 BOOST_CHECK_EQUAL((t3.component<int32_t,
"int_column"_hash>()), -98);
298 BOOST_CHECK_EQUAL((t.component<
float,
"float_column"_hash>()), -11.2f);
299 BOOST_CHECK_EQUAL((t2.component<
float,
"float_column"_hash>()), 42.4f);
300 BOOST_CHECK_EQUAL((t3.component<
float,
"float_column"_hash>()), -98.9f);
306 BOOST_AUTO_TEST_SUITE_END()