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>
34 #include <edm4hep/TrackCollection.h>
37 using namespace Acts::UnitLiterals;
38 BOOST_AUTO_TEST_SUITE(EDM4hepParameterConversion)
41 auto refSurface = Surface::makeShared<PerigeeSurface>(
Vector3{50, 30, 20});
44 par << 1_mm, 5_mm, 0, M_PI_2, -1 / 1_GeV,
65 BOOST_CHECK_EQUAL(par.template head<2>(),
66 converted.
values.template head<2>());
68 (converted.
covariance.value().template topLeftCorner<4, 4>()),
70 BOOST_CHECK(converted.
covariance.value()(4, 4) > 0);
71 BOOST_CHECK_EQUAL(converted.
covariance.value()(5, 5), 25_ns);
78 BOOST_CHECK(roundtripPar.
parameters().isApprox(boundPar.parameters()));
79 BOOST_CHECK(roundtripPar.
covariance().value().isApprox(
80 boundPar.covariance().value()));
84 auto refSurface = Surface::makeShared<PlaneSurface>(
88 par << 1_mm, 5_mm, M_PI / 4., M_PI_2, -1 / 1_GeV, 5_ns;
104 BOOST_CHECK(converted.
covariance.has_value());
105 BOOST_CHECK(converted.
surface);
108 BOOST_CHECK_EQUAL(converted.
values.template head<2>(), (
Vector2{0, 0}));
111 BOOST_CHECK((converted.covariance.value().template topLeftCorner<4, 4>())
113 BOOST_CHECK(converted.covariance.value()(4, 4) > 0);
114 BOOST_CHECK_EQUAL(converted.covariance.value()(5, 5), 25_ns);
120 BOOST_CHECK_EQUAL(roundtripPar.parameters().template head<2>(),
122 BOOST_CHECK(roundtripPar.parameters().tail<4>().isApprox(par.tail<4>()));
123 BOOST_CHECK(roundtripPar.covariance().value().isApprox(
124 boundPar.covariance().value()));
128 auto refSurface = Surface::makeShared<PerigeeSurface>(
Vector3{50, 30, 20});
131 par << 1_mm, 5_mm, 0, M_PI_2, -1 / 1_GeV,
144 BOOST_CHECK(!converted.
covariance.has_value());
145 BOOST_CHECK(converted.
surface);
148 BOOST_CHECK_EQUAL(par.template head<2>(),
149 converted.
values.template head<2>());
156 BOOST_CHECK(roundtripPar.
parameters().isApprox(boundPar.parameters()));
157 BOOST_CHECK(!roundtripPar.
covariance().has_value());
161 auto refSurface = Surface::makeShared<PlaneSurface>(
165 par << 1_mm, 5_mm, M_PI / 4., M_PI_2, -1 / 1_GeV, 5_ns;
177 BOOST_CHECK(!converted.
covariance.has_value());
178 BOOST_CHECK(converted.
surface);
181 BOOST_CHECK_EQUAL(converted.
values.template head<2>(), (
Vector2{0, 0}));
188 BOOST_CHECK_EQUAL(roundtripPar.parameters().template head<2>(),
190 BOOST_CHECK(roundtripPar.parameters().tail<4>().isApprox(par.tail<4>()));
191 BOOST_CHECK(!roundtripPar.covariance().has_value());
197 m << 1, 2, 3, 4, 5, 6,
205 std::array<float, 21>
values{};
216 auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
217 auto trackStateContainer = std::make_shared<Acts::VectorMultiTrajectory>();
220 using mutable_proxy_t = decltype(tracks)::
TrackProxy;
221 using const_proxy_t = decltype(tracks)::ConstTrackProxy;
223 std::mt19937
rng{42};
224 std::normal_distribution<double>
gauss(0., 1.);
225 std::uniform_real_distribution<double>
f(-1, 1);
226 std::uniform_real_distribution<double>
r(0, 1);
227 std::uniform_int_distribution<unsigned int> nTracks(2, 20);
228 std::uniform_int_distribution<unsigned int> nTs(1, 20);
229 std::uniform_real_distribution<double>
phiDist(-M_PI, M_PI);
230 std::uniform_real_distribution<double>
etaDist(-4, 4);
231 std::uniform_real_distribution<double> ptDist(1_MeV, 10_GeV);
232 std::uniform_real_distribution<double>
qDist(0., 1.);
234 auto genParams = [&]() -> std::pair<BoundVector, BoundMatrix> {
239 double theta = 2 * atan(exp(-eta));
240 double pt = ptDist(
rng);
241 double p = pt / sin(theta);
243 double qop = charge /
p;
249 cov = BoundMatrix::Identity();
250 cov.diagonal() << 20_um * 20_um, 20_mm * 20_mm, 0.1, 0.1, 1_GeV, 25_ns;
254 size_t numT = nTracks(
rng);
255 for (
size_t t = 0;
t < numT;
t++) {
256 auto track = tracks.getTrack(tracks.addTrack());
258 auto [par,
cov] = genParams();
259 track.parameters() = par;
260 track.covariance() =
cov;
262 track.setReferenceSurface(
263 Acts::Surface::makeShared<PerigeeSurface>(
Vector3{0, 0, 0}));
265 size_t numTs = nTs(
rng);
266 for (
size_t i = 0;
i < numTs;
i++) {
267 auto ts = track.appendTrackState(TrackStatePropMask::Smoothed);
268 double crit =
r(
rng);
272 }
else if (crit < 0.2) {
275 }
else if (crit < 0.3) {
277 }
else if (crit < 0.4) {
284 auto [par,
cov] = genParams();
286 ts.smoothedCovariance() =
cov;
289 ts.setReferenceSurface(Acts::Surface::makeShared<PerigeeSurface>(pos));
295 edm4hep::TrackCollection edm4hepTracks;
303 for (const_proxy_t track : tracks) {
304 auto to = edm4hepTracks.create();
308 BOOST_CHECK_EQUAL(edm4hepTracks.size(), tracks.size());
310 auto tIt = tracks.begin();
311 for (
auto edm4hepTrack : edm4hepTracks) {
313 BOOST_CHECK_EQUAL(track.nMeasurements(),
314 edm4hepTrack.trackStates_size() - 1);
319 const edm4hep::TrackCollection& edm4hepTracksConst = edm4hepTracks;
321 TrackContainer readTracks(std::make_shared<Acts::VectorTrackContainer>(),
322 std::make_shared<Acts::VectorMultiTrajectory>());
324 for (
const auto edm4hepTrack : edm4hepTracksConst) {
326 edm4hepTrack, readTracks.getTrack(readTracks.addTrack()), Bz, *
logger);
329 BOOST_CHECK_EQUAL(tracks.size(), readTracks.size());
332 auto origTrackIt = tracks.begin();
333 auto readTrackIt = readTracks.begin();
334 while (origTrackIt != tracks.end() && readTrackIt != readTracks.end()) {
335 BOOST_TEST_INFO_SCOPE(
"Track #" << t);
336 auto orig = *origTrackIt;
337 auto read = *readTrackIt;
341 BOOST_CHECK_EQUAL(orig.referenceSurface().center(gctx),
342 read.referenceSurface().center(gctx));
344 auto origTsIt = orig.trackStatesReversed().begin();
345 auto readTsIt =
read.trackStatesReversed().begin();
348 while (origTsIt != orig.trackStatesReversed().end() &&
349 readTsIt !=
read.trackStatesReversed().end()) {
350 BOOST_TEST_INFO_SCOPE(
"TS: #" << tsi);
351 auto nextMeas = std::find_if(
352 origTsIt, orig.trackStatesReversed().end(), [](
const auto& ts) {
355 BOOST_CHECK(nextMeas != orig.trackStatesReversed().end());
357 auto origTs = *origTsIt;
358 auto readTs = *readTsIt;
360 BOOST_TEST_INFO_SCOPE(
361 "orig parameters: " << origTs.parameters().transpose());
362 BOOST_TEST_INFO_SCOPE(
363 "read parameters: " << readTs.parameters().transpose());
365 readTs.smoothedCovariance(), 1
e-5, 1
e-6);
366 Vector3 newCenter = readTs.referenceSurface().center(
369 BOOST_CHECK(origTs.referenceSurface().isOnSurface(gctx, newCenter,
373 Vector3 readGlobal = readTs.referenceSurface().localToGlobal(
374 gctx, readTs.parameters().template head<2>(), Vector3::Zero());
375 Vector3 origGlobal = origTs.referenceSurface().localToGlobal(
376 gctx, origTs.parameters().template head<2>(), Vector3::Zero());
389 BOOST_AUTO_TEST_SUITE_END()