From d088d6c79cbdb7566db7b267fc101177c5fe073d Mon Sep 17 00:00:00 2001 From: tmadlener Date: Wed, 27 Sep 2023 11:27:44 +0200 Subject: [PATCH] Fix minor issues uncovered by tests - Reset SimCalorimeterHit energy after adding Contributions as adding contributions changes the energy - Make sure to populate daughters in the right order in the example MCCollection creation --- k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp | 6 +++++- tests/edm4hep_to_lcio.cpp | 10 ++++------ tests/src/EDM4hep2LCIOUtilities.cc | 16 ++++++++++++++-- tests/src/EDM4hep2LCIOUtilities.h | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp b/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp index d0f4ef92..32ceceea 100644 --- a/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp +++ b/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp @@ -873,7 +873,11 @@ namespace EDM4hep2LCIOConv { // << std::endl; } } // all emd4hep contributions - } // SimCaloHit + + // We need to reset the energy to the original one, because adding + // contributions alters the energy in LCIO + lcio_sch->setEnergy(edm_sch.getEnergy()); + } // SimCaloHit // Fill missing SimTrackerHit collections for (auto& [lcio_strh, edm_strh] : collection_pairs.simtrackerhits) { diff --git a/tests/edm4hep_to_lcio.cpp b/tests/edm4hep_to_lcio.cpp index a8c96cf0..2ee20461 100644 --- a/tests/edm4hep_to_lcio.cpp +++ b/tests/edm4hep_to_lcio.cpp @@ -9,11 +9,6 @@ #include "podio/Frame.h" -#include - -template -struct TD; - int main() { const auto edmEvent = createExampleEvent(); @@ -45,8 +40,11 @@ int main() const auto objectMapping = ObjectMappings::fromEvent(lcioEvent.get(), edmEvent); for (const auto& name : edmEvent.getAvailableCollections()) { - const auto* lcioColl = lcioEvent->getCollection(name); const auto type = edmEvent.get(name)->getTypeName(); + if (type == "edm4hep::CaloHitContributionCollection" || type == "edm4hep::ParticleIDCollection") { + continue; + } + const auto* lcioColl = lcioEvent->getCollection(name); ASSERT_COMPARE_OR_EXIT(edm4hep::MCParticleCollection) ASSERT_COMPARE_OR_EXIT(edm4hep::ReconstructedParticleCollection) diff --git a/tests/src/EDM4hep2LCIOUtilities.cc b/tests/src/EDM4hep2LCIOUtilities.cc index 2bceb13d..dce03cb5 100644 --- a/tests/src/EDM4hep2LCIOUtilities.cc +++ b/tests/src/EDM4hep2LCIOUtilities.cc @@ -77,7 +77,16 @@ edm4hep::MCParticleCollection createMCParticles( for (const auto& [orig_idx, link_idx] : mcp_parents_idx) { coll[orig_idx].addToParents(coll[link_idx]); - coll[link_idx].addToDaughters(coll[orig_idx]); + } + // We assign the daughters after all the parents are assigned simply because + // LCIO adds the daughters in the call to add parents and relation comparison + // in the tests assume that all relations are in the same order + for (auto particle : coll) { + // Workaround as proposed in https://github.com/AIDASoft/podio/issues/347 + for (auto p : particle.getParents()) { + auto parent = coll[p.getObjectID().index]; + parent.addToDaughters(particle); + } } return coll; @@ -166,9 +175,12 @@ edm4hep::TrackCollection createTracks( elem.setType(2); // TODO specific type elem.setChi2(i * 10.f); elem.setNdf(i * 12); + elem.setRadiusOfInnermostHit(i * 5.f); + elem.setDEdx(i); elem.setDEdxError(i / std::sqrt(i + 1)); - elem.setRadiusOfInnermostHit(i * 5.f); + // Also add a DxQuantity since the comparison expects that + elem.addToDxQuantities({0, i * 1.f, i / std::sqrt(i + 1.f)}); for (int j = 0; j < subdetectorhitnumbers; ++j) { elem.addToSubdetectorHitNumbers(i + 10 * j); diff --git a/tests/src/EDM4hep2LCIOUtilities.h b/tests/src/EDM4hep2LCIOUtilities.h index dd4dc4fc..783bdb2f 100644 --- a/tests/src/EDM4hep2LCIOUtilities.h +++ b/tests/src/EDM4hep2LCIOUtilities.h @@ -26,7 +26,7 @@ namespace test_config { using IdxPair = std::pair; /// How to create the MC particle hierarchy, e.g. {4, 0} means that mc[4] will - /// have mc[0] as a parente, and mc[0] will get mc[4] as a daughter + /// have mc[0] as a parent, and mc[0] will get mc[4] as a daughter const static std::vector mcpParentIdcs = {{4, 0}, {4, 1}, {3, 2}, {3, 0}, {3, 1}, {2, 1}}; constexpr static int nCaloHits = 2; ///< The number of CalorimeterHits to generate