Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DDG4DetectorConstruction.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DDG4DetectorConstruction.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
12 
13 #include <memory>
14 #include <stdexcept>
15 
16 #include <DD4hep/DetElement.h>
17 #include <DD4hep/Detector.h>
18 #include <DDG4/Geant4Converter.h>
19 #include <DDG4/Geant4GeometryInfo.h>
20 #include <DDG4/Geant4Mapping.h>
21 #include <Parsers/Printout.h>
22 
23 class G4VPhysicalVolume;
24 
26  std::shared_ptr<DD4hep::DD4hepDetector> detector)
27  : G4VUserDetectorConstruction(), m_detector(std::move(detector)) {}
28 
30 
32  const {
33  return m_detector->geometryService->detector();
34 }
35 
36 // See DD4hep::Simulation::Geant4DetectorConstruction::Construct()
38  if (m_world == nullptr) {
39  dd4hep::sim::Geant4Mapping& g4map = dd4hep::sim::Geant4Mapping::instance();
40  auto conv = dd4hep::sim::Geant4Converter(dd4hepDetector(),
42  dd4hep::sim::Geant4GeometryInfo* geo_info =
43  conv.create(dd4hepDetector().world()).detach();
44  g4map.attach(geo_info);
45  // All volumes are deleted in ~G4PhysicalVolumeStore()
46  m_world = geo_info->world();
47  // Create Geant4 volume manager
48  g4map.volumeManager();
49  }
50  return m_world;
51 }
52 
54  std::shared_ptr<DD4hep::DD4hepDetector> detector)
55  : m_detector(std::move(detector)) {}
56 
59 
60 std::unique_ptr<G4VUserDetectorConstruction>
62  return std::make_unique<DDG4DetectorConstruction>(m_detector);
63 }