Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-13 09:23:30

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/Surfaces/PlaneSurface.hpp"
0014 #include "Acts/Surfaces/RectangleBounds.hpp"
0015 #include "ActsPlugins/Json/TrackParametersJsonConverter.hpp"
0016 
0017 #include <memory>
0018 
0019 #include <nlohmann/json.hpp>
0020 
0021 using namespace Acts;
0022 
0023 namespace ActsTests {
0024 
0025 BOOST_AUTO_TEST_SUITE(JsonSuite)
0026 
0027 BOOST_AUTO_TEST_CASE(TrackParametersJsonIO) {
0028   GeometryContext gctx;
0029 
0030   // Track parameters
0031   Vector4 position(1., 2., 3., 4.);
0032   double phi = 0.1;
0033   double theta = 0.2;
0034   double qOverP = 3.0;
0035   ParticleHypothesis particle = ParticleHypothesis::electron();
0036   FreeMatrix freeCov = FreeMatrix::Identity();
0037   BoundMatrix boundCov = BoundMatrix::Identity();
0038 
0039   auto surface = Surface::makeShared<PlaneSurface>(
0040       Transform3::Identity(), std::make_shared<RectangleBounds>(10., 10.));
0041   surface->assignGeometryId(GeometryIdentifier(1u));
0042 
0043   // Free track parameters conversion
0044   FreeTrackParameters ftp(position, phi, theta, qOverP, freeCov, particle);
0045 
0046   nlohmann::json ftpJson = ftp;
0047 
0048   FreeTrackParameters ftpRead = ftpJson;
0049 
0050   BOOST_CHECK_EQUAL(ftp.position(), ftpRead.position());
0051   BOOST_CHECK_EQUAL(ftp.direction(), ftpRead.direction());
0052   BOOST_CHECK_EQUAL(ftp.qOverP(), ftpRead.qOverP());
0053   BOOST_CHECK_EQUAL(ftp.covariance().value(), ftpRead.covariance().value());
0054   BOOST_CHECK_EQUAL(ftp.particleHypothesis(), ftpRead.particleHypothesis());
0055 
0056   // Curvilinear track parameters conversion
0057   BoundTrackParameters ctp = BoundTrackParameters::createCurvilinear(
0058       position, phi, theta, qOverP, boundCov, particle);
0059 
0060   nlohmann::json ctpJson = ctp;
0061 
0062   BoundTrackParameters ctpRead = ctpJson;
0063 
0064   BOOST_CHECK_EQUAL(ctp.position(gctx), ctpRead.position(gctx));
0065   BOOST_CHECK_EQUAL(ctp.direction(), ctpRead.direction());
0066   BOOST_CHECK_EQUAL(ctp.qOverP(), ctpRead.qOverP());
0067   BOOST_CHECK_EQUAL(ctp.covariance().value(), ctpRead.covariance().value());
0068   BOOST_CHECK_EQUAL(ctp.particleHypothesis(), ctpRead.particleHypothesis());
0069 
0070   BOOST_CHECK(ctp.referenceSurface().transform(gctx).isApprox(
0071       ctpRead.referenceSurface().transform(gctx)));
0072   BOOST_CHECK_EQUAL(ctp.referenceSurface().geometryId(),
0073                     ctpRead.referenceSurface().geometryId());
0074   BOOST_CHECK_EQUAL(ctp.referenceSurface().bounds(),
0075                     ctpRead.referenceSurface().bounds());
0076 
0077   // Bound track parameters conversion
0078   BoundVector boundPosition{1., 2., 3., 4., 5., 6.};
0079   BoundTrackParameters btp(surface, boundPosition, boundCov, particle);
0080 
0081   nlohmann::json btpJson = btp;
0082 
0083   BoundTrackParameters btpRead = btpJson;
0084 
0085   BOOST_CHECK_EQUAL(btp.position(gctx), btpRead.position(gctx));
0086   BOOST_CHECK_EQUAL(btp.direction(), btpRead.direction());
0087   BOOST_CHECK_EQUAL(btp.qOverP(), btpRead.qOverP());
0088   BOOST_CHECK_EQUAL(btp.covariance().value(), btpRead.covariance().value());
0089   BOOST_CHECK_EQUAL(btp.particleHypothesis(), btpRead.particleHypothesis());
0090 
0091   BOOST_CHECK(btp.referenceSurface().transform(gctx).isApprox(
0092       btpRead.referenceSurface().transform(gctx)));
0093   BOOST_CHECK_EQUAL(btp.referenceSurface().geometryId(),
0094                     btpRead.referenceSurface().geometryId());
0095   BOOST_CHECK_EQUAL(btp.referenceSurface().bounds(),
0096                     btpRead.referenceSurface().bounds());
0097 }
0098 
0099 BOOST_AUTO_TEST_SUITE_END()
0100 
0101 }  // namespace ActsTests