File indexing completed on 2025-01-18 09:11:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/EDM4hep/EDM4hepMeasurementReader.hpp"
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Plugins/EDM4hep/TrackerHitCompatibility.hpp"
0013 #include "Acts/Plugins/Podio/PodioUtil.hpp"
0014 #include "ActsExamples/EventData/Cluster.hpp"
0015 #include "ActsExamples/EventData/Measurement.hpp"
0016 #include "ActsExamples/Framework/WhiteBoard.hpp"
0017 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0018
0019 #include <list>
0020 #include <stdexcept>
0021
0022 #include <edm4hep/TrackerHitPlane.h>
0023 #include <edm4hep/TrackerHitPlaneCollection.h>
0024
0025 namespace ActsExamples {
0026
0027 EDM4hepMeasurementReader::EDM4hepMeasurementReader(
0028 const EDM4hepMeasurementReader::Config& config, Acts::Logging::Level level)
0029 : m_cfg(config),
0030 m_logger(Acts::getDefaultLogger("EDM4hepMeasurementReader", level)) {
0031 if (m_cfg.outputMeasurements.empty()) {
0032 throw std::invalid_argument("Missing measurement output collection");
0033 }
0034
0035 m_eventsRange = std::make_pair(0, reader().getEntries("events"));
0036
0037 m_outputMeasurements.initialize(m_cfg.outputMeasurements);
0038 m_outputMeasurementSimHitsMap.initialize(m_cfg.outputMeasurementSimHitsMap);
0039 m_outputClusters.maybeInitialize(m_cfg.outputClusters);
0040 }
0041
0042 std::string EDM4hepMeasurementReader::EDM4hepMeasurementReader::name() const {
0043 return "EDM4hepMeasurementReader";
0044 }
0045
0046 std::pair<std::size_t, std::size_t> EDM4hepMeasurementReader::availableEvents()
0047 const {
0048 return m_eventsRange;
0049 }
0050
0051 ProcessCode EDM4hepMeasurementReader::read(const AlgorithmContext& ctx) {
0052 MeasurementContainer measurements;
0053 ClusterContainer clusters;
0054
0055 IndexMultimap<Index> measurementSimHitsMap;
0056
0057 podio::Frame frame = reader().readEntry("events", ctx.eventNumber);
0058
0059 const auto& trackerHitPlaneCollection =
0060 frame.get<edm4hep::TrackerHitPlaneCollection>("ActsTrackerHitsPlane");
0061 const auto& trackerHitRawCollection =
0062 frame.get<edm4hep::TrackerHit3DCollection>("ActsTrackerHitsRaw");
0063
0064 for (const auto& trackerHitPlane : trackerHitPlaneCollection) {
0065 Cluster cluster;
0066 EDM4hepUtil::readMeasurement(
0067 measurements, trackerHitPlane, &trackerHitRawCollection, &cluster,
0068 [](std::uint64_t cellId) { return Acts::GeometryIdentifier(cellId); });
0069
0070 clusters.push_back(std::move(cluster));
0071 }
0072
0073
0074 m_outputMeasurements(ctx, std::move(measurements));
0075 m_outputMeasurementSimHitsMap(ctx, std::move(measurementSimHitsMap));
0076 if (!m_cfg.outputClusters.empty()) {
0077 m_outputClusters(ctx, std::move(clusters));
0078 }
0079
0080 return ProcessCode::SUCCESS;
0081 }
0082
0083 Acts::PodioUtil::ROOTReader& EDM4hepMeasurementReader::reader() {
0084 bool exists = false;
0085 auto& reader = m_reader.local(exists);
0086 if (!exists) {
0087 reader.openFile(m_cfg.inputPath);
0088 }
0089
0090 return reader;
0091 }
0092
0093 }