Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:45

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2017-2024 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Geant4/GdmlDetectorConstruction.hpp"
0010 
0011 #include <utility>
0012 
0013 #include <G4GDMLParser.hh>
0014 
0015 class G4VPhysicalVolume;
0016 
0017 using namespace ActsExamples;
0018 
0019 GdmlDetectorConstruction::GdmlDetectorConstruction(
0020     std::string path,
0021     std::vector<std::shared_ptr<RegionCreator>> regionCreators)
0022     : G4VUserDetectorConstruction(),
0023       m_path(std::move(path)),
0024       m_regionCreators(std::move(regionCreators)) {}
0025 
0026 G4VPhysicalVolume* GdmlDetectorConstruction::Construct() {
0027   if (m_world == nullptr) {
0028     G4GDMLParser parser;
0029     // TODO how to handle errors
0030     parser.Read(m_path);
0031     m_world = parser.GetWorldVolume();
0032 
0033     // Create regions
0034     for (const auto& regionCreator : m_regionCreators) {
0035       regionCreator->Construct();
0036     }
0037   }
0038   return m_world;
0039 }
0040 
0041 GdmlDetectorConstructionFactory::GdmlDetectorConstructionFactory(
0042     std::string path,
0043     std::vector<std::shared_ptr<RegionCreator>> regionCreators)
0044     : m_path(std::move(path)), m_regionCreators(std::move(regionCreators)) {}
0045 
0046 std::unique_ptr<G4VUserDetectorConstruction>
0047 GdmlDetectorConstructionFactory::factorize() const {
0048   return std::make_unique<GdmlDetectorConstruction>(m_path, m_regionCreators);
0049 }