Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Refactor Examples to use tracks instead of trajectories #2560

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0a6e2ad
rename
andiwand Oct 20, 2023
a15a214
draft
andiwand Oct 20, 2023
4ac193d
apply to TrackFitterPerformanceWriter
andiwand Oct 20, 2023
0ef92c2
add missing impl
andiwand Oct 20, 2023
f4b5011
fix reco
andiwand Oct 20, 2023
6ae742c
handle vertexing and more
andiwand Oct 21, 2023
622dd28
fix formatting
andiwand Oct 21, 2023
c46b50d
fix
andiwand Oct 21, 2023
6eca1e8
minor
andiwand Oct 21, 2023
0266d43
fix
andiwand Oct 21, 2023
771f3c7
fix
andiwand Oct 21, 2023
4677721
fix
andiwand Oct 21, 2023
fee1ecf
fix?
andiwand Oct 21, 2023
71daa9b
Merge branch 'main' into refactor-examples-use-tracks-instead-of-traj…
andiwand Oct 24, 2023
d800722
Merge branch 'main' of github.com:acts-project/acts into refactor-exa…
andiwand Oct 24, 2023
370814c
fix and remove dead code
andiwand Oct 24, 2023
9cb3684
remove track->traj conversions
andiwand Oct 24, 2023
5d08165
fix gsf
andiwand Oct 24, 2023
d96c258
Merge branch 'main' into refactor-examples-use-tracks-instead-of-traj…
andiwand Oct 24, 2023
19783de
stuff and fix vertex performance writer
andiwand Oct 24, 2023
1338984
restore faulty behavior
andiwand Oct 25, 2023
b53c84f
Merge branch 'main' into refactor-examples-use-tracks-instead-of-traj…
andiwand Oct 25, 2023
3a763ac
update gsf ref
andiwand Oct 25, 2023
68c887d
fix track summary writer
andiwand Oct 25, 2023
6a76ed2
fix ckf examples
andiwand Oct 25, 2023
7a4176c
port csv track writer
andiwand Oct 25, 2023
e8d1fe3
fix writer test
andiwand Oct 25, 2023
cb54a3b
fix; port more
andiwand Oct 25, 2023
cbe05de
remove hole recalc in gsf
andiwand Oct 26, 2023
c8309e8
Merge branch 'main' of github.com:acts-project/acts into refactor-exa…
andiwand Oct 26, 2023
a71489c
restore ids
andiwand Oct 26, 2023
faa89b3
use track nr
andiwand Oct 26, 2023
e0f6105
exclude track_nr from plotting
andiwand Oct 27, 2023
de8355e
Merge branch 'main' into refactor-examples-use-tracks-instead-of-traj…
andiwand Oct 27, 2023
ceae285
update hashes
andiwand Oct 27, 2023
f6188e8
pr feedback
andiwand Oct 28, 2023
91d0be8
Merge branch 'main' into refactor-examples-use-tracks-instead-of-traj…
andiwand Oct 28, 2023
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
3 changes: 1 addition & 2 deletions CI/physmon/tracksummary_ckf_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ histograms:

exclude:
- event_nr
- track_nr
- hasFittedParams
- majorityParticleId
- multiTraj_nr
- subTraj_nr
17 changes: 14 additions & 3 deletions CI/physmon/workflows/physmon_ckf_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,32 @@ def run_ckf_tracking(truthSmearedSeeded, truthEstimatedSeeded, label):
outputDirRoot=tp,
)

s.addAlgorithm(
acts.examples.TracksToParameters(
level=acts.logging.INFO,
inputTracks="tracks",
outputTrackParameters="trackParameters",
)
)

addVertexFitting(
s,
setup.field,
seeder=acts.VertexSeedFinder.GaussianSeeder,
trackParameters="trackParameters",
outputProtoVertices="ivf_protovertices",
outputVertices="ivf_fittedVertices",
seeder=acts.VertexSeedFinder.GaussianSeeder,
vertexFinder=VertexFinder.Iterative,
outputDirRoot=tp / "ivf",
)

addVertexFitting(
s,
setup.field,
seeder=acts.VertexSeedFinder.GaussianSeeder,
trackParameters="trackParameters",
outputProtoVertices="amvf_protovertices",
outputVertices="amvf_fittedVertices",
seeder=acts.VertexSeedFinder.GaussianSeeder,
vertexFinder=VertexFinder.AMVF,
outputDirRoot=tp / "amvf",
)
Expand All @@ -162,9 +172,10 @@ def run_ckf_tracking(truthSmearedSeeded, truthEstimatedSeeded, label):
addVertexFitting(
s,
setup.field,
seeder=acts.VertexSeedFinder.AdaptiveGridSeeder,
trackParameters="trackParameters",
outputProtoVertices="amvf_gridseeder_protovertices",
outputVertices="amvf_gridseeder_fittedVertices",
seeder=acts.VertexSeedFinder.AdaptiveGridSeeder,
vertexFinder=VertexFinder.AMVF,
outputDirRoot=tp / "amvf_gridseeder",
)
Expand Down
16 changes: 14 additions & 2 deletions CI/physmon/workflows/physmon_track_finding_ttbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,34 @@
outputDirRoot=tp,
)

s.addAlgorithm(
acts.examples.TracksToParameters(
level=acts.logging.INFO,
inputTracks="tracks",
outputTrackParameters="trackParameters",
)
)

addVertexFitting(
s,
setup.field,
seeder=acts.VertexSeedFinder.GaussianSeeder,
tracks="tracks",
trackParameters="trackParameters",
outputProtoVertices="amvf_protovertices",
outputVertices="amvf_fittedVertices",
seeder=acts.VertexSeedFinder.GaussianSeeder,
vertexFinder=VertexFinder.AMVF,
outputDirRoot=tp / "amvf",
)

addVertexFitting(
s,
setup.field,
seeder=acts.VertexSeedFinder.AdaptiveGridSeeder,
tracks="tracks",
trackParameters="trackParameters",
outputProtoVertices="amvf_gridseeder_protovertices",
outputVertices="amvf_gridseeder_fittedVertices",
seeder=acts.VertexSeedFinder.AdaptiveGridSeeder,
vertexFinder=VertexFinder.AMVF,
outputDirRoot=tp / "amvf_gridseeder",
)
Expand Down
9 changes: 9 additions & 0 deletions Core/include/Acts/EventData/TrackProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/EventData/MultiTrajectory.hpp"
#include "Acts/EventData/ParticleHypothesis.hpp"
#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/EventData/TrackStatePropMask.hpp"
#include "Acts/Utilities/Concepts.hpp"
#include "Acts/Utilities/HashedString.hpp"
Expand Down Expand Up @@ -618,6 +619,14 @@ class TrackProxy {
return m_index;
}

/// Return the track parameters at the reference surface
/// @note The parameters are created on the fly
/// @return the track parameters
BoundTrackParameters createParametersAtReference() const {
return BoundTrackParameters(referenceSurface().getSharedPtr(), parameters(),
covariance(), particleHypothesis());
}

/// Return a reference to the track container backend, mutable version.
/// @return reference to the track container backend
template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
Expand Down
3 changes: 2 additions & 1 deletion Core/include/Acts/TrackFinding/TrackSelector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ bool TrackSelector::isValidTrack(const track_proxy_t& track) const {

const Config& cuts = *cutsPtr;

return within(track.transverseMomentum(), cuts.ptMin, cuts.ptMax) and
return track.hasReferenceSurface() and
within(track.transverseMomentum(), cuts.ptMin, cuts.ptMax) and
(m_noEtaCuts || (within(absEta(), cuts.absEtaMin, cuts.absEtaMax) and
within(_eta, cuts.etaMin, cuts.etaMax))) and
within(track.phi(), cuts.phiMin, cuts.phiMax) and
Expand Down
3 changes: 0 additions & 3 deletions Core/include/Acts/TrackFitting/GaussianSumFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,6 @@ struct GaussianSumFitter {

calculateTrackQuantities(track);

track.nMeasurements() = measurementStatesFinal;
track.nHoles() = fwdGsfResult.measurementHoles;

return track;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,96 +27,66 @@ struct AlgorithmContext;
ActsExamples::TrackModifier::TrackModifier(const Config& config,
Acts::Logging::Level level)
: IAlgorithm("TrackModifier", level), m_cfg(config) {
if (m_cfg.inputTrajectories.empty() == m_cfg.inputTrackParameters.empty()) {
throw std::invalid_argument(
"Exactly one of trajectories or track parameters input must be set");
if (m_cfg.inputTracks.empty()) {
throw std::invalid_argument("Missing input tracks");
}
if (m_cfg.outputTrajectories.empty() == m_cfg.outputTrackParameters.empty()) {
throw std::invalid_argument(
"Exactly one of trajectories or track parameters output must be set");
}
if (m_cfg.inputTrajectories.empty() != m_cfg.outputTrajectories.empty()) {
throw std::invalid_argument(
"Input and output for trajectories and track parameters have to be "
"used consistently");
if (m_cfg.outputTracks.empty()) {
throw std::invalid_argument("Missing output tracks");
}

m_inputTrackParameters.maybeInitialize(m_cfg.inputTrackParameters);
m_inputTrajectories.maybeInitialize(m_cfg.inputTrajectories);
m_outputTrackParameters.maybeInitialize(m_cfg.outputTrackParameters);
m_outputTrajectories.maybeInitialize(m_cfg.outputTrajectories);
m_inputTracks.initialize(m_cfg.inputTracks);
m_outputTracks.initialize(m_cfg.outputTracks);
}

ActsExamples::ProcessCode ActsExamples::TrackModifier::execute(
const ActsExamples::AlgorithmContext& ctx) const {
auto modifyTrack = [this](auto trk) {
auto modifyTrack = [this](auto& trk) {
{
auto& params = trk.parameters();

if (m_cfg.killTime) {
params[Acts::eBoundTime] = 0;
trk.parameters()[Acts::eBoundTime] = 0;
}
}

{
auto& optCov = trk.covariance();

if (optCov) {
auto& cov = *optCov;

if (m_cfg.dropCovariance) {
cov = Acts::BoundSquareMatrix(cov.diagonal().asDiagonal());
}
if (m_cfg.covScale != 1) {
cov *= m_cfg.covScale;
}
if (m_cfg.killTime) {
cov.row(Acts::eBoundTime).setZero();
cov.col(Acts::eBoundTime).setZero();
cov(Acts::eBoundTime, Acts::eBoundTime) = 1;
}
if (m_cfg.dropCovariance) {
trk.covariance() =
Acts::BoundSquareMatrix(trk.covariance().diagonal().asDiagonal());
}
if (m_cfg.covScale != 1) {
trk.covariance() *= m_cfg.covScale;
}
if (m_cfg.killTime) {
trk.covariance().row(Acts::eBoundTime).setZero();
trk.covariance().col(Acts::eBoundTime).setZero();
trk.covariance()(Acts::eBoundTime, Acts::eBoundTime) = 1;
}
}

return trk;
};

if (!m_cfg.inputTrackParameters.empty()) {
const auto& inputTrackParameters = m_inputTrackParameters(ctx);
TrackParametersContainer outputTrackParameters;
outputTrackParameters.reserve(inputTrackParameters.size());
const auto& inputTracks = m_inputTracks(ctx);

for (uint32_t i = 0; i < inputTrackParameters.size(); ++i) {
const auto& trk = inputTrackParameters[i];
outputTrackParameters.push_back(modifyTrack(trk));
}

m_outputTrackParameters(ctx, std::move(outputTrackParameters));
} else if (!m_cfg.inputTrajectories.empty()) {
const auto& inputTrajectories = m_inputTrajectories(ctx);
TrajectoriesContainer outputTrajectories;
outputTrajectories.reserve(inputTrajectories.size());
auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
auto trackStateContainer = std::make_shared<Acts::VectorMultiTrajectory>();
TrackContainer outputTracks(trackContainer, trackStateContainer);
outputTracks.ensureDynamicColumns(inputTracks);

for (const auto& trajectories : inputTrajectories) {
std::vector<Acts::MultiTrajectoryTraits::IndexType> tips;
tips.reserve(trajectories.tips().size());
Trajectories::IndexedParameters parameters;

for (auto tip : trajectories.tips()) {
if (!trajectories.hasTrackParameters(tip)) {
continue;
}
const auto& trk = trajectories.trackParameters(tip);
tips.push_back(tip);
parameters.emplace(tip, modifyTrack(trk));
}
for (const auto& inputTrack : inputTracks) {
auto outputTrack = outputTracks.getTrack(outputTracks.addTrack());
outputTrack.copyFrom(inputTrack);
modifyTrack(outputTrack);
}

outputTrajectories.emplace_back(trajectories.multiTrajectory(), tips,
parameters);
}
auto constTrackStateContainer =
std::make_shared<Acts::ConstVectorMultiTrajectory>(
std::move(*trackStateContainer));
auto constTrackContainer = std::make_shared<Acts::ConstVectorTrackContainer>(
std::move(*trackContainer));
ConstTrackContainer constTracks{constTrackContainer,
constTrackStateContainer};

m_outputTrajectories(ctx, std::move(outputTrajectories));
}
m_outputTracks(ctx, std::move(constTracks));

return ProcessCode::SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,10 @@ struct AlgorithmContext;
class TrackModifier final : public IAlgorithm {
public:
struct Config {
/// Optional. Input trajectories container. Mutually exclusive with track
/// parameters input.
std::string inputTrajectories;
/// Optional. Input track parameters collection. Mutually exclusive with
/// trajectories input.
std::string inputTrackParameters;
/// Optional. Output trajectories container. Will only be set if
/// trajectories input was set
std::string outputTrajectories;
/// Optional. Output track parameters collection. Will only be set if track
/// parameters input was set.
std::string outputTrackParameters;
/// Input track collection.
std::string inputTracks;
/// Output track collection.
std::string outputTracks;

/// When turned on, only keep the diagonal of the cov matrix.
bool dropCovariance{false};
Expand All @@ -56,15 +48,9 @@ class TrackModifier final : public IAlgorithm {
private:
Config m_cfg;

ReadDataHandle<TrackParametersContainer> m_inputTrackParameters{
this, "InputTrackParameters"};
ReadDataHandle<TrajectoriesContainer> m_inputTrajectories{
this, "InputTrajectories"};
ReadDataHandle<ConstTrackContainer> m_inputTracks{this, "InputTracks"};

WriteDataHandle<TrackParametersContainer> m_outputTrackParameters{
this, "OutputTrackParameters"};
WriteDataHandle<TrajectoriesContainer> m_outputTrajectories{
this, "OutputTrajectories"};
WriteDataHandle<ConstTrackContainer> m_outputTracks{this, "OutputTracks"};
};

} // namespace ActsExamples
3 changes: 2 additions & 1 deletion Examples/Algorithms/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ add_library(
src/SeedsToPrototracks.cpp
src/TrajectoriesToPrototracks.cpp
src/TrackSelectorAlgorithm.cpp
src/TracksToTrajectories.cpp)
src/TracksToTrajectories.cpp
src/TracksToParameters.cpp)
target_include_directories(
ActsExamplesUtilities
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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/.

#pragma once

#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/EventData/Track.hpp"
#include "ActsExamples/EventData/Trajectories.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
#include "ActsExamples/Framework/IAlgorithm.hpp"
#include "ActsExamples/Framework/ProcessCode.hpp"

#include <string>

namespace ActsExamples {

struct AlgorithmContext;

class TracksToParameters final : public IAlgorithm {
public:
struct Config {
std::string inputTracks = "tracks";
std::string outputTrackParameters = "parameters-from-tracks";
};

/// Construct the algorithm.
///
/// @param cfg is the algorithm configuration
/// @param lvl is the logging level
TracksToParameters(Config cfg, Acts::Logging::Level lvl);

/// 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;

ReadDataHandle<ConstTrackContainer> m_inputTracks{this, "InputTracks"};
WriteDataHandle<TrackParametersContainer> m_outputTrackParameters{
this, "OutputTrackParameters"};
};

} // namespace ActsExamples
Loading
Loading