Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-04 09:24:11

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/Utilities/Intersection.hpp"
0013 
0014 #include <algorithm>
0015 #include <array>
0016 #include <sstream>
0017 #include <string>
0018 #include <vector>
0019 
0020 using namespace Acts;
0021 
0022 namespace ActsTests {
0023 
0024 BOOST_AUTO_TEST_SUITE(UtilitiesSuite)
0025 
0026 /// test of the intersection class
0027 BOOST_AUTO_TEST_CASE(IntersectionTest) {
0028   // a few valid intersections
0029   // all positively sortered
0030   Intersection3D fIp(Vector3(0., 1., 0.), 1., IntersectionStatus::reachable);
0031   Intersection3D sIp(Vector3(0., 2., 0.), 2., IntersectionStatus::reachable);
0032   Intersection3D tIp(Vector3(0., 3., 0.), 3., IntersectionStatus::reachable);
0033   BOOST_CHECK(fIp.isValid());
0034   BOOST_CHECK(sIp.isValid());
0035   BOOST_CHECK(tIp.isValid());
0036 
0037   // a non-valid intersection
0038   Intersection3D nIp(Vector3(3., 3., 0.), 3., IntersectionStatus::unreachable);
0039   BOOST_CHECK(!nIp.isValid());
0040 
0041   std::vector<Intersection3D> fstpIntersections = {fIp, sIp, tIp};
0042   std::vector<Intersection3D> tsfpIntersections = {tIp, sIp, fIp};
0043 
0044   // let's sort the tsf intersection, it should give fst
0045   std::ranges::sort(tsfpIntersections, Intersection3D::pathLengthOrder);
0046   BOOST_CHECK_EQUAL(fstpIntersections[0].pathLength(),
0047                     tsfpIntersections[0].pathLength());
0048   BOOST_CHECK_EQUAL(fstpIntersections[1].pathLength(),
0049                     tsfpIntersections[1].pathLength());
0050   BOOST_CHECK_EQUAL(fstpIntersections[2].pathLength(),
0051                     tsfpIntersections[2].pathLength());
0052 
0053   // now let's create one with a non-valid intersection, it should be shuffled
0054   // last
0055   std::vector<Intersection3D> ntfspIntersections = {nIp, tIp, fIp, sIp};
0056   std::vector<Intersection3D> tfnsnpIntersections = {tIp, fIp, nIp, sIp, nIp};
0057 
0058   // shuffle the intersections
0059   std::ranges::sort(ntfspIntersections, Intersection3D::pathLengthOrder);
0060   BOOST_CHECK_EQUAL(fstpIntersections[0].pathLength(),
0061                     ntfspIntersections[0].pathLength());
0062   BOOST_CHECK_EQUAL(fstpIntersections[1].pathLength(),
0063                     ntfspIntersections[1].pathLength());
0064   BOOST_CHECK_EQUAL(fstpIntersections[2].pathLength(),
0065                     ntfspIntersections[2].pathLength());
0066 
0067   std::ranges::sort(tfnsnpIntersections, Intersection3D::pathLengthOrder);
0068   BOOST_CHECK_EQUAL(fstpIntersections[0].pathLength(),
0069                     tfnsnpIntersections[0].pathLength());
0070   BOOST_CHECK_EQUAL(fstpIntersections[1].pathLength(),
0071                     tfnsnpIntersections[1].pathLength());
0072   BOOST_CHECK_EQUAL(fstpIntersections[2].pathLength(),
0073                     tfnsnpIntersections[2].pathLength());
0074 
0075   /// let's make a bunch of negative solution
0076   Intersection3D fIn(Vector3(0., -1., 0.), -1., IntersectionStatus::reachable);
0077   Intersection3D sIn(Vector3(0., -2., 0.), -2., IntersectionStatus::reachable);
0078   Intersection3D tIn(Vector3(0., -3., 0.), -3., IntersectionStatus::reachable);
0079 
0080   std::vector<Intersection3D> tsfnIntersections = {tIn, sIn, fIn};
0081   std::vector<Intersection3D> fstnIntersections = {fIn, sIn, tIn};
0082 
0083   // this time around, sort the f-s-t-n to match the t-s-f-n
0084   std::ranges::sort(fstnIntersections, Intersection3D::pathLengthOrder);
0085   BOOST_CHECK_EQUAL(fstnIntersections[0].pathLength(),
0086                     tsfnIntersections[0].pathLength());
0087   BOOST_CHECK_EQUAL(fstnIntersections[1].pathLength(),
0088                     tsfnIntersections[1].pathLength());
0089   BOOST_CHECK_EQUAL(fstnIntersections[2].pathLength(),
0090                     tsfnIntersections[2].pathLength());
0091 
0092   // shuffle negative and positive solutions
0093   std::vector<Intersection3D> pnsolutions = {tIp, sIn, sIp, fIn, tIn, fIp};
0094   std::ranges::sort(pnsolutions, Intersection3D::pathLengthOrder);
0095 
0096   BOOST_CHECK_EQUAL(pnsolutions[0].pathLength(), -3.);
0097   BOOST_CHECK_EQUAL(pnsolutions[1].pathLength(), -2.);
0098   BOOST_CHECK_EQUAL(pnsolutions[2].pathLength(), -1.);
0099   BOOST_CHECK_EQUAL(pnsolutions[3].pathLength(), 1.);
0100   BOOST_CHECK_EQUAL(pnsolutions[4].pathLength(), 2.);
0101   BOOST_CHECK_EQUAL(pnsolutions[5].pathLength(), 3.);
0102 
0103   // sort intersections with zero path length
0104   Intersection3D zI(Vector3(0., 0., 0.), 0., IntersectionStatus::onSurface);
0105   std::vector<Intersection3D> tszfpIntersections = {tIp, sIp, zI, fIp};
0106 
0107   std::ranges::sort(tszfpIntersections, Intersection3D::pathLengthOrder);
0108   BOOST_CHECK_EQUAL(tszfpIntersections[0].pathLength(), 0.);
0109   BOOST_CHECK_EQUAL(tszfpIntersections[1].pathLength(), 1.);
0110   BOOST_CHECK_EQUAL(tszfpIntersections[2].pathLength(), 2.);
0111   BOOST_CHECK_EQUAL(tszfpIntersections[3].pathLength(), 3.);
0112 
0113   std::vector<Intersection3D> tfsznIntersections = {tIn, fIn, sIn, zI};
0114   std::vector<Intersection3D> ztfsnIntersections = {zI, tIn, fIn, sIn};
0115 
0116   std::ranges::sort(tfsznIntersections, Intersection3D::pathLengthOrder);
0117   BOOST_CHECK_EQUAL(tfsznIntersections[0].pathLength(), -3.);
0118   BOOST_CHECK_EQUAL(tfsznIntersections[1].pathLength(), -2.);
0119   BOOST_CHECK_EQUAL(tfsznIntersections[2].pathLength(), -1.);
0120   BOOST_CHECK_EQUAL(tfsznIntersections[3].pathLength(), 0.);
0121 }
0122 
0123 BOOST_AUTO_TEST_CASE(IntersectionStatusPrinting) {
0124   std::array<IntersectionStatus, 4> status_values = {
0125       {IntersectionStatus::unreachable, IntersectionStatus::unreachable,
0126        IntersectionStatus::reachable, IntersectionStatus::onSurface}};
0127   std::array<std::string, 4> expected_messages = {
0128       {"missed/unreachable", "missed/unreachable", "reachable", "onSurface"}};
0129 
0130   for (int i = 0; i < 4; ++i) {
0131     std::stringstream ss;
0132     ss << status_values[i];
0133     BOOST_CHECK_EQUAL(ss.str(), expected_messages[i]);
0134   }
0135 }
0136 
0137 BOOST_AUTO_TEST_SUITE_END()
0138 
0139 }  // namespace ActsTests