Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-12 09:43:10

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 particleHypothesis = ParticleHypothesis::pionLike(std::abs(q));
0036 
0037   const auto qOverP = particleHypothesis.qOverP(p, q);
0038   const auto pos = pos4.segment<3>(ePos0);
0039 
0040   // native values
0041   CHECK_CLOSE_OR_SMALL(params.template get<eFreePos0>(), pos4[ePos0], eps, eps);
0042   CHECK_CLOSE_OR_SMALL(params.template get<eFreePos1>(), pos4[ePos1], eps, eps);
0043   CHECK_CLOSE_OR_SMALL(params.template get<eFreePos2>(), pos4[ePos2], eps, eps);
0044   CHECK_CLOSE_OR_SMALL(params.template get<eFreeTime>(), pos4[eTime], eps, eps);
0045   CHECK_CLOSE_OR_SMALL(params.template get<eFreeDir0>(), unitDir[eMom0], eps,
0046                        eps);
0047   CHECK_CLOSE_OR_SMALL(params.template get<eFreeDir1>(), unitDir[eMom1], eps,
0048                        eps);
0049   CHECK_CLOSE_OR_SMALL(params.template get<eFreeDir2>(), unitDir[eMom2], eps,
0050                        eps);
0051   CHECK_CLOSE_OR_SMALL(params.template get<eFreeQOverP>(), qOverP, eps, eps);
0052   // convenience accessors
0053   BOOST_CHECK_EQUAL(params.charge(), q);
0054   CHECK_CLOSE_OR_SMALL(params.fourPosition(), pos4, eps, eps);
0055   CHECK_CLOSE_OR_SMALL(params.position(), pos, eps, eps);
0056   CHECK_CLOSE_OR_SMALL(params.time(), pos4[eFreeTime], eps, eps);
0057   CHECK_CLOSE_OR_SMALL(params.direction(), unitDir, eps, eps);
0058   if (q != 0) {
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   }
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   // reflection
0072   FreeTrackParameters reflectedParams = params;
0073   reflectedParams.reflectInPlace();
0074   CHECK_CLOSE_OR_SMALL(params.reflect().parameters(),
0075                        reflectedParams.parameters(), eps, eps);
0076   CHECK_CLOSE_OR_SMALL(reflectedParams.reflect().parameters(),
0077                        params.parameters(), eps, eps);
0078 
0079   // particle hypothesis
0080   const auto newHypothesis = ParticleHypothesis::electron();
0081   const FreeTrackParameters withHypothesis =
0082       params.withParticleHypothesis(newHypothesis);
0083   BOOST_CHECK(withHypothesis.particleHypothesis() == newHypothesis);
0084   BOOST_CHECK(withHypothesis.parameters() == params.parameters());
0085   BOOST_CHECK(withHypothesis.covariance() == params.covariance());
0086   FreeTrackParameters setHypothesis = params;
0087   setHypothesis.setParticleHypothesis(newHypothesis);
0088   BOOST_CHECK(setHypothesis.particleHypothesis() == newHypothesis);
0089   BOOST_CHECK(setHypothesis.parameters() == params.parameters());
0090 }
0091 
0092 }  // namespace
0093 
0094 namespace ActsTests {
0095 
0096 BOOST_AUTO_TEST_SUITE(EventDataSuite)
0097 
0098 BOOST_DATA_TEST_CASE(NeutralConstructFromAngles,
0099                      posSymmetric * posSymmetric * posSymmetric * ts * phis *
0100                          thetas * ps,
0101                      x, y, z, time, phi, theta, p) {
0102   Vector4 pos4(x, y, z, time);
0103   Vector3 dir = makeDirectionFromPhiTheta(phi, theta);
0104 
0105   FreeTrackParameters params(pos4, phi, theta, 0, std::nullopt,
0106                              ParticleHypothesis::pion0());
0107   checkParameters(params, pos4, dir, p, 0_e);
0108   BOOST_CHECK(!params.covariance());
0109 
0110   // reassign w/ covariance
0111   params = FreeTrackParameters(pos4, phi, theta, 0, cov,
0112                                ParticleHypothesis::pion0());
0113   BOOST_CHECK(params.covariance());
0114   BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0115 }
0116 
0117 BOOST_DATA_TEST_CASE(ChargedConstructFromAngles,
0118                      posSymmetric * posSymmetric * posSymmetric * ts * phis *
0119                          thetas * ps * qsNonZero,
0120                      x, y, z, time, phi, theta, p, q) {
0121   Vector4 pos4(x, y, z, time);
0122   Vector3 dir = makeDirectionFromPhiTheta(phi, theta);
0123 
0124   FreeTrackParameters params(pos4, phi, theta, q / p, std::nullopt,
0125                              ParticleHypothesis::pionLike(std::abs(q)));
0126   checkParameters(params, pos4, dir, p, q);
0127   BOOST_CHECK(!params.covariance());
0128 
0129   // reassign w/ covariance
0130   params = FreeTrackParameters(pos4, phi, theta, q / p, cov,
0131                                ParticleHypothesis::pionLike(std::abs(q)));
0132   BOOST_CHECK(params.covariance());
0133   BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0134 }
0135 
0136 BOOST_DATA_TEST_CASE(AnyConstructFromAngles,
0137                      posSymmetric * posSymmetric * posSymmetric * ts * phis *
0138                          thetas * ps * qsNonZero,
0139                      x, y, z, time, phi, theta, p, q) {
0140   Vector4 pos4(x, y, z, time);
0141   Vector3 dir = makeDirectionFromPhiTheta(phi, theta);
0142 
0143   FreeTrackParameters params(pos4, phi, theta, q / p, std::nullopt,
0144                              ParticleHypothesis::pionLike(std::abs(q)));
0145   checkParameters(params, pos4, dir, p, q);
0146   BOOST_CHECK(!params.covariance());
0147 
0148   // reassign w/ covariance
0149   params = FreeTrackParameters(pos4, phi, theta, q / p, cov,
0150                                ParticleHypothesis::pionLike(std::abs(q)));
0151   BOOST_CHECK(params.covariance());
0152   BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0153 }
0154 
0155 BOOST_AUTO_TEST_SUITE_END()
0156 
0157 }  // namespace ActsTests