Skip to content

Commit

Permalink
add ndf and chi2 to track container
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger committed Apr 4, 2023
1 parent 1316c69 commit aa6bc1d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
26 changes: 26 additions & 0 deletions Core/include/Acts/EventData/TrackProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,32 @@ class TrackProxy {
return component<unsigned int>(hashString("nHoles"));
}

/// Return a mutable reference to the chi squared
/// Mutable version
/// @return The chi squared
template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
float& chiSquared() {
return component<float>(hashString("chi2"));
}

/// Return the chi squared for the track. Const version
/// @return The chi squared
float chiSquared() const { return component<float>(hashString("chi2")); }

/// Return a mutable reference to the number of degrees of freedom for the
/// track. Mutable version
/// @return The the number of degrees of freedom
template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
unsigned int& nDoF() {
return component<unsigned int>(hashString("nHoles"));
}

/// Return the number of degrees of freedom for the track. Const version
/// @return The number of degrees of freedom
unsigned int nDoF() const {
return component<unsigned int>(hashString("nHoles"));
}

/// Return the index of this track in the track container
/// @note This is separate from the tip index
/// @return the track index
Expand Down
10 changes: 10 additions & 0 deletions Core/include/Acts/EventData/VectorTrackContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class VectorTrackContainerBase {
return &instance.m_nMeasurements[itrack];
case "nHoles"_hash:
return &instance.m_nHoles[itrack];
case "chi2"_hash:
return &instance.m_chi2[itrack];
case "ndf"_hash:
return &instance.m_ndf[itrack];
default:
auto it = instance.m_dynamic.find(key);
if (it == instance.m_dynamic.end()) {
Expand Down Expand Up @@ -97,6 +101,10 @@ class VectorTrackContainerBase {
result = result && m_nMeasurements.size() == size;
assert(result);
result = result && m_nHoles.size() == size;
assert(result);
result = result && m_chi2.size() == size;
assert(result);
result = result && m_ndf.size() == size;

for (const auto& [key, col] : m_dynamic) {
(void)key;
Expand Down Expand Up @@ -128,6 +136,8 @@ class VectorTrackContainerBase {

std::vector<unsigned int> m_nMeasurements;
std::vector<unsigned int> m_nHoles;
std::vector<float> m_chi2;
std::vector<unsigned int> m_ndf;

std::unordered_map<HashedString, std::unique_ptr<detail::DynamicColumnBase>>
m_dynamic;
Expand Down
13 changes: 12 additions & 1 deletion Core/src/EventData/VectorTrackContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ VectorTrackContainerBase::VectorTrackContainerBase(
m_cov{other.m_cov},
m_referenceSurfaces{other.m_referenceSurfaces},
m_nMeasurements{other.m_nMeasurements},
m_nHoles{other.m_nHoles} {
m_nHoles{other.m_nHoles},
m_chi2{other.m_chi2},
m_ndf{other.m_ndf} {
for (const auto& [key, value] : other.m_dynamic) {
m_dynamic.insert({key, value->clone()});
}
Expand All @@ -39,6 +41,9 @@ VectorTrackContainer::IndexType VectorTrackContainer::addTrack_impl() {
m_nMeasurements.emplace_back();
m_nHoles.emplace_back();

m_chi2.emplace_back();
m_ndf.emplace_back();

// dynamic columns
for (auto& [key, vec] : m_dynamic) {
vec->add();
Expand Down Expand Up @@ -66,6 +71,9 @@ void VectorTrackContainer::removeTrack_impl(IndexType itrack) {
erase(m_nMeasurements);
erase(m_nHoles);

erase(m_chi2);
erase(m_ndf);

for (auto& [key, vec] : m_dynamic) {
vec->erase(itrack);
}
Expand Down Expand Up @@ -103,6 +111,9 @@ void VectorTrackContainer::reserve(IndexType size) {
m_nMeasurements.reserve(size);
m_nHoles.reserve(size);

m_chi2.reserve(size);
m_ndf.reserve(size);

for (auto& [key, vec] : m_dynamic) {
vec->reserve(size);
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/UnitTests/Core/EventData/TrackTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Build, factory_t, holder_types) {
t2.nHoles() = 67;
BOOST_CHECK_EQUAL(t.nHoles(), 67);

t2.chiSquared() = 555.0;
BOOST_CHECK_EQUAL(t2.chiSquared(), 555.0);

t2.nDoF() = 123;
BOOST_CHECK_EQUAL(t2.nDoF(), 123);

// const checks: should not compile
// const auto& ctc = tc;
// ctc.getTrack(idx).covariance().setRandom();
Expand Down

0 comments on commit aa6bc1d

Please sign in to comment.