Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 08:34:00

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 - 2024, Dmitry Romanov, Wouter Deconinck
0003 
0004 #pragma once
0005 
0006 #include <Acts/EventData/TrackParameters.hpp>
0007 #include <Acts/Geometry/GeometryContext.hpp>
0008 #include <Acts/Geometry/GeometryIdentifier.hpp>
0009 #include <Acts/MagneticField/MagneticFieldContext.hpp>
0010 #include <Acts/Surfaces/Surface.hpp>
0011 #include <Acts/Utilities/Result.hpp>
0012 #include <ActsExamples/EventData/Track.hpp>
0013 #include <ActsExamples/EventData/Trajectories.hpp>
0014 #include <DD4hep/Detector.h>
0015 #include <edm4eic/TrackCollection.h>
0016 #include <edm4eic/TrackPoint.h>
0017 #include <edm4eic/TrackSegmentCollection.h>
0018 #include <fmt/core.h>
0019 #include <spdlog/logger.h>
0020 #include <cstddef>
0021 #include <memory>
0022 #include <tuple>
0023 #include <vector>
0024 
0025 #include "algorithms/interfaces/WithPodConfig.h"
0026 #include "algorithms/tracking/ActsGeometryProvider.h"
0027 #include "algorithms/tracking/TrackPropagationConfig.h"
0028 
0029 namespace eicrecon {
0030 
0031 using ActsTrackPropagationResult = Acts::Result<std::unique_ptr<const Acts::BoundTrackParameters>>;
0032 
0033 /** Extract the particles form fit trajectories.
0034      *
0035      * \ingroup tracking
0036      */
0037 class TrackPropagation : public eicrecon::WithPodConfig<TrackPropagationConfig> {
0038 
0039 public:
0040   /** Initialize algorithm */
0041   void init(const dd4hep::Detector* detector, std::shared_ptr<const ActsGeometryProvider> geo_svc,
0042             std::shared_ptr<spdlog::logger> logger);
0043 
0044   void process(const std::tuple<const edm4eic::TrackCollection&,
0045                                 const std::vector<const ActsExamples::Trajectories*>,
0046                                 const std::vector<const ActsExamples::ConstTrackContainer*>>
0047                    input,
0048                const std::tuple<edm4eic::TrackSegmentCollection*> output) const {
0049 
0050     const auto [tracks, acts_trajectories, acts_tracks] = input;
0051     auto [propagated_tracks]                            = output;
0052 
0053     for (std::size_t i = 0; auto traj : acts_trajectories) {
0054       auto this_propagated_track = propagated_tracks->create();
0055       if (tracks.size() == acts_trajectories.size()) {
0056         m_log->trace("track segment connected to track {}", i);
0057         this_propagated_track.setTrack(tracks[i]);
0058       }
0059       for (auto& surf : m_target_surfaces) {
0060         auto prop_point = propagate(
0061             tracks.size() == acts_trajectories.size() ? tracks[i] : edm4eic::Track{}, traj, surf);
0062         if (!prop_point)
0063           continue;
0064         prop_point->surface = surf->geometryId().layer();
0065         prop_point->system  = surf->geometryId().extra();
0066         this_propagated_track.addToPoints(*prop_point);
0067       }
0068       ++i;
0069     }
0070   }
0071 
0072   /** Propagates a single trajectory to a given surface */
0073   std::unique_ptr<edm4eic::TrackPoint>
0074   propagate(const edm4eic::Track&, const ActsExamples::Trajectories*,
0075             const std::shared_ptr<const Acts::Surface>& targetSurf) const;
0076 
0077   /** Propagates a collection of trajectories to a list of surfaces, and returns the full `TrackSegment`;
0078          * @param trajectories the input collection of trajectories
0079          * @return the resulting collection of propagated tracks
0080          */
0081   void propagateToSurfaceList(
0082       const std::tuple<const edm4eic::TrackCollection&,
0083                        const std::vector<const ActsExamples::Trajectories*>,
0084                        const std::vector<const ActsExamples::ConstTrackContainer*>>
0085           input,
0086       const std::tuple<edm4eic::TrackSegmentCollection*> output) const;
0087 
0088 private:
0089   Acts::GeometryContext m_geoContext;
0090   Acts::MagneticFieldContext m_fieldContext;
0091   std::shared_ptr<const ActsGeometryProvider> m_geoSvc;
0092   std::shared_ptr<spdlog::logger> m_log;
0093 
0094   std::vector<std::shared_ptr<Acts::Surface>> m_filter_surfaces;
0095   std::vector<std::shared_ptr<Acts::Surface>> m_target_surfaces;
0096 };
0097 } // namespace eicrecon