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