EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackFindingAlgorithm.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackFindingAlgorithm.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
14 
15 #include <stdexcept>
16 
18  Config cfg, Acts::Logging::Level level)
19  : ActsExamples::BareAlgorithm("TrackFindingAlgorithm", level),
20  m_cfg(std::move(cfg)) {
21  if (m_cfg.inputSourceLinks.empty()) {
22  throw std::invalid_argument("Missing input source links collection");
23  }
24  if (m_cfg.inputInitialTrackParameters.empty()) {
25  throw std::invalid_argument(
26  "Missing input initial track parameters collection");
27  }
28  if (m_cfg.outputTrajectories.empty()) {
29  throw std::invalid_argument("Missing output trajectories collection");
30  }
31 }
32 
34  const ActsExamples::AlgorithmContext& ctx) const {
35  // Read input data
36  const auto sourceLinks =
37  ctx.eventStore.get<SimSourceLinkContainer>(m_cfg.inputSourceLinks);
38  const auto initialParameters = ctx.eventStore.get<TrackParametersContainer>(
39  m_cfg.inputInitialTrackParameters);
40 
41  // Prepare the output data with MultiTrajectory
42  TrajectoryContainer trajectories;
43  trajectories.reserve(initialParameters.size());
44 
45  // Construct a perigee surface as the target surface
46  auto pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(
47  Acts::Vector3D{0., 0., 0.});
48 
50  pOptions.maxSteps = 10000;
51 
52  // Set the CombinatorialKalmanFilter options
55  m_cfg.sourcelinkSelectorCfg, Acts::LoggerWrapper{logger()}, pOptions,
56  &(*pSurface));
57 
58  // Perform the track finding for each starting parameter
59  // @TODO: use seeds from track seeding algorithm as starting parameter
60  for (std::size_t iseed = 0; iseed < initialParameters.size(); ++iseed) {
61  const auto& initialParams = initialParameters[iseed];
62 
63  ACTS_DEBUG("Invoke track finding seeded by truth particle " << iseed);
64  auto result = m_cfg.findTracks(sourceLinks, initialParams, ckfOptions);
65  if (result.ok()) {
66  // Get the track finding output object
67  const auto& trackFindingOutput = result.value();
68  // Create a SimMultiTrajectory
69  trajectories.emplace_back(std::move(trackFindingOutput.fittedStates),
70  std::move(trackFindingOutput.trackTips),
71  std::move(trackFindingOutput.fittedParameters));
72  } else {
73  ACTS_WARNING("Track finding failed for truth seed "
74  << iseed << " with error" << result.error());
75  // Track finding failed, but still create an empty SimMultiTrajectory
76  trajectories.push_back(SimMultiTrajectory());
77  }
78  }
79 
80  ctx.eventStore.add(m_cfg.outputTrajectories, std::move(trajectories));
82 }