Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:23:51

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Io/EDM4hep/EDM4hepMeasurementInputConverter.hpp"
0010 
0011 #include "ActsExamples/EventData/Cluster.hpp"
0012 #include "ActsExamples/EventData/Measurement.hpp"
0013 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0014 #include "ActsPlugins/EDM4hep/PodioUtil.hpp"
0015 
0016 #include <stdexcept>
0017 
0018 #include <edm4hep/TrackerHitPlane.h>
0019 #include <edm4hep/TrackerHitPlaneCollection.h>
0020 #include <podio/Frame.h>
0021 
0022 namespace ActsExamples {
0023 
0024 EDM4hepMeasurementInputConverter::EDM4hepMeasurementInputConverter(
0025     const EDM4hepMeasurementInputConverter::Config& config,
0026     Acts::Logging::Level level)
0027     : PodioInputConverter("EDM4hepMeasurementInputConverter", level,
0028                           config.inputFrame),
0029       m_cfg(config) {
0030   if (m_cfg.outputMeasurements.empty()) {
0031     throw std::invalid_argument("Missing measurement output collection");
0032   }
0033 
0034   if (m_cfg.inputFrame.empty()) {
0035     throw std::invalid_argument("Missing input frame");
0036   }
0037 
0038   m_inputFrame.initialize(m_cfg.inputFrame);
0039 
0040   m_outputMeasurements.initialize(m_cfg.outputMeasurements);
0041   m_outputMeasurementSimHitsMap.initialize(m_cfg.outputMeasurementSimHitsMap);
0042   m_outputClusters.maybeInitialize(m_cfg.outputClusters);
0043 }
0044 
0045 ProcessCode EDM4hepMeasurementInputConverter::convert(
0046     const AlgorithmContext& ctx, const podio::Frame& frame) const {
0047   MeasurementContainer measurements;
0048   ClusterContainer clusters;
0049   // TODO what about those?
0050   IndexMultimap<Index> measurementSimHitsMap;
0051 
0052   const auto& trackerHitPlaneCollection =
0053       frame.get<edm4hep::TrackerHitPlaneCollection>("ActsTrackerHitsPlane");
0054   const auto& trackerHitRawCollection =
0055       frame.get<edm4hep::TrackerHit3DCollection>("ActsTrackerHitsRaw");
0056 
0057   for (const auto& trackerHitPlane : trackerHitPlaneCollection) {
0058     Cluster cluster;
0059     EDM4hepUtil::readMeasurement(
0060         measurements, trackerHitPlane, &trackerHitRawCollection, &cluster,
0061         [](std::uint64_t cellId) { return Acts::GeometryIdentifier(cellId); });
0062 
0063     clusters.push_back(std::move(cluster));
0064   }
0065 
0066   // Write the data to the EventStore
0067   m_outputMeasurements(ctx, std::move(measurements));
0068   m_outputMeasurementSimHitsMap(ctx, std::move(measurementSimHitsMap));
0069   if (!m_cfg.outputClusters.empty()) {
0070     m_outputClusters(ctx, std::move(clusters));
0071   }
0072 
0073   return ProcessCode::SUCCESS;
0074 }
0075 
0076 }  // namespace ActsExamples