Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /acts/Examples/Algorithms/Utilities/src/ProtoTracksToTracks.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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