Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 07:50:06

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/Detector/DetectorBuilder.hpp"
0010 
0011 #include "Acts/Detector/Detector.hpp"
0012 #include "Acts/Detector/DetectorVolume.hpp"
0013 #include "Acts/Detector/interface/IGeometryIdGenerator.hpp"
0014 #include "Acts/Material/IMaterialDecorator.hpp"
0015 #include "Acts/Navigation/DetectorVolumeFinders.hpp"
0016 
0017 #include <algorithm>
0018 #include <stdexcept>
0019 
0020 Acts::Experimental::DetectorBuilder::DetectorBuilder(
0021     const Acts::Experimental::DetectorBuilder::Config& cfg,
0022     std::unique_ptr<const Acts::Logger> mlogger)
0023     : IDetectorBuilder(), m_cfg(cfg), m_logger(std::move(mlogger)) {
0024   if (m_cfg.builder == nullptr) {
0025     throw std::invalid_argument(
0026         "DetectorBuilder: no top level builder defined.");
0027   }
0028 }
0029 
0030 std::shared_ptr<const Acts::Experimental::Detector>
0031 Acts::Experimental::DetectorBuilder::construct(
0032     const GeometryContext& gctx) const {
0033   // Screen printout of the auxiliary information
0034   if (!m_cfg.auxiliary.empty()) {
0035     ACTS_DEBUG(m_cfg.auxiliary);
0036   }
0037   ACTS_DEBUG("Building a detector with name " << m_cfg.name);
0038 
0039   auto [volumes, portals, roots] = m_cfg.builder->construct(gctx);
0040 
0041   // Assign the geometry ids to the detector - if configured
0042   if (m_cfg.geoIdGenerator != nullptr) {
0043     ACTS_DEBUG("Assigning geometry ids to the detector");
0044     auto cache = m_cfg.geoIdGenerator->generateCache();
0045     std::ranges::for_each(roots.volumes, [&](auto& v) {
0046       ACTS_VERBOSE("-> Assigning geometry id to volume " << v->name());
0047       m_cfg.geoIdGenerator->assignGeometryId(cache, *v);
0048     });
0049   }
0050 
0051   // Decorate the volumes with material - Surface material only at this moment
0052   if (m_cfg.materialDecorator != nullptr) {
0053     ACTS_DEBUG("Decorating the detector with material");
0054     std::ranges::for_each(volumes, [&](auto& v) {
0055       // Assign to surfaces
0056       for (auto& sf : v->surfacePtrs()) {
0057         m_cfg.materialDecorator->decorate(*sf);
0058       }
0059       // Assign to portals
0060       for (auto& p : v->portalPtrs()) {
0061         m_cfg.materialDecorator->decorate(p->surface());
0062       }
0063     });
0064   }
0065 
0066   return Detector::makeShared(m_cfg.name, std::move(roots.volumes),
0067                               std::move(roots.volumeFinder));
0068 }