Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-08 08:10:30

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