-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add track to trajectory converter (#1857)
Add a dedicated conversion algorithm from tracks to trajectories. Blocked by: - #1839 Co-authored-by: Louis-Guillaume Gagnon <2743680+gagnonlg@users.noreply.github.com> Co-authored-by: Pierfrancesco Butti <25535240+pbutti@users.noreply.github.com>
- Loading branch information
1 parent
4fac4ae
commit 1e06090
Showing
4 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Examples/Algorithms/Utilities/include/ActsExamples/Utilities/TracksToTrajectories.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2023 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "ActsExamples/Framework/BareAlgorithm.hpp" | ||
|
||
namespace ActsExamples { | ||
|
||
class TracksToTrajectories final : public BareAlgorithm { | ||
public: | ||
struct Config { | ||
std::string inputTracks = "tracks"; | ||
std::string outputTrajectories = "trajectories-from-tracks"; | ||
}; | ||
|
||
/// Construct the algorithm. | ||
/// | ||
/// @param cfg is the algorithm configuration | ||
/// @param lvl is the logging level | ||
TracksToTrajectories(Config cfg, Acts::Logging::Level lvl) | ||
: BareAlgorithm("TracksToTrajectories", lvl), m_cfg(std::move(cfg)) {} | ||
|
||
/// Run the algorithm. | ||
/// | ||
/// @param ctx is the algorithm context with event information | ||
/// @return a process code indication success or failure | ||
ProcessCode execute(const AlgorithmContext& ctx) const final; | ||
|
||
/// Const access to the config | ||
const Config& config() const { return m_cfg; } | ||
|
||
private: | ||
Config m_cfg; | ||
}; | ||
|
||
} // namespace ActsExamples |
89 changes: 89 additions & 0 deletions
89
Examples/Algorithms/Utilities/src/TracksToTrajectories.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2023 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "ActsExamples/Utilities/TracksToTrajectories.hpp" | ||
|
||
#include "ActsExamples/EventData/IndexSourceLink.hpp" | ||
#include "ActsExamples/EventData/ProtoTrack.hpp" | ||
#include "ActsExamples/EventData/Track.hpp" | ||
#include "ActsExamples/EventData/Trajectories.hpp" | ||
#include "ActsExamples/Framework/WhiteBoard.hpp" | ||
|
||
namespace ActsExamples { | ||
|
||
ProcessCode TracksToTrajectories::execute(const AlgorithmContext& ctx) const { | ||
const auto& tracks = ctx.eventStore.get<TrackContainer>(m_cfg.inputTracks); | ||
|
||
// Prepare the output data with MultiTrajectory | ||
TrajectoriesContainer trajectories; | ||
trajectories.reserve(tracks.size()); | ||
|
||
static const Acts::ConstTrackAccessor<unsigned int> seedNumber("trackGroup"); | ||
|
||
if (tracks.hasColumn(Acts::hashString("trackGroup"))) { | ||
// track group by seed is available, produce grouped trajectories | ||
std::optional<unsigned int> lastSeed; | ||
|
||
Trajectories::IndexedParameters parameters; | ||
std::vector<Acts::MultiTrajectoryTraits::IndexType> tips; | ||
|
||
for (const auto& track : tracks) { | ||
if (!lastSeed) { | ||
lastSeed = seedNumber(track); | ||
} | ||
|
||
if (seedNumber(track) != lastSeed.value()) { | ||
// make copies and clear vectors | ||
trajectories.emplace_back(tracks.trackStateContainer(), tips, | ||
parameters); | ||
tips.clear(); | ||
parameters.clear(); | ||
} | ||
|
||
lastSeed = seedNumber(track); | ||
|
||
tips.push_back(track.tipIndex()); | ||
parameters.emplace( | ||
std::pair{track.tipIndex(), | ||
TrackParameters{track.referenceSurface().getSharedPtr(), | ||
track.parameters(), track.covariance()}}); | ||
} | ||
|
||
if (tips.empty()) { | ||
ACTS_ERROR("Last trajectory is empty"); | ||
} | ||
|
||
// last entry: move vectors | ||
trajectories.emplace_back(tracks.trackStateContainer(), std::move(tips), | ||
std::move(parameters)); | ||
|
||
} else { | ||
// no grouping by seed, make one trajectory per track | ||
|
||
for (const auto& track : tracks) { | ||
Trajectories::IndexedParameters parameters; | ||
parameters.reserve(1); | ||
std::vector<Acts::MultiTrajectoryTraits::IndexType> tips; | ||
tips.reserve(1); | ||
|
||
tips.push_back(track.tipIndex()); | ||
parameters.emplace( | ||
std::pair{track.tipIndex(), | ||
TrackParameters{track.referenceSurface().getSharedPtr(), | ||
track.parameters(), track.covariance()}}); | ||
|
||
trajectories.emplace_back(tracks.trackStateContainer(), std::move(tips), | ||
std::move(parameters)); | ||
} | ||
} | ||
|
||
ctx.eventStore.add(m_cfg.outputTrajectories, std::move(trajectories)); | ||
|
||
return ProcessCode::SUCCESS; | ||
} | ||
} // namespace ActsExamples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters