diff --git a/doc/starterkit/k4MarlinWrapperCLIC/Readme.md b/doc/starterkit/k4MarlinWrapperCLIC/Readme.md index 3008ef6c..46a2a340 100644 --- a/doc/starterkit/k4MarlinWrapperCLIC/Readme.md +++ b/doc/starterkit/k4MarlinWrapperCLIC/Readme.md @@ -157,3 +157,23 @@ result=$? [ $result = "0" ] || [ $result = "4" ] && true ``` +### DD4hep Geometry Information + +The ``MarlinDD4hep::InitializeDD4hep`` processor can be replaced by the ``k4SimGeant4::GeoSvc`` and the +``TrackingCellIDEncodingSvc`` the latter of which is part of the k4MarlinWrapper reposityr. + +For example: + +```python +svcList = [] +geoservice = GeoSvc("GeoSvc") +geoservice.detectors = [os.environ["K4GEO"]+"/CLIC/compact/CLIC_o3_v15/CLIC_o3_v15.xml"] +geoservice.OutputLevel = INFO +geoservice.EnableGeant4Geo = False +svcList.append(geoservice) + +cellIDSvc = TrackingCellIDEncodingSvc("CellIDSvc") +cellIDSvc.EncodingStringParameterName = "GlobalTrackerReadoutID" +cellIDSvc.OutputLevel = INFO +svcList.append(cellIDSvc) +``` diff --git a/k4MarlinWrapper/CMakeLists.txt b/k4MarlinWrapper/CMakeLists.txt index 5de73dc8..73054ede 100644 --- a/k4MarlinWrapper/CMakeLists.txt +++ b/k4MarlinWrapper/CMakeLists.txt @@ -40,9 +40,11 @@ target_include_directories(k4MarlinWrapperPlugins PUBLIC gaudi_add_module(MarlinWrapper SOURCES src/components/MarlinProcessorWrapper.cpp + src/components/TrackingCellIDEncodingSvc.cpp LINK Gaudi::GaudiAlgLib k4FWCore::k4FWCore + k4FWCore::k4Interface ${Marlin_LIBRARIES} EDM4HEP::edm4hep ) diff --git a/k4MarlinWrapper/k4MarlinWrapper/TrackingCellIDEncodingSvc.h b/k4MarlinWrapper/k4MarlinWrapper/TrackingCellIDEncodingSvc.h new file mode 100644 index 00000000..3b0e52c3 --- /dev/null +++ b/k4MarlinWrapper/k4MarlinWrapper/TrackingCellIDEncodingSvc.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019-2023 Key4hep-Project. + * + * This file is part of Key4hep. + * See https://key4hep.github.io/key4hep-doc/ for further info. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef CELLIDSVC_H +#define CELLIDSVC_H + +#include + +//LCIO Includes +#include + +#include + +class IGeoSvc; + +class TrackingCellIDEncodingSvc : public extends { +public: + TrackingCellIDEncodingSvc(const std::string& name, ISvcLocator* svc); + + virtual ~TrackingCellIDEncodingSvc(); + virtual StatusCode initialize() final; + virtual StatusCode finalize() final; + + /// Property to configure which DD4hep constant to use for the encodingString + Gaudi::Property m_encodingStringVariable{ + this, "EncodingStringParameterName", "GlobalTrackerReadoutID", + "The name of the DD4hep constant that contains the Encoding string for tracking detectors"}; + +private: + SmartIF m_geoSvc; +}; + +#endif // CELLIDSVC_H diff --git a/k4MarlinWrapper/src/components/TrackingCellIDEncodingSvc.cpp b/k4MarlinWrapper/src/components/TrackingCellIDEncodingSvc.cpp new file mode 100644 index 00000000..08837df0 --- /dev/null +++ b/k4MarlinWrapper/src/components/TrackingCellIDEncodingSvc.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2019-2023 Key4hep-Project. + * + * This file is part of Key4hep. + * See https://key4hep.github.io/key4hep-doc/ for further info. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "k4MarlinWrapper/TrackingCellIDEncodingSvc.h" + +// k4fwcore +#include + +#include + +DECLARE_COMPONENT(TrackingCellIDEncodingSvc); + +TrackingCellIDEncodingSvc::TrackingCellIDEncodingSvc(const std::string& name, ISvcLocator* svc) + : base_class(name, svc), m_geoSvc(svc->service("GeoSvc")) {} + +TrackingCellIDEncodingSvc::~TrackingCellIDEncodingSvc() {} + +StatusCode TrackingCellIDEncodingSvc::initialize() { + try { + info() << "Taking the encoding string as specified in dd4hep constant: " << m_encodingStringVariable.value() + << endmsg; + + auto encodingString = m_geoSvc->constantAsString(m_encodingStringVariable.value()); + + info() << "LCTrackerCellID::_encoding will be set to " << encodingString << endmsg; + + UTIL::LCTrackerCellID::instance().set_encoding_string(encodingString); + + return StatusCode::SUCCESS; + + } catch (std::exception& e) { + error() << "Failed to set the encoding string!\n"; + error() << e.what() << endmsg; + return StatusCode::FAILURE; + } +} + +StatusCode TrackingCellIDEncodingSvc::finalize() { return StatusCode::SUCCESS; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 39708722..6d4b7e2b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -86,6 +86,9 @@ if (BASH_PROGRAM) # Run clicReconstruction sequence with LCIO input and output, no converters, with inter-event parallelism add_test( clicRec_lcio_mt ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/clicRec_lcio_mt.sh ) + # Test the GeoSvc and TrackingCellIDEncodingSvc + add_test( clic_geo_test ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/clicGeoTest.sh ) + set_tests_properties ( simple_processors simple_processors2 @@ -97,6 +100,7 @@ if (BASH_PROGRAM) same_num_io clicRec_lcio_mt clicRec_edm4hep_input + clic_geo_test PROPERTIES ENVIRONMENT "TEST_DIR=${CMAKE_CURRENT_SOURCE_DIR};LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64:$ENV{LD_LIBRARY_PATH};PYTHONPATH=${CMAKE_INSTALL_PREFIX}/python:$ENV{PYTHONPATH}" ) diff --git a/test/gaudi_opts/geoTest_cld.py b/test/gaudi_opts/geoTest_cld.py new file mode 100644 index 00000000..60efec27 --- /dev/null +++ b/test/gaudi_opts/geoTest_cld.py @@ -0,0 +1,42 @@ +# +# Copyright (c) 2019-2023 Key4hep-Project. +# +# This file is part of Key4hep. +# See https://key4hep.github.io/key4hep-doc/ for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from Gaudi.Configuration import * + +from Configurables import TrackingCellIDEncodingSvc, GeoSvc +algList = [] +svcList = [] + +geoservice = GeoSvc("GeoSvc") +geoservice.detectors = [os.environ["K4GEO"]+"/CLIC/compact/CLIC_o3_v15/CLIC_o3_v15.xml"] +geoservice.OutputLevel = INFO +geoservice.EnableGeant4Geo = False +svcList.append(geoservice) + +cellIDSvc = TrackingCellIDEncodingSvc("CellIDSvc") +cellIDSvc.EncodingStringParameterName = "GlobalTrackerReadoutID" +cellIDSvc.OutputLevel = DEBUG +svcList.append(cellIDSvc) + +from Configurables import ApplicationMgr +ApplicationMgr( TopAlg = algList, + EvtSel = 'NONE', + EvtMax = 3, + ExtSvc = svcList, + OutputLevel=WARNING + ) diff --git a/test/scripts/clicGeoTest.sh b/test/scripts/clicGeoTest.sh new file mode 100644 index 00000000..2bfdf594 --- /dev/null +++ b/test/scripts/clicGeoTest.sh @@ -0,0 +1,24 @@ +#!/bin/bash +## +## Copyright (c) 2019-2023 Key4hep-Project. +## +## This file is part of Key4hep. +## See https://key4hep.github.io/key4hep-doc/ for further info. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +# exit if command or variable fails +set -eu + +k4run $TEST_DIR/gaudi_opts/geoTest_cld.py