Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:20

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