Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:08:06

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/PrototracksToTracks.hpp"
0010 
0011 #include "Acts/EventData/SourceLink.hpp"
0012 #include "ActsExamples/EventData/IndexSourceLink.hpp"
0013 #include "ActsExamples/EventData/Track.hpp"
0014 
0015 #include <algorithm>
0016 #include <limits>
0017 
0018 namespace ActsExamples {
0019 
0020 PrototracksToTracks::PrototracksToTracks(Config cfg, Acts::Logging::Level lvl)
0021     : IAlgorithm("PrototracksToTracks", lvl), m_cfg(std::move(cfg)) {
0022   m_outputTracks.initialize(m_cfg.outputTracks);
0023   m_inputMeasurements.initialize(m_cfg.inputMeasurements);
0024   m_inputTrackParameters.maybeInitialize(m_cfg.inputTrackParameters);
0025   m_inputProtoTracks.initialize(m_cfg.inputProtoTracks);
0026 }
0027 
0028 ProcessCode PrototracksToTracks::execute(const AlgorithmContext& ctx) const {
0029   const auto& measurements = m_inputMeasurements(ctx);
0030 
0031   auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
0032   auto mtj = std::make_shared<Acts::VectorMultiTrajectory>();
0033   TrackContainer tracks(trackContainer, mtj);
0034 
0035   const auto& prototracks = m_inputProtoTracks(ctx);
0036   ACTS_DEBUG("Received " << prototracks.size() << " prototracks");
0037 
0038   const TrackParametersContainer* trackParameters = nullptr;
0039   if (m_inputTrackParameters.isInitialized()) {
0040     trackParameters = &m_inputTrackParameters(ctx);
0041 
0042     if (trackParameters->size() != prototracks.size()) {
0043       throw std::runtime_error(
0044           "Number of prototracks and track parameters do not match");
0045     }
0046   }
0047 
0048   float avgSize = 0;
0049   std::size_t minSize = std::numeric_limits<std::size_t>::max();
0050   std::size_t maxSize = 0;
0051 
0052   for (std::size_t i = 0; i < prototracks.size(); ++i) {
0053     const auto& protoTrack = prototracks[i];
0054 
0055     if (protoTrack.empty()) {
0056       continue;
0057     }
0058 
0059     avgSize += static_cast<float>(protoTrack.size());
0060     minSize = std::min(minSize, protoTrack.size());
0061     maxSize = std::max(maxSize, protoTrack.size());
0062 
0063     auto track = tracks.makeTrack();
0064     for (auto measIndex : protoTrack) {
0065       ConstVariableBoundMeasurementProxy measurement =
0066           measurements.getMeasurement(measIndex);
0067       IndexSourceLink sourceLink(measurement.geometryId(), measIndex);
0068 
0069       auto trackStateProxy =
0070           track.appendTrackState(Acts::TrackStatePropMask::None);
0071       trackStateProxy.typeFlags().setIsMeasurement();
0072       trackStateProxy.setUncalibratedSourceLink(Acts::SourceLink(sourceLink));
0073     }
0074 
0075     track.nMeasurements() = static_cast<std::uint32_t>(protoTrack.size());
0076     track.nHoles() = 0;
0077     track.nOutliers() = 0;
0078 
0079     if (trackParameters != nullptr) {
0080       const auto& trackParams = trackParameters->at(i);
0081 
0082       track.setReferenceSurface(trackParams.referenceSurface().getSharedPtr());
0083       track.parameters() = trackParams.parameters();
0084       if (trackParams.covariance().has_value()) {
0085         track.covariance() = *trackParams.covariance();
0086       }
0087     }
0088   }
0089 
0090   ConstTrackContainer constTracks{
0091       std::make_shared<Acts::ConstVectorTrackContainer>(
0092           std::move(*trackContainer)),
0093       std::make_shared<Acts::ConstVectorMultiTrajectory>(std::move(*mtj))};
0094 
0095   ACTS_DEBUG("Produced " << constTracks.size() << " tracks");
0096   ACTS_DEBUG(
0097       "Avg track size: " << (constTracks.size() > 0
0098                                  ? avgSize / constTracks.size()
0099                                  : std::numeric_limits<float>::quiet_NaN()));
0100   ACTS_DEBUG("Min track size: " << minSize << ", max track size " << maxSize);
0101 
0102   m_outputTracks(ctx, std::move(constTracks));
0103 
0104   return ProcessCode::SUCCESS;
0105 }
0106 
0107 }  // namespace ActsExamples