Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 08:18:58

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Utilities/SeedsToTracks.hpp"
0010 
0011 #include "Acts/EventData/SourceLink.hpp"
0012 #include "Acts/Geometry/TrackingGeometry.hpp"
0013 #include "ActsExamples/EventData/IndexSourceLink.hpp"
0014 
0015 #include <sstream>
0016 #include <stdexcept>
0017 #include <utility>
0018 
0019 namespace ActsExamples {
0020 
0021 SeedsToTracks::SeedsToTracks(Config cfg,
0022                              std::unique_ptr<const Acts::Logger> logger)
0023     : IAlgorithm("SeedsToTracks", std::move(logger)), m_cfg(std::move(cfg)) {
0024   m_inputSeeds.initialize(m_cfg.inputSeeds);
0025   m_inputTrackParameters.maybeInitialize(m_cfg.inputTrackParameters);
0026   m_outputTracks.initialize(m_cfg.outputTracks);
0027 }
0028 
0029 ProcessCode SeedsToTracks::execute(const AlgorithmContext& ctx) const {
0030   const SeedContainer& seeds = m_inputSeeds(ctx);
0031   ACTS_DEBUG("Received " << seeds.size() << " seeds");
0032 
0033   const TrackParametersContainer* trackParameters = nullptr;
0034   if (m_inputTrackParameters.isInitialized()) {
0035     trackParameters = &m_inputTrackParameters(ctx);
0036 
0037     if (trackParameters->size() != seeds.size()) {
0038       throw std::runtime_error(
0039           "Number of seeds and track parameters do not match");
0040     }
0041   }
0042 
0043   const bool hasTrackParameters = trackParameters != nullptr;
0044 
0045   auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
0046   auto mtj = std::make_shared<Acts::VectorMultiTrajectory>();
0047   TrackContainer tracks(trackContainer, mtj);
0048 
0049   for (std::size_t i = 0; i < seeds.size(); ++i) {
0050     const auto seed = seeds.at(i);
0051 
0052     auto track = tracks.makeTrack();
0053     std::uint32_t nMeasurements = 0;
0054 
0055     for (const auto& sp : seed.spacePoints()) {
0056       for (const auto& sourceLink : sp.sourceLinks()) {
0057         // `TrackParamsEstimationAlgorithm` expresses the estimate on the
0058         // bottom space point's surface, which is the first one here
0059         const bool attachParameters = hasTrackParameters &&
0060                                       nMeasurements == 0 &&
0061                                       m_cfg.trackingGeometry != nullptr;
0062 
0063         auto trackStateProxy = track.appendTrackState(
0064             attachParameters ? Acts::TrackStatePropMask::Predicted
0065                              : Acts::TrackStatePropMask::None);
0066         trackStateProxy.typeFlags().setIsMeasurement();
0067         trackStateProxy.setUncalibratedSourceLink(Acts::SourceLink(sourceLink));
0068         ++nMeasurements;
0069 
0070         if (m_cfg.trackingGeometry != nullptr) {
0071           const Acts::GeometryIdentifier geoId =
0072               sourceLink.get<IndexSourceLink>().geometryId();
0073           const Acts::Surface* surface =
0074               m_cfg.trackingGeometry->findSurface(geoId);
0075           if (surface == nullptr) {
0076             std::ostringstream oss;
0077             oss << "No surface found for source-link geometry id " << geoId;
0078             throw std::runtime_error(oss.str());
0079           }
0080           trackStateProxy.setReferenceSurface(surface->getSharedPtr());
0081         }
0082 
0083         if (attachParameters) {
0084           const auto& trackParams = trackParameters->at(i);
0085           trackStateProxy.predicted() = trackParams.parameters();
0086           trackStateProxy.predictedCovariance() =
0087               trackParams.covariance().value_or(Acts::BoundMatrix::Zero());
0088           // the estimate is all that is known at this state, so it stands in
0089           // for the filtered and smoothed parameters rather than being stored
0090           // again. that is also what lets
0091           // `Acts::findTrackStateForExtrapolation` start from this state.
0092           trackStateProxy.shareFrom(Acts::TrackStatePropMask::Predicted,
0093                                     Acts::TrackStatePropMask::Filtered);
0094           trackStateProxy.shareFrom(Acts::TrackStatePropMask::Predicted,
0095                                     Acts::TrackStatePropMask::Smoothed);
0096         }
0097       }
0098     }
0099 
0100     track.nMeasurements() = nMeasurements;
0101     track.nHoles() = 0;
0102     track.nOutliers() = 0;
0103 
0104     if (hasTrackParameters) {
0105       const auto& trackParams = trackParameters->at(i);
0106 
0107       track.setReferenceSurface(trackParams.referenceSurface().getSharedPtr());
0108       track.parameters() = trackParams.parameters();
0109       track.covariance() =
0110           trackParams.covariance().value_or(Acts::BoundMatrix::Zero());
0111     }
0112   }
0113 
0114   ConstTrackContainer constTracks{
0115       std::make_shared<Acts::ConstVectorTrackContainer>(
0116           std::move(*trackContainer)),
0117       std::make_shared<Acts::ConstVectorMultiTrajectory>(std::move(*mtj))};
0118 
0119   ACTS_DEBUG("Produced " << constTracks.size() << " tracks");
0120 
0121   m_outputTracks(ctx, std::move(constTracks));
0122 
0123   return ProcessCode::SUCCESS;
0124 }
0125 
0126 }  // namespace ActsExamples