Back to home page

EIC code displayed by LXR

 
 

    


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

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