Skip to content

Commit

Permalink
refactor!: Rename trackStates to trackStatesReverse (#2426)
Browse files Browse the repository at this point in the history
This better indicates that the iterations is outside in

Preparation for #2418.
  • Loading branch information
paulgessinger committed Sep 15, 2023
1 parent fb15929 commit c4433bc
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void GreedyAmbiguityResolution::computeInitialState(
continue;
}
std::vector<std::size_t> measurements;
for (auto ts : track.trackStates()) {
for (auto ts : track.trackStatesReversed()) {
if (ts.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) {
SourceLink sourceLink = ts.getUncalibratedSourceLink();
// assign a new measurement index if the source link was not seen yet
Expand Down
4 changes: 2 additions & 2 deletions Core/include/Acts/EventData/MultiTrajectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ class MultiTrajectory {
/// @param iendpoint Trajectory entry point to start from
/// @return Iterator pair to iterate over
/// @note Const version
auto trackStateRange(IndexType iendpoint) const {
auto reverseTrackStateRange(IndexType iendpoint) const {
using range_t =
decltype(detail_lt::TrackStateRange{getTrackState(iendpoint)});
if (iendpoint == kInvalid) {
Expand All @@ -1147,7 +1147,7 @@ class MultiTrajectory {
/// @return Iterator pair to iterate over
/// @note Mutable version
template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
auto trackStateRange(IndexType iendpoint) {
auto reverseTrackStateRange(IndexType iendpoint) {
using range_t =
decltype(detail_lt::TrackStateRange{getTrackState(iendpoint)});
if (iendpoint == kInvalid) {
Expand Down
8 changes: 4 additions & 4 deletions Core/include/Acts/EventData/TrackContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@ class TrackContainer {
}

template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
auto trackStateRange(IndexType itrack) {
auto reverseTrackStateRange(IndexType itrack) {
auto tip = component<IndexType, hashString("tipIndex")>(itrack);
return m_traj->trackStateRange(tip);
return m_traj->reverseTrackStateRange(tip);
}

auto trackStateRange(IndexType itrack) const {
auto reverseTrackStateRange(IndexType itrack) const {
auto tip = component<IndexType, hashString("tipIndex")>(itrack);
return m_traj->trackStateRange(tip);
return m_traj->reverseTrackStateRange(tip);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion Core/include/Acts/EventData/TrackHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void calculateTrackQuantities(
track.nSharedHits() = 0;
track.nOutliers() = 0;

for (const auto& trackState : track.trackStates()) {
for (const auto& trackState : track.trackStatesReversed()) {
auto typeFlags = trackState.typeFlags();

if (typeFlags.test(Acts::TrackStateFlag::MeasurementFlag)) {
Expand Down
12 changes: 6 additions & 6 deletions Core/include/Acts/EventData/TrackProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,16 @@ class TrackProxy {
/// Get a range over the track states of this track. Return value is
/// compatible with range based for loop. Const version
/// @return Track state range to iterate over
auto trackStates() const {
return m_container->trackStateRange(m_index);
auto trackStatesReversed() const {
return m_container->reverseTrackStateRange(m_index);
}

/// Get a range over the track states of this track. Return value is
/// compatible with range based for loop. Mutable version
/// @return Track state range to iterate over
template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
auto trackStates() {
return m_container->trackStateRange(m_index);
auto trackStatesReversed() {
return m_container->reverseTrackStateRange(m_index);
}

/// Append a track state to this track. This will modify the tip index to
Expand Down Expand Up @@ -426,7 +426,7 @@ class TrackProxy {
// no tip index -> no track states
return 0;
}
auto tsRange = trackStates();
auto tsRange = trackStatesReversed();
return std::distance(tsRange.begin(), tsRange.end());
}

Expand Down Expand Up @@ -540,7 +540,7 @@ class TrackProxy {

if (copyTrackStates) {
// append track states (cheap), but they're in the wrong order
for (const auto& srcTrackState : other.trackStates()) {
for (const auto& srcTrackState : other.trackStatesReversed()) {
auto destTrackState = appendTrackState(srcTrackState.getMask());
if (srcTrackState.hasCalibrated()) {
destTrackState.allocateCalibrated(srcTrackState.calibratedSize());
Expand Down
4 changes: 2 additions & 2 deletions Core/include/Acts/TrackFitting/GaussianSumFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ struct GaussianSumFitter {
const auto& foundBwd = bwdGsfResult.surfacesVisitedBwdAgain;
std::size_t measurementStatesFinal = 0;

for (auto state :
fwdGsfResult.fittedStates->trackStateRange(fwdGsfResult.currentTip)) {
for (auto state : fwdGsfResult.fittedStates->reverseTrackStateRange(
fwdGsfResult.currentTip)) {
const bool found = std::find(foundBwd.begin(), foundBwd.end(),
&state.referenceSurface()) != foundBwd.end();
if (not found && state.typeFlags().test(MeasurementFlag)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void TrackFindingAlgorithm::computeSharedHits(
sourceLinks.size(), std::numeric_limits<std::size_t>::max());

for (auto track : tracks) {
for (auto state : track.trackStates()) {
for (auto state : track.trackStatesReversed()) {
if (not state.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ActsExamples::ProcessCode ActsExamples::RefittingAlgorithm::execute(
trackSourceLinks.clear();
surfSequence.clear();

for (auto state : track.trackStates()) {
for (auto state : track.trackStatesReversed()) {
surfSequence.push_back(&state.referenceSurface());

if (not state.hasCalibrated()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void writeTrack(

ACTS_VERBOSE("Converting " << track.nTrackStates() << " track states");

for (const auto& state : track.trackStates()) {
for (const auto& state : track.trackStatesReversed()) {
auto typeFlags = state.typeFlags();
if (!typeFlags.test(Acts::TrackStateFlag::MeasurementFlag)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MultiTrajectoryTestsCommon {
exp.end());

act.clear();
for (const auto& p : t.trackStateRange(i2a)) {
for (const auto& p : t.reverseTrackStateRange(i2a)) {
act.push_back(p.index());
}
BOOST_CHECK_EQUAL_COLLECTIONS(act.begin(), act.end(), exp.begin(),
Expand All @@ -79,7 +79,7 @@ class MultiTrajectoryTestsCommon {
exp.end());

act.clear();
for (const auto& p : t.trackStateRange(i2b)) {
for (const auto& p : t.reverseTrackStateRange(i2b)) {
act.push_back(p.index());
}
BOOST_CHECK_EQUAL_COLLECTIONS(act.begin(), act.end(), exp.begin(),
Expand All @@ -90,19 +90,19 @@ class MultiTrajectoryTestsCommon {
BOOST_CHECK_EQUAL_COLLECTIONS(act.begin(), act.end(), exp.begin(),
exp.end());

auto r = t.trackStateRange(i2b);
auto r = t.reverseTrackStateRange(i2b);
BOOST_CHECK_EQUAL(std::distance(r.begin(), r.end()), 3);

// check const-correctness
const auto& ct = t;
std::vector<BoundVector> predicteds;
// mutation in this loop works!
for (auto p : t.trackStateRange(i2b)) {
for (auto p : t.reverseTrackStateRange(i2b)) {
predicteds.push_back(BoundVector::Random());
p.predicted() = predicteds.back();
}
std::vector<BoundVector> predictedsAct;
for (const auto& p : ct.trackStateRange(i2b)) {
for (const auto& p : ct.reverseTrackStateRange(i2b)) {
predictedsAct.push_back(p.predicted());
// mutation in this loop doesn't work: does not compile
// p.predicted() = BoundVector::Random();
Expand Down
12 changes: 6 additions & 6 deletions Tests/UnitTests/Core/EventData/TrackTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(TrackStateAccess, factory_t, holder_types) {
t.tipIndex() = ts5.index();

std::vector<IndexType> act;
for (const auto& ts : t.trackStates()) {
for (const auto& ts : t.trackStatesReversed()) {
act.push_back(ts.index());
}

Expand All @@ -322,7 +322,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(TrackStateAccess, factory_t, holder_types) {

const auto& ct = t;

for (const auto& ts : ct.trackStates()) {
for (const auto& ts : ct.trackStatesReversed()) {
(void)ts;
}

Expand All @@ -331,11 +331,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(TrackStateAccess, factory_t, holder_types) {
auto tNone = tc.getTrack(tc.addTrack());
BOOST_CHECK_EQUAL(tNone.nTrackStates(), 0);

auto tsRange = tNone.trackStates();
auto tsRange = tNone.trackStatesReversed();
BOOST_CHECK(tsRange.begin() == tsRange.end());

size_t i = 0;
for (const auto& state : tNone.trackStates()) {
for (const auto& state : tNone.trackStatesReversed()) {
(void)state;
i++;
}
Expand Down Expand Up @@ -552,7 +552,7 @@ BOOST_AUTO_TEST_CASE(ReverseTrackStates) {
exp.resize(t.nTrackStates());
std::iota(exp.rbegin(), exp.rend(), 0);
std::vector<IndexType> act;
std::transform(t.trackStates().begin(), t.trackStates().end(),
std::transform(t.trackStatesReversed().begin(), t.trackStatesReversed().end(),
std::back_inserter(act),
[](const auto& ts) { return ts.index(); });

Expand All @@ -563,7 +563,7 @@ BOOST_AUTO_TEST_CASE(ReverseTrackStates) {

std::iota(exp.begin(), exp.end(), 0);
act.clear();
std::transform(t.trackStates().begin(), t.trackStates().end(),
std::transform(t.trackStatesReversed().begin(), t.trackStatesReversed().end(),
std::back_inserter(act),
[](const auto& ts) { return ts.index(); });
BOOST_CHECK_EQUAL_COLLECTIONS(exp.begin(), exp.end(), act.begin(), act.end());
Expand Down
6 changes: 4 additions & 2 deletions Tests/UnitTests/Core/EventData/TrackTestsExtra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ BOOST_AUTO_TEST_CASE(CopyTracksIncludingDynamicColumns) {
BOOST_CHECK(t3.nTrackStates() > 0);
BOOST_REQUIRE_EQUAL(t.nTrackStates(), t3.nTrackStates());

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

Expand Down Expand Up @@ -87,7 +88,8 @@ BOOST_AUTO_TEST_CASE(CopyTracksIncludingDynamicColumns) {
BOOST_CHECK(t5.nTrackStates() > 0);
BOOST_REQUIRE_EQUAL(t4.nTrackStates(), t5.nTrackStates());

for (auto [tsa, tsb] : zip(t4.trackStates(), t5.trackStates())) {
for (auto [tsa, tsb] :
zip(t4.trackStatesReversed(), t5.trackStatesReversed())) {
BOOST_CHECK_EQUAL(tsa.predicted(), tsb.predicted());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ BOOST_AUTO_TEST_CASE(ZeroFieldForward) {
// find the number of hits not originating from the right track
size_t numHits = 0u;
size_t nummismatchedHits = 0u;
for (const auto trackState : track.trackStates()) {
for (const auto trackState : track.trackStatesReversed()) {
numHits += 1u;
auto sl =
trackState.getUncalibratedSourceLink().template get<TestSourceLink>();
Expand Down Expand Up @@ -395,7 +395,7 @@ BOOST_AUTO_TEST_CASE(ZeroFieldBackward) {
// find the number of hits not originating from the right track
size_t numHits = 0u;
size_t nummismatchedHits = 0u;
for (const auto trackState : track.trackStates()) {
for (const auto trackState : track.trackStatesReversed()) {
numHits += 1u;
auto sl =
trackState.getUncalibratedSourceLink().template get<TestSourceLink>();
Expand Down
6 changes: 3 additions & 3 deletions Tests/UnitTests/Core/TrackFitting/FitterTestsCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ struct FitterTester {
// count the number of `smoothed` states
if (expected_reversed && expected_smoothed) {
size_t nSmoothed = 0;
for (const auto ts : track.trackStates()) {
for (const auto ts : track.trackStatesReversed()) {
nSmoothed += ts.hasSmoothed();
}
BOOST_CHECK_EQUAL(nSmoothed, sourceLinks.size());
Expand Down Expand Up @@ -312,7 +312,7 @@ struct FitterTester {
// count the number of `smoothed` states
if (expected_reversed && expected_smoothed) {
size_t nSmoothed = 0;
for (const auto ts : track.trackStates()) {
for (const auto ts : track.trackStatesReversed()) {
nSmoothed += ts.hasSmoothed();
}
BOOST_CHECK_EQUAL(nSmoothed, sourceLinks.size());
Expand Down Expand Up @@ -512,7 +512,7 @@ struct FitterTester {
BOOST_CHECK_NE(track.tipIndex(), Acts::MultiTrajectoryTraits::kInvalid);
// count the number of outliers
size_t nOutliers = 0;
for (const auto state : track.trackStates()) {
for (const auto state : track.trackStatesReversed()) {
nOutliers += state.typeFlags().test(Acts::TrackStateFlag::OutlierFlag);
}
BOOST_CHECK_EQUAL(nOutliers, 1u);
Expand Down
14 changes: 7 additions & 7 deletions Tests/UnitTests/Plugins/EDM4hep/ConvertTrackEDM4hepTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,18 @@ BOOST_AUTO_TEST_CASE(RoundTripTests) {
BOOST_CHECK_EQUAL(orig.referenceSurface().center(gctx),
read.referenceSurface().center(gctx));

auto origTsIt = orig.trackStates().begin();
auto readTsIt = read.trackStates().begin();
auto origTsIt = orig.trackStatesReversed().begin();
auto readTsIt = read.trackStatesReversed().begin();

size_t tsi = 0;
while (origTsIt != orig.trackStates().end() &&
readTsIt != read.trackStates().end()) {
while (origTsIt != orig.trackStatesReversed().end() &&
readTsIt != read.trackStatesReversed().end()) {
BOOST_TEST_INFO_SCOPE("TS: #" << tsi);
auto nextMeas =
std::find_if(origTsIt, orig.trackStates().end(), [](const auto& ts) {
auto nextMeas = std::find_if(
origTsIt, orig.trackStatesReversed().end(), [](const auto& ts) {
return ts.typeFlags().test(TrackStateFlag::MeasurementFlag);
});
BOOST_CHECK(nextMeas != orig.trackStates().end());
BOOST_CHECK(nextMeas != orig.trackStatesReversed().end());
origTsIt = nextMeas;
auto origTs = *origTsIt;
auto readTs = *readTsIt;
Expand Down

0 comments on commit c4433bc

Please sign in to comment.