Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-07 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 #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/Trajectories.hpp"
0014 #include "ActsFatras/EventData/Hit.hpp"
0015 #include "ActsFatras/EventData/Particle.hpp"
0016 
0017 #include <functional>
0018 
0019 #include "edm4hep/MCParticle.h"
0020 #include "edm4hep/MutableMCParticle.h"
0021 #include "edm4hep/MutableSimTrackerHit.h"
0022 #include "edm4hep/MutableTrack.h"
0023 #include "edm4hep/MutableTrackerHit.h"
0024 #include "edm4hep/MutableTrackerHitPlane.h"
0025 #include "edm4hep/SimTrackerHit.h"
0026 #include "edm4hep/TrackerHit.h"
0027 #include "edm4hep/TrackerHitCollection.h"
0028 #include "edm4hep/TrackerHitPlane.h"
0029 
0030 namespace ActsExamples::EDM4hepUtil {
0031 
0032 using MapParticleIdFrom =
0033     std::function<ActsFatras::Barcode(const edm4hep::MCParticle& particle)>;
0034 using MapParticleIdTo =
0035     std::function<edm4hep::MCParticle(ActsFatras::Barcode particleId)>;
0036 
0037 inline ActsFatras::Barcode zeroParticleMapper(
0038     const edm4hep::MCParticle& /*particle*/) {
0039   return 0;
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 ActsFatras::Particle 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 ActsFatras::Particle& from,
0062                    edm4hep::MutableMCParticle to);
0063 
0064 /// Reads a Fatras hit from EDM4hep.
0065 ///
0066 /// Inpersistent information:
0067 /// - after4 momentum
0068 /// - hit index
0069 /// - digitization channel
0070 ActsFatras::Hit readSimHit(const edm4hep::SimTrackerHit& from,
0071                            const MapParticleIdFrom& particleMapper,
0072                            const MapGeometryIdFrom& geometryMapper);
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 Measurement readMeasurement(const edm4hep::TrackerHitPlane& from,
0095                             const edm4hep::TrackerHitCollection* fromClusters,
0096                             Cluster* toCluster,
0097                             const MapGeometryIdFrom& geometryMapper);
0098 
0099 /// Writes a measurement cluster to EDM4hep.
0100 ///
0101 /// Inpersistent information:
0102 /// - hit index
0103 /// - 1D local coords?
0104 /// - segment path
0105 ///
0106 /// Known issues:
0107 /// - cluster channels are written to inappropriate fields
0108 /// - local 2D coordinates and time are written to position
0109 void writeMeasurement(const Measurement& from,
0110                       edm4hep::MutableTrackerHitPlane to,
0111                       const Cluster* fromCluster,
0112                       edm4hep::TrackerHitCollection& toClusters,
0113                       const MapGeometryIdTo& geometryMapper);
0114 
0115 /// Writes a trajectory to EDM4hep.
0116 ///
0117 /// Inpersistent information:
0118 /// - trajectory state incomplete
0119 /// - relation to the particles
0120 void writeTrajectory(const Acts::GeometryContext& gctx, double Bz,
0121                      const Trajectories& from, edm4hep::MutableTrack to,
0122                      std::size_t fromIndex,
0123                      const Acts::ParticleHypothesis& particleHypothesis,
0124                      const IndexMultimap<ActsFatras::Barcode>& hitParticlesMap);
0125 
0126 /// Helper function to either return an id as is, or unpack an index from it
0127 /// if it is a podio::ObjectID.
0128 /// @tparam T The type of the id.
0129 /// @param o The id to convert.
0130 /// @return The id as an unsigned integer.
0131 template <typename T>
0132 uint64_t podioObjectIDToInteger(T&& o) {
0133   if constexpr (!std::is_same_v<T, podio::ObjectID>) {
0134     return o;
0135   } else {
0136     return o.index;
0137   }
0138 }
0139 
0140 }  // namespace ActsExamples::EDM4hepUtil