Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:18

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