Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-30 07:52:59

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/GeoShiftConverter.hpp"
0010 
0011 #include "Acts/Plugins/GeoModel/GeoModelConversionError.hpp"
0012 #include "Acts/Plugins/GeoModel/detail/GeoBoxConverter.hpp"
0013 #include "Acts/Plugins/GeoModel/detail/GeoTrdConverter.hpp"
0014 #include "Acts/Plugins/GeoModel/detail/GeoTubeConverter.hpp"
0015 #include "Acts/Surfaces/PlaneSurface.hpp"
0016 #include "Acts/Surfaces/StrawSurface.hpp"
0017 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0018 
0019 #include <GeoModelKernel/GeoShapeShift.h>
0020 #include <GeoModelKernel/GeoTube.h>
0021 
0022 namespace Acts::detail {
0023 
0024 namespace {
0025 
0026 template <typename ContainedShape, typename Converter, typename Surface,
0027           typename Bounds>
0028 Result<GeoModelSensitiveSurface> impl(PVConstLink geoPV,
0029                                       const GeoShapeShift& geoShift,
0030                                       const Transform3& absTransform,
0031                                       SurfaceBoundFactory& boundFactory,
0032                                       bool sensitive) {
0033   auto trd = dynamic_cast<const ContainedShape*>(geoShift.getOp());
0034 
0035   if (trd == nullptr) {
0036     return GeoModelConversionError::WrongShapeForConverter;
0037     ;
0038   }
0039 
0040   const Transform3& shift = geoShift.getX();
0041 
0042   const auto& conversionRes =
0043       Converter{}(geoPV, *trd, absTransform * shift, boundFactory, sensitive);
0044   if (!conversionRes.ok()) {
0045     return conversionRes.error();
0046   }
0047   auto [el, surface] = conversionRes.value();
0048 
0049   // Use knowledge from GeoTrdConverter to make shared bounds object
0050   const auto& bounds = static_cast<const Bounds&>(surface->bounds());
0051   auto sharedBounds = boundFactory.makeBounds<Bounds>(bounds);
0052 
0053   // TODO this procedure could be stripped from all converters because it is
0054   // pretty generic
0055   if (!sensitive) {
0056     auto newSurface = Surface::template makeShared<Surface>(
0057         surface->transform({}), sharedBounds);
0058     return std::make_tuple(nullptr, newSurface);
0059   }
0060 
0061   auto newEl = GeoModelDetectorElement::createDetectorElement<Surface>(
0062       el->physicalVolume(), sharedBounds, el->transform({}), el->thickness());
0063   auto newSurface = newEl->surface().getSharedPtr();
0064   return std::make_tuple(newEl, newSurface);
0065 }
0066 
0067 }  // namespace
0068 
0069 Result<GeoModelSensitiveSurface> GeoShiftConverter::operator()(
0070     const PVConstLink& geoPV, const GeoShapeShift& geoShift,
0071     const Transform3& absTransform, SurfaceBoundFactory& boundFactory,
0072     bool sensitive) const {
0073   auto r = impl<GeoTrd, detail::GeoTrdConverter, PlaneSurface, TrapezoidBounds>(
0074       geoPV, geoShift, absTransform, boundFactory, sensitive);
0075 
0076   if (r.ok()) {
0077     return r;
0078   }
0079 
0080   r = impl<GeoBox, detail::GeoBoxConverter, PlaneSurface, RectangleBounds>(
0081       geoPV, geoShift, absTransform, boundFactory, sensitive);
0082 
0083   if (r.ok()) {
0084     return r;
0085   }
0086 
0087   // For now this does straw by default
0088   r = impl<GeoTube, detail::GeoTubeConverter, StrawSurface, LineBounds>(
0089       geoPV, geoShift, absTransform, boundFactory, sensitive);
0090 
0091   if (r.ok()) {
0092     return r;
0093   }
0094 
0095   return GeoModelConversionError::WrongShapeForConverter;
0096 }
0097 
0098 }  // namespace Acts::detail