Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GeoSvc to get dd4hep geometry instead of loading it ourselves #17

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 5 additions & 38 deletions k4ActsTracking/src/components/ActsGeoSvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,20 @@
#include "DD4hep/Printout.h"
#include "GaudiKernel/Service.h"
#include "TGeoManager.h"
#include "k4Interface/IGeoSvc.h"

using namespace Gaudi;

DECLARE_COMPONENT(ActsGeoSvc)

ActsGeoSvc::ActsGeoSvc(const std::string& name, ISvcLocator* svc) : base_class(name, svc), m_log(msgSvc(), name) {}

ActsGeoSvc::~ActsGeoSvc() {
if (m_dd4hepGeo != nullptr) {
try {
m_dd4hepGeo->destroyInstance();
m_dd4hepGeo = nullptr;
} catch (...) {
}
}
}
ActsGeoSvc::~ActsGeoSvc(){};

StatusCode ActsGeoSvc::initialize() {
if (m_xmlFileNames.size() > 0) {
m_log << MSG::INFO << "Loading xml files from: '" << m_xmlFileNames << "'" << endmsg;
} else {
m_log << MSG::ERROR << "No xml file!" << endmsg;
return StatusCode::FAILURE;
}

/// Check if the DD4Hep Geometry is built successfully
if (buildDD4HepGeo().isFailure()) {
m_log << MSG::ERROR << "Could not build DD4Hep geometry" << endmsg;
return StatusCode::FAILURE;
} else {
m_log << MSG::INFO << "DD4Hep geometry SUCCESSFULLY built" << endmsg;
}
m_dd4hepGeo = svcLocator()->service<IGeoSvc>(m_geoSvcName)->getDetector();
// necessary?
// m_dd4hepGeo->addExtension<IActsGeoSvc>(this);

Acts::BinningType bTypePhi = Acts::equidistant;
Acts::BinningType bTypeR = Acts::equidistant;
Expand Down Expand Up @@ -96,21 +78,6 @@ StatusCode ActsGeoSvc::execute() { return StatusCode::SUCCESS; }

StatusCode ActsGeoSvc::finalize() { return StatusCode::SUCCESS; }

StatusCode ActsGeoSvc::buildDD4HepGeo() {
m_dd4hepGeo = &(dd4hep::Detector::getInstance());
m_dd4hepGeo->addExtension<IActsGeoSvc>(this);

/// Load geometry
for (auto& filename : m_xmlFileNames) {
m_log << MSG::INFO << "Loading geometry from file: '" << filename << "'" << endmsg;
m_dd4hepGeo->fromCompact(filename);
}
m_dd4hepGeo->volumeManager();
m_dd4hepGeo->apply("DD4hepVolumeManager", 0, nullptr);

return StatusCode::SUCCESS;
}

/// Create a geometry OBJ file
StatusCode ActsGeoSvc::createGeoObj() {
// Convert DD4Hep geometry to acts
Expand Down
9 changes: 3 additions & 6 deletions k4ActsTracking/src/components/ActsGeoSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* limitations under the License.
*/

#ifndef GEOSVC_H
#define GEOSVC_H
#ifndef ACTSGEOSVC_H
#define ACTSGEOSVC_H

#include <Acts/Material/IMaterialDecorator.hpp>
#include "Acts/Definitions/Common.hpp"
Expand Down Expand Up @@ -62,8 +62,7 @@ class ActsGeoSvc : public extends<Service, IActsGeoSvc> {
/// ACTS surface lookup container for hit surfaces that generate smeared hits
VolumeSurfaceMap m_surfaces;

/// XML-files with the detector description
Gaudi::Property<std::vector<std::string>> m_xmlFileNames{this, "detectors", {}, "Detector descriptions XML-files"};
Gaudi::Property<std::string> m_geoSvcName{this, "GeoSvcName", "GeoSvc", "The name of the GeoSvc instance"};

/// Option for the Debug Geometry
Gaudi::Property<bool> m_debugGeometry{this, "debugGeometry", false, "Option for geometry debugging"};
Expand All @@ -84,8 +83,6 @@ class ActsGeoSvc : public extends<Service, IActsGeoSvc> {

virtual StatusCode finalize() final;

StatusCode buildDD4HepGeo();

StatusCode createGeoObj();

virtual const Acts::TrackingGeometry& trackingGeometry() const;
Expand Down
6 changes: 3 additions & 3 deletions k4ActsTracking/src/components/IActsGeoSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* limitations under the License.
*/

#ifndef IGEOSVC_H
#define IGEOSVC_H
#ifndef IACTSGEOSVC_H
#define IACTSGEOSVC_H

#include <GaudiKernel/IService.h>
#include <unordered_map>
Expand Down Expand Up @@ -46,4 +46,4 @@ class GAUDI_API IActsGeoSvc : virtual public IService {
virtual ~IActsGeoSvc() {}
};

#endif // IGEOSVC_H
#endif // IACTSGEOSVC_H
6 changes: 6 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ add_test(NAME LoadODD
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND k4run options/geosvc.py)
set_test_env(LoadODD)

add_test(NAME CheckODDObjFile
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND test -s MyObjFile.mtl)
set_test_env(CheckODDObjFile)
set_tests_properties(CheckODDObjFile PROPERTIES DEPENDS LoadODD)
29 changes: 18 additions & 11 deletions test/options/geosvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,26 @@
# limitations under the License.
#
import os
from pprint import pprint
from Gaudi.Configuration import *
from Gaudi.Configuration import INFO

from Configurables import ActsGeoSvc
from Configurables import ActsGeoSvc, ApplicationMgr, GeoSvc

algList = []

a = ActsGeoSvc("ActsGeoSvc")
a.detectors = [f"{os.environ['OPENDATADETECTOR']}/xml/OpenDataDetector.xml"]
a.debugGeometry = True
a.outputFileName = "MyObjFile"
from Configurables import ApplicationMgr
dd4hep_geo = GeoSvc("GeoSvc")
dd4hep_geo.detectors = [f"{os.environ['OPENDATADETECTOR']}/xml/OpenDataDetector.xml"]
dd4hep_geo.EnableGeant4Geo = False

ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=2, ExtSvc=[
a
], OutputLevel=INFO)
acts_geo = ActsGeoSvc("ActsGeoSvc")
acts_geo.GeoSvcName = dd4hep_geo.name()
acts_geo.debugGeometry = True
acts_geo.outputFileName = "MyObjFile"

ApplicationMgr(
TopAlg=algList,
EvtSel="NONE",
EvtMax=2,
# order dependent...
ExtSvc=[dd4hep_geo, acts_geo],
OutputLevel=INFO,
)