diff --git a/Detector/DetComponents/src/GeoConstruction.cpp b/Detector/DetComponents/src/GeoConstruction.cpp index 5bbca28..57ef044 100644 --- a/Detector/DetComponents/src/GeoConstruction.cpp +++ b/Detector/DetComponents/src/GeoConstruction.cpp @@ -15,7 +15,7 @@ namespace det { -GeoConstruction::GeoConstruction(dd4hep::Detector& lcdd, std::map sensitive_types) : m_lcdd(lcdd), m_sensitive_types(sensitive_types) {} +GeoConstruction::GeoConstruction(dd4hep::Detector& detector, std::map sensitive_types) : m_detector(detector), m_sensitive_types(sensitive_types) {} GeoConstruction::~GeoConstruction() {} @@ -35,15 +35,15 @@ void GeoConstruction::ConstructSDandField() { typ = m_sensitive_types[typ]; } // Sensitive detectors are deleted in ~G4SDManager - G4VSensitiveDetector* g4sd = dd4hep::PluginService::Create(typ, nam, &m_lcdd); + G4VSensitiveDetector* g4sd = dd4hep::PluginService::Create(typ, nam, &m_detector); if (g4sd == nullptr) { std::string tmp = typ; tmp[0] = ::toupper(tmp[0]); typ = "Geant4" + tmp; - g4sd = dd4hep::PluginService::Create(typ, nam, &m_lcdd); + g4sd = dd4hep::PluginService::Create(typ, nam, &m_detector); if (g4sd == nullptr) { dd4hep::PluginDebug dbg; - g4sd = dd4hep::PluginService::Create(typ, nam, &m_lcdd); + g4sd = dd4hep::PluginService::Create(typ, nam, &m_detector); if (g4sd == nullptr) { throw std::runtime_error("ConstructSDandField: FATAL Failed to " "create Geant4 sensitive detector " + @@ -70,14 +70,14 @@ void GeoConstruction::ConstructSDandField() { // method borrowed from dd4hep::sim::Geant4DetectorConstruction::Construct() G4VPhysicalVolume* GeoConstruction::Construct() { dd4hep::sim::Geant4Mapping& g4map = dd4hep::sim::Geant4Mapping::instance(); - dd4hep::DetElement world = m_lcdd.world(); - dd4hep::sim::Geant4Converter conv(m_lcdd, dd4hep::DEBUG); + dd4hep::DetElement world = m_detector.world(); + dd4hep::sim::Geant4Converter conv(m_detector, dd4hep::DEBUG); dd4hep::sim::Geant4GeometryInfo* geo_info = conv.create(world).detach(); g4map.attach(geo_info); // All volumes are deleted in ~G4PhysicalVolumeStore() G4VPhysicalVolume* m_world = geo_info->world(); - if(not m_lcdd.volumeManager().isValid()) { - m_lcdd.apply("DD4hepVolumeManager", 0, 0); + if(not m_detector.volumeManager().isValid()) { + m_detector.apply("DD4hepVolumeManager", 0, 0); } // Create Geant4 volume manager g4map.volumeManager(); diff --git a/Detector/DetComponents/src/GeoConstruction.h b/Detector/DetComponents/src/GeoConstruction.h index c057b53..521f9a3 100644 --- a/Detector/DetComponents/src/GeoConstruction.h +++ b/Detector/DetComponents/src/GeoConstruction.h @@ -24,7 +24,7 @@ namespace det { class GeoConstruction : public G4VUserDetectorConstruction { public: /// Constructor - GeoConstruction(dd4hep::Detector& lcdd, std::map sensitive_types); + GeoConstruction(dd4hep::Detector& detector, std::map sensitive_types); /// Default destructor virtual ~GeoConstruction(); /// Geometry construction callback: Invoke the conversion to Geant4 @@ -35,7 +35,7 @@ class GeoConstruction : public G4VUserDetectorConstruction { private: /// Reference to geometry object - dd4hep::Detector& m_lcdd; + dd4hep::Detector& m_detector; std::map m_sensitive_types; }; } diff --git a/Detector/DetComponents/src/GeoSvc.cpp b/Detector/DetComponents/src/GeoSvc.cpp index d487161..0c85607 100644 --- a/Detector/DetComponents/src/GeoSvc.cpp +++ b/Detector/DetComponents/src/GeoSvc.cpp @@ -46,13 +46,15 @@ StatusCode GeoSvc::initialize() { } // Build Geant4 Geometry - { + if(m_buildGeant4Geo) { StatusCode sc = buildGeant4Geo(); if (sc.isFailure()) { error() << "Could not build Geant4 geometry!" << endmsg; } else { info() << "Geant4 geometry SUCCESSFULLY built." << endmsg; } + } else { + debug() << "Conversion to Geant4 Geometry is disabled" << endmsg; } return StatusCode::SUCCESS; @@ -82,13 +84,17 @@ StatusCode GeoSvc::buildDD4HepGeo() { return StatusCode::SUCCESS; } -dd4hep::Detector* GeoSvc::lcdd() { return (m_dd4hepgeo); } +dd4hep::Detector* GeoSvc::lcdd() { return m_dd4hepgeo; } + +dd4hep::Detector* GeoSvc::getDetector() { return m_dd4hepgeo; } -dd4hep::DetElement GeoSvc::getDD4HepGeo() { return (lcdd()->world()); } +dd4hep::DetElement GeoSvc::getDD4HepGeo() { return m_dd4hepgeo->world(); } StatusCode GeoSvc::buildGeant4Geo() { - std::shared_ptr detector(new det::GeoConstruction(*lcdd(), m_sensitive_types)); - m_geant4geo = detector; + if (not m_buildGeant4Geo) { + return StatusCode::SUCCESS; + } + m_geant4geo = std::make_shared(*m_dd4hepgeo, m_sensitive_types); if (nullptr != m_geant4geo) { return StatusCode::SUCCESS; } @@ -97,3 +103,7 @@ StatusCode GeoSvc::buildGeant4Geo() { } G4VUserDetectorConstruction* GeoSvc::getGeant4Geo() { return (m_geant4geo.get()); } + +std::string GeoSvc::constantAsString(std::string const& name) { + return m_dd4hepgeo->constantAsString(name); +} diff --git a/Detector/DetComponents/src/GeoSvc.h b/Detector/DetComponents/src/GeoSvc.h index 580cb53..2626b33 100644 --- a/Detector/DetComponents/src/GeoSvc.h +++ b/Detector/DetComponents/src/GeoSvc.h @@ -37,7 +37,10 @@ class GeoSvc : public extends { StatusCode buildGeant4Geo(); // receive DD4hep Geometry virtual dd4hep::DetElement getDD4HepGeo() override; + [[deprecated("Use getDetector() instead")]] virtual dd4hep::Detector* lcdd() override; + virtual dd4hep::Detector* getDetector() override; + virtual std::string constantAsString(std::string const& name) override; // receive Geant4 Geometry virtual G4VUserDetectorConstruction* getGeant4Geo() override; @@ -50,6 +53,9 @@ class GeoSvc : public extends { Gaudi::Property> m_xmlFileNames{this, "detectors", {}, "Detector descriptions XML-files"}; /// mapping of sensitive detector names Gaudi::Property> m_sensitive_types{this, "sensitiveTypes", {{"tracker", "SimpleTrackerSD"}, {"calorimeter", "SimpleCalorimeterSD"}}}; + /// Whether to create the geant4 geometry or not + Gaudi::Property m_buildGeant4Geo{this, "EnableGeant4Geo", true, "If True the DD4hep geometry is converted for Geant4 Simulations"}; + }; #endif // GEOSVC_H diff --git a/Detector/DetComponents/src/MaterialScan.cpp b/Detector/DetComponents/src/MaterialScan.cpp index 986c805..cc2c48f 100644 --- a/Detector/DetComponents/src/MaterialScan.cpp +++ b/Detector/DetComponents/src/MaterialScan.cpp @@ -65,7 +65,7 @@ StatusCode MaterialScan::initialize() { tree->Branch("matDepth", &matDepthPtr); tree->Branch("material", &materialPtr); - auto lcdd = m_geoSvc->lcdd(); + auto lcdd = m_geoSvc->getDetector(); dd4hep::rec::MaterialManager matMgr(lcdd->detector(m_envelopeName).volume()); dd4hep::rec::Vector3D beginning(0, 0, 0); auto boundaryVol = lcdd->detector(m_envelopeName).volume()->GetShape(); diff --git a/Detector/DetComponents/src/MaterialScan_2D_genericAngle.cpp b/Detector/DetComponents/src/MaterialScan_2D_genericAngle.cpp index e64bbe2..d4ea2e0 100644 --- a/Detector/DetComponents/src/MaterialScan_2D_genericAngle.cpp +++ b/Detector/DetComponents/src/MaterialScan_2D_genericAngle.cpp @@ -67,7 +67,7 @@ StatusCode MaterialScan_2D_genericAngle::initialize() { tree->Branch("matDepth", &matDepthPtr); tree->Branch("material", &materialPtr); - auto lcdd = m_geoSvc->lcdd(); + auto lcdd = m_geoSvc->getDetector(); dd4hep::rec::MaterialManager matMgr(lcdd->detector(m_envelopeName).volume()); dd4hep::rec::Vector3D beginning(0, 0, 0); auto boundaryVol = lcdd->detector(m_envelopeName).volume()->GetShape(); diff --git a/Detector/DetComponents/src/MaterialScan_genericAngle.cpp b/Detector/DetComponents/src/MaterialScan_genericAngle.cpp index ed061da..36b1fce 100644 --- a/Detector/DetComponents/src/MaterialScan_genericAngle.cpp +++ b/Detector/DetComponents/src/MaterialScan_genericAngle.cpp @@ -72,7 +72,7 @@ StatusCode MaterialScan_genericAngle::initialize() { tree->Branch("matDepth", &matDepthPtr); tree->Branch("material", &materialPtr); - auto lcdd = m_geoSvc->lcdd(); + auto lcdd = m_geoSvc->getDetector(); dd4hep::rec::MaterialManager matMgr(lcdd->detector(m_envelopeName).volume()); dd4hep::rec::Vector3D beginning(0, 0, 0); auto boundaryVol = lcdd->detector(m_envelopeName).volume()->GetShape(); diff --git a/Detector/DetComponents/src/MergeCells.cpp b/Detector/DetComponents/src/MergeCells.cpp index 1b0cc22..b4e1e3c 100644 --- a/Detector/DetComponents/src/MergeCells.cpp +++ b/Detector/DetComponents/src/MergeCells.cpp @@ -34,11 +34,11 @@ StatusCode MergeCells::initialize() { return StatusCode::FAILURE; } // check if readout exists - if (m_geoSvc->lcdd()->readouts().find(m_readoutName) == m_geoSvc->lcdd()->readouts().end()) { + if (m_geoSvc->getDetector()->readouts().find(m_readoutName) == m_geoSvc->getDetector()->readouts().end()) { error() << "Readout <<" << m_readoutName << ">> does not exist." << endmsg; return StatusCode::FAILURE; } - auto readout = m_geoSvc->lcdd()->readout(m_readoutName); + auto readout = m_geoSvc->getDetector()->readout(m_readoutName); m_descriptor = readout.idSpec(); // check if identifier exists in the decoder auto itIdentifier = std::find_if(m_descriptor.fields().begin(), diff --git a/Detector/DetComponents/src/MergeLayers.cpp b/Detector/DetComponents/src/MergeLayers.cpp index 4d2dfb7..5e5ccc2 100644 --- a/Detector/DetComponents/src/MergeLayers.cpp +++ b/Detector/DetComponents/src/MergeLayers.cpp @@ -37,11 +37,11 @@ StatusCode MergeLayers::initialize() { return StatusCode::FAILURE; } // check if readout exists - if (m_geoSvc->lcdd()->readouts().find(m_readoutName) == m_geoSvc->lcdd()->readouts().end()) { + if (m_geoSvc->getDetector()->readouts().find(m_readoutName) == m_geoSvc->getDetector()->readouts().end()) { error() << "Readout <<" << m_readoutName << ">> does not exist." << endmsg; return StatusCode::FAILURE; } - auto readout = m_geoSvc->lcdd()->readout(m_readoutName); + auto readout = m_geoSvc->getDetector()->readout(m_readoutName); m_descriptor = readout.idSpec(); // check if identifier exists in the decoder auto itIdentifier = std::find_if(m_descriptor.fields().begin(), diff --git a/Detector/DetComponents/src/RedoSegmentation.cpp b/Detector/DetComponents/src/RedoSegmentation.cpp index a8d1a3d..9db5e38 100644 --- a/Detector/DetComponents/src/RedoSegmentation.cpp +++ b/Detector/DetComponents/src/RedoSegmentation.cpp @@ -21,16 +21,16 @@ StatusCode RedoSegmentation::initialize() { return StatusCode::FAILURE; } // check if readouts exist - if (m_geoSvc->lcdd()->readouts().find(m_oldReadoutName) == m_geoSvc->lcdd()->readouts().end()) { + if (m_geoSvc->getDetector()->readouts().find(m_oldReadoutName) == m_geoSvc->getDetector()->readouts().end()) { error() << "Readout <<" << m_oldReadoutName << ">> does not exist." << endmsg; return StatusCode::FAILURE; } - if (m_geoSvc->lcdd()->readouts().find(m_newReadoutName) == m_geoSvc->lcdd()->readouts().end()) { + if (m_geoSvc->getDetector()->readouts().find(m_newReadoutName) == m_geoSvc->getDetector()->readouts().end()) { error() << "Readout <<" << m_newReadoutName << ">> does not exist." << endmsg; return StatusCode::FAILURE; } // Take readout, bitfield from GeoSvc - m_oldDecoder = m_geoSvc->lcdd()->readout(m_oldReadoutName).idSpec().decoder(); + m_oldDecoder = m_geoSvc->getDetector()->readout(m_oldReadoutName).idSpec().decoder(); // segmentation identifiers to be overwritten if (m_oldIdentifiers.size() == 0) { // it is not an error, maybe no segmentation was used previously @@ -45,7 +45,7 @@ StatusCode RedoSegmentation::initialize() { } } // Take new segmentation from geometry service - m_segmentation = m_geoSvc->lcdd()->readout(m_newReadoutName).segmentation().segmentation(); + m_segmentation = m_geoSvc->getDetector()->readout(m_newReadoutName).segmentation().segmentation(); // check if detector identifiers (old and new) agree std::vector newFields; for (uint itField = 0; itField < m_segmentation->decoder()->size(); itField++) { diff --git a/Detector/DetComponents/src/RewriteBitfield.cpp b/Detector/DetComponents/src/RewriteBitfield.cpp index 70f569a..1792691 100644 --- a/Detector/DetComponents/src/RewriteBitfield.cpp +++ b/Detector/DetComponents/src/RewriteBitfield.cpp @@ -28,16 +28,16 @@ StatusCode RewriteBitfield::initialize() { return StatusCode::FAILURE; } // check if readouts exist - if (m_geoSvc->lcdd()->readouts().find(m_oldReadoutName) == m_geoSvc->lcdd()->readouts().end()) { + if (m_geoSvc->getDetector()->readouts().find(m_oldReadoutName) == m_geoSvc->getDetector()->readouts().end()) { error() << "Readout <<" << m_oldReadoutName << ">> does not exist." << endmsg; return StatusCode::FAILURE; } - if (m_geoSvc->lcdd()->readouts().find(m_newReadoutName) == m_geoSvc->lcdd()->readouts().end()) { + if (m_geoSvc->getDetector()->readouts().find(m_newReadoutName) == m_geoSvc->getDetector()->readouts().end()) { error() << "Readout <<" << m_newReadoutName << ">> does not exist." << endmsg; return StatusCode::FAILURE; } // Take readout, bitfield from GeoSvc - m_oldDecoder = m_geoSvc->lcdd()->readout(m_oldReadoutName).idSpec().decoder(); + m_oldDecoder = m_geoSvc->getDetector()->readout(m_oldReadoutName).idSpec().decoder(); // segmentation identifiers to be overwritten if (m_oldIdentifiers.size() == 0) { // it is not an error, maybe no segmentation was used previously @@ -52,7 +52,7 @@ StatusCode RewriteBitfield::initialize() { } } std::vector newFields; - m_newDecoder = m_geoSvc->lcdd()->readout(m_newReadoutName).idSpec().decoder(); + m_newDecoder = m_geoSvc->getDetector()->readout(m_newReadoutName).idSpec().decoder(); for (uint itField = 0; itField < m_newDecoder->size(); itField++) { newFields.push_back((*m_newDecoder)[itField].name()); } diff --git a/Detector/DetStudies/src/components/EnergyInCaloLayers.cpp b/Detector/DetStudies/src/components/EnergyInCaloLayers.cpp index f6c3c6b..8252f24 100644 --- a/Detector/DetStudies/src/components/EnergyInCaloLayers.cpp +++ b/Detector/DetStudies/src/components/EnergyInCaloLayers.cpp @@ -40,7 +40,7 @@ StatusCode EnergyInCaloLayers::initialize() { } // Check if readout exists - if (m_geoSvc->lcdd()->readouts().find(m_readoutName) == m_geoSvc->lcdd()->readouts().end()) { + if (m_geoSvc->getDetector()->readouts().find(m_readoutName) == m_geoSvc->getDetector()->readouts().end()) { error() << "Can't find readout <<" << m_readoutName << ">>!" << endmsg; return StatusCode::FAILURE; } @@ -64,7 +64,7 @@ StatusCode EnergyInCaloLayers::initialize() { StatusCode EnergyInCaloLayers::execute() { - auto decoder = m_geoSvc->lcdd()->readout(m_readoutName).idSpec().decoder(); + auto decoder = m_geoSvc->getDetector()->readout(m_readoutName).idSpec().decoder(); // Initialize output variables std::vector* energyInLayer = m_energyInLayer.createAndPut(); diff --git a/Detector/DetStudies/src/components/SamplingFractionInLayers.cpp b/Detector/DetStudies/src/components/SamplingFractionInLayers.cpp index 1a71a7b..1c1fca5 100644 --- a/Detector/DetStudies/src/components/SamplingFractionInLayers.cpp +++ b/Detector/DetStudies/src/components/SamplingFractionInLayers.cpp @@ -32,7 +32,7 @@ StatusCode SamplingFractionInLayers::initialize() { return StatusCode::FAILURE; } // check if readouts exist - if (m_geoSvc->lcdd()->readouts().find(m_readoutName) == m_geoSvc->lcdd()->readouts().end()) { + if (m_geoSvc->getDetector()->readouts().find(m_readoutName) == m_geoSvc->getDetector()->readouts().end()) { error() << "Readout <<" << m_readoutName << ">> does not exist." << endmsg; return StatusCode::FAILURE; } @@ -78,7 +78,7 @@ StatusCode SamplingFractionInLayers::initialize() { } StatusCode SamplingFractionInLayers::execute() { - auto decoder = m_geoSvc->lcdd()->readout(m_readoutName).idSpec().decoder(); + auto decoder = m_geoSvc->getDetector()->readout(m_readoutName).idSpec().decoder(); double sumE = 0.; std::vector sumElayers; double sumEactive = 0.; diff --git a/SimG4Components/src/InspectHitsCollectionsTool.cpp b/SimG4Components/src/InspectHitsCollectionsTool.cpp index f81a9f9..deda4d8 100644 --- a/SimG4Components/src/InspectHitsCollectionsTool.cpp +++ b/SimG4Components/src/InspectHitsCollectionsTool.cpp @@ -1,7 +1,9 @@ #include "InspectHitsCollectionsTool.h" +// k4FWCore +#include "k4Interface/IGeoSvc.h" + // FCCSW -#include "SimG4Interface/IGeoSvc.h" #include "SimG4Common/Geant4CaloHit.h" #include "SimG4Common/Geant4PreDigiTrackHit.h" diff --git a/SimG4Components/src/SimG4DD4hepDetector.cpp b/SimG4Components/src/SimG4DD4hepDetector.cpp index 74dd1de..2ef500e 100644 --- a/SimG4Components/src/SimG4DD4hepDetector.cpp +++ b/SimG4Components/src/SimG4DD4hepDetector.cpp @@ -1,7 +1,7 @@ #include "SimG4DD4hepDetector.h" -// FCCSW -#include "SimG4Interface/IGeoSvc.h" +// k4FWCore +#include "k4Interface/IGeoSvc.h" // Geant4 #include "G4VUserDetectorConstruction.hh" diff --git a/SimG4Components/src/SimG4MagneticFieldTool.cpp b/SimG4Components/src/SimG4MagneticFieldTool.cpp index de5d17c..71c923b 100644 --- a/SimG4Components/src/SimG4MagneticFieldTool.cpp +++ b/SimG4Components/src/SimG4MagneticFieldTool.cpp @@ -56,7 +56,7 @@ StatusCode SimG4MagneticFieldTool::initialize() { } info() << "Adding following field(s):" << endmsg; - dd4hep::Detector* detDescription = m_geoSvc->lcdd(); + dd4hep::Detector* detDescription = m_geoSvc->getDetector(); auto fields = detDescription->fields(); for (const auto& field : fields) { info() << " - " << field.first << ": " << field.second->type << endmsg; diff --git a/SimG4Components/src/SimG4SaveCalHits.cpp b/SimG4Components/src/SimG4SaveCalHits.cpp index 408a5aa..4a6d2bc 100644 --- a/SimG4Components/src/SimG4SaveCalHits.cpp +++ b/SimG4Components/src/SimG4SaveCalHits.cpp @@ -66,7 +66,7 @@ StatusCode SimG4SaveCalHits::initialize() { return StatusCode::FAILURE; } - auto lcdd = m_geoSvc->lcdd(); + auto lcdd = m_geoSvc->getDetector(); auto allReadouts = lcdd->readouts(); if (allReadouts.find(m_readoutName) == allReadouts.end()) { error() << "Readout " << m_readoutName << " not found! " diff --git a/SimG4Components/src/SimG4SaveTrackerHits.cpp b/SimG4Components/src/SimG4SaveTrackerHits.cpp index ca7d344..7b8cc09 100644 --- a/SimG4Components/src/SimG4SaveTrackerHits.cpp +++ b/SimG4Components/src/SimG4SaveTrackerHits.cpp @@ -65,7 +65,7 @@ StatusCode SimG4SaveTrackerHits::initialize() { return StatusCode::FAILURE; } - auto lcdd = m_geoSvc->lcdd(); + auto lcdd = m_geoSvc->getDetector(); auto allReadouts = lcdd->readouts(); if (allReadouts.find(m_readoutName) == allReadouts.end()) { error() << "Readout " << m_readoutName << " not found! " diff --git a/SimG4Components/src/SimG4SaveTrajectory.cpp b/SimG4Components/src/SimG4SaveTrajectory.cpp index 21722a9..12cc083 100644 --- a/SimG4Components/src/SimG4SaveTrajectory.cpp +++ b/SimG4Components/src/SimG4SaveTrajectory.cpp @@ -1,7 +1,9 @@ #include "SimG4SaveTrajectory.h" +// k4FwCore +#include "k4Interface/IGeoSvc.h" + // FCCSW -#include "SimG4Interface/IGeoSvc.h" #include "SimG4Common/Units.h" // Geant4 diff --git a/SimG4Interface/include/SimG4Interface/IGeoSvc.h b/SimG4Interface/include/SimG4Interface/IGeoSvc.h deleted file mode 100644 index 4aa7c04..0000000 --- a/SimG4Interface/include/SimG4Interface/IGeoSvc.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// IGeoSvc.h -// -// -// Created by Julia Hrdinka on 30/03/15. -// -// - -#ifndef IGEOSVC_H -#define IGEOSVC_H - -#include "GaudiKernel/IService.h" - -namespace dd4hep { -class Detector; -class DetElement; -} - -class G4VUserDetectorConstruction; - -class GAUDI_API IGeoSvc : virtual public IService { - -public: - /// InterfaceID - DeclareInterfaceID(IGeoSvc, 1, 0); - // receive DD4hep Geometry - virtual dd4hep::DetElement getDD4HepGeo() = 0; - virtual dd4hep::Detector* lcdd() = 0; - // receive Geant4 Geometry - virtual G4VUserDetectorConstruction* getGeant4Geo() = 0; - - virtual ~IGeoSvc() {} -}; - -#endif // IGEOSVC_H