Skip to content

Commit

Permalink
Make sure that TrackerHitPlanes and TrackerHit3Ds get converted to LC…
Browse files Browse the repository at this point in the history
…IO (#185)

* Make sure that TrackerHitPlanes and TrackerHit3D get converted to LCIO

* Make sure to keep existing behavior by defaulting to empty CellIDEncoding

* Make sure TrackerHit3D conversions work
  • Loading branch information
tmadlener authored Jun 9, 2024
1 parent c2fd175 commit 4f66668
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
29 changes: 16 additions & 13 deletions k4MarlinWrapper/k4MarlinWrapper/converters/EDM4hep2Lcio.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@
// std
#include <map>
#include <string>
#include <tuple>
#include <vector>

template <typename K, typename V> using ObjMapT = k4EDM4hep2LcioConv::VecMapT<K, V>;

using TrackMap = ObjMapT<lcio::TrackImpl*, edm4hep::Track>;
using ClusterMap = ObjMapT<lcio::ClusterImpl*, edm4hep::Cluster>;
using VertexMap = ObjMapT<lcio::VertexImpl*, edm4hep::Vertex>;
using TrackerHitMap = ObjMapT<lcio::TrackerHitImpl*, edm4hep::TrackerHit3D>;
using SimTrackerHitMap = ObjMapT<lcio::SimTrackerHitImpl*, edm4hep::SimTrackerHit>;
using CaloHitMap = ObjMapT<lcio::CalorimeterHitImpl*, edm4hep::CalorimeterHit>;
using SimCaloHitMap = ObjMapT<lcio::SimCalorimeterHitImpl*, edm4hep::SimCalorimeterHit>;
using RawCaloHitMap = ObjMapT<lcio::RawCalorimeterHitImpl*, edm4hep::RawCalorimeterHit>;
using TPCHitMap = ObjMapT<lcio::TPCHitImpl*, edm4hep::RawTimeSeries>;
using RecoParticleMap = ObjMapT<lcio::ReconstructedParticleImpl*, edm4hep::ReconstructedParticle>;
using MCParticleMap = ObjMapT<lcio::MCParticleImpl*, edm4hep::MCParticle>;
using ParticleIDMap = ObjMapT<lcio::ParticleIDImpl*, edm4hep::ParticleID>;
using TrackMap = ObjMapT<lcio::TrackImpl*, edm4hep::Track>;
using ClusterMap = ObjMapT<lcio::ClusterImpl*, edm4hep::Cluster>;
using VertexMap = ObjMapT<lcio::VertexImpl*, edm4hep::Vertex>;
using TrackerHitMap = ObjMapT<lcio::TrackerHitImpl*, edm4hep::TrackerHit3D>;
using TrackerHitPlaneMap = ObjMapT<lcio::TrackerHitPlaneImpl*, edm4hep::TrackerHitPlane>;
using SimTrackerHitMap = ObjMapT<lcio::SimTrackerHitImpl*, edm4hep::SimTrackerHit>;
using CaloHitMap = ObjMapT<lcio::CalorimeterHitImpl*, edm4hep::CalorimeterHit>;
using SimCaloHitMap = ObjMapT<lcio::SimCalorimeterHitImpl*, edm4hep::SimCalorimeterHit>;
using RawCaloHitMap = ObjMapT<lcio::RawCalorimeterHitImpl*, edm4hep::RawCalorimeterHit>;
using TPCHitMap = ObjMapT<lcio::TPCHitImpl*, edm4hep::RawTimeSeries>;
using RecoParticleMap = ObjMapT<lcio::ReconstructedParticleImpl*, edm4hep::ReconstructedParticle>;
using MCParticleMap = ObjMapT<lcio::MCParticleImpl*, edm4hep::MCParticle>;
using ParticleIDMap = ObjMapT<lcio::ParticleIDImpl*, edm4hep::ParticleID>;

struct CollectionPairMappings;

Expand All @@ -76,6 +76,9 @@ class EDM4hep2LcioTool : public GaudiTool, virtual public IEDMConverter {
void convertTrackerHits(TrackerHitMap& trackerhits_vec, const std::string& e4h_coll_name,
const std::string& lcio_coll_name, lcio::LCEventImpl* lcio_event);

void convertTrackerHitPlanes(TrackerHitPlaneMap& trackerhits_vec, const std::string& e4h_coll_name,
const std::string& lcio_coll_name, lcio::LCEventImpl* lcio_event);

void convertSimTrackerHits(SimTrackerHitMap& simtrackerhits_vec, const std::string& e4h_coll_name,
const std::string& lcio_coll_name, lcio::LCEventImpl* lcio_event);

Expand Down
47 changes: 32 additions & 15 deletions k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ using namespace k4MarlinWrapper;
using GlobalMapWrapper = AnyDataWrapper<GlobalConvertedObjectsMap>;

struct CollectionPairMappings {
TrackMap tracks{};
TrackerHitMap trackerHits{};
SimTrackerHitMap simTrackerHits{};
CaloHitMap caloHits{};
RawCaloHitMap rawCaloHits{};
SimCaloHitMap simCaloHits{};
TPCHitMap tpcHits{};
ClusterMap clusters{};
VertexMap vertices{};
RecoParticleMap recoParticles{};
MCParticleMap mcParticles{};
ParticleIDMap particleIDs{};
TrackMap tracks{};
TrackerHitMap trackerHits{};
TrackerHitPlaneMap trackerHitsPlane{};
SimTrackerHitMap simTrackerHits{};
CaloHitMap caloHits{};
RawCaloHitMap rawCaloHits{};
SimCaloHitMap simCaloHits{};
TPCHitMap tpcHits{};
ClusterMap clusters{};
VertexMap vertices{};
RecoParticleMap recoParticles{};
MCParticleMap mcParticles{};
ParticleIDMap particleIDs{};
};

EDM4hep2LcioTool::EDM4hep2LcioTool(const std::string& type, const std::string& name, const IInterface* parent)
Expand Down Expand Up @@ -95,7 +96,7 @@ void EDM4hep2LcioTool::convertTrackerHits(TrackerHitMap& trackerhits_vec, const
MetaDataHandle<std::string> cellIDStrHandle{trackerhits_handle, edm4hep::CellIDEncoding, Gaudi::DataHandle::Reader};

auto conv_trackerhits =
EDM4hep2LCIOConv::convertTrackerHits(trackerhits_coll, cellIDStrHandle.get(), trackerhits_vec);
EDM4hep2LCIOConv::convertTrackerHits(trackerhits_coll, cellIDStrHandle.get(""), trackerhits_vec);

// Add all trackerhits to event
lcio_event->addCollection(conv_trackerhits.release(), lcio_coll_name);
Expand All @@ -107,6 +108,20 @@ void EDM4hep2LcioTool::convertParticleIDs(ParticleIDMap& pidMap, const std::stri
EDM4hep2LCIOConv::convertParticleIDs(pidHandle.get(), pidMap, algoId);
}

void EDM4hep2LcioTool::convertTrackerHitPlanes(TrackerHitPlaneMap& trackerhits_vec, const std::string& e4h_coll_name,
const std::string& lcio_coll_name, lcio::LCEventImpl* lcio_event) {
DataHandle<edm4hep::TrackerHitPlaneCollection> trackerhits_handle{e4h_coll_name, Gaudi::DataHandle::Reader, this};
const auto trackerhits_coll = trackerhits_handle.get();

MetaDataHandle<std::string> cellIDStrHandle{trackerhits_handle, edm4hep::CellIDEncoding, Gaudi::DataHandle::Reader};

auto conv_trackerhits =
EDM4hep2LCIOConv::convertTrackerHitPlanes(trackerhits_coll, cellIDStrHandle.get(""), trackerhits_vec);

// Add all trackerhits to event
lcio_event->addCollection(conv_trackerhits.release(), lcio_coll_name);
}

// Convert EDM4hep SimTrackerHits to LCIO
// Add converted LCIO ptr and original EDM4hep collection to vector of pairs
// Add LCIO Collection Vector to LCIO event
Expand Down Expand Up @@ -275,8 +290,10 @@ void EDM4hep2LcioTool::convertAdd(const std::string& e4h_coll_name, const std::s

if (fulltype == "edm4hep::Track") {
convertTracks(collection_pairs.tracks, e4h_coll_name, lcio_coll_name, lcio_event);
} else if (fulltype == "edm4hep::TrackerHit") {
} else if (fulltype == "edm4hep::TrackerHit" || fulltype == "edm4hep::TrackerHit3D") {
convertTrackerHits(collection_pairs.trackerHits, e4h_coll_name, lcio_coll_name, lcio_event);
} else if (fulltype == "edm4hep::TrackerHitPlane") {
convertTrackerHitPlanes(collection_pairs.trackerHitsPlane, e4h_coll_name, lcio_coll_name, lcio_event);
} else if (fulltype == "edm4hep::SimTrackerHit") {
convertSimTrackerHits(collection_pairs.simTrackerHits, e4h_coll_name, lcio_coll_name, lcio_event);
} else if (fulltype == "edm4hep::CalorimeterHit") {
Expand Down Expand Up @@ -308,7 +325,7 @@ void EDM4hep2LcioTool::convertAdd(const std::string& e4h_coll_name, const std::s
} else {
warning() << "Error trying to convert requested " << fulltype << " with name " << e4h_coll_name << endmsg;
warning() << "List of supported types: "
<< "Track, TrackerHit, SimTrackerHit, "
<< "Track, TrackerHit3D, TrackerHitPlane, SimTrackerHit, "
<< "Cluster, CalorimeterHit, RawCalorimeterHit, "
<< "SimCalorimeterHit, Vertex, ReconstructedParticle, "
<< "MCParticle." << endmsg;
Expand Down

0 comments on commit 4f66668

Please sign in to comment.