EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DD4hepDetectorConstruction.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DD4hepDetectorConstruction.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2020 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 
11 #include <stdexcept>
12 
13 #include <DD4hep/Detector.h>
14 #include <DD4hep/Plugins.h>
15 #include <DDG4/Geant4Converter.h>
16 #include <DDG4/Geant4GeometryInfo.h>
17 
18 using namespace ActsExamples;
19 
21  dd4hep::Detector& detector)
22  : G4VUserDetectorConstruction(), m_detector(detector) {}
23 
24 // See DD4hep::Simulation::Geant4DetectorConstruction::Construct()
26  dd4hep::sim::Geant4Mapping& g4map = dd4hep::sim::Geant4Mapping::instance();
27  dd4hep::DetElement world = m_detector.world();
28  dd4hep::sim::Geant4Converter conv(m_detector, dd4hep::INFO);
29  dd4hep::sim::Geant4GeometryInfo* geo_info = conv.create(world).detach();
30  g4map.attach(geo_info);
31  // All volumes are deleted in ~G4PhysicalVolumeStore()
32  G4VPhysicalVolume* m_world = geo_info->world();
33  m_detector.apply("DD4hepVolumeManager", 0, 0);
34  // Create Geant4 volume manager
35  g4map.volumeManager();
36  return m_world;
37 }