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

WIP: An example to decode the CellID using the DD4hep way.

parent 35e658aa
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,11 @@ find_package(podio REQUIRED) ...@@ -6,6 +6,11 @@ find_package(podio REQUIRED)
find_package(LCIO REQUIRED) find_package(LCIO REQUIRED)
find_package(EDM4HEP REQUIRED) find_package(EDM4HEP REQUIRED)
find_package(K4FWCore REQUIRED) find_package(K4FWCore REQUIRED)
find_package(DD4hep COMPONENTS DDRec DDParsers REQUIRED)
gaudi_depends_on_subdirs(
Detector/DetInterface
)
set(Examples_srcs set(Examples_srcs
src/HelloWorld/*.cpp src/HelloWorld/*.cpp
...@@ -13,6 +18,7 @@ set(Examples_srcs ...@@ -13,6 +18,7 @@ set(Examples_srcs
src/SecondAlg/*.cpp src/SecondAlg/*.cpp
# src/PlcioTest/*.cpp # src/PlcioTest/*.cpp
src/Edm4hepTest/*.cpp src/Edm4hepTest/*.cpp
src/DumpIDAlg/*.cpp
) )
# Headers and Libraries # Headers and Libraries
...@@ -23,6 +29,7 @@ gaudi_install_headers(Examples) ...@@ -23,6 +29,7 @@ gaudi_install_headers(Examples)
gaudi_add_module(Examples ${Examples_srcs} gaudi_add_module(Examples ${Examples_srcs}
INCLUDE_DIRS K4FWCore GaudiAlgLib GaudiKernel ${podio_INCLUDE_DIRS} ${LCIO_INCLUDE_DIRS} INCLUDE_DIRS K4FWCore GaudiAlgLib GaudiKernel ${podio_INCLUDE_DIRS} ${LCIO_INCLUDE_DIRS}
LINK_LIBRARIES K4FWCore GaudiAlgLib GaudiKernel ${LCIO_LIBRARIES} LINK_LIBRARIES K4FWCore GaudiAlgLib GaudiKernel ${LCIO_LIBRARIES}
DD4hep ${DD4hep_COMPONENT_LIBRARIES}
# Force loading the libraries. # Force loading the libraries.
-Wl,--no-as-needed EDM4HEP::edm4hep EDM4HEP::edm4hepDict ${podio_LIBRARIES} podio::podioRootIO -Wl,--as-needed -Wl,--no-as-needed EDM4HEP::edm4hep EDM4HEP::edm4hepDict ${podio_LIBRARIES} podio::podioRootIO -Wl,--as-needed
) )
......
#include "DumpIDAlg.h"
#include "edm4hep/EventHeaderCollection.h"
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/SimCalorimeterHitCollection.h"
#include "edm4hep/CaloHitContributionCollection.h"
#include "DD4hep/Detector.h"
#include "DD4hep/IDDescriptor.h"
#include "DD4hep/Plugins.h"
DECLARE_COMPONENT(DumpIDAlg)
DumpIDAlg::DumpIDAlg(const std::string& name, ISvcLocator* svcLoc)
: GaudiAlgorithm(name, svcLoc), m_dd4hep_geo(nullptr), m_decoder(nullptr)
{
}
StatusCode DumpIDAlg::initialize()
{
m_geosvc = service<IGeoSvc>("GeoSvc");
if (!m_geosvc) {
error() << "Failed to find GeoSvc." << endmsg;
return StatusCode::FAILURE;
}
m_dd4hep_geo = m_geosvc->lcdd();
if (!m_dd4hep_geo) {
error() << "failed to retrieve dd4hep_geo: " << m_dd4hep_geo << endmsg;
return StatusCode::FAILURE;
}
// get the DD4hep readout
auto readouts = m_dd4hep_geo->readouts();
const std::string name_readout = "EcalBarrelCollection";
if (readouts.find(name_readout) != readouts.end()) {
dd4hep::Readout readout = m_dd4hep_geo->readout(name_readout);
auto m_idspec = readout.idSpec();
info() << "The idspec is " << m_idspec.fieldDescription() << " for " << name_readout << endmsg;
dd4hep::DDSegmentation::BitFieldCoder* decoder = m_idspec.decoder();
m_decoder = decoder;
}
if (!m_decoder) {
error() << "Failed to get the decoder. " << endmsg;
return StatusCode::FAILURE;
}
return GaudiAlgorithm::initialize();
}
StatusCode DumpIDAlg::execute()
{
auto ecalBarrelCol = m_EcalBarrelCol.get();
for (auto calohit: *ecalBarrelCol) {
auto cellid = calohit.getCellID();
int id_system = m_decoder->get(cellid, "system");
int id_module = m_decoder->get(cellid, "module");
int id_stave = m_decoder->get(cellid, "stave");
int id_tower = m_decoder->get(cellid, "tower");
int id_layer = m_decoder->get(cellid, "layer");
int id_wafer = m_decoder->get(cellid, "wafer");
int id_cellX = m_decoder->get(cellid, "cellX");
int id_cellY = m_decoder->get(cellid, "cellY");
info() << "Calo hit cellid: " << cellid
<< " system: " << id_system
<< " module: " << id_module
<< " stave: " << id_stave
<< " tower: " << id_tower
<< " layer: " << id_layer
<< " wafer: " << id_wafer
<< " cellX: " << id_cellX
<< " cellY: " << id_cellY
<< endmsg;
}
return StatusCode::SUCCESS;
}
StatusCode DumpIDAlg::finalize()
{
return GaudiAlgorithm::finalize();
}
#ifndef DumpIDAlg_h
#define DumpIDAlg_h
#include "FWCore/DataHandle.h"
#include "GaudiAlg/GaudiAlgorithm.h"
#include "DetInterface/IGeoSvc.h"
#include "DD4hep/Detector.h"
namespace edm4hep {
class EventHeaderCollection;
class MCParticleCollection;
class SimCalorimeterHitCollection;
class CaloHitContributionCollection;
}
class DumpIDAlg: public GaudiAlgorithm
{
public:
DumpIDAlg(const std::string& name, ISvcLocator* svcLoc);
virtual StatusCode initialize();
virtual StatusCode execute();
virtual StatusCode finalize();
private:
SmartIF<IGeoSvc> m_geosvc;
dd4hep::Detector* m_dd4hep_geo;
dd4hep::DDSegmentation::BitFieldCoder* m_decoder;
DataHandle<edm4hep::SimCalorimeterHitCollection> m_EcalBarrelCol{"EcalBarrelCollection",
Gaudi::DataHandle::Reader, this};
};
#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