Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the conversion of edm4hep::Clusters to LCIO::Clusters #36

Merged
merged 7 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,11 @@ namespace EDM4hep2LCIOConv {
}
lcio_cluster->setShape(shape_vec);

auto& subdetEnergies = lcio_cluster->subdetectorEnergies();
for (const auto edmEnergy : edm_cluster.getSubdetectorEnergies()) {
subdetEnergies.push_back(edmEnergy);
}

// Convert ParticleIDs associated to the recoparticle
for (const auto& edm_pid : edm_cluster.getParticleIDs()) {
if (edm_pid.isAvailable()) {
Expand All @@ -452,19 +457,6 @@ namespace EDM4hep2LCIOConv {
}
}

// Link associated clusters after converting all clusters
for (auto& [lcio_cluster, edm_cluster] : cluster_vec) {
for (const auto& edm_linked_cluster : edm_cluster.getClusters()) {
if (edm_linked_cluster.isAvailable()) {
if (
const auto lcio_cluster_linked =
k4EDM4hep2LcioConv::detail::mapLookupFrom(edm_linked_cluster, cluster_vec)) {
lcio_cluster->addCluster(lcio_cluster_linked.value());
}
}
}
}

return clusters;
}

Expand Down Expand Up @@ -833,6 +825,27 @@ namespace EDM4hep2LCIOConv {
}

} // SimTrackerHits

// Resolve relations for clusters
for (auto& [lcio_cluster, edm_cluster] : update_pairs.clusters) {
for (const auto& edm_linked_cluster : edm_cluster.getClusters()) {
if (edm_linked_cluster.isAvailable()) {
if (
const auto lcio_cluster_linked =
k4EDM4hep2LcioConv::detail::mapLookupFrom(edm_linked_cluster, lookup_pairs.clusters)) {
lcio_cluster->addCluster(lcio_cluster_linked.value());
}
}
}

for (const auto& edm_calohit : edm_cluster.getHits()) {
if (edm_calohit.isAvailable()) {
if (const auto lcio_calohit = k4EDM4hep2LcioConv::detail::mapLookupFrom(edm_calohit, update_pairs.caloHits)) {
tmadlener marked this conversation as resolved.
Show resolved Hide resolved
lcio_cluster->addHit(lcio_calohit.value(), 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDM4hep doesn't have a weight for the calo hits(?). What is the proper value to set here?

Copy link
Contributor Author

@tmadlener tmadlener Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking this in key4hep/EDM4hep#236

}
}
}
}
}

} // namespace EDM4hep2LCIOConv
1 change: 1 addition & 0 deletions tests/edm4hep_roundtrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ int main()
ASSERT_SAME_OR_ABORT(edm4hep::SimCalorimeterHitCollection, "simCaloHits");
ASSERT_SAME_OR_ABORT(edm4hep::TrackCollection, "tracks");
ASSERT_SAME_OR_ABORT(edm4hep::TrackerHitCollection, "trackerHits");
ASSERT_SAME_OR_ABORT(edm4hep::ClusterCollection, "clusters");

return 0;
}
26 changes: 26 additions & 0 deletions tests/src/CompareEDM4hepEDM4hep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "edm4hep/SimCalorimeterHitCollection.h"
#include "edm4hep/TrackCollection.h"
#include "edm4hep/TrackerHitCollection.h"
#include "edm4hep/ClusterCollection.h"

#include <edm4hep/TrackState.h>
#include <iostream>
Expand Down Expand Up @@ -216,3 +217,28 @@ bool compare(const edm4hep::TrackerHitCollection& origColl, const edm4hep::Track

return true;
}

bool compare(const edm4hep::ClusterCollection& origColl, const edm4hep::ClusterCollection& roundtripColl)
{
REQUIRE_SAME(origColl.size(), roundtripColl.size(), "collection sizes");
for (size_t i = 0; i < origColl.size(); ++i) {
auto origCluster = origColl[i];
auto cluster = roundtripColl[i];

const auto origHits = origCluster.getHits();
const auto hits = cluster.getHits();
REQUIRE_SAME(origHits.size(), hits.size(), "number of calorimeter hits in cluster " << i);
for (size_t iH = 0; iH < origHits.size(); ++iH) {
REQUIRE_SAME(origHits[iH].getObjectID(), hits[iH].getObjectID(), "calorimeter hit " << iH << " in cluster " << i);
}

const auto& origSubdetE = origCluster.getSubdetectorEnergies();
const auto& subdetE = cluster.getSubdetectorEnergies();
REQUIRE_SAME(origSubdetE.size(), subdetE.size(), "sizes of subdetector energies in cluster " << i);
for (size_t iSE = 0; iSE < origSubdetE.size(); ++iSE) {
REQUIRE_SAME(origSubdetE[iSE], subdetE[iSE], "subdetector energy " << iSE << " in cluster " << i);
}
}

return true;
}
2 changes: 2 additions & 0 deletions tests/src/CompareEDM4hepEDM4hep.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ bool compare(const edm4hep::TrackCollection& origColl, const edm4hep::TrackColle

bool compare(const edm4hep::TrackerHitCollection& origColl, const edm4hep::TrackerHitCollection& roundtripColl);

bool compare(const edm4hep::ClusterCollection& origColl, const edm4hep::ClusterCollection& roundtripColl);

#endif // K4EDM4HEP2LCIOCONV_TEST_COMPAREEDM4HEPEDM4HEP_H
26 changes: 26 additions & 0 deletions tests/src/EDM4hep2LCIOUtilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "edm4hep/TrackCollection.h"
#include "edm4hep/SimCalorimeterHitCollection.h"
#include "edm4hep/CaloHitContributionCollection.h"
#include "edm4hep/ClusterCollection.h"

#include "podio/Frame.h"

Expand All @@ -22,6 +23,14 @@ constexpr std::uint64_t operator""_u64(unsigned long long num) { return static_c
// Some pre-defined cellIDs that can be used below
constexpr static std::array CELLIDS = {0xcaffee_u64, 0xbeef_u64, 0xfe47_u64, 0x12345678_u64, 0_u64, -1_u64};

// Get the i-th element from the collection (with rolling back to 0 if i exceeds
// the collection size)
template<typename CollT>
const auto getModElement(const CollT& coll, size_t i)
{
return coll[i % coll.size()];
}

constexpr static uint64_t createCellID(int i) { return CELLIDS[i % CELLIDS.size()]; }

/// Create a covariance matrix for N dimensions in lower triangular form
Expand Down Expand Up @@ -266,6 +275,22 @@ edm4hep::EventHeaderCollection createEventHeader()
return evtHeaderColl;
}

edm4hep::ClusterCollection
createClusters(const int num_elements, const edm4hep::CalorimeterHitCollection& caloHits, const int num_subdet_energies)
{
auto clusterColl = edm4hep::ClusterCollection {};
for (int i = 0; i < num_elements; ++i) {
auto cluster = clusterColl.create();

cluster.addToHits(getModElement(caloHits, i));
for (int j = 0; j < num_subdet_energies; ++j) {
cluster.addToSubdetectorEnergies(j);
}
}

return clusterColl;
}

podio::Frame createExampleEvent()
{
podio::Frame event;
Expand All @@ -286,6 +311,7 @@ podio::Frame createExampleEvent()
test_config::trackTrackerHitIdcs,
test_config::trackTrackIdcs),
"tracks");
event.put(createClusters(test_config::nClusters, caloHits, test_config::nSubdetectorEnergies), "clusters");

auto [tmpSimCaloHits, tmpCaloHitConts] = createSimCalorimeterHits(
test_config::nSimCaloHits, test_config::nCaloHitContributions, mcParticles, test_config::simCaloHitMCIdcs);
Expand Down
11 changes: 11 additions & 0 deletions tests/src/EDM4hep2LCIOUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace edm4hep {
class SimCalorimeterHitCollection;
class CaloHitContributionCollection;
class EventHeaderCollection;
class ClusterCollection;
} // namespace edm4hep

namespace podio {
Expand Down Expand Up @@ -67,6 +68,10 @@ namespace test_config {
{2, 2, 2},
{2, 3, 0}};

/// The number of clusters to create
constexpr static int nClusters = 5;
/// The number of subdetector energy entries to create
constexpr static int nSubdetectorEnergies = 6;
} // namespace test_config

/**
Expand Down Expand Up @@ -123,6 +128,11 @@ std::pair<edm4hep::SimCalorimeterHitCollection, edm4hep::CaloHitContributionColl

edm4hep::EventHeaderCollection createEventHeader();

edm4hep::ClusterCollection createClusters(
const int num_elements,
const edm4hep::CalorimeterHitCollection& caloHits,
const int num_subdet_energies);

/**
* Create an example event that can be used to test the converter.
*
Expand All @@ -140,6 +150,7 @@ edm4hep::EventHeaderCollection createEventHeader();
* | trackerHits | TrackerHit | createTrackerHits |
* | simCaloHits | SimCalorimeterHit | createSimCalorimeterHits |
* | caloHitContributions | CaloHitContribution | createSimCalorimeterHits |
* | clusters | ClusterCollection | createClusters |
*/
podio::Frame createExampleEvent();

Expand Down
Loading