Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

add association conversion #15

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Changes from 1 commit
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
37 changes: 37 additions & 0 deletions k4LCIOReader/src/k4LCIOConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "edm4hep/MCRecoTrackerHitPlaneAssociationCollection.h"
#include "edm4hep/MCRecoClusterParticleAssociationCollection.h"
#include "edm4hep/MCRecoTrackParticleAssociationCollection.h"
#include "edm4hep/RecoParticleVertexAssociationCollection.h"

k4LCIOConverter::k4LCIOConverter(podio::CollectionIDTable *table)
: m_table(table)
Expand Down Expand Up @@ -1084,6 +1085,42 @@ podio::CollectionBase *k4LCIOConverter::cnvAssociationCollection(EVENT::LCCollec

result = dest;
}
else if ( fromType == "ReconstructedParticle" && toType == "Vertex" ) {
// get all collections that this collection depends on
for (auto& [name, coll] : m_name2src) {
if ((coll->getTypeName() == fromType) ||
(coll->getTypeName() == toType) {
vvolkl marked this conversation as resolved.
Show resolved Hide resolved
getCollection(name);
}
}

auto dest = new edm4hep::RecoParticleVertexAssociationCollection();

// here is the concrete convertions
for (unsigned i = 0, N = src->getNumberOfElements(); i < N; ++i)
{
auto rval = (EVENT::LCRelation *)src->getElementAt(i);
if((EVENT::ReconstructedParticle *)rval->getFrom()==0 || (EVENT::Vertex *)rval->getTo()==0) continue;//remove 0
edm4hep::RecoParticleVertexAssociation lval = dest->create();

// find and set the associated data objects
auto rFrom = (EVENT::ReconstructedParticle *)rval->getFrom();
auto lFrom =
getCorresponding<edm4hep::ReconstructedParticle, edm4hep::ReconstructedParticleCollection,
EVENT::ReconstructedParticle>("ReconstructedParticle", rFrom);
lval.setRec(lFrom);

auto rTo = (EVENT::Vertex *)rval->getTo();
auto lTo =
getCorresponding<edm4hep::Vertex, edm4hep::VertexCollection,
EVENT::Vertex>("Vertex", rTo);
lval.setSim(lTo);
vvolkl marked this conversation as resolved.
Show resolved Hide resolved

lval.setWeight(rval->getWeight());
}

result = dest;
}
else {
std::cout<<"Error: could not find correct fromType="<<fromType<<" or toType="<<toType<<", stop here."<<std::endl;
throw;
Expand Down