Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:12

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/EventData/ParticleHypothesis.hpp"
0012 #include "Acts/EventData/TrackParameters.hpp"
0013 #include "Acts/Plugins/Json/TrackParametersJsonConverter.hpp"
0014 #include "Acts/Surfaces/PlaneSurface.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 
0017 #include <memory>
0018 
0019 #include <nlohmann/json.hpp>
0020 
0021 BOOST_AUTO_TEST_SUITE(TrackParametersJsonIO)
0022 
0023 BOOST_AUTO_TEST_CASE(TrackParametersJsonIO) {
0024   Acts::GeometryContext gctx;
0025 
0026   // Track parameters
0027   Acts::Vector4 position(1., 2., 3., 4.);
0028   double phi = 0.1;
0029   double theta = 0.2;
0030   double qOverP = 3.0;
0031   Acts::ParticleHypothesis particle = Acts::ParticleHypothesis::electron();
0032   Acts::FreeMatrix freeCov = Acts::FreeMatrix::Identity();
0033   Acts::BoundMatrix boundCov = Acts::BoundMatrix::Identity();
0034 
0035   auto surface = Acts::Surface::makeShared<Acts::PlaneSurface>(
0036       Acts::Transform3::Identity(),
0037       std::make_shared<Acts::RectangleBounds>(10., 10.));
0038   surface->assignGeometryId(Acts::GeometryIdentifier(1u));
0039 
0040   // Free track parameters conversion
0041   Acts::FreeTrackParameters ftp(position, phi, theta, qOverP, freeCov,
0042                                 particle);
0043 
0044   nlohmann::json ftpJson = ftp;
0045 
0046   Acts::FreeTrackParameters ftpRead = ftpJson;
0047 
0048   BOOST_CHECK_EQUAL(ftp.position(), ftpRead.position());
0049   BOOST_CHECK_EQUAL(ftp.direction(), ftpRead.direction());
0050   BOOST_CHECK_EQUAL(ftp.qOverP(), ftpRead.qOverP());
0051   BOOST_CHECK_EQUAL(ftp.covariance().value(), ftpRead.covariance().value());
0052   BOOST_CHECK_EQUAL(ftp.particleHypothesis(), ftpRead.particleHypothesis());
0053 
0054   // Curvilinear track parameters conversion
0055   Acts::CurvilinearTrackParameters ctp(position, phi, theta, qOverP, boundCov,
0056                                        particle);
0057 
0058   nlohmann::json ctpJson = ctp;
0059 
0060   Acts::CurvilinearTrackParameters ctpRead = ctpJson;
0061 
0062   BOOST_CHECK_EQUAL(ctp.position(), ctpRead.position());
0063   BOOST_CHECK_EQUAL(ctp.direction(), ctpRead.direction());
0064   BOOST_CHECK_EQUAL(ctp.qOverP(), ctpRead.qOverP());
0065   BOOST_CHECK_EQUAL(ctp.covariance().value(), ctpRead.covariance().value());
0066   BOOST_CHECK_EQUAL(ctp.particleHypothesis(), ctpRead.particleHypothesis());
0067 
0068   BOOST_CHECK(ctp.referenceSurface().transform(gctx).isApprox(
0069       ctpRead.referenceSurface().transform(gctx)));
0070   BOOST_CHECK_EQUAL(ctp.referenceSurface().geometryId(),
0071                     ctpRead.referenceSurface().geometryId());
0072   BOOST_CHECK_EQUAL(ctp.referenceSurface().bounds(),
0073                     ctpRead.referenceSurface().bounds());
0074 
0075   // Bound track parameters conversion
0076   Acts::BoundVector boundPosition{1., 2., 3., 4., 5., 6.};
0077   Acts::BoundTrackParameters btp(surface, boundPosition, boundCov, particle);
0078 
0079   nlohmann::json btpJson = btp;
0080 
0081   Acts::BoundTrackParameters btpRead = btpJson;
0082 
0083   BOOST_CHECK_EQUAL(btp.position(gctx), btpRead.position(gctx));
0084   BOOST_CHECK_EQUAL(btp.direction(), btpRead.direction());
0085   BOOST_CHECK_EQUAL(btp.qOverP(), btpRead.qOverP());
0086   BOOST_CHECK_EQUAL(btp.covariance().value(), btpRead.covariance().value());
0087   BOOST_CHECK_EQUAL(btp.particleHypothesis(), btpRead.particleHypothesis());
0088 
0089   BOOST_CHECK(btp.referenceSurface().transform(gctx).isApprox(
0090       btpRead.referenceSurface().transform(gctx)));
0091   BOOST_CHECK_EQUAL(btp.referenceSurface().geometryId(),
0092                     btpRead.referenceSurface().geometryId());
0093   BOOST_CHECK_EQUAL(btp.referenceSurface().bounds(),
0094                     btpRead.referenceSurface().bounds());
0095 }
0096 
0097 BOOST_AUTO_TEST_SUITE_END()