Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-16 09:25:46

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