Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-04 07:48:20

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 #pragma once
0010 
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "ActsExamples/EventData/Cluster.hpp"
0013 #include "ActsExamples/EventData/Measurement.hpp"
0014 #include "ActsExamples/EventData/SimParticle.hpp"
0015 #include "ActsExamples/EventData/Trajectories.hpp"
0016 #include "ActsExamples/EventData/TruthMatching.hpp"
0017 #include "ActsFatras/EventData/Hit.hpp"
0018 #include <ActsPodioEdm/MutableTrackerHitLocal.h>
0019 #include <ActsPodioEdm/TrackerHitLocal.h>
0020 
0021 #include <functional>
0022 
0023 #include <edm4hep/MCParticle.h>
0024 #include <edm4hep/MutableMCParticle.h>
0025 #include <edm4hep/MutableSimTrackerHit.h>
0026 #include <edm4hep/MutableTrack.h>
0027 #include <edm4hep/MutableTrackerHitPlane.h>
0028 #include <edm4hep/SimTrackerHit.h>
0029 #include <edm4hep/TrackerHitPlane.h>
0030 
0031 namespace ActsExamples::EDM4hepUtil {
0032 
0033 using MapParticleIdFrom =
0034     std::function<SimBarcode(const edm4hep::MCParticle& particle)>;
0035 using MapParticleIdTo =
0036     std::function<edm4hep::MCParticle(SimBarcode particleId)>;
0037 
0038 inline SimBarcode zeroParticleMapper(const edm4hep::MCParticle& /*particle*/) {
0039   return SimBarcode::Invalid();
0040 }
0041 
0042 using MapGeometryIdFrom =
0043     std::function<Acts::GeometryIdentifier(std::uint64_t cellId)>;
0044 using MapGeometryIdTo =
0045     std::function<std::uint64_t(Acts::GeometryIdentifier geometryId)>;
0046 
0047 /// Reads a Fatras particle from EDM4hep.
0048 ///
0049 /// Inpersistent information:
0050 /// - particle ID
0051 /// - process
0052 SimParticle readParticle(
0053     const edm4hep::MCParticle& from,
0054     const MapParticleIdFrom& particleMapper = zeroParticleMapper);
0055 
0056 /// Write a Fatras particle into EDM4hep.
0057 ///
0058 /// Inpersistent information:
0059 /// - particle ID
0060 /// - process
0061 void writeParticle(const SimParticle& from, edm4hep::MutableMCParticle to);
0062 
0063 /// Reads a Fatras hit from EDM4hep.
0064 ///
0065 /// Inpersistent information:
0066 /// - after4 momentum
0067 /// - hit index
0068 /// - digitization channel
0069 ActsFatras::Hit readSimHit(const edm4hep::SimTrackerHit& from,
0070                            const MapParticleIdFrom& particleMapper,
0071                            const MapGeometryIdFrom& geometryMapper,
0072                            std::uint32_t index = -1);
0073 
0074 /// Writes a Fatras hit to EDM4hep.
0075 ///
0076 /// Inpersistent information:
0077 /// - after4 momentum
0078 /// - hit index
0079 /// - digitization channel
0080 void writeSimHit(const ActsFatras::Hit& from, edm4hep::MutableSimTrackerHit to,
0081                  const MapParticleIdTo& particleMapper,
0082                  const MapGeometryIdTo& geometryMapper);
0083 
0084 /// Reads a measurement cluster from EDM4hep.
0085 ///
0086 /// Inpersistent information:
0087 /// - hit index
0088 /// - 1D local coords?
0089 /// - segment path
0090 ///
0091 /// Known issues:
0092 /// - cluster channels are read from inappropriate fields
0093 /// - local 2D coordinates and time are read from position
0094 VariableBoundMeasurementProxy readMeasurement(
0095     MeasurementContainer& container, const edm4hep::TrackerHitPlane& from,
0096     const edm4hep::TrackerHit3DCollection* fromClusters, Cluster* toCluster,
0097     const MapGeometryIdFrom& geometryMapper);
0098 
0099 /// Writes an ACTS measurement to EDM4hep.
0100 ///
0101 /// Converts bound parameters (local coordinates, time) and covariance from an
0102 /// ACTS measurement to a MutableTrackerHitLocal. The surface is used
0103 /// to obtain the detector cell ID from the DD4hepDetectorElement and to
0104 /// transform local coordinates to global position.
0105 ///
0106 /// @param gctx The geometry context for coordinate transformations.
0107 /// @param from The ACTS measurement to convert.
0108 /// @param to The EDM4hep tracker hit to write to.
0109 /// @param surface The surface associated with the measurement (must have a
0110 ///        DD4hepDetectorElement placement).
0111 void writeMeasurement(const Acts::GeometryContext& gctx,
0112                       const ConstVariableBoundMeasurementProxy& from,
0113                       ActsPodioEdm::MutableTrackerHitLocal& to,
0114                       const Acts::Surface& surface);
0115 
0116 /// Reads a measurement from an EDM4hep TrackerHitLocal.
0117 ///
0118 /// Converts bound parameters, covariance, and indices from an EDM4hep
0119 /// TrackerHitLocal into an ACTS measurement. The geometry mapper is used to
0120 /// convert the cell ID to a geometry identifier.
0121 ///
0122 /// @param container The measurement container to insert into.
0123 /// @param from The EDM4hep tracker hit to read from.
0124 /// @param geometryMapper Function to map cell ID to geometry identifier.
0125 /// @return Proxy to the created measurement.
0126 VariableBoundMeasurementProxy readMeasurement(
0127     MeasurementContainer& container, const ActsPodioEdm::TrackerHitLocal& from,
0128     const MapGeometryIdFrom& geometryMapper);
0129 
0130 /// Writes a trajectory to EDM4hep.
0131 ///
0132 /// Inpersistent information:
0133 /// - trajectory state incomplete
0134 /// - relation to the particles
0135 void writeTrajectory(const Acts::GeometryContext& gctx, double Bz,
0136                      const Trajectories& from, edm4hep::MutableTrack to,
0137                      std::size_t fromIndex,
0138                      const Acts::ParticleHypothesis& particleHypothesis,
0139                      const MeasurementParticlesMap& measurementParticlesMap);
0140 
0141 /// Helper function to either return an id as is, or unpack an index from it
0142 /// if it is a podio::ObjectID.
0143 /// @tparam T The type of the id.
0144 /// @param o The id to convert.
0145 /// @return The id as an unsigned integer.
0146 template <typename T>
0147 std::uint64_t podioObjectIDToInteger(T&& o) {
0148   if constexpr (!std::is_same_v<T, podio::ObjectID>) {
0149     return o;
0150   } else {
0151     return o.index;
0152   }
0153 }
0154 
0155 }  // namespace ActsExamples::EDM4hepUtil