Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-16 07:37:00

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/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Definitions/Common.hpp"
0014 #include "Acts/Definitions/TrackParametrization.hpp"
0015 #include "Acts/Definitions/Units.hpp"
0016 #include "Acts/EventData/FreeTrackParameters.hpp"
0017 #include "Acts/Utilities/UnitVectors.hpp"
0018 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0019 
0020 #include <limits>
0021 #include <optional>
0022 
0023 #include "TrackParametersDatasets.hpp"
0024 
0025 using namespace Acts;
0026 using namespace Acts::UnitLiterals;
0027 
0028 namespace {
0029 
0030 constexpr auto eps = 8 * std::numeric_limits<double>::epsilon();
0031 const FreeMatrix cov = FreeMatrix::Identity();
0032 
0033 void checkParameters(const FreeTrackParameters& params, const Vector4& pos4,
0034                      const Vector3& unitDir, double p, double q) {
0035   const auto qOverP = (q != 0) ? (q / p) : (1 / p);
0036   const auto pos = pos4.segment<3>(ePos0);
0037 
0038   // native values
0039   CHECK_CLOSE_OR_SMALL(params.template get<eFreePos0>(), pos4[ePos0], eps, eps);
0040   CHECK_CLOSE_OR_SMALL(params.template get<eFreePos1>(), pos4[ePos1], eps, eps);
0041   CHECK_CLOSE_OR_SMALL(params.template get<eFreePos2>(), pos4[ePos2], eps, eps);
0042   CHECK_CLOSE_OR_SMALL(params.template get<eFreeTime>(), pos4[eTime], eps, eps);
0043   CHECK_CLOSE_OR_SMALL(params.template get<eFreeDir0>(), unitDir[eMom0], eps,
0044                        eps);
0045   CHECK_CLOSE_OR_SMALL(params.template get<eFreeDir1>(), unitDir[eMom1], eps,
0046                        eps);
0047   CHECK_CLOSE_OR_SMALL(params.template get<eFreeDir2>(), unitDir[eMom2], eps,
0048                        eps);
0049   CHECK_CLOSE_OR_SMALL(params.template get<eFreeQOverP>(), qOverP, eps, eps);
0050   // convenience accessors
0051   CHECK_CLOSE_OR_SMALL(params.fourPosition(), pos4, eps, eps);
0052   CHECK_CLOSE_OR_SMALL(params.position(), pos, eps, eps);
0053   CHECK_CLOSE_OR_SMALL(params.time(), pos4[eFreeTime], eps, eps);
0054   CHECK_CLOSE_OR_SMALL(params.direction(), unitDir, eps, eps);
0055   CHECK_CLOSE_OR_SMALL(params.absoluteMomentum(), p, eps, eps);
0056   CHECK_CLOSE_OR_SMALL(params.transverseMomentum(),
0057                        p * unitDir.template head<2>().norm(), eps, eps);
0058   CHECK_CLOSE_OR_SMALL(params.momentum(), p * unitDir, eps, eps);
0059   BOOST_CHECK_EQUAL(params.charge(), q);
0060   // self-consistency
0061   CHECK_CLOSE_OR_SMALL(params.position(),
0062                        params.parameters().template segment<3>(eFreePos0), eps,
0063                        eps);
0064   CHECK_CLOSE_OR_SMALL(params.time(), params.template get<eFreeTime>(), eps,
0065                        eps);
0066 
0067   // reflection
0068   FreeTrackParameters reflectedParams = params;
0069   reflectedParams.reflectInPlace();
0070   CHECK_CLOSE_OR_SMALL(params.reflect().parameters(),
0071                        reflectedParams.parameters(), eps, eps);
0072   CHECK_CLOSE_OR_SMALL(reflectedParams.reflect().parameters(),
0073                        params.parameters(), eps, eps);
0074 }
0075 
0076 }  // namespace
0077 
0078 namespace ActsTests {
0079 
0080 BOOST_AUTO_TEST_SUITE(EventDataSuite)
0081 
0082 BOOST_DATA_TEST_CASE(NeutralConstructFromAngles,
0083                      posSymmetric * posSymmetric * posSymmetric * ts * phis *
0084                          thetas * ps,
0085                      x, y, z, time, phi, theta, p) {
0086   Vector4 pos4(x, y, z, time);
0087   Vector3 dir = makeDirectionFromPhiTheta(phi, theta);
0088 
0089   FreeTrackParameters params(pos4, phi, theta, 1 / p, std::nullopt,
0090                              ParticleHypothesis::pion0());
0091   checkParameters(params, pos4, dir, p, 0_e);
0092   BOOST_CHECK(!params.covariance());
0093 
0094   // reassign w/ covariance
0095   params = FreeTrackParameters(pos4, phi, theta, 1 / p, cov,
0096                                ParticleHypothesis::pion0());
0097   BOOST_CHECK(params.covariance());
0098   BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0099 }
0100 
0101 BOOST_DATA_TEST_CASE(ChargedConstructFromAngles,
0102                      posSymmetric * posSymmetric * posSymmetric * ts * phis *
0103                          thetas * ps * qsNonZero,
0104                      x, y, z, time, phi, theta, p, q) {
0105   Vector4 pos4(x, y, z, time);
0106   Vector3 dir = makeDirectionFromPhiTheta(phi, theta);
0107 
0108   FreeTrackParameters params(pos4, phi, theta, q / p, std::nullopt,
0109                              ParticleHypothesis::pionLike(std::abs(q)));
0110   checkParameters(params, pos4, dir, p, q);
0111   BOOST_CHECK(!params.covariance());
0112 
0113   // reassign w/ covariance
0114   params = FreeTrackParameters(pos4, phi, theta, q / p, cov,
0115                                ParticleHypothesis::pionLike(std::abs(q)));
0116   BOOST_CHECK(params.covariance());
0117   BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0118 }
0119 
0120 BOOST_DATA_TEST_CASE(AnyConstructFromAngles,
0121                      posSymmetric * posSymmetric * posSymmetric * ts * phis *
0122                          thetas * ps * qsNonZero,
0123                      x, y, z, time, phi, theta, p, q) {
0124   Vector4 pos4(x, y, z, time);
0125   Vector3 dir = makeDirectionFromPhiTheta(phi, theta);
0126 
0127   FreeTrackParameters params(pos4, phi, theta, q / p, std::nullopt,
0128                              ParticleHypothesis::pionLike(std::abs(q)));
0129   checkParameters(params, pos4, dir, p, q);
0130   BOOST_CHECK(!params.covariance());
0131 
0132   // reassign w/ covariance
0133   params = FreeTrackParameters(pos4, phi, theta, q / p, cov,
0134                                ParticleHypothesis::pionLike(std::abs(q)));
0135   BOOST_CHECK(params.covariance());
0136   BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0137 }
0138 
0139 BOOST_AUTO_TEST_SUITE_END()
0140 
0141 }  // namespace ActsTests