Skip to content
Snippets Groups Projects
Commit f876c6bd authored by lintao@ihep.ac.cn's avatar lintao@ihep.ac.cn
Browse files

WIP: accessing dd4hep lcdd uses the geosvc.

parent eb901fd7
No related branches found
No related tags found
No related merge requests found
......@@ -93,7 +93,7 @@
<readouts>
<readout name="VXDCollection">
<!-- fixme: for now DD4hep cannot handle signed values - side should actually be "-2" -->
<id>system:5,side:2,layer:9,module:8,sensor:8</id>
<id>system:5,side:-2,layer:9,module:8,sensor:8</id>
</readout>
</readouts>
......
......@@ -13,6 +13,27 @@ from Gaudi.Configuration import *
from Configurables import CEPCDataSvc
dsvc = CEPCDataSvc("EventDataSvc")
##############################################################################
# Geometry Svc
##############################################################################
# geometry_option = "CepC_v4-onlyTracker.xml"
geometry_option = "CepC_v4-onlyVXD.xml"
if not os.getenv("DETCEPCV4ROOT"):
print("Can't find the geometry. Please setup envvar DETCEPCV4ROOT." )
sys.exit(-1)
geometry_path = os.path.join(os.getenv("DETCEPCV4ROOT"), "compact", geometry_option)
if not os.path.exists(geometry_path):
print("Can't find the compact geometry file: %s"%geometry_path)
sys.exit(-1)
from Configurables import GeoSvc
geosvc = GeoSvc("GeoSvc")
geosvc.compact = geometry_path
##############################################################################
# Physics Generator
##############################################################################
......@@ -51,14 +72,6 @@ detsimalg.RootDetElem = "WorldDetElemTool"
from Configurables import AnExampleDetElemTool
example_dettool = AnExampleDetElemTool("AnExampleDetElemTool")
# geometry_option = "CepC_v4-onlyTracker.xml"
geometry_option = "CepC_v4-onlyVXD.xml"
if os.getenv("DETCEPCV4ROOT"):
example_dettool.detxml = os.path.join(os.getenv("DETCEPCV4ROOT"), "compact", geometry_option)
else:
print("Can't find the geometry. Please setup envvar DETCEPCV4ROOT." )
sys.exit(-1)
##############################################################################
# POD I/O
......
......@@ -3,6 +3,7 @@ gaudi_subdir(DetSimGeom v0r0)
gaudi_depends_on_subdirs(
Simulation/DetSimInterface
Detector/DetInterface
)
find_package(Geant4 REQUIRED ui_all vis_all)
......@@ -15,6 +16,6 @@ set(DetSimGeom_srcs
)
gaudi_add_module(DetSimGeom ${DetSimGeom_srcs}
INCLUDE_DIRS DetSimInterface DD4hep GaudiKernel Geant4
INCLUDE_DIRS DetSimInterface DetInterface DD4hep GaudiKernel Geant4
LINK_LIBRARIES DetSimInterface DD4hep ${DD4hep_COMPONENT_LIBRARIES} GaudiKernel Geant4
)
......@@ -24,6 +24,7 @@
#include "DDG4/Geant4Converter.h"
#include "DDG4/Geant4Mapping.h"
DECLARE_COMPONENT(AnExampleDetElemTool)
G4LogicalVolume*
......@@ -35,9 +36,13 @@ AnExampleDetElemTool::getLV() {
// 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::Detector* dd4hep_geo = &(dd4hep::Detector::getInstance());
// dd4hep_geo->fromCompact(m_dd4hep_xmls.value());
// dd4hep::DetElement world = dd4hep_geo->world();
dd4hep::Detector* dd4hep_geo = m_geosvc->lcdd();
dd4hep::DetElement world = m_geosvc->getDD4HepGeo();
dd4hep::sim::Geant4Converter conv((*dd4hep_geo), dd4hep::DEBUG);
dd4hep::sim::Geant4GeometryInfo* geo_info = conv.create(world).detach();
......@@ -76,7 +81,7 @@ AnExampleDetElemTool::ConstructSDandField() {
dd4hep::sim::Geant4GeometryInfo* p = dd4hep::sim::Geant4Mapping::instance().ptr();
_SV& vols = p->sensitives;
auto lcdd = &(dd4hep::Detector::getInstance());
auto lcdd = m_geosvc->lcdd();
for (_SV::const_iterator iv = vols.begin(); iv != vols.end(); ++iv) {
dd4hep::SensitiveDetector sd = (*iv).first;
......@@ -125,6 +130,13 @@ AnExampleDetElemTool::ConstructSDandField() {
StatusCode
AnExampleDetElemTool::initialize() {
StatusCode sc;
m_geosvc = service<IGeoSvc>("GeoSvc");
if (!m_geosvc) {
error() << "Failed to find GeoSvc." << endmsg;
return StatusCode::FAILURE;
}
return sc;
}
......
......@@ -7,6 +7,8 @@
#include "G4SystemOfUnits.hh"
#include "G4PhysicalConstants.hh"
#include "DetInterface/IGeoSvc.h"
class AnExampleDetElemTool: public extends<AlgTool, IDetElemTool> {
......@@ -25,6 +27,9 @@ private:
Gaudi::Property<double> m_z{this, "Z", 30.*m};
// DD4hep XML compact file path
Gaudi::Property<std::string> m_dd4hep_xmls{this, "detxml"};
SmartIF<IGeoSvc> m_geosvc;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment