Skip to content

Commit

Permalink
Convert all TrackerHit types (#49)
Browse files Browse the repository at this point in the history
* Also attach TrackerHitPlane to Tracks

* Make sure to also TrackerHits correctly from EDM4hep to LCIO
  • Loading branch information
tmadlener authored Feb 23, 2024
1 parent 491011a commit 715bc62
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,11 @@ namespace EDM4hep2LCIOConv {
if (const auto lcio_trh = k4EDM4hep2LcioConv::detail::mapLookupFrom(edm_tr_trh, lookup_pairs.trackerHits)) {
lcio_tr->addHit(lcio_trh.value());
}
else if (
const auto lcio_trh =
k4EDM4hep2LcioConv::detail::mapLookupFrom(edm_tr_trh, lookup_pairs.trackerHitPlanes)) {
lcio_tr->addHit(lcio_trh.value());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@ namespace LCIO2EDM4hepConv {
/**
* Resolve the relations for Tracks
*/
template<typename TrackMapT, typename TrackHitMapT, typename TPCHitMapT, typename THPlaneHitMapT>
template<typename TrackMapT, typename TrackHitMapT, typename THPlaneHitMapT, typename TPCHitMapT>
void resolveRelationsTracks(
TrackMapT& tracksMap,
const TrackHitMapT& trackerHitMap,
const TPCHitMapT&,
const THPlaneHitMapT&);
const THPlaneHitMapT&,
const TPCHitMapT&);

/**
* Resolve the relations for Vertices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,16 +782,15 @@ namespace LCIO2EDM4hepConv {
}
}

template<typename TrackMapT, typename TrackHitMapT, typename TPCHitMapT, typename THPlaneHitMapT>
template<typename TrackMapT, typename TrackHitMapT, typename THPlaneHitMapT, typename TPCHitMapT>
void resolveRelationsTracks(
TrackMapT& tracksMap,
const TrackHitMapT& trackerHitMap,
const TPCHitMapT&,
const THPlaneHitMapT&)
const THPlaneHitMapT& trackerHitPlaneMap,
const TPCHitMapT&)
{
for (auto& [lcio, edm] : tracksMap) {
auto tracks = lcio->getTracks();
auto trackerHits = lcio->getTrackerHits();
for (auto t : tracks) {
if (t == nullptr) {
continue;
Expand All @@ -803,42 +802,29 @@ namespace LCIO2EDM4hepConv {
// std::cerr << "Couldn't find tracks to add to Tracks Relations in edm" << std::endl;
}
}
for (auto th : trackerHits) {
const auto trackerHits = lcio->getTrackerHits();
for (const auto th : trackerHits) {
bool found = false;
if (th == nullptr) {
continue;
}
if (const auto trHit = k4EDM4hep2LcioConv::detail::mapLookupTo(th, trackerHitMap)) {
edm.addToTrackerHits(trHit.value());
if (const auto typedTH = dynamic_cast<EVENT::TrackerHitPlane*>(th)) {
if (const auto trHit = k4EDM4hep2LcioConv::detail::mapLookupTo(typedTH, trackerHitPlaneMap)) {
edm.addToTrackerHits(trHit.value());
found = true;
}
}
else if (auto typedTH = dynamic_cast<EVENT::TrackerHit*>(th)) {
if (const auto trHit = k4EDM4hep2LcioConv::detail::mapLookupTo(typedTH, trackerHitMap)) {
edm.addToTrackerHits(trHit.value());
found = true;
}
}

if (!found) {
std::cerr << "Couldn't find a edm4hep TrackerHit for an LCIO TrackerHit when resolving "
<< "relations for a Track" << std::endl;
}
// else {
// std::cerr << "Couldn't find trackerHit to add to Relations for tracks in edm\n"
// << " This is due to it being a TrackerHitPlane or TPCHit" << std::endl;

// // This Code looks for the trackerHit in the TPCHit Map aswell as the
// // trackerHitPlane Map. Those relations can not be set for a track in
// // edm4HEP. In all tests the missing trackerHits were located in
// // either of these maps.
// const auto tpchit = dynamic_cast<lcio::TPCHit*>(th);
// const auto trackerhitplane = dynamic_cast<lcio::TrackerHitPlane*>(th);
// if (tpchit != nullptr) {
// const auto it = TPCHitMap.find(tpchit);
// if (it != TPCHitMap.end()) {
// std::cout << "trackerHit found in TPCHit map !" << std::endl;
// }
// else {
// std::cerr << "TRACKERHIT also could not be found in TPCHit Map" << std::endl;
// }
// }
// else if (trackerhitplane != nullptr) {
// const auto it = trackerhitplaneMap.find(trackerhitplane);
// if (it != trackerhitplaneMap.end()) {
// std::cout << "trackerHit found in TrackerHitPlane map !" << std::endl;
// }
// else {
// std::cerr << "TRACKERHIT also could not be found in TrackerHitPlane Map" << std::endl;
// }
// }
// }
}
}
}
Expand Down Expand Up @@ -875,7 +861,7 @@ namespace LCIO2EDM4hepConv {
updateMaps.recoParticles, lookupMaps.recoParticles, lookupMaps.vertices, lookupMaps.clusters, lookupMaps.tracks);
resolveRelationsSimTrackerHits(updateMaps.simTrackerHits, lookupMaps.mcParticles);
resolveRelationsClusters(updateMaps.clusters, lookupMaps.caloHits);
resolveRelationsTracks(updateMaps.tracks, lookupMaps.trackerHits, lookupMaps.tpcHits, lookupMaps.trackerHitPlanes);
resolveRelationsTracks(updateMaps.tracks, lookupMaps.trackerHits, lookupMaps.trackerHitPlanes, lookupMaps.tpcHits);
resolveRelationsVertices(updateMaps.vertices, lookupMaps.recoParticles);
}

Expand Down
13 changes: 10 additions & 3 deletions tests/src/CompareEDM4hepLCIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,19 @@ bool compare(const EVENT::Track* lcioElem, const edm4hep::Track& edm4hepElem, co
}
}

const auto& lcioHits = lcioElem->getTrackerHits();
const auto edmHits = edm4hepElem.getTrackerHits();
ASSERT_COMPARE_VALS(lcioHits.size(), edmHits.size(), "number of tracker hits in Track");
int iHit = 0;
for (const auto* lcioHit : lcioElem->getTrackerHits()) {
// In EDM4hep only TrackerHits can be used in Tracks, so here we also only
// compare those
if (dynamic_cast<const IMPL::TrackerHitImpl*>(lcioHit)) {
if (const auto typedHit = dynamic_cast<const EVENT::TrackerHitPlane*>(lcioHit)) {
if (!compareRelation(
typedHit, edmHits[iHit], objectMaps.trackerHitPlanes, "TrackerHit " + std::to_string(iHit) + " in Track")) {
return false;
}
iHit++;
}
else if (dynamic_cast<const IMPL::TrackerHitImpl*>(lcioHit)) {
if (!compareRelation(
lcioHit, edmHits[iHit], objectMaps.trackerHits, "TrackerHit " + std::to_string(iHit) + " in Track")) {
return false;
Expand Down
3 changes: 3 additions & 0 deletions tests/src/EDM4hep2LCIOUtilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ edm4hep::TrackCollection createTracks(
const int subdetectorhitnumbers,
const int num_track_states,
const edm4hep::TrackerHit3DCollection& trackerHits,
const edm4hep::TrackerHitPlaneCollection& trackerHitPlanes,
const std::vector<std::size_t>& link_trackerhit_idcs,
const std::vector<test_config::IdxPair>& track_link_tracks_idcs)
{
Expand All @@ -220,6 +221,7 @@ edm4hep::TrackCollection createTracks(

for (auto& idx : link_trackerhit_idcs) {
elem.addToTrackerHits(trackerHits[idx]);
elem.addToTrackerHits(trackerHitPlanes[idx]);
}

for (int j = 0; j < num_track_states; ++j) {
Expand Down Expand Up @@ -342,6 +344,7 @@ podio::Frame createExampleEvent()
test_config::nSubdetectorHitNumbers,
test_config::nTrackStates,
trackerHits,
trackerHitPlanes,
test_config::trackTrackerHitIdcs,
test_config::trackTrackIdcs),
"tracks");
Expand Down

0 comments on commit 715bc62

Please sign in to comment.