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/GeoPolygonConverter.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/DiamondBounds.hpp"
0015 #include "Acts/Surfaces/PlaneSurface.hpp"
0016 #include "Acts/Surfaces/RectangleBounds.hpp"
0017 #include "Acts/Surfaces/Surface.hpp"
0018 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0019 
0020 #include <algorithm>
0021 
0022 #include <GeoModelKernel/GeoBox.h>
0023 #include <GeoModelKernel/GeoFullPhysVol.h>
0024 #include <GeoModelKernel/GeoLogVol.h>
0025 #include <GeoModelKernel/GeoShape.h>
0026 #include <GeoModelKernel/Units.h>
0027 
0028 Acts::Result<Acts::GeoModelSensitiveSurface>
0029 Acts::detail::GeoPolygonConverter::operator()(
0030     const PVConstLink& geoPV, const GeoSimplePolygonBrep& polygon,
0031     const Transform3& absTransform, bool sensitive) const {
0032   /// auto-calculate the unit length conversion
0033   static constexpr double unitLength =
0034       Acts::UnitConstants::mm / GeoModelKernelUnits::millimeter;
0035 
0036   // Create the surface transform
0037   Transform3 transform = Transform3::Identity();
0038   transform.translation() = unitLength * absTransform.translation();
0039   auto rotation = absTransform.rotation();
0040   // Get the half lengths
0041   int nVertices = polygon.getNVertices();
0042   std::vector<std::vector<double>> vertices;
0043 
0044   for (int i = 0; i < nVertices; i++) {
0045     vertices.push_back({polygon.getXVertex(i), polygon.getYVertex(i)});
0046   }
0047   // sort based on the y-coordinate
0048   std::ranges::sort(vertices, {}, [](const auto& v) { return v[1]; });
0049   if (nVertices == 4) {
0050     double hlxnegy = std::abs(vertices[0][0] - vertices[1][0]) / 2;
0051     double hlxposy = std::abs(vertices[2][0] - vertices[3][0]) / 2;
0052     double hly = std::abs(vertices[0][1] - vertices[3][1]) / 2;
0053     std::vector<double> halfLengths = {hlxnegy, hlxposy, hly};
0054 
0055     // Create the surface
0056     Vector3 colX = rotation.col(0);
0057     Vector3 colY = rotation.col(1);
0058     Vector3 colZ = rotation.col(2);
0059     rotation.col(0) = colX;
0060     rotation.col(1) = colY;
0061     rotation.col(2) = colZ;
0062     transform.linear() = rotation;
0063     // Create the surface bounds
0064     double halfXnegY = unitLength * halfLengths[0];
0065     double halfXposY = unitLength * halfLengths[1];
0066     double halfY = unitLength * halfLengths[2];
0067     auto trapBounds =
0068         std::make_shared<Acts::TrapezoidBounds>(halfXnegY, halfXposY, halfY);
0069     if (!sensitive) {
0070       auto surface = Surface::makeShared<PlaneSurface>(transform, trapBounds);
0071       return std::make_tuple(nullptr, surface);
0072     }
0073     // Create the element and the surface
0074     auto detectorElement =
0075         GeoModelDetectorElement::createDetectorElement<PlaneSurface>(
0076             geoPV, trapBounds, transform, unitLength * polygon.getDZ());
0077     auto surface = detectorElement->surface().getSharedPtr();
0078     // Return the detector element and surface
0079     return std::make_tuple(detectorElement, surface);
0080   } else if (nVertices == 6) {
0081     double hlxnegy = std::abs(vertices[0][0] - vertices[1][0]) / 2;
0082     double hlxzeroy = std::abs(vertices[2][0] - vertices[3][0]) / 2;
0083     double hlxposy = std::abs(vertices[4][0] - vertices[5][0]) / 2;
0084     double hly = std::abs(vertices[0][1] - vertices[4][1]) / 2;
0085     std::vector<double> halfLengths = {hlxnegy, hlxzeroy, hlxposy, hly, hly};
0086 
0087     // Create the surface
0088 
0089     Vector3 colX = rotation.col(0);
0090     Vector3 colY = rotation.col(1);
0091     Vector3 colZ = rotation.col(2);
0092     rotation.col(0) = colX;
0093     rotation.col(1) = colY;
0094     rotation.col(2) = colZ;
0095     transform.linear() = rotation;
0096 
0097     // Create the surface bounds
0098     double halfXnegY = unitLength * halfLengths[0];
0099     double halfXzeroY = unitLength * halfLengths[1];
0100     double halfXposY = unitLength * halfLengths[2];
0101     double halfYnegX = unitLength * halfLengths[3];
0102     double halfYposX = unitLength * halfLengths[4];
0103 
0104     auto diamondBounds = std::make_shared<Acts::DiamondBounds>(
0105         halfXnegY, halfXzeroY, halfXposY, halfYnegX, halfYposX);
0106     if (!sensitive) {
0107       auto surface =
0108           Surface::makeShared<PlaneSurface>(transform, diamondBounds);
0109       return std::make_tuple(nullptr, surface);
0110     }
0111     // Create the element and the surface
0112     auto detectorElement =
0113         GeoModelDetectorElement::createDetectorElement<PlaneSurface>(
0114             geoPV, diamondBounds, transform, unitLength * polygon.getDZ());
0115     auto surface = detectorElement->surface().getSharedPtr();
0116     // Return the detector element and surface
0117     return std::make_tuple(detectorElement, surface);
0118   } else {
0119     throw std::runtime_error("GeoSimplePolygonBrep with " +
0120                              std::to_string(nVertices) +
0121                              " vertices can not be converted");
0122   }
0123 }