Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:15:34

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 "Acts/Plugins/GeoModel/detail/GeoIntersectionAnnulusConverter.hpp"
0010 
0011 #include "Acts/Definitions/Common.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/Plugins/GeoModel/GeoModelConversionError.hpp"
0014 #include "Acts/Surfaces/AnnulusBounds.hpp"
0015 #include "Acts/Surfaces/DiscSurface.hpp"
0016 #include "Acts/Surfaces/Surface.hpp"
0017 #include "Acts/Surfaces/detail/AnnulusBoundsHelper.hpp"
0018 
0019 #include <algorithm>
0020 
0021 #include <GeoModelKernel/GeoFullPhysVol.h>
0022 #include <GeoModelKernel/GeoGenericTrap.h>
0023 #include <GeoModelKernel/GeoLogVol.h>
0024 #include <GeoModelKernel/GeoShape.h>
0025 #include <GeoModelKernel/GeoShapeIntersection.h>
0026 #include <GeoModelKernel/GeoShapeShift.h>
0027 #include <GeoModelKernel/GeoTubs.h>
0028 
0029 Acts::Result<Acts::GeoModelSensitiveSurface>
0030 Acts::detail::GeoIntersectionAnnulusConverter::operator()(
0031     const PVConstLink& geoPV, const GeoShapeIntersection& geoIntersection,
0032     const Transform3& absTransform, bool sensitive) const {
0033   /// auto-calculate the unit length conversion
0034   static constexpr double unitLength =
0035       Acts::UnitConstants::mm / GeoModelKernelUnits::millimeter;
0036 
0037   // Returns the first operand being ANDed
0038   const GeoShape* opA = geoIntersection.getOpA();
0039   const GeoShape* opB = geoIntersection.getOpB();
0040 
0041   const GeoTubs* tubs = dynamic_cast<const GeoTubs*>(opA);
0042   if (tubs != nullptr) {
0043     // rMin, rMax
0044     double rMin = unitLength * tubs->getRMin();
0045     double rMax = unitLength * tubs->getRMax();
0046 
0047     // Get the shift
0048     const GeoShapeShift* shapeShift = dynamic_cast<const GeoShapeShift*>(opB);
0049     if (shapeShift != nullptr) {
0050       const Transform3& shift = shapeShift->getX();
0051       const GeoGenericTrap* trap =
0052           dynamic_cast<const GeoGenericTrap*>(shapeShift->getOp());
0053       if (trap != nullptr) {
0054         double thickness = 2 * unitLength * trap->getZHalfLength();
0055         //    X half length at -z, -y.
0056         auto trapVertices = trap->getVertices();
0057 
0058         std::vector<Vector2> faceVertices(trapVertices.begin(),
0059                                           trapVertices.begin() + 4u);
0060         // to make sure they are in the right order
0061         std::ranges::sort(faceVertices, std::greater{}, [](const auto& f) {
0062           return (VectorHelpers::phi(f));
0063         });
0064 
0065         // Turn them into global
0066         std::vector<Vector3> faceVertices3D;
0067         for (const auto& v : faceVertices) {
0068           faceVertices3D.push_back(
0069               shift * Vector3{unitLength * v.x(), unitLength * v.y(), 0.});
0070         }
0071 
0072         faceVertices.clear();
0073         for (auto& v : faceVertices3D) {
0074           faceVertices.push_back(v.block<2, 1>(0, 0));
0075         }
0076 
0077         auto [annulusBounds, annulusTransform] =
0078             Acts::detail::AnnulusBoundsHelper::create(absTransform, rMin, rMax,
0079                                                       faceVertices);
0080         if (!sensitive) {
0081           auto surface =
0082               Surface::makeShared<DiscSurface>(annulusTransform, annulusBounds);
0083           return std::make_tuple(nullptr, surface);
0084         }
0085 
0086         // Create the detector element
0087         auto detectorElement =
0088             GeoModelDetectorElement::createDetectorElement<DiscSurface>(
0089                 geoPV, annulusBounds, annulusTransform, thickness);
0090         auto surface = detectorElement->surface().getSharedPtr();
0091         return std::make_tuple(detectorElement, surface);
0092       }
0093       return std::make_tuple(nullptr, nullptr);
0094     }
0095     return std::make_tuple(nullptr, nullptr);
0096   }
0097   return std::make_tuple(nullptr, nullptr);
0098 }