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 #pragma once
0010 
0011 #include "ActsExamples/Geant4/DetectorConstructionFactory.hpp"
0012 #include "ActsExamples/Geant4/RegionCreator.hpp"
0013 
0014 #include <memory>
0015 
0016 #include <G4VUserDetectorConstruction.hh>
0017 
0018 class G4VPhysicalVolume;
0019 
0020 namespace dd4hep {
0021 class Detector;
0022 }
0023 namespace ActsExamples {
0024 
0025 namespace DD4hep {
0026 struct DD4hepDetector;
0027 }
0028 
0029 /// Construct the Geant4 detector from a DD4hep description.
0030 class DDG4DetectorConstruction final : public G4VUserDetectorConstruction {
0031  public:
0032   DDG4DetectorConstruction(
0033       std::shared_ptr<DD4hep::DD4hepDetector> detector,
0034       std::vector<std::shared_ptr<RegionCreator>> regionCreators = {});
0035   ~DDG4DetectorConstruction() final;
0036 
0037   /// Convert the stored DD4hep detector to a Geant4 description.
0038   ///
0039   /// Transfers ownership of the created object as all volumes (including world)
0040   /// are deleted in ~G4PhysicalVolumeStore().
0041   ///
0042   /// @note for facilitating configuration within the ACTS framework the world
0043   /// volume is cached
0044   G4VPhysicalVolume* Construct() final;
0045 
0046  private:
0047   /// The Acts DD4hep detector instance
0048   std::shared_ptr<DD4hep::DD4hepDetector> m_detector;
0049   /// Region creators
0050   std::vector<std::shared_ptr<RegionCreator>> m_regionCreators;
0051   /// The world volume
0052   G4VPhysicalVolume* m_world = nullptr;
0053 
0054   /// The DD4hep detector instance
0055   dd4hep::Detector& dd4hepDetector() const;
0056 };
0057 
0058 class DDG4DetectorConstructionFactory final
0059     : public DetectorConstructionFactory {
0060  public:
0061   DDG4DetectorConstructionFactory(
0062       std::shared_ptr<DD4hep::DD4hepDetector> detector,
0063       std::vector<std::shared_ptr<RegionCreator>> regionCreators = {});
0064   ~DDG4DetectorConstructionFactory() final;
0065 
0066   std::unique_ptr<G4VUserDetectorConstruction> factorize() const override;
0067 
0068  private:
0069   /// The Acts DD4hep detector instance
0070   std::shared_ptr<DD4hep::DD4hepDetector> m_detector;
0071   /// Region creators
0072   std::vector<std::shared_ptr<RegionCreator>> m_regionCreators;
0073 };
0074 
0075 }  // namespace ActsExamples