30 #include <system_error>
36 : ActsExamples::
IAlgorithm(
"TrackFittingAlgorithm", level),
39 throw std::invalid_argument(
"Missing input measurement collection");
42 throw std::invalid_argument(
"Missing input source links collection");
45 throw std::invalid_argument(
"Missing input proto tracks collection");
48 throw std::invalid_argument(
49 "Missing input initial track parameters collection");
52 throw std::invalid_argument(
"Missing output tracks collection");
55 throw std::invalid_argument(
"Missing calibrator");
58 throw std::invalid_argument(
"The configured calibrator needs clusters");
72 const auto& measurements = m_inputMeasurements(ctx);
73 const auto& sourceLinks = m_inputSourceLinks(ctx);
74 const auto& protoTracks = m_inputProtoTracks(ctx);
75 const auto& initialParameters = m_inputInitialTrackParameters(ctx);
78 m_inputClusters.isInitialized() ? &m_inputClusters(ctx) :
nullptr;
81 if (protoTracks.size() != initialParameters.size()) {
82 ACTS_FATAL(
"Inconsistent number of proto tracks and parameters "
83 << protoTracks.size() <<
" vs " << initialParameters.size());
84 return ProcessCode::ABORT;
88 auto pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(
95 measurements, clusters);
101 auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
102 auto trackStateContainer = std::make_shared<Acts::VectorMultiTrajectory>();
106 std::vector<Acts::SourceLink> trackSourceLinks;
107 for (std::size_t itrack = 0; itrack < protoTracks.size(); ++itrack) {
109 if (
m_cfg.pickTrack > -1 and
m_cfg.pickTrack != static_cast<int>(itrack)) {
114 const auto& protoTrack = protoTracks[itrack];
115 const auto& initialParams = initialParameters[itrack];
119 if (protoTrack.empty()) {
125 << initialParams.fourPosition(ctx.
geoContext).transpose()
126 <<
" -> " << initialParams.direction().transpose());
129 trackSourceLinks.clear();
130 trackSourceLinks.reserve(protoTrack.size());
133 for (
auto hitIndex : protoTrack) {
134 if (
auto it = sourceLinks.nth(hitIndex);
it != sourceLinks.end()) {
138 ACTS_FATAL(
"Proto track " << itrack <<
" contains invalid hit index"
140 return ProcessCode::ABORT;
144 ACTS_DEBUG(
"Invoke direct fitter for track " << itrack);
145 auto result = (*
m_cfg.fit)(trackSourceLinks, initialParams,
options,
150 const auto& track = result.value();
151 if (track.hasReferenceSurface()) {
155 ACTS_DEBUG(
"No fitted parameters for track " << itrack);
159 << itrack <<
" with error: " << result.error() <<
", "
160 << result.error().message());
164 std::stringstream ss;
165 trackStateContainer->statistics().toStream(ss);
169 std::make_shared<Acts::ConstVectorTrackContainer>(
171 std::make_shared<Acts::ConstVectorMultiTrajectory>(
174 m_outputTracks(ctx,
std::move(constTracks));