Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Examples/Algorithms/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ acts_add_library(
ExamplesUtilities
src/ProtoTracksToSeeds.cpp
src/SeedsToProtoTracks.cpp
src/SeedsToTracks.cpp
src/TrajectoriesToProtoTracks.cpp
src/TrackSelectorAlgorithm.cpp
src/TracksToTrajectories.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.

#pragma once

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

#include <memory>
#include <string>

namespace Acts {
class TrackingGeometry;
}

namespace ActsExamples {

/// Convert seeds into tracks with one track state per space-point source link.
///
/// Estimated track parameters are optionally attached at track level and as
/// *predicted* parameters on the innermost state, whose surface they are
/// expressed on. State reference surfaces are optionally taken from the
/// source-link geometry identifiers.
///
/// @note A space point can carry several source links, e.g. the two sides of a
/// strip module, and each becomes its own state. `nMeasurements` and any
/// downstream `Acts::TrackSelector::MeasurementCounter` threshold
/// therefore count source links, not space points.
class SeedsToTracks final : public IAlgorithm {
public:
struct Config {
/// Input seeds.
std::string inputSeeds = "seeds";
/// Optional. Track parameters parallel to the input seeds.
std::string inputTrackParameters;
/// Output tracks.
std::string outputTracks = "tracks-from-seeds";
/// Optional. Source of the track-state reference surfaces.
std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry;
};

/// Construct the algorithm.
///
/// @param cfg is the algorithm configuration
/// @param logger is the logger
explicit SeedsToTracks(Config cfg,
std::unique_ptr<const Acts::Logger> logger = nullptr);

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

/// Const access to the config
const Config& config() const { return m_cfg; }

private:
Config m_cfg;

ReadDataHandle<SeedContainer> m_inputSeeds{this, "InputSeeds"};
ReadDataHandle<TrackParametersContainer> m_inputTrackParameters{
this, "InputTrackParameters"};
WriteDataHandle<ConstTrackContainer> m_outputTracks{this, "OutputTracks"};
};

} // namespace ActsExamples
126 changes: 126 additions & 0 deletions Examples/Algorithms/Utilities/src/SeedsToTracks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.

#include "ActsExamples/Utilities/SeedsToTracks.hpp"

#include "Acts/EventData/SourceLink.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "ActsExamples/EventData/IndexSourceLink.hpp"

#include <sstream>
#include <stdexcept>
#include <utility>

namespace ActsExamples {

SeedsToTracks::SeedsToTracks(Config cfg,
std::unique_ptr<const Acts::Logger> logger)
: IAlgorithm("SeedsToTracks", std::move(logger)), m_cfg(std::move(cfg)) {
m_inputSeeds.initialize(m_cfg.inputSeeds);
m_inputTrackParameters.maybeInitialize(m_cfg.inputTrackParameters);
m_outputTracks.initialize(m_cfg.outputTracks);
}

ProcessCode SeedsToTracks::execute(const AlgorithmContext& ctx) const {
const SeedContainer& seeds = m_inputSeeds(ctx);
ACTS_DEBUG("Received " << seeds.size() << " seeds");

const TrackParametersContainer* trackParameters = nullptr;
if (m_inputTrackParameters.isInitialized()) {
trackParameters = &m_inputTrackParameters(ctx);

if (trackParameters->size() != seeds.size()) {
throw std::runtime_error(
"Number of seeds and track parameters do not match");
}
}

const bool hasTrackParameters = trackParameters != nullptr;

auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
auto mtj = std::make_shared<Acts::VectorMultiTrajectory>();
TrackContainer tracks(trackContainer, mtj);

for (std::size_t i = 0; i < seeds.size(); ++i) {
const auto seed = seeds.at(i);

auto track = tracks.makeTrack();
std::uint32_t nMeasurements = 0;

for (const auto& sp : seed.spacePoints()) {
for (const auto& sourceLink : sp.sourceLinks()) {
// `TrackParamsEstimationAlgorithm` expresses the estimate on the
// bottom space point's surface, which is the first one here
const bool attachParameters = hasTrackParameters &&
nMeasurements == 0 &&
m_cfg.trackingGeometry != nullptr;

auto trackStateProxy = track.appendTrackState(
attachParameters ? Acts::TrackStatePropMask::Predicted
: Acts::TrackStatePropMask::None);
trackStateProxy.typeFlags().setIsMeasurement();
trackStateProxy.setUncalibratedSourceLink(Acts::SourceLink(sourceLink));
++nMeasurements;

if (m_cfg.trackingGeometry != nullptr) {
const Acts::GeometryIdentifier geoId =
sourceLink.get<IndexSourceLink>().geometryId();
const Acts::Surface* surface =
m_cfg.trackingGeometry->findSurface(geoId);
if (surface == nullptr) {
std::ostringstream oss;
oss << "No surface found for source-link geometry id " << geoId;
throw std::runtime_error(oss.str());
}
trackStateProxy.setReferenceSurface(surface->getSharedPtr());
}

if (attachParameters) {
const auto& trackParams = trackParameters->at(i);
trackStateProxy.predicted() = trackParams.parameters();
trackStateProxy.predictedCovariance() =
trackParams.covariance().value_or(Acts::BoundMatrix::Zero());
// the estimate is all that is known at this state, so it stands in
// for the filtered and smoothed parameters rather than being stored
// again. that is also what lets
// `Acts::findTrackStateForExtrapolation` start from this state.
trackStateProxy.shareFrom(Acts::TrackStatePropMask::Predicted,
Acts::TrackStatePropMask::Filtered);
trackStateProxy.shareFrom(Acts::TrackStatePropMask::Predicted,
Acts::TrackStatePropMask::Smoothed);
}
}
}

track.nMeasurements() = nMeasurements;
track.nHoles() = 0;
track.nOutliers() = 0;

if (hasTrackParameters) {
const auto& trackParams = trackParameters->at(i);

track.setReferenceSurface(trackParams.referenceSurface().getSharedPtr());
track.parameters() = trackParams.parameters();
track.covariance() =
trackParams.covariance().value_or(Acts::BoundMatrix::Zero());
}
}

ConstTrackContainer constTracks{
std::make_shared<Acts::ConstVectorTrackContainer>(
std::move(*trackContainer)),
std::make_shared<Acts::ConstVectorMultiTrajectory>(std::move(*mtj))};

ACTS_DEBUG("Produced " << constTracks.size() << " tracks");

m_outputTracks(ctx, std::move(constTracks));

return ProcessCode::SUCCESS;
}

} // namespace ActsExamples
6 changes: 3 additions & 3 deletions Python/Examples/python/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,12 @@ def addSeeding(

tracks = f"{prefix}seed-tracks"
s.addAlgorithm(
acts.examples.ProtoTracksToTracks(
acts.examples.SeedsToTracks(
level=logLevel,
inputProtoTracks=protoTracks,
inputSeeds=f"{prefix}estimatedseeds",
inputTrackParameters=f"{prefix}estimatedparameters",
inputMeasurements=f"{prefix}measurement_subset",
outputTracks=tracks,
trackingGeometry=trackingGeometry,
)
)

Expand Down
5 changes: 5 additions & 0 deletions Python/Examples/src/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ActsExamples/Utilities/ProtoTracksToSeeds.hpp"
#include "ActsExamples/Utilities/ProtoTracksToTracks.hpp"
#include "ActsExamples/Utilities/SeedsToProtoTracks.hpp"
#include "ActsExamples/Utilities/SeedsToTracks.hpp"
#include "ActsExamples/Utilities/TracksToParameters.hpp"
#include "ActsExamples/Utilities/TracksToTrajectories.hpp"
#include "ActsExamples/Utilities/TrajectoriesToProtoTracks.hpp"
Expand Down Expand Up @@ -41,6 +42,10 @@ void addUtilities(py::module& mex) {
ACTS_PYTHON_DECLARE_ALGORITHM(SeedsToProtoTracks, mex, "SeedsToProtoTracks",
inputSeeds, outputProtoTracks);

ACTS_PYTHON_DECLARE_ALGORITHM(SeedsToTracks, mex, "SeedsToTracks", inputSeeds,
inputTrackParameters, outputTracks,
trackingGeometry);

ACTS_PYTHON_DECLARE_ALGORITHM(ProtoTracksToSeeds, mex, "ProtoTracksToSeeds",
inputProtoTracks, inputSpacePoints, outputSeeds,
outputProtoTracks);
Expand Down
Loading