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) 2017-2020 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/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Common.hpp"
0013 #include "Acts/Definitions/TrackParametrization.hpp"
0014 #include "Acts/Definitions/Units.hpp"
0015 #include "Acts/EventData/Charge.hpp"
0016 #include "Acts/EventData/GenericCurvilinearTrackParameters.hpp"
0017 #include "Acts/EventData/TrackParameters.hpp"
0018 #include "Acts/Geometry/GeometryContext.hpp"
0019 #include "Acts/Surfaces/PlaneSurface.hpp"
0020 #include "Acts/Surfaces/RegularSurface.hpp"
0021 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0022 #include "Acts/Utilities/UnitVectors.hpp"
0023 #include "Acts/Utilities/detail/periodic.hpp"
0024 
0025 #include <cmath>
0026 #include <limits>
0027 #include <optional>
0028 #include <utility>
0029 #include <vector>
0030 
0031 #include "TrackParametersDatasets.hpp"
0032 
0033 namespace {
0034 
0035 using namespace Acts;
0036 using namespace Acts::UnitLiterals;
0037 
0038 constexpr auto eps = 8 * std::numeric_limits<ActsScalar>::epsilon();
0039 const GeometryContext geoCtx;
0040 const BoundSquareMatrix cov = BoundSquareMatrix::Identity();
0041 
0042 void checkParameters(const CurvilinearTrackParameters& params, double phi,
0043                      double theta, double p, double q, const Vector4& pos4,
0044                      const Vector3& unitDir) {
0045   const auto qOverP = (q != 0) ? (q / p) : (1 / p);
0046   const auto pos = pos4.segment<3>(ePos0);
0047 
0048   const auto* referenceSurface =
0049       dynamic_cast<const PlaneSurface*>(&params.referenceSurface());
0050   BOOST_REQUIRE_MESSAGE(referenceSurface != nullptr,
0051                         "Reference surface is not a plane");
0052 
0053   // native values
0054   CHECK_SMALL(params.template get<eBoundLoc0>(), eps);
0055   CHECK_SMALL(params.template get<eBoundLoc1>(), eps);
0056   CHECK_CLOSE_OR_SMALL(params.template get<eBoundTime>(), pos4[eTime], eps,
0057                        eps);
0058   CHECK_CLOSE_OR_SMALL(detail::radian_sym(params.template get<eBoundPhi>()),
0059                        detail::radian_sym(phi), eps, eps);
0060   CHECK_CLOSE_OR_SMALL(params.template get<eBoundTheta>(), theta, eps, eps);
0061   CHECK_CLOSE_OR_SMALL(params.template get<eBoundQOverP>(), qOverP, eps, eps);
0062   // convenience accessorss
0063   CHECK_CLOSE_OR_SMALL(params.fourPosition(geoCtx), pos4, eps, eps);
0064   CHECK_CLOSE_OR_SMALL(params.position(geoCtx), pos, eps, eps);
0065   CHECK_CLOSE_OR_SMALL(params.time(), pos4[eTime], eps, eps);
0066   CHECK_CLOSE_OR_SMALL(params.direction(), unitDir, eps, eps);
0067   CHECK_CLOSE_OR_SMALL(params.absoluteMomentum(), p, eps, eps);
0068   CHECK_CLOSE_OR_SMALL(params.transverseMomentum(), p * std::sin(theta), eps,
0069                        eps);
0070   CHECK_CLOSE_OR_SMALL(params.momentum(), p * unitDir, eps, eps);
0071   BOOST_CHECK_EQUAL(params.charge(), q);
0072   // curvilinear reference surface
0073   CHECK_CLOSE_OR_SMALL(referenceSurface->center(geoCtx), pos, eps, eps);
0074   CHECK_CLOSE_OR_SMALL(referenceSurface->normal(geoCtx), unitDir, eps, eps);
0075   // TODO verify reference frame
0076 }
0077 
0078 }  // namespace
0079 
0080 BOOST_AUTO_TEST_SUITE(EventDataCurvilinearTrackParameters)
0081 
0082 BOOST_DATA_TEST_CASE(
0083     NeutralConstruct,
0084     posSymmetric* posSymmetric* posSymmetric* ts* phis* thetas* ps, x, y, z,
0085     time, phiInput, theta, p) {
0086   // phi is ill-defined in forward/backward tracks
0087   const auto phi = ((0 < theta) && (theta < M_PI)) ? phiInput : 0.0;
0088   const Vector4 pos4(x, y, z, time);
0089   const Vector3 dir = makeDirectionFromPhiTheta(phi, theta);
0090 
0091   CurvilinearTrackParameters params(pos4, dir, 1 / p, std::nullopt,
0092                                     ParticleHypothesis::pion0());
0093   checkParameters(params, phi, theta, p, 0_e, pos4, dir);
0094   BOOST_CHECK(!params.covariance());
0095 
0096   // reassign w/ covariance
0097   params = CurvilinearTrackParameters(pos4, dir, 1 / p, cov,
0098                                       ParticleHypothesis::pion0());
0099   BOOST_CHECK(params.covariance());
0100   BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0101 }
0102 
0103 BOOST_DATA_TEST_CASE(
0104     ChargedConstruct,
0105     posSymmetric* posSymmetric* posSymmetric* ts* phis* thetas* ps* qsNonZero,
0106     x, y, z, time, phiInput, theta, p, q) {
0107   // phi is ill-defined in forward/backward tracks
0108   const auto phi = ((0 < theta) && (theta < M_PI)) ? phiInput : 0.0;
0109   const Vector4 pos4(x, y, z, time);
0110   const Vector3 dir = makeDirectionFromPhiTheta(phi, theta);
0111 
0112   CurvilinearTrackParameters params(pos4, dir, q / p, std::nullopt,
0113                                     ParticleHypothesis::pionLike(std::abs(q)));
0114   checkParameters(params, phi, theta, p, q, pos4, dir);
0115   BOOST_CHECK(!params.covariance());
0116 
0117   // reassign w/ covariance
0118   params = CurvilinearTrackParameters(
0119       pos4, dir, q / p, cov, ParticleHypothesis::pionLike(std::abs(q)));
0120   BOOST_CHECK(params.covariance());
0121   BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0122 }
0123 
0124 BOOST_DATA_TEST_CASE(
0125     AnyConstruct,
0126     posSymmetric* posSymmetric* posSymmetric* ts* phis* thetas* ps* qsAny, x, y,
0127     z, time, phiInput, theta, p, q) {
0128   // phi is ill-defined in forward/backward tracks
0129   const auto phi = ((0 < theta) && (theta < M_PI)) ? phiInput : 0.0;
0130   const Vector4 pos4(x, y, z, time);
0131   const Vector3 dir = makeDirectionFromPhiTheta(phi, theta);
0132 
0133   auto particleHypothesis = ParticleHypothesis::pionLike(std::abs(q));
0134   auto qOverP = particleHypothesis.qOverP(p, q);
0135 
0136   CurvilinearTrackParameters params(pos4, dir, qOverP, std::nullopt,
0137                                     particleHypothesis);
0138   checkParameters(params, phi, theta, p, q, pos4, dir);
0139   BOOST_CHECK(!params.covariance());
0140 
0141   // reassign w/ covariance
0142   params =
0143       CurvilinearTrackParameters(pos4, dir, qOverP, cov, particleHypothesis);
0144   BOOST_CHECK(params.covariance());
0145   BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0146 }
0147 
0148 BOOST_AUTO_TEST_SUITE_END()