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/GeoBoxConverter.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/PlaneSurface.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/Surface.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 Acts::Result<Acts::GeoModelSensitiveSurface>
0025 Acts::detail::GeoBoxConverter::operator()(const PVConstLink& geoPV,
0026                                           const GeoBox& geoBox,
0027                                           const Transform3& absTransform,
0028                                           bool sensitive) const {
0029   /// auto-calculate the unit length conversion
0030   static constexpr double unitLength =
0031       Acts::UnitConstants::mm / GeoModelKernelUnits::millimeter;
0032 
0033   // Create the surface transform
0034   Transform3 transform = Transform3::Identity();
0035   transform.translation() = unitLength * absTransform.translation();
0036   auto rotation = absTransform.rotation();
0037   // Get the half lengths
0038   std::vector<double> halfLengths = {geoBox.getXHalfLength(),
0039                                      geoBox.getYHalfLength(),
0040                                      geoBox.getZHalfLength()};
0041   // Create the surface
0042   auto minElement = std::min_element(halfLengths.begin(), halfLengths.end());
0043   auto zIndex = std::distance(halfLengths.begin(), minElement);
0044   std::size_t yIndex = zIndex > 0u ? zIndex - 1u : 2u;
0045   std::size_t xIndex = yIndex > 0u ? yIndex - 1u : 2u;
0046 
0047   Vector3 colX = rotation.col(xIndex);
0048   Vector3 colY = rotation.col(yIndex);
0049   Vector3 colZ = rotation.col(zIndex);
0050   rotation.col(0) = colX;
0051   rotation.col(1) = colY;
0052   rotation.col(2) = colZ;
0053   transform.linear() = rotation;
0054 
0055   // Create the surface bounds
0056   double halfX = unitLength * halfLengths[xIndex];
0057   double halfY = unitLength * halfLengths[yIndex];
0058   auto rectangleBounds = std::make_shared<Acts::RectangleBounds>(halfX, halfY);
0059   if (!sensitive) {
0060     auto surface =
0061         Surface::makeShared<PlaneSurface>(transform, rectangleBounds);
0062     return std::make_tuple(nullptr, surface);
0063   }
0064   // Create the element and the surface
0065   auto detectorElement =
0066       GeoModelDetectorElement::createDetectorElement<PlaneSurface>(
0067           geoPV, rectangleBounds, transform,
0068           2 * unitLength * halfLengths[zIndex]);
0069   auto surface = detectorElement->surface().getSharedPtr();
0070   // Return the detector element and surface
0071   return std::make_tuple(detectorElement, surface);
0072 }