Back to home page

EIC code displayed by LXR

 
 

    


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

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/GeometryContext.hpp"
0014 #include "Acts/Surfaces/PlaneSurface.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/Surface.hpp"
0017 #include "Acts/Utilities/Result.hpp"
0018 
0019 #include <array>
0020 #include <memory>
0021 #include <utility>
0022 
0023 namespace Acts {
0024 class PlanarBounds;
0025 }  // namespace Acts
0026 
0027 using namespace Acts::UnitLiterals;
0028 
0029 namespace Acts::Test {
0030 
0031 /// @class AlignmentContext
0032 struct AlignmentContext {
0033   /// We have 2 different transforms
0034   std::shared_ptr<const std::array<Transform3, 2>> alignmentStore = nullptr;
0035 
0036   /// Context index
0037   unsigned int alignmentIndex{0};
0038 
0039   /// Default constructor
0040   AlignmentContext() = default;
0041 
0042   /// Constructor with Store and context index
0043   AlignmentContext(std::shared_ptr<const std::array<Transform3, 2>> aStore,
0044                    unsigned int aIndex = 0)
0045       : alignmentStore(std::move(aStore)), alignmentIndex(aIndex) {}
0046 };
0047 
0048 /// @class AlignableDetectorElement
0049 ///
0050 /// This is a lightweight type of detector element,
0051 /// it simply implements the base class.
0052 class AlignableDetectorElement : public DetectorElementBase {
0053  public:
0054   // Deleted default constructor
0055   AlignableDetectorElement() = delete;
0056 
0057   /// Constructor for single sided detector element
0058   /// - bound to a Plane Surface
0059   ///
0060   /// @param transform is the transform that element the layer in 3D frame
0061   /// @param pBounds is the planar bounds for the planar detector element
0062   /// @param thickness is the module thickness
0063   AlignableDetectorElement(std::shared_ptr<const Transform3> transform,
0064                            const std::shared_ptr<const PlanarBounds>& pBounds,
0065                            double thickness)
0066       : DetectorElementBase(),
0067         m_elementTransform(std::move(transform)),
0068         m_elementThickness(thickness) {
0069     m_elementSurface = Surface::makeShared<PlaneSurface>(pBounds, *this);
0070   }
0071 
0072   ///  Destructor
0073   ~AlignableDetectorElement() override = default;
0074 
0075   /// Return local to global transform associated with this identifier
0076   ///
0077   /// @param gctx The current geometry context object, e.g. alignment
0078   ///
0079   /// @note this is called from the surface().transform() in the PROXY mode
0080   const Transform3& transform(const GeometryContext& gctx) const override;
0081 
0082   /// Return surface associated with this detector element
0083   const Surface& surface() const override;
0084 
0085   /// Non-const access to the surface associated with this detector element
0086   Surface& surface() override;
0087 
0088   /// The maximal thickness of the detector element wrt normal axis
0089   double thickness() const override;
0090 
0091  private:
0092   /// the transform for positioning in 3D space
0093   std::shared_ptr<const Transform3> m_elementTransform;
0094   /// the surface represented by it
0095   std::shared_ptr<Surface> m_elementSurface{nullptr};
0096   /// the element thickness
0097   double m_elementThickness{0.};
0098 };
0099 
0100 inline const Transform3& AlignableDetectorElement::transform(
0101     const GeometryContext& gctx) const {
0102   auto alignContext = gctx.get<AlignmentContext>();
0103   if (alignContext.alignmentStore != nullptr &&
0104       alignContext.alignmentIndex < 2) {
0105     return (*(alignContext.alignmentStore))[alignContext.alignmentIndex];
0106   }
0107   return (*m_elementTransform);
0108 }
0109 
0110 inline const Surface& AlignableDetectorElement::surface() const {
0111   return *m_elementSurface;
0112 }
0113 
0114 inline Surface& AlignableDetectorElement::surface() {
0115   return *m_elementSurface;
0116 }
0117 
0118 inline double AlignableDetectorElement::thickness() const {
0119   return m_elementThickness;
0120 }
0121 
0122 /// Unit test for creating compliant/non-compliant Surface object
0123 BOOST_AUTO_TEST_CASE(AlignmentContextTests) {
0124   // The nominal and alignments
0125   Vector3 nominalCenter(0., 0., 0.);
0126   Vector3 negativeCenter(0., 0., -1.);
0127   Vector3 positiveCenter(0., 0., 1.);
0128 
0129   // Checkpoints
0130   Vector3 onNominal(3., 3., 0.);
0131   Vector3 onNegative(3., 3., -1.);
0132   Vector3 onPositive(3., 3., 1.);
0133 
0134   // Local position
0135   Vector2 localPosition(3., 3.);
0136 
0137   // A position placeholder and dummy momentum
0138   Vector3 globalPosition(100_cm, 100_cm, 100_cm);
0139   Vector3 dummyMomentum(4., 4., 4.);
0140 
0141   Transform3 negativeTransform = Transform3::Identity();
0142   negativeTransform.translation() = negativeCenter;
0143 
0144   Transform3 positiveTransform = Transform3::Identity();
0145   positiveTransform.translation() = positiveCenter;
0146 
0147   std::array<Transform3, 2> alignmentArray = {negativeTransform,
0148                                               positiveTransform};
0149 
0150   std::shared_ptr<const std::array<Transform3, 2>> alignmentStore =
0151       std::make_shared<const std::array<Transform3, 2>>(alignmentArray);
0152 
0153   // The detector element at nominal position
0154   AlignableDetectorElement alignedElement(
0155       std::make_shared<const Transform3>(Transform3::Identity()),
0156       std::make_shared<const RectangleBounds>(100_cm, 100_cm), 1_mm);
0157 
0158   const auto& alignedSurface = alignedElement.surface();
0159 
0160   // The alignment contexts
0161   GeometryContext defaultContext{AlignmentContext{}};
0162   GeometryContext negativeContext{AlignmentContext{alignmentStore, 0}};
0163   GeometryContext positiveContext{AlignmentContext{alignmentStore, 1}};
0164 
0165   // Test the transforms
0166   BOOST_CHECK(alignedSurface.transform(defaultContext)
0167                   .isApprox(Transform3::Identity()));
0168   BOOST_CHECK(
0169       alignedSurface.transform(negativeContext).isApprox(negativeTransform));
0170   BOOST_CHECK(
0171       alignedSurface.transform(positiveContext).isApprox(positiveTransform));
0172 
0173   // Test the centers
0174   BOOST_CHECK_EQUAL(alignedSurface.center(defaultContext), nominalCenter);
0175   BOOST_CHECK_EQUAL(alignedSurface.center(negativeContext), negativeCenter);
0176   BOOST_CHECK_EQUAL(alignedSurface.center(positiveContext), positiveCenter);
0177 
0178   // Test OnSurface
0179   BOOST_CHECK(
0180       alignedSurface.isOnSurface(defaultContext, onNominal, dummyMomentum));
0181   BOOST_CHECK(
0182       alignedSurface.isOnSurface(negativeContext, onNegative, dummyMomentum));
0183   BOOST_CHECK(
0184       alignedSurface.isOnSurface(positiveContext, onPositive, dummyMomentum));
0185 
0186   // Test local to Global and vice versa
0187   globalPosition = alignedSurface.localToGlobal(defaultContext, localPosition,
0188                                                 dummyMomentum);
0189   BOOST_CHECK_EQUAL(globalPosition, onNominal);
0190   localPosition =
0191       alignedSurface.globalToLocal(defaultContext, onNominal, dummyMomentum)
0192           .value();
0193   BOOST_CHECK_EQUAL(localPosition, Vector2(3., 3.));
0194 
0195   globalPosition = alignedSurface.localToGlobal(negativeContext, localPosition,
0196                                                 dummyMomentum);
0197   BOOST_CHECK_EQUAL(globalPosition, onNegative);
0198   localPosition =
0199       alignedSurface.globalToLocal(negativeContext, onNegative, dummyMomentum)
0200           .value();
0201   BOOST_CHECK_EQUAL(localPosition, Vector2(3., 3.));
0202 
0203   globalPosition = alignedSurface.localToGlobal(positiveContext, localPosition,
0204                                                 dummyMomentum);
0205   BOOST_CHECK_EQUAL(globalPosition, onPositive);
0206   localPosition =
0207       alignedSurface.globalToLocal(positiveContext, onPositive, dummyMomentum)
0208           .value();
0209   BOOST_CHECK_EQUAL(localPosition, Vector2(3., 3.));
0210 }
0211 
0212 }  // namespace Acts::Test