Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 08:22:53

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/Geant4Detector/Geant4Detector.hpp"
0010 
0011 #include "Acts/Surfaces/Surface.hpp"
0012 #include "ActsPlugins/Geant4/Geant4DetectorElement.hpp"
0013 
0014 #include <memory>
0015 #include <ostream>
0016 #include <stdexcept>
0017 
0018 #include "G4Transform3D.hh"
0019 #include "G4VPhysicalVolume.hh"
0020 
0021 namespace ActsExamples {
0022 
0023 Geant4Detector::Geant4Detector(const Config& cfg)
0024     : Detector(Acts::getDefaultLogger("Geant4Detector", cfg.logLevel)),
0025       m_cfg(cfg) {
0026   if (m_cfg.g4World == nullptr) {
0027     throw std::invalid_argument(
0028         "Geant4Detector: no world Geant4 volume provided");
0029   }
0030 
0031   ACTS_INFO("Building an Acts::TrackingGeometry called '"
0032             << m_cfg.name << "' from the Geant4PhysVolume '"
0033             << m_cfg.g4World->GetName() << "'");
0034 
0035   m_nominalGeometryContext =
0036       Acts::GeometryContext::dangerouslyDefaultConstruct();
0037 
0038   auto [surfaces, elements] = buildGeant4Volumes(cfg, logger());
0039 }
0040 
0041 std::tuple<std::vector<std::shared_ptr<Acts::Surface>>,
0042            std::vector<std::shared_ptr<ActsPlugins::Geant4DetectorElement>>>
0043 Geant4Detector::buildGeant4Volumes(const Config& cfg,
0044                                    const Acts::Logger& logger) {
0045   // Generate the surface cache
0046   ActsPlugins::Geant4DetectorSurfaceFactory::Config g4SurfaceConfig;
0047   ActsPlugins::Geant4DetectorSurfaceFactory::Cache g4SurfaceCache;
0048   G4Transform3D g4ToWorld;
0049 
0050   ActsPlugins::Geant4DetectorSurfaceFactory(g4SurfaceConfig)
0051       .construct(g4SurfaceCache, g4ToWorld, *cfg.g4World, cfg.g4SurfaceOptions);
0052 
0053   ACTS_INFO("Found " << g4SurfaceCache.matchedG4Volumes
0054                      << " matching  Geant4 Physical volumes.");
0055   ACTS_INFO("Found " << g4SurfaceCache.sensitiveSurfaces.size()
0056                      << " converted sensitive Geant4 Physical volumes.");
0057   ACTS_INFO("Found " << g4SurfaceCache.passiveSurfaces.size()
0058                      << " converted passive Geant4 Physical volumes.");
0059   ACTS_INFO("Found " << g4SurfaceCache.convertedMaterials
0060                      << " converted Geant4 Material slabs.");
0061 
0062   std::vector<std::shared_ptr<Acts::Surface>> surfaces;
0063   std::vector<std::shared_ptr<ActsPlugins::Geant4DetectorElement>> elements;
0064 
0065   // Reserve the right amount of surfaces
0066   surfaces.reserve(g4SurfaceCache.sensitiveSurfaces.size() +
0067                    g4SurfaceCache.passiveSurfaces.size());
0068   elements.reserve(g4SurfaceCache.sensitiveSurfaces.size());
0069 
0070   // Add the sensitive surfaces
0071   for (const auto& [e, s] : g4SurfaceCache.sensitiveSurfaces) {
0072     surfaces.push_back(s);
0073     elements.push_back(e);
0074   }
0075   // Add the passive surfaces
0076   surfaces.insert(surfaces.end(), g4SurfaceCache.passiveSurfaces.begin(),
0077                   g4SurfaceCache.passiveSurfaces.end());
0078 
0079   return {std::move(surfaces), std::move(elements)};
0080 }
0081 
0082 }  // namespace ActsExamples