Back to home page

EIC code displayed by LXR

 
 

    


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

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/Units.hpp"
0012 #include "Acts/EventData/Charge.hpp"
0013 #include "Acts/EventData/ParticleHypothesis.hpp"
0014 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0015 
0016 #include <limits>
0017 #include <type_traits>
0018 
0019 using namespace Acts::UnitLiterals;
0020 
0021 static auto eps = std::numeric_limits<double>::epsilon();
0022 
0023 BOOST_AUTO_TEST_SUITE(EventDataParticleHypothesis)
0024 
0025 BOOST_AUTO_TEST_CASE(Neutral) {
0026   auto p = Acts::NeutralParticleHypothesis::pion0();
0027 
0028   BOOST_CHECK_EQUAL(p.extractCharge(1.23), 0_e);
0029   BOOST_CHECK_EQUAL(p.extractCharge(2.54), 0_e);
0030   BOOST_CHECK_EQUAL(p.extractCharge(-1.98), 0_e);
0031   BOOST_CHECK_EQUAL(p.extractCharge(-2.23), 0_e);
0032   CHECK_CLOSE_REL(p.extractMomentum(1 / 64_GeV), 64_GeV, eps);
0033   CHECK_CLOSE_REL(p.extractMomentum(1 / 128_MeV), 128_MeV, eps);
0034 }
0035 
0036 BOOST_AUTO_TEST_CASE(SinglyCharged) {
0037   auto p = Acts::SinglyChargedParticleHypothesis::pion();
0038 
0039   BOOST_CHECK_EQUAL(p.extractCharge(1.23), 1_e);
0040   BOOST_CHECK_EQUAL(p.extractCharge(2.54), 1_e);
0041   BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -1_e);
0042   BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -1_e);
0043   CHECK_CLOSE_REL(p.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
0044   CHECK_CLOSE_REL(p.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
0045   CHECK_CLOSE_REL(p.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
0046 }
0047 
0048 BOOST_AUTO_TEST_CASE(NonNeutralChargeSingle) {
0049   auto p = Acts::NonNeutralChargedParticleHypothesis::pion();
0050 
0051   BOOST_CHECK_EQUAL(p.extractCharge(1.23), 1_e);
0052   BOOST_CHECK_EQUAL(p.extractCharge(2.54), 1_e);
0053   BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -1_e);
0054   BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -1_e);
0055   CHECK_CLOSE_REL(p.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
0056   CHECK_CLOSE_REL(p.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
0057   CHECK_CLOSE_REL(p.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
0058 }
0059 
0060 BOOST_AUTO_TEST_CASE(NonNeutralChargeMultiple) {
0061   auto p = Acts::NonNeutralChargedParticleHypothesis::pionLike(3_e);
0062 
0063   BOOST_CHECK_EQUAL(p.extractCharge(1.23), 3_e);
0064   BOOST_CHECK_EQUAL(p.extractCharge(2.54), 3_e);
0065   BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -3_e);
0066   BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -3_e);
0067   CHECK_CLOSE_REL(p.extractMomentum(3_e / 64_GeV), 64_GeV, eps);
0068   CHECK_CLOSE_REL(p.extractMomentum(3_e / 128_MeV), 128_MeV, eps);
0069   CHECK_CLOSE_REL(p.extractMomentum(-3_e / 128_MeV), 128_MeV, eps);
0070 }
0071 
0072 BOOST_AUTO_TEST_CASE(AnyChargeNeutral) {
0073   auto p = Acts::ParticleHypothesis::pion0();
0074 
0075   BOOST_CHECK_EQUAL(p.extractCharge(1.23), 0_e);
0076   BOOST_CHECK_EQUAL(p.extractCharge(2.54), 0_e);
0077   BOOST_CHECK_EQUAL(p.extractCharge(-1.98), 0_e);
0078   BOOST_CHECK_EQUAL(p.extractCharge(-2.23), 0_e);
0079   CHECK_CLOSE_REL(p.extractMomentum(1 / 64_GeV), 64_GeV, eps);
0080   CHECK_CLOSE_REL(p.extractMomentum(1 / 128_MeV), 128_MeV, eps);
0081 
0082   // negative inputs should not occur for neutral particles
0083   // the result is not defined, but we check it anyway
0084   CHECK_CLOSE_REL(p.extractMomentum(-1 / 128_MeV), -128_MeV, eps);
0085 }
0086 
0087 BOOST_AUTO_TEST_CASE(AnyChargeSingle) {
0088   auto p = Acts::ParticleHypothesis::pion();
0089 
0090   BOOST_CHECK_EQUAL(p.extractCharge(1.23), 1_e);
0091   BOOST_CHECK_EQUAL(p.extractCharge(2.54), 1_e);
0092   BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -1_e);
0093   BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -1_e);
0094   CHECK_CLOSE_REL(p.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
0095   CHECK_CLOSE_REL(p.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
0096   CHECK_CLOSE_REL(p.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
0097 }
0098 
0099 BOOST_AUTO_TEST_CASE(AnyChargeMultiple) {
0100   auto p = Acts::ParticleHypothesis::pionLike(3_e);
0101 
0102   BOOST_CHECK_EQUAL(p.extractCharge(1.23), 3_e);
0103   BOOST_CHECK_EQUAL(p.extractCharge(2.54), 3_e);
0104   BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -3_e);
0105   BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -3_e);
0106   CHECK_CLOSE_REL(p.extractMomentum(3_e / 64_GeV), 64_GeV, eps);
0107   CHECK_CLOSE_REL(p.extractMomentum(3_e / 128_MeV), 128_MeV, eps);
0108   CHECK_CLOSE_REL(p.extractMomentum(-3_e / 128_MeV), 128_MeV, eps);
0109 }
0110 
0111 BOOST_AUTO_TEST_SUITE_END()