Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-05 09:16:47

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