Skip to content

Commit

Permalink
update PODIO track backend to be complete and current (missing particle
Browse files Browse the repository at this point in the history
hypothesis still)
  • Loading branch information
paulgessinger committed Nov 22, 2023
1 parent 8956d6c commit bfb8f41
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ concept CommonMultiTrajectoryBackend = requires(const T& cv, HashedString key,
{ cv.component_impl(key, istate) } -> std::same_as<std::any>;

{ cv.hasColumn_impl(key) } -> std::same_as<bool>;

{ cv.dynamicKeys_impl() } -> std::same_as<std::vector<Acts::HashedString>>;
};

template <typename T>
Expand Down Expand Up @@ -125,7 +127,7 @@ concept MutableMultiTrajectoryBackend = CommonMultiTrajectoryBackend<T> &&

{v.setReferenceSurface_impl(istate, surface)};

// @TODO: Add copyDynamicFrom + ensureDynamicColumns for MTJ like in TrackContainer
{v.copyDynamicFrom_impl(istate, key, std::declval<const std::any&>())};
};

} // namespace Acts
Expand Down
12 changes: 8 additions & 4 deletions Core/include/Acts/EventData/TrackContainerBackendConcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ concept ConstTrackContainerBackend = requires(const T& cv, HashedString key,
{ cv.hasColumn_impl(key) } -> std::same_as<bool>;

{ cv.referenceSurface_impl(itrack) } -> std::same_as<const Surface*>;

{ cv.dynamicKeys_impl() } -> std::same_as<std::vector<Acts::HashedString>>;
};

template <typename T>
Expand All @@ -57,22 +59,25 @@ concept MutableTrackContainerBackend = ConstTrackContainerBackend<T> &&

{v.removeTrack_impl(itrack)};

// As far as I know there's no good way to assert that there's a generic
// template function
// As far as I know there's no good way to assert that there's a
// generic template function
{v.template addColumn_impl<uint32_t>(col)};
{v.template addColumn_impl<uint64_t>(col)};
{v.template addColumn_impl<int32_t>(col)};
{v.template addColumn_impl<int64_t>(col)};
{v.template addColumn_impl<float>(col)};
{v.template addColumn_impl<double>(col)};

{v.copyDynamicFrom_impl(itrack, other, itrack)};
{v.copyDynamicFrom_impl(itrack, key, std::declval<const std::any&>())};

{v.ensureDynamicColumns_impl(other)};

{v.reserve(itrack)};

{v.setReferenceSurface_impl(itrack, sharedSurface)};

{v.setParticleHypothesis_impl(itrack,
std::declval<const ParticleHypothesis&>())};
};

template <typename T>
Expand All @@ -81,7 +86,6 @@ struct IsReadOnlyTrackContainer;
template <typename T>
concept TrackContainerBackend = ConstTrackContainerBackend<T> &&
(IsReadOnlyTrackContainer<T>::value || MutableTrackContainerBackend<T>);

} // namespace Acts

#endif
2 changes: 2 additions & 0 deletions Plugins/Podio/edm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ components:
- std::array<double, 6> parameters
- std::array<double, 36> covariance // local covariance
- uint32_t tipIndex // index of the outermost track state
- uint32_t stemIndex // index of the innermost track state
- unsigned int nMeasurements // number of measurements
- unsigned int nHoles // number of holes
- float chi2 // chi squared of the track
Expand All @@ -45,6 +46,7 @@ components:
ActsPodioEdm::TrackStateInfo:
Members:
- uint32_t previous
- uint32_t next

- uint32_t ipredicted;
- uint32_t ifiltered;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct DynamicColumnBase : public ConstDynamicColumnBase {
virtual void erase(std::size_t i) = 0;
virtual void copyFrom(std::size_t dstIdx, const DynamicColumnBase& src,
std::size_t srcIdx) = 0;
virtual void copyFrom(std::size_t dstIdx, const std::any& srcPtr) = 0;

virtual std::unique_ptr<DynamicColumnBase> clone(
bool empty = false) const = 0;
Expand Down Expand Up @@ -86,6 +87,13 @@ struct DynamicColumn : public DynamicColumnBase {
m_collection.vec().at(dstIdx) = other->m_collection.vec().at(srcIdx);
}

void copyFrom(std::size_t dstIdx, const std::any& srcPtr) override {
const auto* other = std::any_cast<const T*>(srcPtr);
assert(other != nullptr &&
"Source column is not of same type as destination");
m_collection.vec().at(dstIdx) = *other;
}

void releaseInto(podio::Frame& frame, const std::string& prefix) override {
frame.put(std::move(m_collection), prefix + m_name);
}
Expand Down
42 changes: 38 additions & 4 deletions Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class PodioTrackContainerBase {
switch (key) {
case "tipIndex"_hash:
return &data.tipIndex;
case "stemIndex"_hash:
return &data.stemIndex;
case "params"_hash:
return data.parameters.data();
case "cov"_hash:
Expand All @@ -95,6 +97,9 @@ class PodioTrackContainerBase {
return &data.nOutliers;
case "nSharedHits"_hash:
return &data.nSharedHits;
case "particleHypothesis"_hash:
// @TODO: Implement particle hypothesis for PODIO backend
return nullptr;
default:
auto it = instance.m_dynamic.find(key);
if (it == instance.m_dynamic.end()) {
Expand All @@ -110,6 +115,16 @@ class PodioTrackContainerBase {
}
}

template <typename T>
static std::vector<Acts::HashedString> dynamicKeys_impl(T& instance) {
std::vector<Acts::HashedString> result;
result.reserve(instance.m_dynamic.size());
for (const auto& [key, value] : instance.m_dynamic) {
result.push_back(key);
}
return result;
}

static void populateSurfaceBuffer(
const PodioUtil::ConversionHelper& helper,
const ActsPodioEdm::TrackCollection& collection,
Expand Down Expand Up @@ -218,10 +233,16 @@ class MutablePodioTrackContainer : public PodioTrackContainerBase {
m_collection->at(itrack).getData().covariance.data()};
}

// @TODO What's the equivalent of this?
void copyDynamicFrom_impl(IndexType dstIdx,
const MutablePodioTrackContainer& src,
IndexType srcIdx);
void copyDynamicFrom_impl(IndexType dstIdx, HashedString key,
const std::any& srcPtr) {
auto it = m_dynamic.find(key);
if (it == m_dynamic.end()) {
throw std::invalid_argument{
"Destination container does not have matching dynamic column"};
}

it->second->copyFrom(dstIdx, srcPtr);
}

void ensureDynamicColumns_impl(const MutablePodioTrackContainer& other);

Expand All @@ -242,6 +263,15 @@ class MutablePodioTrackContainer : public PodioTrackContainerBase {
}
}

std::vector<Acts::HashedString> dynamicKeys_impl() const {
return PodioTrackContainerBase::dynamicKeys_impl(*this);
}

void setParticleHypothesis_impl(
IndexType /*itrack*/, const ParticleHypothesis& /*particleHypothesis*/) {
// @TODO: Implement particle hypothesis in podio
}

// END INTERFACE

private:
Expand Down Expand Up @@ -361,6 +391,10 @@ class ConstPodioTrackContainer : public PodioTrackContainerBase {
return *m_collection;
}

std::vector<Acts::HashedString> dynamicKeys_impl() const {
return PodioTrackContainerBase::dynamicKeys_impl(*this);
}

private:
friend PodioTrackContainerBase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class PodioTrackStateContainerBase {
case "uncalibratedSourceLink"_hash:
return data.uncalibratedIdentifier != PodioUtil::kNoIdentifier;
case "previous"_hash:
case "next"_hash:
case "measdim"_hash:
case "referenceSurface"_hash:
case "chi2"_hash:
Expand Down Expand Up @@ -111,6 +112,8 @@ class PodioTrackStateContainerBase {
switch (key) {
case "previous"_hash:
return &data.previous;
case "next"_hash:
return &data.next;
case "predicted"_hash:
return &data.ipredicted;
case "filtered"_hash:
Expand Down Expand Up @@ -151,6 +154,7 @@ class PodioTrackStateContainerBase {
case "jacobian"_hash:
case "projector"_hash:
case "previous"_hash:
case "next"_hash:
case "uncalibratedSourceLink"_hash:
case "referenceSurface"_hash:
case "measdim"_hash:
Expand All @@ -173,6 +177,16 @@ class PodioTrackStateContainerBase {
helper, trackState.getReferenceSurface()));
}
}

template <typename T>
static std::vector<Acts::HashedString> dynamicKeys_impl(T& instance) {
std::vector<Acts::HashedString> result;
result.reserve(instance.m_dynamic.size());
for (const auto& [key, value] : instance.m_dynamic) {
result.push_back(key);
}
return result;
}
};

template <>
Expand Down Expand Up @@ -284,6 +298,10 @@ class ConstPodioTrackStateContainer final
}
}

std::vector<Acts::HashedString> dynamicKeys_impl() const {
return PodioTrackStateContainerBase::dynamicKeys_impl(*this);
}

private:
template <typename collection_t>
static void loadCollection(collection_t const*& dest,
Expand Down Expand Up @@ -651,6 +669,21 @@ class MutablePodioTrackStateContainer final
}
}

std::vector<Acts::HashedString> dynamicKeys_impl() const {
return PodioTrackStateContainerBase::dynamicKeys_impl(*this);
}

void copyDynamicFrom_impl(IndexType dstIdx, HashedString key,
const std::any& srcPtr) {
auto it = m_dynamic.find(key);
if (it == m_dynamic.end()) {
throw std::invalid_argument{
"Destination container does not have matching dynamic column"};
}

it->second->copyFrom(dstIdx, srcPtr);
}

private:
friend class PodioTrackStateContainerBase;
friend class ConstPodioTrackStateContainer;
Expand Down
78 changes: 77 additions & 1 deletion Tests/UnitTests/Plugins/Podio/ConvertTrackPodioTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Acts/Definitions/Units.hpp"
#include "Acts/EventData/MultiTrajectory.hpp"
#include "Acts/EventData/VectorMultiTrajectory.hpp"
#include "Acts/EventData/VectorTrackContainer.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Plugins/Podio/PodioTrackContainer.hpp"
#include "Acts/Plugins/Podio/PodioTrackStateContainer.hpp"
Expand Down Expand Up @@ -301,6 +302,81 @@ BOOST_AUTO_TEST_CASE(ConvertTrack) {
}
}

// @TODO: Add ensure dynamic columns
BOOST_AUTO_TEST_CASE(CopyTracksIncludingDynamicColumns) {
MapHelper helper;

podio::Frame frame;

// mutable source
VectorTrackContainer vtc{};
VectorMultiTrajectory mtj{};
TrackContainer tc{vtc, mtj};
tc.addColumn<uint64_t>("counter");
tc.addColumn<uint8_t>("odd");
mtj.addColumn<uint64_t>("ts_counter");
mtj.addColumn<uint8_t>("ts_odd");

Acts::MutablePodioTrackStateContainer tsc2{helper};
Acts::MutablePodioTrackContainer ptc2{helper};
Acts::TrackContainer tc2{ptc2, tsc2};
// doesn't have the dynamic column

Acts::MutablePodioTrackStateContainer tsc3{helper};
Acts::MutablePodioTrackContainer ptc3{helper};
Acts::TrackContainer tc3{ptc3, tsc3};

tc3.addColumn<uint64_t>("counter");
tc3.addColumn<uint8_t>("odd");
tsc3.addColumn<uint64_t>("ts_counter");
tsc3.addColumn<uint8_t>("ts_odd");

for (std::size_t i = 0; i < 10; i++) {
auto t = tc.getTrack(tc.addTrack());
auto ts = t.appendTrackState();
ts.predicted() = BoundVector::Ones();
ts.component<uint64_t, "ts_counter"_hash>() = i;

ts = t.appendTrackState();
ts.predicted().setOnes();
ts.predicted() *= 2;
ts.component<uint64_t, "ts_counter"_hash>() = i + 1;

ts = t.appendTrackState();
ts.predicted().setOnes();
ts.predicted() *= 3;
ts.component<uint64_t, "ts_counter"_hash>() = i + 2;

t.template component<uint64_t>("counter") = i;
t.template component<uint8_t>("odd") = static_cast<uint8_t>(i % 2 == 0);

auto t2 = tc2.getTrack(tc2.addTrack());
BOOST_CHECK_THROW(t2.copyFrom(t),
std::invalid_argument); // this should fail

auto t3 = tc3.getTrack(tc3.addTrack());
t3.copyFrom(t); // this should work

BOOST_CHECK_NE(t3.tipIndex(), MultiTrajectoryTraits::kInvalid);
BOOST_CHECK_GT(t3.nTrackStates(), 0);
BOOST_REQUIRE_EQUAL(t.nTrackStates(), t3.nTrackStates());

// for (auto [tsa, tsb] :
// zip(t.trackStatesReversed(), t3.trackStatesReversed())) {
// BOOST_CHECK_EQUAL(tsa.predicted(), tsb.predicted());

// BOOST_CHECK_EQUAL(
// (tsa.template component<std::size_t, "ts_counter"_hash>()),
// (tsb.template component<std::size_t, "ts_counter"_hash>()));

// BOOST_CHECK_EQUAL((tsa.template component<bool, "ts_odd"_hash>()),
// (tsb.template component<bool, "ts_odd"_hash>()));
// }

BOOST_CHECK_EQUAL(t.template component<uint64_t>("counter"),
t3.template component<uint64_t>("counter"));
BOOST_CHECK_EQUAL(t.template component<uint8_t>("odd"),
t3.template component<uint8_t>("odd"));
}
}

BOOST_AUTO_TEST_SUITE_END()
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ BOOST_AUTO_TEST_CASE(TrackStateProxyCopyDiffMTJ) {
ct.testTrackStateProxyCopyDiffMTJ();
}

BOOST_AUTO_TEST_CASE(TrackStateCopyDynamicColumns) {
CommonTests ct;
ct.testTrackStateCopyDynamicColumns();
}

BOOST_AUTO_TEST_CASE(ProxyAssignment) {
CommonTests ct;
ct.testProxyAssignment();
Expand Down

0 comments on commit bfb8f41

Please sign in to comment.