Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 08:55:21

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/Definitions/Units.hpp"
0013 #include "Acts/Geometry/Extent.hpp"
0014 #include "Acts/Utilities/BinningType.hpp"
0015 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0016 
0017 #include <array>
0018 #include <cmath>
0019 #include <string>
0020 #include <vector>
0021 
0022 using namespace Acts;
0023 using namespace Acts::UnitLiterals;
0024 
0025 namespace ActsTests {
0026 
0027 BOOST_AUTO_TEST_SUITE(GeometrSuite)
0028 
0029 /// Unit tests for Polyderon construction & operator +=
0030 BOOST_AUTO_TEST_CASE(ExtentTest) {
0031   std::vector<Vector3> vertices = {
0032       Vector3(15_mm, -3_mm, -10_mm), Vector3(18_mm, 0_mm, -10_mm),
0033       Vector3(15_mm, 3_mm, -10_mm),  Vector3(15_mm, -3_mm, 10_mm),
0034       Vector3(18_mm, 0_mm, 10_mm),   Vector3(15_mm, 3_mm, 10_mm)};
0035 
0036   // Create an Extent / without envelope
0037   Extent gExt;
0038   for (const auto& v : vertices) {
0039     gExt.extend(v);
0040   }
0041 
0042   double phiMin = std::atan2(-3_mm, 15_mm);
0043   double phiMax = std::atan2(3_mm, 15_mm);
0044   double rMin = std::hypot(15_mm, 3_mm);
0045 
0046   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisX), 15_mm, 1e-6);
0047   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisX), 18_mm, 1e-6);
0048   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisY), -3_mm, 1e-6);
0049   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisY), 3_mm, 1e-6);
0050   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisZ), -10_mm, 1e-6);
0051   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisZ), 10_mm, 1e-6);
0052   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisR), rMin, 1e-6);
0053   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisR), 18_mm, 1e-6);
0054   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisPhi), phiMin, 1e-6);
0055   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisPhi), phiMax, 1e-6);
0056 
0057   // Call with histogram filling
0058   Extent gExtHist;
0059   for (const auto& v : vertices) {
0060     gExtHist.extend(v, {AxisDirection::AxisX}, false, true);
0061   }
0062   const auto& vHist = gExtHist.valueHistograms();
0063   auto xVals = vHist[toUnderlying(AxisDirection::AxisX)];
0064 
0065   BOOST_CHECK_EQUAL(xVals.size(), 6u);
0066   std::vector<double> reference = {15_mm, 18_mm, 15_mm, 15_mm, 18_mm, 15_mm};
0067   BOOST_CHECK(xVals == reference);
0068 
0069   // Call with ieterator range
0070   Extent gExtItr;
0071   gExtItr.extend(vertices.begin(), vertices.end());
0072   CHECK_CLOSE_ABS(gExtItr.min(AxisDirection::AxisX), 15_mm, 1e-6);
0073   CHECK_CLOSE_ABS(gExtItr.max(AxisDirection::AxisX), 18_mm, 1e-6);
0074   CHECK_CLOSE_ABS(gExtItr.min(AxisDirection::AxisY), -3_mm, 1e-6);
0075   CHECK_CLOSE_ABS(gExtItr.max(AxisDirection::AxisY), 3_mm, 1e-6);
0076   CHECK_CLOSE_ABS(gExtItr.min(AxisDirection::AxisZ), -10_mm, 1e-6);
0077   CHECK_CLOSE_ABS(gExtItr.max(AxisDirection::AxisZ), 10_mm, 1e-6);
0078   CHECK_CLOSE_ABS(gExtItr.min(AxisDirection::AxisR), rMin, 1e-6);
0079   CHECK_CLOSE_ABS(gExtItr.max(AxisDirection::AxisR), 18_mm, 1e-6);
0080   CHECK_CLOSE_ABS(gExtItr.min(AxisDirection::AxisPhi), phiMin, 1e-6);
0081   CHECK_CLOSE_ABS(gExtItr.max(AxisDirection::AxisPhi), phiMax, 1e-6);
0082 
0083   // Create a second Extent
0084   Extent gExtCopy;
0085   gExtCopy.extend(gExt);
0086 
0087   CHECK_CLOSE_ABS(gExtCopy.min(AxisDirection::AxisX), 15_mm, 1e-6);
0088   CHECK_CLOSE_ABS(gExtCopy.max(AxisDirection::AxisX), 18_mm, 1e-6);
0089   CHECK_CLOSE_ABS(gExtCopy.min(AxisDirection::AxisY), -3_mm, 1e-6);
0090   CHECK_CLOSE_ABS(gExtCopy.max(AxisDirection::AxisY), 3_mm, 1e-6);
0091   CHECK_CLOSE_ABS(gExtCopy.min(AxisDirection::AxisZ), -10_mm, 1e-6);
0092   CHECK_CLOSE_ABS(gExtCopy.max(AxisDirection::AxisZ), 10_mm, 1e-6);
0093   CHECK_CLOSE_ABS(gExtCopy.min(AxisDirection::AxisR), rMin, 1e-6);
0094   CHECK_CLOSE_ABS(gExtCopy.max(AxisDirection::AxisR), 18_mm, 1e-6);
0095   CHECK_CLOSE_ABS(gExtCopy.min(AxisDirection::AxisPhi), phiMin, 1e-6);
0096   CHECK_CLOSE_ABS(gExtCopy.max(AxisDirection::AxisPhi), phiMax, 1e-6);
0097 
0098   // Check containment
0099   Extent unbound;
0100   BOOST_CHECK(unbound.contains(gExt));
0101   BOOST_CHECK(unbound.contains(gExtCopy));
0102 
0103   // Check application of an envelope on it
0104   ExtentEnvelope xEnvelopes = ExtentEnvelope::Zero();
0105   xEnvelopes[AxisDirection::AxisX] = {1., 2.};
0106 
0107   // Take the extent and extend by an envelope
0108   Extent envelope(xEnvelopes);
0109   gExt.extend(envelope);
0110   // Changed ones
0111   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisX), 14_mm, 1e-6);
0112   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisX), 20_mm, 1e-6);
0113   // Unchanged ones
0114   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisY), -3_mm, 1e-6);
0115   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisY), 3_mm, 1e-6);
0116   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisZ), -10_mm, 1e-6);
0117   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisZ), 10_mm, 1e-6);
0118   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisR), rMin, 1e-6);
0119   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisR), 18_mm, 1e-6);
0120   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisPhi), phiMin, 1e-6);
0121   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisPhi), phiMax, 1e-6);
0122 
0123   // Fill it with envelope
0124   Extent gExtEnv(envelope);
0125   gExtEnv.extend(vertices.begin(), vertices.end());
0126   // Changed ones
0127   CHECK_CLOSE_ABS(gExtEnv.min(AxisDirection::AxisX), 14_mm, 1e-6);
0128   CHECK_CLOSE_ABS(gExtEnv.max(AxisDirection::AxisX), 20_mm, 1e-6);
0129 
0130   // Check the set method
0131   gExt.set(AxisDirection::AxisX, 2_mm, 8_mm);
0132   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisX), 2_mm, 1e-6);
0133   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisX), 8_mm, 1e-6);
0134 
0135   // Radius can not go below 0
0136   gExt.set(AxisDirection::AxisR, -2_mm, 18_mm);
0137   CHECK_CLOSE_ABS(gExt.min(AxisDirection::AxisR), 0_mm, 1e-6);
0138   CHECK_CLOSE_ABS(gExt.max(AxisDirection::AxisR), 18_mm, 1e-6);
0139 
0140   // Take an Extent and add a constraint
0141   Extent gExtConst;
0142   gExtConst.set(AxisDirection::AxisR, 0., 5.);
0143   Extent gExtNonConst;
0144   BOOST_CHECK(!gExtNonConst.constrains(AxisDirection::AxisR));
0145   gExtNonConst.addConstrain(gExtConst);
0146   BOOST_CHECK(gExtNonConst.constrains(AxisDirection::AxisR));
0147 
0148   std::string tString = gExtConst.toString();
0149   BOOST_CHECK(!tString.empty());
0150 
0151   // Check single vertex containment
0152   Extent gExtVertexCheck;
0153   gExtVertexCheck.set(AxisDirection::AxisR, 0., 5.);
0154   BOOST_CHECK(gExtVertexCheck.contains(Vector3(1., 0., 0.)));
0155   BOOST_CHECK(!gExtVertexCheck.contains(Vector3(6., 0., 0.)));
0156 }
0157 
0158 // Test that the constrains() check advances when the extend() method
0159 // is used with a new binning type
0160 BOOST_AUTO_TEST_CASE(ProtoSupportCaseTests) {
0161   std::vector<Vector3> vertices = {
0162       Vector3(15_mm, -3_mm, -10_mm), Vector3(18_mm, 0_mm, -10_mm),
0163       Vector3(15_mm, 3_mm, -10_mm),  Vector3(15_mm, -3_mm, 10_mm),
0164       Vector3(18_mm, 0_mm, 10_mm),   Vector3(15_mm, 3_mm, 10_mm)};
0165 
0166   Extent volumeExtent;
0167   volumeExtent.set(AxisDirection::AxisZ, -300_mm, 300_mm);
0168 
0169   BOOST_CHECK(volumeExtent.constrains(AxisDirection::AxisZ));
0170   BOOST_CHECK(!volumeExtent.constrains(AxisDirection::AxisR));
0171 
0172   for (const auto& v : vertices) {
0173     volumeExtent.extend(v, {AxisDirection::AxisR});
0174   }
0175 
0176   BOOST_CHECK(volumeExtent.constrains(AxisDirection::AxisR));
0177 }
0178 
0179 BOOST_AUTO_TEST_CASE(DesignatedInitializers) {
0180   using enum AxisDirection;
0181   ExtentEnvelope exp;
0182   exp[AxisX] = {1., 2.};
0183   exp[AxisEta] = {-1., 1.};
0184 
0185   ExtentEnvelope act{{.x = {1., 2.}, .eta = {-1., 1.}}};
0186 
0187   BOOST_CHECK(exp == act);
0188 }
0189 
0190 BOOST_AUTO_TEST_SUITE_END()
0191 
0192 }  // namespace ActsTests