Skip to content

Commit

Permalink
Fix minor issues uncovered by tests
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tmadlener committed Sep 27, 2023
1 parent bd3b706 commit d088d6c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
6 changes: 5 additions & 1 deletion k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 4 additions & 6 deletions tests/edm4hep_to_lcio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

#include "podio/Frame.h"

#include <type_traits>

template<typename>
struct TD;

int main()
{
const auto edmEvent = createExampleEvent();
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions tests/src/EDM4hep2LCIOUtilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/EDM4hep2LCIOUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace test_config {

using IdxPair = std::pair<std::size_t, std::size_t>;
/// 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<IdxPair> mcpParentIdcs = {{4, 0}, {4, 1}, {3, 2}, {3, 0}, {3, 1}, {2, 1}};

constexpr static int nCaloHits = 2; ///< The number of CalorimeterHits to generate
Expand Down

0 comments on commit d088d6c

Please sign in to comment.