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/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/GenericBoundTrackParameters.hpp"
0018 #include "Acts/EventData/ParticleHypothesis.hpp"
0019 #include "Acts/EventData/TrackParameters.hpp"
0020 #include "Acts/Geometry/GeometryContext.hpp"
0021 #include "Acts/Surfaces/ConeSurface.hpp"
0022 #include "Acts/Surfaces/CylinderSurface.hpp"
0023 #include "Acts/Surfaces/DiscSurface.hpp"
0024 #include "Acts/Surfaces/PerigeeSurface.hpp"
0025 #include "Acts/Surfaces/PlaneSurface.hpp"
0026 #include "Acts/Surfaces/StrawSurface.hpp"
0027 #include "Acts/Surfaces/Surface.hpp"
0028 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0029 #include "Acts/Utilities/Result.hpp"
0030 #include "Acts/Utilities/UnitVectors.hpp"
0031 #include "Acts/Utilities/detail/periodic.hpp"
0032 
0033 #include <algorithm>
0034 #include <cmath>
0035 #include <limits>
0036 #include <memory>
0037 #include <optional>
0038 #include <utility>
0039 #include <vector>
0040 
0041 #include "TrackParametersDatasets.hpp"
0042 
0043 namespace {
0044 
0045 namespace bdata = boost::unit_test::data;
0046 using namespace Acts;
0047 using namespace Acts::UnitLiterals;
0048 
0049 constexpr auto eps = 8 * std::numeric_limits<ActsScalar>::epsilon();
0050 const GeometryContext geoCtx;
0051 const BoundSquareMatrix cov = BoundSquareMatrix::Identity();
0052 
0053 void checkParameters(const BoundTrackParameters& params, double l0, double l1,
0054                      double time, double phi, double theta, double p, double q,
0055                      const Vector3& pos, const Vector3& unitDir) {
0056   const auto particleHypothesis = ParticleHypothesis::pionLike(std::abs(q));
0057 
0058   const auto qOverP = particleHypothesis.qOverP(p, q);
0059   const auto pos4 = VectorHelpers::makeVector4(pos, time);
0060 
0061   // native values
0062   CHECK_CLOSE_OR_SMALL(params.template get<eBoundLoc0>(), l0, eps, eps);
0063   CHECK_CLOSE_OR_SMALL(params.template get<eBoundLoc1>(), l1, eps, eps);
0064   CHECK_CLOSE_OR_SMALL(params.template get<eBoundTime>(), time, eps, eps);
0065   CHECK_CLOSE_OR_SMALL(detail::radian_sym(params.template get<eBoundPhi>()),
0066                        detail::radian_sym(phi), eps, eps);
0067   CHECK_CLOSE_OR_SMALL(params.template get<eBoundTheta>(), theta, eps, eps);
0068   CHECK_CLOSE_OR_SMALL(params.template get<eBoundQOverP>(), qOverP, eps, eps);
0069   // convenience accessors
0070   CHECK_CLOSE_OR_SMALL(params.fourPosition(geoCtx), pos4, eps, eps);
0071   CHECK_CLOSE_OR_SMALL(params.position(geoCtx), pos, eps, eps);
0072   CHECK_CLOSE_OR_SMALL(params.time(), time, eps, eps);
0073   CHECK_CLOSE_OR_SMALL(params.direction(), unitDir, eps, eps);
0074   CHECK_CLOSE_OR_SMALL(params.absoluteMomentum(), p, eps, eps);
0075   CHECK_CLOSE_OR_SMALL(params.transverseMomentum(), p * std::sin(theta), eps,
0076                        eps);
0077   CHECK_CLOSE_OR_SMALL(params.momentum(), p * unitDir, eps, eps);
0078   BOOST_CHECK_EQUAL(params.charge(), q);
0079 }
0080 
0081 void runTest(const std::shared_ptr<const Surface>& surface, double l0,
0082              double l1, double time, double phi, double theta, double p) {
0083   // phi is ill-defined in forward/backward tracks
0084   phi = ((0 < theta) && (theta < M_PI)) ? phi : 0.0;
0085 
0086   // global direction for reference
0087   const Vector3 dir = makeDirectionFromPhiTheta(phi, theta);
0088   // convert local-to-global for reference
0089   const Vector2 loc(l0, l1);
0090   const Vector3 pos = surface->localToGlobal(geoCtx, loc, dir);
0091   // global four-position as input
0092   Vector4 pos4;
0093   pos4.segment<3>(ePos0) = pos;
0094   pos4[eTime] = time;
0095 
0096   // neutral parameters from local vector
0097   {
0098     BoundVector vector = BoundVector::Zero();
0099     vector[eBoundLoc0] = l0;
0100     vector[eBoundLoc1] = l1;
0101     vector[eBoundTime] = time;
0102     vector[eBoundPhi] = phi;
0103     vector[eBoundTheta] = theta;
0104     vector[eBoundQOverP] = 1 / p;
0105     BoundTrackParameters params(surface, vector, std::nullopt,
0106                                 ParticleHypothesis::pion0());
0107     checkParameters(params, l0, l1, time, phi, theta, p, 0_e, pos, dir);
0108     BOOST_CHECK(!params.covariance());
0109 
0110     // reassign w/ covariance
0111     params =
0112         BoundTrackParameters(surface, vector, cov, ParticleHypothesis::pion0());
0113     checkParameters(params, l0, l1, time, phi, theta, p, 0_e, pos, dir);
0114     BOOST_CHECK(params.covariance());
0115     BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0116   }
0117   // negative charged parameters from local vector
0118   {
0119     BoundVector vector = BoundVector::Zero();
0120     vector[eBoundLoc0] = l0;
0121     vector[eBoundLoc1] = l1;
0122     vector[eBoundTime] = time;
0123     vector[eBoundPhi] = phi;
0124     vector[eBoundTheta] = theta;
0125     vector[eBoundQOverP] = -1_e / p;
0126     BoundTrackParameters params(surface, vector, std::nullopt,
0127                                 ParticleHypothesis::pion());
0128     checkParameters(params, l0, l1, time, phi, theta, p, -1_e, pos, dir);
0129     BOOST_CHECK(!params.covariance());
0130 
0131     // reassign w/ covariance
0132     params =
0133         BoundTrackParameters(surface, vector, cov, ParticleHypothesis::pion());
0134     checkParameters(params, l0, l1, time, phi, theta, p, -1_e, pos, dir);
0135     BOOST_CHECK(params.covariance());
0136     BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0137   }
0138   // positive charged parameters from local vector
0139   {
0140     BoundVector vector = BoundVector::Zero();
0141     vector[eBoundLoc0] = l0;
0142     vector[eBoundLoc1] = l1;
0143     vector[eBoundTime] = time;
0144     vector[eBoundPhi] = phi;
0145     vector[eBoundTheta] = theta;
0146     vector[eBoundQOverP] = 1_e / p;
0147     BoundTrackParameters params(surface, vector, std::nullopt,
0148                                 ParticleHypothesis::pion());
0149     checkParameters(params, l0, l1, time, phi, theta, p, 1_e, pos, dir);
0150     BOOST_CHECK(!params.covariance());
0151 
0152     // reassign w/ covariance
0153     params =
0154         BoundTrackParameters(surface, vector, cov, ParticleHypothesis::pion());
0155     checkParameters(params, l0, l1, time, phi, theta, p, 1_e, pos, dir);
0156     BOOST_CHECK(params.covariance());
0157     BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0158   }
0159   // double-negative charged any parameters from local vector
0160   {
0161     BoundVector vector = BoundVector::Zero();
0162     vector[eBoundLoc0] = l0;
0163     vector[eBoundLoc1] = l1;
0164     vector[eBoundTime] = time;
0165     vector[eBoundPhi] = phi;
0166     vector[eBoundTheta] = theta;
0167     vector[eBoundQOverP] = -2_e / p;
0168     BoundTrackParameters params(surface, vector, std::nullopt,
0169                                 ParticleHypothesis::pionLike(2_e));
0170     checkParameters(params, l0, l1, time, phi, theta, p, -2_e, pos, dir);
0171     BOOST_CHECK(!params.covariance());
0172 
0173     // reassign w/ covariance
0174     params = BoundTrackParameters(surface, vector, cov,
0175                                   ParticleHypothesis::pionLike(2_e));
0176     checkParameters(params, l0, l1, time, phi, theta, p, -2_e, pos, dir);
0177     BOOST_CHECK(params.covariance());
0178     BOOST_CHECK_EQUAL(params.covariance().value(), cov);
0179   }
0180   // neutral parameters from global information
0181   {
0182     auto params =
0183         BoundTrackParameters::create(surface, geoCtx, pos4, dir, 1 / p,
0184                                      std::nullopt, ParticleHypothesis::pion0())
0185             .value();
0186     checkParameters(params, l0, l1, time, phi, theta, p, 0_e, pos, dir);
0187     BOOST_CHECK(!params.covariance());
0188   }
0189   // negative charged parameters from global information
0190   {
0191     auto params =
0192         BoundTrackParameters::create(surface, geoCtx, pos4, dir, -1_e / p,
0193                                      std::nullopt, ParticleHypothesis::pion())
0194             .value();
0195     checkParameters(params, l0, l1, time, phi, theta, p, -1_e, pos, dir);
0196     BOOST_CHECK(!params.covariance());
0197   }
0198   // positive charged parameters from global information
0199   {
0200     auto params =
0201         BoundTrackParameters::create(surface, geoCtx, pos4, dir, 1_e / p,
0202                                      std::nullopt, ParticleHypothesis::pion())
0203             .value();
0204     checkParameters(params, l0, l1, time, phi, theta, p, 1_e, pos, dir);
0205     BOOST_CHECK(!params.covariance());
0206   }
0207   // neutral any parameters from global information
0208   {
0209     auto params =
0210         BoundTrackParameters::create(surface, geoCtx, pos4, dir, 1 / p,
0211                                      std::nullopt, ParticleHypothesis::pion0())
0212             .value();
0213     checkParameters(params, l0, l1, time, phi, theta, p, 0_e, pos, dir);
0214     BOOST_CHECK(!params.covariance());
0215   }
0216   // double-negative any parameters from global information
0217   {
0218     auto params = BoundTrackParameters::create(
0219                       surface, geoCtx, pos4, dir, -2_e / p, std::nullopt,
0220                       ParticleHypothesis::pionLike(2_e))
0221                       .value();
0222     checkParameters(params, l0, l1, time, phi, theta, p, -2_e, pos, dir);
0223     BOOST_CHECK(!params.covariance());
0224   }
0225   // triple-positive any parameters from global information
0226   {
0227     auto params = BoundTrackParameters::create(
0228                       surface, geoCtx, pos4, dir, 3_e / p, std::nullopt,
0229                       ParticleHypothesis::pionLike(3_e))
0230                       .value();
0231     checkParameters(params, l0, l1, time, phi, theta, p, 3_e, pos, dir);
0232     BOOST_CHECK(!params.covariance());
0233   }
0234 }
0235 
0236 // different surfaces
0237 // parameters must be chosen such that all possible local positions (as defined
0238 // in the dataset's header) represent valid points on the surface.
0239 const auto cones = bdata::make({
0240     Surface::makeShared<ConeSurface>(Transform3::Identity(),
0241                                      0.5 /* opening angle */),
0242 });
0243 const auto cylinders = bdata::make({
0244     Surface::makeShared<CylinderSurface>(Transform3::Identity(),
0245                                          10.0 /* radius */, 100 /* half z */),
0246 });
0247 const auto discs = bdata::make({
0248     Surface::makeShared<DiscSurface>(Transform3::Identity(), 0 /* radius min */,
0249                                      100 /* radius max */),
0250 });
0251 const auto perigees = bdata::make({
0252     Surface::makeShared<PerigeeSurface>(Vector3(0, 0, -1.5)),
0253 });
0254 const auto planes = bdata::make({
0255     Surface::makeShared<PlaneSurface>(Vector3(1, 2, 3), Vector3::UnitX()),
0256     Surface::makeShared<PlaneSurface>(Vector3(-2, -3, -4), Vector3::UnitY()),
0257     Surface::makeShared<PlaneSurface>(Vector3(3, -4, 5), Vector3::UnitZ()),
0258 });
0259 const auto straws = bdata::make({
0260     Surface::makeShared<StrawSurface>(Transform3::Identity(), 2.0 /* radius */,
0261                                       200.0 /* half z */),
0262 });
0263 
0264 }  // namespace
0265 
0266 BOOST_AUTO_TEST_SUITE(EventDataBoundTrackParameters)
0267 
0268 BOOST_DATA_TEST_CASE(ConeSurface,
0269                      cones* posAngle* posPositiveNonzero* ts* phis* thetas* ps,
0270                      surface, lphi, lz, time, phi, theta, p) {
0271   // TODO extend lz to zero after fixing the transform implementation
0272   // local parameter r*phi has limits that depend on the z position
0273   const auto r = lz * surface->bounds().tanAlpha();
0274   // local coordinates are singular at z = 0 -> normalize local r*phi
0275   runTest(surface, (0 < lz) ? (r * lphi) : 0.0, lz, time, phi, theta, p);
0276 }
0277 
0278 BOOST_DATA_TEST_CASE(
0279     CylinderSurface,
0280     cylinders* posSymmetric* posSymmetric* ts* phis* thetas* ps, surface, lrphi,
0281     lz, time, phi, theta, p) {
0282   runTest(surface, lrphi, lz, time, phi, theta, p);
0283 }
0284 
0285 BOOST_DATA_TEST_CASE(DiscSurface,
0286                      discs* posPositive* posAngle* ts* phis* thetas* ps,
0287                      surface, lr, lphi, time, phi, theta, p) {
0288   // local coordinates are singular at r = 0 -> normalize local phi
0289   runTest(surface, lr, (0 < lr) ? lphi : 0.0, time, phi, theta, p);
0290 }
0291 
0292 BOOST_DATA_TEST_CASE(
0293     PerigeeSurface,
0294     perigees* posSymmetric* posSymmetric* ts* phis* thetasNoForwardBackward* ps,
0295     surface, d0, z0, time, phi, theta, p) {
0296   // TODO extend theta to forward/back extreme cases fixing the transform
0297   runTest(surface, d0, z0, time, phi, theta, p);
0298 }
0299 
0300 BOOST_DATA_TEST_CASE(PlaneSurface,
0301                      planes* posSymmetric* posSymmetric* ts* phis* thetas* ps,
0302                      surface, l0, l1, time, phi, theta, p) {
0303   runTest(surface, l0, l1, time, phi, theta, p);
0304 }
0305 
0306 BOOST_DATA_TEST_CASE(
0307     StrawSurface,
0308     straws* posPositive* posSymmetric* ts* phis* thetasNoForwardBackward* ps,
0309     surface, lr, lz, time, phi, theta, p) {
0310   // TODO extend theta to forward/back extreme cases fixing the transform
0311   runTest(surface, lr, lz, time, phi, theta, p);
0312 }
0313 
0314 BOOST_AUTO_TEST_SUITE_END()