Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11: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 "ActsExamples/TGeoDetector/TGeoITkModuleSplitter.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Plugins/TGeo/TGeoDetectorElement.hpp"
0013 #include "Acts/Surfaces/AnnulusBounds.hpp"
0014 #include "Acts/Surfaces/RectangleBounds.hpp"
0015 #include "Acts/Surfaces/Surface.hpp"
0016 #include "Acts/Surfaces/SurfaceBounds.hpp"
0017 #include "ActsExamples/ITkModuleSplitting/ITkModuleSplitting.hpp"
0018 
0019 #include <algorithm>
0020 #include <array>
0021 #include <cstddef>
0022 #include <sstream>
0023 
0024 namespace ActsExamples {
0025 
0026 TGeoITkModuleSplitter::TGeoITkModuleSplitter(
0027     const TGeoITkModuleSplitter::Config& cfg,
0028     std::unique_ptr<const Acts::Logger> logger)
0029     : m_cfg(cfg), m_logger(std::move(logger)) {
0030   initSplitCategories();
0031 }
0032 
0033 void TGeoITkModuleSplitter::initSplitCategories() {
0034   m_splitCategories.reserve(m_cfg.splitPatterns.size());
0035   for (const std::pair<const std::string, std::string>& pattern_split_category :
0036        m_cfg.splitPatterns) {
0037     // mark pattern for disc or barrel module splits:
0038     bool is_disk = false;
0039     if (m_cfg.discMap.contains(pattern_split_category.second)) {
0040       is_disk = true;
0041     } else if (!m_cfg.barrelMap.contains(pattern_split_category.second)) {
0042       ACTS_ERROR(
0043           pattern_split_category.second +
0044           " is neither a category name for barrel or disk module splits.");
0045       continue;
0046     }
0047     m_splitCategories.push_back(
0048         std::make_tuple(std::regex(pattern_split_category.first),
0049                         pattern_split_category.second, is_disk));
0050   }
0051 }
0052 
0053 /// If applicable, returns a split detector element
0054 inline std::vector<std::shared_ptr<const Acts::TGeoDetectorElement>>
0055 TGeoITkModuleSplitter::split(
0056     const Acts::GeometryContext& gctx,
0057     std::shared_ptr<const Acts::TGeoDetectorElement> detElement) const {
0058   // Is the current node covered by this splitter?
0059   const TGeoNode& node = detElement->tgeoNode();
0060   auto sensorName = std::string(node.GetName());
0061 
0062   static const char* category_names[2] = {"barrel", "disc"};
0063   for (const std::tuple<std::regex, std::string, bool>& split_category :
0064        m_splitCategories) {
0065     if (std::regex_match(sensorName, std::get<0>(split_category))) {
0066       ACTS_DEBUG("Splitting " +
0067                  std::string(category_names[std::get<2>(split_category)]) +
0068                  " node " + sensorName + " using split ranges of category " +
0069                  std::get<1>(split_category));
0070       if (!std::get<2>(split_category)) {
0071         return TGeoITkModuleSplitter::splitBarrelModule(
0072             gctx, detElement, m_cfg.barrelMap.at(std::get<1>(split_category)));
0073       } else {
0074         return TGeoITkModuleSplitter::splitDiscModule(
0075             gctx, detElement, m_cfg.discMap.at(std::get<1>(split_category)));
0076       }
0077     }
0078   }
0079   ACTS_DEBUG("No matching configuration found. Node " +
0080              std::string(detElement->tgeoNode().GetName()) +
0081              " will not be split.");
0082 
0083   return {detElement};
0084 }
0085 
0086 /// If applicable, returns a split detector element
0087 inline std::vector<std::shared_ptr<const Acts::TGeoDetectorElement>>
0088 TGeoITkModuleSplitter::splitBarrelModule(
0089     const Acts::GeometryContext& gctx,
0090     const std::shared_ptr<const Acts::TGeoDetectorElement>& detElement,
0091     unsigned int nSegments) const {
0092   auto name = detElement->tgeoNode().GetName();
0093 
0094   auto factory = [&](const auto& trafo, const auto& bounds) {
0095     return std::make_shared<const Acts::TGeoDetectorElement>(
0096         detElement->identifier(), detElement->tgeoNode(), trafo, bounds,
0097         detElement->thickness());
0098   };
0099 
0100   return ITk::splitBarrelModule(gctx, detElement, nSegments, factory, name,
0101                                 logger());
0102 }
0103 
0104 /// If applicable, returns a split detector element
0105 inline std::vector<std::shared_ptr<const Acts::TGeoDetectorElement>>
0106 TGeoITkModuleSplitter::splitDiscModule(
0107     const Acts::GeometryContext& gctx,
0108     const std::shared_ptr<const Acts::TGeoDetectorElement>& detElement,
0109     const std::vector<TGeoITkModuleSplitter::SplitRange>& splitRanges) const {
0110   auto name = detElement->tgeoNode().GetName();
0111 
0112   auto factory = [&](const auto& trafo, const auto& bounds) {
0113     return std::make_shared<const Acts::TGeoDetectorElement>(
0114         detElement->identifier(), detElement->tgeoNode(), trafo, bounds,
0115         detElement->thickness());
0116   };
0117 
0118   return ITk::splitDiscModule(gctx, detElement, splitRanges, factory, name,
0119                               logger());
0120 }
0121 
0122 }  // namespace ActsExamples