diff --git a/Simulation/DetSimGeom/CMakeLists.txt b/Simulation/DetSimGeom/CMakeLists.txt index f35a12b7c98a88d37d5adc0d3918b7490cf7751a..f546652d47bf44188d3b03046bfc57efc3a91874 100644 --- a/Simulation/DetSimGeom/CMakeLists.txt +++ b/Simulation/DetSimGeom/CMakeLists.txt @@ -7,6 +7,7 @@ gaudi_depends_on_subdirs( find_package(Geant4 REQUIRED ui_all vis_all) include(${Geant4_USE_FILE}) +find_package(DD4hep COMPONENTS DDG4 REQUIRED) set(DetSimGeom_srcs src/WorldDetElemTool.cpp @@ -14,6 +15,6 @@ set(DetSimGeom_srcs ) gaudi_add_module(DetSimGeom ${DetSimGeom_srcs} - INCLUDE_DIRS DetSimInterface GaudiKernel Geant4 - LINK_LIBRARIES DetSimInterface GaudiKernel Geant4 + INCLUDE_DIRS DetSimInterface DD4hep GaudiKernel Geant4 + LINK_LIBRARIES DetSimInterface DD4hep ${DD4hep_COMPONENT_LIBRARIES} GaudiKernel Geant4 ) diff --git a/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp b/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp index e2b297fc5e03e27ad108f1804f2e31b091278c6b..54dd53e9d9873e6c47158cdfb0a46813ab3f8aea 100644 --- a/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp +++ b/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp @@ -19,6 +19,9 @@ #include "G4PhysicalVolumeStore.hh" #include "G4OpticalSurface.hh" +#include "DD4hep/Detector.h" +#include "DDG4/Geant4Converter.h" +#include "DDG4/Geant4Mapping.h" DECLARE_COMPONENT(AnExampleDetElemTool) @@ -30,6 +33,32 @@ AnExampleDetElemTool::getLV() { G4VSolid* solidAnExample= new G4Box("sAnExample", m_x.value(), m_y.value(), m_z.value()); G4LogicalVolume* logicAnExample= new G4LogicalVolume( solidAnExample, Galactic, "lAnExample", 0, 0, 0); + // Following is an example to get the DD4hep volume + dd4hep::Detector* dd4hep_geo = &(dd4hep::Detector::getInstance()); + dd4hep_geo->fromCompact(m_dd4hep_xmls.value()); + dd4hep::DetElement world = dd4hep_geo->world(); + dd4hep::sim::Geant4Converter conv((*dd4hep_geo), dd4hep::DEBUG); + + dd4hep::sim::Geant4GeometryInfo* geo_info = conv.create(world).detach(); + dd4hep::sim::Geant4Mapping& g4map = dd4hep::sim::Geant4Mapping::instance(); + g4map.attach(geo_info); + // All volumes are deleted in ~G4PhysicalVolumeStore() + G4VPhysicalVolume* m_world = geo_info->world(); + G4LogicalVolume* logicDD4hepExample = m_world->GetLogicalVolume(); + + if (logicDD4hepExample) { + new G4PVPlacement(0, // no rotation + G4ThreeVector(), // at (0,0,0) + logicDD4hepExample, // logical volume + "lDD4hepExampleDetElem", // name + logicAnExample, // mother volume + false, // no boolean operations + 0); // no field + } else { + warning() << "Can't Find the logical volume lDD4hepExampleDetElem " << std::endl; + } + + return logicAnExample; } diff --git a/Simulation/DetSimGeom/src/AnExampleDetElemTool.h b/Simulation/DetSimGeom/src/AnExampleDetElemTool.h index dcf4cae0b906c91d8e4aa7f09f3a10bce7bfb330..ed8089b496ab9fcc7df309842aace6d6d3e71c9f 100644 --- a/Simulation/DetSimGeom/src/AnExampleDetElemTool.h +++ b/Simulation/DetSimGeom/src/AnExampleDetElemTool.h @@ -22,6 +22,8 @@ private: Gaudi::Property<double> m_x{this, "X", 30.*m}; Gaudi::Property<double> m_y{this, "Y", 30.*m}; Gaudi::Property<double> m_z{this, "Z", 30.*m}; + // DD4hep XML compact file path + Gaudi::Property<std::string> m_dd4hep_xmls{this, "detxml"}; }; #endif