Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:47

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Io/EDM4hep/EDM4hepMeasurementReader.hpp"
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "ActsExamples/EventData/Cluster.hpp"
0013 #include "ActsExamples/EventData/Measurement.hpp"
0014 #include "ActsExamples/Framework/WhiteBoard.hpp"
0015 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0016 
0017 #include <list>
0018 #include <stdexcept>
0019 
0020 #include <edm4hep/TrackerHit.h>
0021 #include <edm4hep/TrackerHitCollection.h>
0022 #include <edm4hep/TrackerHitPlane.h>
0023 #include <edm4hep/TrackerHitPlaneCollection.h>
0024 #include <podio/Frame.h>
0025 
0026 namespace ActsExamples {
0027 
0028 EDM4hepMeasurementReader::EDM4hepMeasurementReader(
0029     const EDM4hepMeasurementReader::Config& config, Acts::Logging::Level level)
0030     : m_cfg(config),
0031       m_logger(Acts::getDefaultLogger("EDM4hepMeasurementReader", level)) {
0032   if (m_cfg.outputMeasurements.empty()) {
0033     throw std::invalid_argument("Missing measurement output collection");
0034   }
0035 
0036   m_eventsRange = std::make_pair(0, reader().getEntries("events"));
0037 
0038   m_outputMeasurements.initialize(m_cfg.outputMeasurements);
0039   m_outputMeasurementSimHitsMap.initialize(m_cfg.outputMeasurementSimHitsMap);
0040   m_outputSourceLinks.initialize(m_cfg.outputSourceLinks);
0041   m_outputClusters.maybeInitialize(m_cfg.outputClusters);
0042 }
0043 
0044 std::string EDM4hepMeasurementReader::EDM4hepMeasurementReader::name() const {
0045   return "EDM4hepMeasurementReader";
0046 }
0047 
0048 std::pair<std::size_t, std::size_t> EDM4hepMeasurementReader::availableEvents()
0049     const {
0050   return m_eventsRange;
0051 }
0052 
0053 ProcessCode EDM4hepMeasurementReader::read(const AlgorithmContext& ctx) {
0054   MeasurementContainer measurements;
0055   ClusterContainer clusters;
0056   // TODO what about those?
0057   IndexMultimap<Index> measurementSimHitsMap;
0058   IndexSourceLinkContainer sourceLinks;
0059 
0060   podio::Frame frame = reader().readEntry("events", ctx.eventNumber);
0061 
0062   const auto& trackerHitPlaneCollection =
0063       frame.get<edm4hep::TrackerHitPlaneCollection>("ActsTrackerHitsPlane");
0064   const auto& trackerHitRawCollection =
0065       frame.get<edm4hep::TrackerHitCollection>("ActsTrackerHitsRaw");
0066 
0067   for (const auto& trackerHitPlane : trackerHitPlaneCollection) {
0068     Cluster cluster;
0069     auto measurement = EDM4hepUtil::readMeasurement(
0070         trackerHitPlane, &trackerHitRawCollection, &cluster,
0071         [](std::uint64_t cellId) { return Acts::GeometryIdentifier(cellId); });
0072 
0073     measurements.push_back(std::move(measurement));
0074     clusters.push_back(std::move(cluster));
0075   }
0076 
0077   // Write the data to the EventStore
0078   m_outputMeasurements(ctx, std::move(measurements));
0079   m_outputMeasurementSimHitsMap(ctx, std::move(measurementSimHitsMap));
0080   m_outputSourceLinks(ctx, std::move(sourceLinks));
0081   if (!m_cfg.outputClusters.empty()) {
0082     m_outputClusters(ctx, std::move(clusters));
0083   }
0084 
0085   return ProcessCode::SUCCESS;
0086 }
0087 
0088 podio::ROOTFrameReader& EDM4hepMeasurementReader::reader() {
0089   bool exists = false;
0090   auto& reader = m_reader.local(exists);
0091   if (!exists) {
0092     reader.openFile(m_cfg.inputPath);
0093   }
0094 
0095   return reader;
0096 }
0097 
0098 }  // namespace ActsExamples