Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:19

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