Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EDM4hepMeasurementReader.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EDM4hepMeasurementReader.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 
16 
17 #include <list>
18 #include <stdexcept>
19 
20 #include <edm4hep/TrackerHit.h>
21 #include <edm4hep/TrackerHitCollection.h>
22 #include <edm4hep/TrackerHitPlane.h>
23 #include <edm4hep/TrackerHitPlaneCollection.h>
24 #include <podio/Frame.h>
25 
26 namespace ActsExamples {
27 
30  : m_cfg(config),
31  m_logger(Acts::getDefaultLogger("EDM4hepMeasurementReader", level)) {
32  if (m_cfg.outputMeasurements.empty()) {
33  throw std::invalid_argument("Missing measurement output collection");
34  }
35 
36  m_reader.openFile(m_cfg.inputPath);
37 
38  m_eventsRange = std::make_pair(0, m_reader.getEntries("events"));
39 
44 }
45 
47  return "EDM4hepMeasurementReader";
48 }
49 
50 std::pair<size_t, size_t> EDM4hepMeasurementReader::availableEvents() const {
51  return m_eventsRange;
52 }
53 
55  MeasurementContainer measurements;
57  // TODO what about those?
58  IndexMultimap<Index> measurementSimHitsMap;
59  IndexSourceLinkContainer sourceLinks;
60 
61  podio::Frame frame = m_reader.readEntry("events", ctx.eventNumber);
62 
63  const auto& trackerHitPlaneCollection =
64  frame.get<edm4hep::TrackerHitPlaneCollection>("ActsTrackerHitsPlane");
65  const auto& trackerHitRawCollection =
66  frame.get<edm4hep::TrackerHitCollection>("ActsTrackerHitsRaw");
67 
68  for (const auto& trackerHitPlane : trackerHitPlaneCollection) {
69  Cluster cluster;
70  auto measurement = EDM4hepUtil::readMeasurement(
71  trackerHitPlane, &trackerHitRawCollection, &cluster,
72  [](std::uint64_t cellId) { return Acts::GeometryIdentifier(cellId); });
73 
74  measurements.push_back(std::move(measurement));
75  clusters.push_back(std::move(cluster));
76  }
77 
78  // Write the data to the EventStore
79  m_outputMeasurements(ctx, std::move(measurements));
80  m_outputMeasurementSimHitsMap(ctx, std::move(measurementSimHitsMap));
81  m_outputSourceLinks(ctx, std::move(sourceLinks));
82  if (not m_cfg.outputClusters.empty()) {
83  m_outputClusters(ctx, std::move(clusters));
84  }
85 
86  return ProcessCode::SUCCESS;
87 }
88 
89 } // namespace ActsExamples