Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EDM4hepTrackReader.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EDM4hepTrackReader.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 
13 
14 #include <stdexcept>
15 
16 #include <edm4hep/TrackCollection.h>
17 #include <podio/Frame.h>
18 
19 namespace ActsExamples {
20 
23  : m_cfg(config),
24  m_logger(Acts::getDefaultLogger("EDM4hepSimHitReader", level)) {
25  if (m_cfg.outputTracks.empty()) {
26  throw std::invalid_argument("Missing output trajectories collection");
27  }
28 
30 
31  m_reader.openFile(m_cfg.inputPath);
32 }
33 
34 std::pair<size_t, size_t> EDM4hepTrackReader::availableEvents() const {
35  return {0, m_reader.getEntries("events")};
36 }
37 
39  return "EDM4hepTrackReader";
40 }
41 
43  podio::Frame frame = m_reader.readEntry("events", ctx.eventNumber);
44 
45  const auto& trackCollection =
46  frame.get<edm4hep::TrackCollection>(m_cfg.inputTracks);
47 
48  auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
49  auto trackStateContainer = std::make_shared<Acts::VectorMultiTrajectory>();
50  TrackContainer tracks(trackContainer, trackStateContainer);
51 
52  for (const auto& inputTrack : trackCollection) {
53  auto track = tracks.getTrack(tracks.addTrack());
54  Acts::EDM4hepUtil::readTrack(inputTrack, track, m_cfg.Bz);
55  }
56 
57  ConstTrackContainer constTracks{
58  std::make_shared<Acts::ConstVectorTrackContainer>(
59  std::move(*trackContainer)),
60  std::make_shared<Acts::ConstVectorMultiTrajectory>(
61  std::move(*trackStateContainer))};
62 
63  m_outputTracks(ctx, std::move(constTracks));
64 
65  return ProcessCode::SUCCESS;
66 }
67 
68 } // namespace ActsExamples