Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-21 08:03: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/GeoBoxConverter.hpp"
0010 
0011 #include "Acts/Definitions/Common.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/Surfaces/PlaneSurface.hpp"
0014 #include "Acts/Surfaces/RectangleBounds.hpp"
0015 #include "Acts/Surfaces/Surface.hpp"
0016 #include "ActsPlugins/GeoModel/GeoModelConversionError.hpp"
0017 
0018 #include <GeoModelKernel/GeoBox.h>
0019 #include <GeoModelKernel/GeoFullPhysVol.h>
0020 #include <GeoModelKernel/GeoLogVol.h>
0021 #include <GeoModelKernel/GeoShape.h>
0022 #include <GeoModelKernel/Units.h>
0023 
0024 using namespace Acts;
0025 
0026 Result<ActsPlugins::GeoModelSensitiveSurface>
0027 ActsPlugins::detail::GeoBoxConverter::operator()(
0028     const PVConstLink& geoPV, const GeoBox& geoBox,
0029     const Transform3& absTransform, SurfaceBoundFactory& boundFactory,
0030     bool sensitive) const {
0031   /// auto-calculate the unit length conversion
0032   static constexpr double unitLength =
0033       UnitConstants::mm / GeoModelKernelUnits::millimeter;
0034 
0035   // Create the surface transform
0036   Transform3 transform = Transform3::Identity();
0037   transform.translation() = unitLength * absTransform.translation();
0038   auto rotation = absTransform.rotation();
0039   // Get the half lengths
0040   std::vector<double> halfLengths = {geoBox.getXHalfLength(),
0041                                      geoBox.getYHalfLength(),
0042                                      geoBox.getZHalfLength()};
0043   // Create the surface
0044   auto minElement = std::min_element(halfLengths.begin(), halfLengths.end());
0045   auto zIndex = std::distance(halfLengths.begin(), minElement);
0046   std::size_t yIndex = zIndex > 0u ? zIndex - 1u : 2u;
0047   std::size_t xIndex = yIndex > 0u ? yIndex - 1u : 2u;
0048 
0049   Vector3 colX = rotation.col(xIndex);
0050   Vector3 colY = rotation.col(yIndex);
0051   Vector3 colZ = rotation.col(zIndex);
0052   rotation.col(0) = colX;
0053   rotation.col(1) = colY;
0054   rotation.col(2) = colZ;
0055   transform.linear() = rotation;
0056 
0057   // Create the surface bounds
0058   double halfX = unitLength * halfLengths[xIndex];
0059   double halfY = unitLength * halfLengths[yIndex];
0060   auto rectangleBounds = boundFactory.makeBounds<RectangleBounds>(halfX, halfY);
0061   if (!sensitive) {
0062     auto surface =
0063         Surface::makeShared<PlaneSurface>(transform, rectangleBounds);
0064     return std::make_tuple(nullptr, surface);
0065   }
0066   // Create the element and the surface
0067   auto detectorElement =
0068       GeoModelDetectorElement::createDetectorElement<PlaneSurface>(
0069           geoPV, rectangleBounds, transform,
0070           2 * unitLength * halfLengths[zIndex]);
0071   auto surface = detectorElement->surface().getSharedPtr();
0072   // Return the detector element and surface
0073   return std::make_tuple(detectorElement, surface);
0074 }