Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-05-15 07:57:13

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/EDM4hepMeasurementOutputConverter.hpp"
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Plugins/EDM4hep/TrackerHitCompatibility.hpp"
0013 #include "ActsExamples/EventData/Cluster.hpp"
0014 #include "ActsExamples/EventData/Measurement.hpp"
0015 #include "ActsExamples/Framework/WhiteBoard.hpp"
0016 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0017 
0018 #include <stdexcept>
0019 
0020 #include <edm4hep/TrackerHitPlane.h>
0021 #include <edm4hep/TrackerHitPlaneCollection.h>
0022 #include <podio/Frame.h>
0023 
0024 namespace ActsExamples {
0025 
0026 EDM4hepMeasurementOutputConverter::EDM4hepMeasurementOutputConverter(
0027     const EDM4hepMeasurementOutputConverter::Config& config,
0028     Acts::Logging::Level level)
0029     : EDM4hepOutputConverter("EDM4hepMeasurementOutputConverter", level),
0030       m_cfg(config) {
0031   m_inputMeasurements.initialize(m_cfg.inputMeasurements);
0032   m_inputClusters.maybeInitialize(m_cfg.inputClusters);
0033   m_outputTrackerHitsPlane.initialize(m_cfg.outputTrackerHitsPlane);
0034   m_outputTrackerHitsRaw.initialize(m_cfg.outputTrackerHitsRaw);
0035 }
0036 
0037 ActsExamples::ProcessCode EDM4hepMeasurementOutputConverter::execute(
0038     const AlgorithmContext& ctx) const {
0039   ClusterContainer clusters;
0040 
0041   edm4hep::TrackerHitPlaneCollection hitsPlane;
0042   edm4hep::TrackerHit3DCollection hits;
0043 
0044   if (!m_cfg.inputClusters.empty()) {
0045     ACTS_VERBOSE("Fetch clusters for writing: " << m_cfg.inputClusters);
0046     clusters = m_inputClusters(ctx);
0047   }
0048 
0049   const auto measurements = m_inputMeasurements(ctx);
0050 
0051   ACTS_VERBOSE("Writing " << measurements.size()
0052                           << " measurements in this event.");
0053 
0054   for (Index hitIdx = 0u; hitIdx < measurements.size(); ++hitIdx) {
0055     ConstVariableBoundMeasurementProxy from =
0056         measurements.getMeasurement(hitIdx);
0057     const Cluster* fromCluster = clusters.empty() ? nullptr : &clusters[hitIdx];
0058 
0059     auto to = hitsPlane.create();
0060     EDM4hepUtil::writeMeasurement(
0061         from, to, fromCluster, hits,
0062         [](Acts::GeometryIdentifier id) { return id.value(); });
0063   }
0064 
0065   m_outputTrackerHitsPlane(ctx, std::move(hitsPlane));
0066   m_outputTrackerHitsRaw(ctx, std::move(hits));
0067 
0068   return ActsExamples::ProcessCode::SUCCESS;
0069 }
0070 
0071 std::vector<std::string> EDM4hepMeasurementOutputConverter::collections()
0072     const {
0073   return {m_cfg.outputTrackerHitsPlane, m_cfg.outputTrackerHitsRaw};
0074 }
0075 
0076 }  // namespace ActsExamples