Back to home page

EIC code displayed by LXR

 
 

    


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

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/Seeding/CandidatesForMiddleSp.hpp"
0012 
0013 #include <algorithm>
0014 #include <limits>
0015 #include <vector>
0016 
0017 #include "SpacePoint.hpp"
0018 
0019 namespace Acts::Test {
0020 
0021 BOOST_AUTO_TEST_CASE(TripletCandidateObject) {
0022   using UnitTestSpacePoint = ::SpacePoint;
0023   std::vector<UnitTestSpacePoint> spacePoints(3);
0024 
0025   // Default Constructor
0026   Acts::TripletCandidate<UnitTestSpacePoint> defaultCandidate;
0027   BOOST_CHECK_EQUAL(defaultCandidate.bottom, nullptr);
0028   BOOST_CHECK_EQUAL(defaultCandidate.middle, nullptr);
0029   BOOST_CHECK_EQUAL(defaultCandidate.top, nullptr);
0030   BOOST_CHECK_EQUAL(defaultCandidate.weight, 0.);
0031   BOOST_CHECK_EQUAL(defaultCandidate.zOrigin, 0.);
0032   BOOST_CHECK_EQUAL(defaultCandidate.isQuality, false);
0033 
0034   // Constructor
0035   Acts::TripletCandidate<UnitTestSpacePoint> constructedCandidate(
0036       spacePoints[0], spacePoints[1], spacePoints[2], 2.4f, 1.1f, true);
0037   BOOST_CHECK_EQUAL(constructedCandidate.bottom, &spacePoints[0]);
0038   BOOST_CHECK_EQUAL(constructedCandidate.middle, &spacePoints[1]);
0039   BOOST_CHECK_EQUAL(constructedCandidate.top, &spacePoints[2]);
0040   BOOST_CHECK_EQUAL(constructedCandidate.weight, 2.4f);
0041   BOOST_CHECK_EQUAL(constructedCandidate.zOrigin, 1.1f);
0042   BOOST_CHECK_EQUAL(constructedCandidate.isQuality, true);
0043 
0044   // Copy Constructor
0045   Acts::TripletCandidate<UnitTestSpacePoint> copiedConstructedCandidate(
0046       constructedCandidate);
0047   BOOST_CHECK_EQUAL(copiedConstructedCandidate.bottom, &spacePoints[0]);
0048   BOOST_CHECK_EQUAL(copiedConstructedCandidate.middle, &spacePoints[1]);
0049   BOOST_CHECK_EQUAL(copiedConstructedCandidate.top, &spacePoints[2]);
0050   BOOST_CHECK_EQUAL(copiedConstructedCandidate.weight, 2.4f);
0051   BOOST_CHECK_EQUAL(copiedConstructedCandidate.zOrigin, 1.1f);
0052   BOOST_CHECK_EQUAL(copiedConstructedCandidate.isQuality, true);
0053 
0054   // Copy Assign
0055   Acts::TripletCandidate<UnitTestSpacePoint> copiedAssignCandidate =
0056       constructedCandidate;
0057   BOOST_CHECK_EQUAL(copiedAssignCandidate.bottom, &spacePoints[0]);
0058   BOOST_CHECK_EQUAL(copiedAssignCandidate.middle, &spacePoints[1]);
0059   BOOST_CHECK_EQUAL(copiedAssignCandidate.top, &spacePoints[2]);
0060   BOOST_CHECK_EQUAL(copiedAssignCandidate.weight, 2.4f);
0061   BOOST_CHECK_EQUAL(copiedAssignCandidate.zOrigin, 1.1f);
0062   BOOST_CHECK_EQUAL(copiedAssignCandidate.isQuality, true);
0063 
0064   // Move Constructor
0065   Acts::TripletCandidate<UnitTestSpacePoint> movedConstructedCandidate(
0066       std::move(constructedCandidate));
0067   BOOST_CHECK_EQUAL(movedConstructedCandidate.bottom, &spacePoints[0]);
0068   BOOST_CHECK_EQUAL(movedConstructedCandidate.middle, &spacePoints[1]);
0069   BOOST_CHECK_EQUAL(movedConstructedCandidate.top, &spacePoints[2]);
0070   BOOST_CHECK_EQUAL(movedConstructedCandidate.weight, 2.4f);
0071   BOOST_CHECK_EQUAL(movedConstructedCandidate.zOrigin, 1.1f);
0072   BOOST_CHECK_EQUAL(movedConstructedCandidate.isQuality, true);
0073   BOOST_CHECK_EQUAL(constructedCandidate.bottom, nullptr);
0074   BOOST_CHECK_EQUAL(constructedCandidate.middle, nullptr);
0075   BOOST_CHECK_EQUAL(constructedCandidate.top, nullptr);
0076 
0077   // Move Assign
0078   Acts::TripletCandidate<UnitTestSpacePoint> movedAssignCandidate =
0079       std::move(copiedAssignCandidate);
0080   BOOST_CHECK_EQUAL(movedAssignCandidate.bottom, &spacePoints[0]);
0081   BOOST_CHECK_EQUAL(movedAssignCandidate.middle, &spacePoints[1]);
0082   BOOST_CHECK_EQUAL(movedAssignCandidate.top, &spacePoints[2]);
0083   BOOST_CHECK_EQUAL(movedAssignCandidate.weight, 2.4f);
0084   BOOST_CHECK_EQUAL(movedAssignCandidate.zOrigin, 1.1f);
0085   BOOST_CHECK_EQUAL(movedAssignCandidate.isQuality, true);
0086   BOOST_CHECK_EQUAL(copiedAssignCandidate.bottom, nullptr);
0087   BOOST_CHECK_EQUAL(copiedAssignCandidate.middle, nullptr);
0088   BOOST_CHECK_EQUAL(copiedAssignCandidate.top, nullptr);
0089 }
0090 
0091 BOOST_AUTO_TEST_CASE(CandidatesForMiddleSpObject) {
0092   using UnitTestSpacePoint = ::SpacePoint;
0093   using value_t =
0094       typename Acts::CandidatesForMiddleSp<UnitTestSpacePoint>::value_type;
0095   UnitTestSpacePoint spacePoint;
0096 
0097   Acts::CandidatesForMiddleSp<UnitTestSpacePoint> container;
0098   container.setMaxElements(std::numeric_limits<std::size_t>::max(),
0099                            std::numeric_limits<std::size_t>::max());
0100   BOOST_CHECK_EQUAL(container.nLowQualityCandidates(), 0);
0101   BOOST_CHECK_EQUAL(container.nHighQualityCandidates(), 0);
0102   for (int i(0); i < 20; ++i) {
0103     container.push(spacePoint, spacePoint, spacePoint, 1, 2.1, false);
0104   }
0105   BOOST_CHECK_EQUAL(container.nLowQualityCandidates(), 20);
0106   BOOST_CHECK_EQUAL(container.nHighQualityCandidates(), 0);
0107   container.clear();
0108 
0109   container.setMaxElements(5, 3);
0110   BOOST_CHECK_EQUAL(container.nLowQualityCandidates(), 0);
0111   BOOST_CHECK_EQUAL(container.nHighQualityCandidates(), 0);
0112 
0113   std::vector<value_t> emptyStorage = container.storage();
0114   BOOST_CHECK_EQUAL(emptyStorage.size(), 0);
0115   BOOST_CHECK_EQUAL(container.nLowQualityCandidates(), 0);
0116   BOOST_CHECK_EQUAL(container.nHighQualityCandidates(), 0);
0117 
0118   // push low quality
0119   for (int i(0); i < 2; ++i) {
0120     container.push(spacePoint, spacePoint, spacePoint, i, 2.1, false);
0121   }
0122   BOOST_CHECK_EQUAL(container.nLowQualityCandidates(), 2);
0123   BOOST_CHECK_EQUAL(container.nHighQualityCandidates(), 0);
0124 
0125   for (int i(0); i < 7; ++i) {
0126     container.push(spacePoint, spacePoint, spacePoint, 2.01, 2.15, false);
0127   }
0128   BOOST_CHECK_EQUAL(container.nLowQualityCandidates(), 5);
0129   BOOST_CHECK_EQUAL(container.nHighQualityCandidates(), 0);
0130 
0131   // push high quality
0132   for (int i(0); i < 5; ++i) {
0133     container.push(spacePoint, spacePoint, spacePoint, 0.5f + i, 2.1, true);
0134   }
0135   BOOST_CHECK_EQUAL(container.nLowQualityCandidates(), 5);
0136   BOOST_CHECK_EQUAL(container.nHighQualityCandidates(), 3);
0137 
0138   std::vector<value_t> storagedValues = container.storage();
0139   // check size array
0140   BOOST_CHECK_EQUAL(storagedValues.size(), 5 + 3);
0141   BOOST_CHECK_EQUAL(container.nLowQualityCandidates(), 0);
0142   BOOST_CHECK_EQUAL(container.nHighQualityCandidates(), 0);
0143 
0144   // check elements are sorted
0145   for (std::size_t i(0); i < storagedValues.size() - 1; ++i) {
0146     BOOST_CHECK(storagedValues[i].weight >= storagedValues[i + 1].weight);
0147   }
0148 
0149   std::ranges::sort(
0150       storagedValues,
0151       Acts::CandidatesForMiddleSp<UnitTestSpacePoint>::ascendingByQuality);
0152   // check values are sorted properly
0153   for (std::size_t i(0); i < storagedValues.size() - 1; ++i) {
0154     BOOST_CHECK(storagedValues[i].weight <= storagedValues[i + 1].weight);
0155   }
0156 
0157   std::ranges::sort(
0158       storagedValues,
0159       Acts::CandidatesForMiddleSp<UnitTestSpacePoint>::descendingByQuality);
0160   // check values are sorted properly
0161   for (std::size_t i(0); i < storagedValues.size() - 1; ++i) {
0162     BOOST_CHECK(storagedValues[i].weight >= storagedValues[i + 1].weight);
0163   }
0164   // push again and check size
0165   for (int i(0); i < 7; ++i) {
0166     container.push(spacePoint, spacePoint, spacePoint, i, 2.15, false);
0167   }
0168   for (int i(0); i < 7; ++i) {
0169     container.push(spacePoint, spacePoint, spacePoint, i, 2.15, true);
0170   }
0171   BOOST_CHECK_EQUAL(container.nLowQualityCandidates(), 5);
0172   BOOST_CHECK_EQUAL(container.nHighQualityCandidates(), 3);
0173   container.clear();
0174   BOOST_CHECK_EQUAL(container.nLowQualityCandidates(), 0);
0175   BOOST_CHECK_EQUAL(container.nHighQualityCandidates(), 0);
0176 }
0177 
0178 }  // namespace Acts::Test