Skip to content

Commit

Permalink
refactor: Refactor Examples to use tracks instead of trajectories (#2560
Browse files Browse the repository at this point in the history
)

Currently we mix the usage of track and trajectory containers. In this PR I replace all the trajectory inputs to our writers in favor of track containers.

blocked by
- #2549
  • Loading branch information
andiwand committed Oct 28, 2023
1 parent 166c57a commit 0e44bd2
Show file tree
Hide file tree
Showing 68 changed files with 2,206 additions and 2,364 deletions.
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

0 comments on commit 0e44bd2

Please sign in to comment.