Skip to content

Commit

Permalink
TrackingCellIDEncodingSvc: add service to set the Cell ID encoding st…
Browse files Browse the repository at this point in the history
…ring for iLCSoft track reconstruction
  • Loading branch information
andresailer committed Aug 30, 2023
1 parent c7f4d40 commit d0b3d2b
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 0 deletions.
20 changes: 20 additions & 0 deletions doc/starterkit/k4MarlinWrapperCLIC/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
2 changes: 2 additions & 0 deletions k4MarlinWrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
48 changes: 48 additions & 0 deletions k4MarlinWrapper/k4MarlinWrapper/TrackingCellIDEncodingSvc.h
Original file line number Diff line number Diff line change
@@ -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 <GaudiKernel/Service.h>

//LCIO Includes
#include <UTIL/LCTrackerConf.h>

#include <string>

class IGeoSvc;

class TrackingCellIDEncodingSvc : public extends<Service, IService> {
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<std::string> m_encodingStringVariable{
this, "EncodingStringParameterName", "GlobalTrackerReadoutID",
"The name of the DD4hep constant that contains the Encoding string for tracking detectors"};

private:
SmartIF<IGeoSvc> m_geoSvc;
};

#endif // CELLIDSVC_H
53 changes: 53 additions & 0 deletions k4MarlinWrapper/src/components/TrackingCellIDEncodingSvc.cpp
Original file line number Diff line number Diff line change
@@ -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 <k4Interface/IGeoSvc.h>

#include <GaudiKernel/MsgStream.h>

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; }
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
)
Expand Down
42 changes: 42 additions & 0 deletions test/gaudi_opts/geoTest_cld.py
Original file line number Diff line number Diff line change
@@ -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
)
24 changes: 24 additions & 0 deletions test/scripts/clicGeoTest.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d0b3d2b

Please sign in to comment.