Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:24:24

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/GeoModelDetectorElementITk.hpp"
0010 
0011 #include "Acts/Surfaces/AnnulusBounds.hpp"
0012 #include "Acts/Surfaces/DiscSurface.hpp"
0013 #include "Acts/Surfaces/PlaneSurface.hpp"
0014 #include "Acts/Surfaces/RectangleBounds.hpp"
0015 
0016 #include <ranges>
0017 
0018 using namespace Acts;
0019 
0020 namespace ActsPlugins {
0021 
0022 // Mapping between the barrel-endcap identifier and its unsigned representation
0023 constexpr static std::array<std::pair<unsigned, int>, 3> s_barrelEndcapMap{
0024     {{0, 0}, {1, 2}, {2, -2}}};
0025 
0026 ITkIdentifier::ITkIdentifier(int hardware, int barrelEndcap, int layerWheel,
0027                              int etaModule, int phiModule, int side) {
0028   assert((hardware == 0) || (hardware == 1));
0029   assert((barrelEndcap == 2) || (barrelEndcap == -2) || (barrelEndcap == 0));
0030   assert(layerWheel >= 0);
0031   assert(phiModule >= 0);
0032   assert((side == 0) || (side == 1));
0033 
0034   m_identifier.set(0, hardware);
0035 
0036   auto found = std::ranges::find(s_barrelEndcapMap, barrelEndcap,
0037                                  &std::pair<unsigned, int>::second);
0038   if (found == s_barrelEndcapMap.end()) {
0039     throw std::invalid_argument("Invalid barrel-endcap specifier");
0040   }
0041   m_identifier.set(1, found->first);
0042   m_identifier.set(2, layerWheel);
0043   m_identifier.set(3, static_cast<std::size_t>(etaModule < 0));
0044   m_identifier.set(4, std::abs(etaModule));
0045   m_identifier.set(5, phiModule);
0046   m_identifier.set(6, side);
0047 }
0048 
0049 int ITkIdentifier::hardware() const {
0050   return m_identifier.level(0);
0051 }
0052 
0053 int ITkIdentifier::barrelEndcap() const {
0054   auto found = std::ranges::find(s_barrelEndcapMap, m_identifier.level(1),
0055                                  &std::pair<unsigned, int>::first);
0056   if (found == s_barrelEndcapMap.end()) {
0057     throw std::invalid_argument("Invalid barrel-endcap specifier");
0058   }
0059   return found->second;
0060 }
0061 
0062 int ITkIdentifier::layerWheel() const {
0063   return m_identifier.level(2);
0064 }
0065 
0066 int ITkIdentifier::etaModule() const {
0067   int sign = (m_identifier.level(3) == 0) ? 1 : -1;
0068   return sign * m_identifier.level(4);
0069 }
0070 
0071 int ITkIdentifier::phiModule() const {
0072   return m_identifier.level(5);
0073 }
0074 
0075 int ITkIdentifier::side() const {
0076   return m_identifier.level(6);
0077 }
0078 
0079 std::size_t ITkIdentifier::value() const {
0080   return m_identifier.value();
0081 }
0082 
0083 std::ostream &operator<<(std::ostream &os, const ITkIdentifier &id) {
0084   os << "(hw: " << id.hardware() << ", be: " << id.barrelEndcap()
0085      << ", lw: " << id.layerWheel() << ", em: " << id.etaModule()
0086      << ", pm: " << id.phiModule() << ", sd: " << id.side() << ")";
0087   return os;
0088 }
0089 
0090 std::tuple<std::shared_ptr<GeoModelDetectorElementITk>,
0091            std::shared_ptr<Surface>>
0092 GeoModelDetectorElementITk::convertFromGeomodel(
0093     std::shared_ptr<GeoModelDetectorElement> detEl,
0094     std::shared_ptr<Surface> srf, const GeometryContext &gctx, int hardware,
0095     int barrelEndcap, int layerWheel, int etaModule, int phiModule, int side) {
0096   auto helper = [&]<typename surface_t, typename bounds_t>() {
0097     auto bounds = std::make_shared<bounds_t>(
0098         dynamic_cast<const bounds_t &>(srf->bounds()));
0099 
0100     auto itkEl = std::make_shared<GeoModelDetectorElementITk>(
0101         detEl->physicalVolume(), nullptr, detEl->transform(gctx),
0102         detEl->thickness(), hardware, barrelEndcap, layerWheel, etaModule,
0103         phiModule, side);
0104     auto surface = Surface::makeShared<surface_t>(bounds, *itkEl);
0105 
0106     itkEl->attachSurface(surface);
0107     itkEl->setDatabaseEntryName(detEl->databaseEntryName());
0108     return std::pair{itkEl, surface};
0109   };
0110 
0111   if (srf->type() == Surface::Plane &&
0112       srf->bounds().type() == SurfaceBounds::eRectangle) {
0113     return helper.operator()<PlaneSurface, RectangleBounds>();
0114   }
0115   if (srf->type() == Surface::Disc &&
0116       srf->bounds().type() == SurfaceBounds::eAnnulus) {
0117     return helper.operator()<DiscSurface, AnnulusBounds>();
0118   }
0119 
0120   throw std::runtime_error(
0121       "Only Plane+Rectangle and Disc+Annulus are converted for the ITk");
0122 }
0123 
0124 }  // namespace ActsPlugins