Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:21:59

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2022-2025 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #pragma once
0009 
0010 // Project include(s).
0011 #include "traccc/edm/track_container.hpp"
0012 #include "traccc/edm/track_state_collection.hpp"
0013 #include "traccc/edm/track_state_helpers.hpp"
0014 #include "traccc/fitting/status_codes.hpp"
0015 
0016 // VecMem include(s).
0017 #include <vecmem/memory/memory_resource.hpp>
0018 #include <vecmem/utils/copy.hpp>
0019 
0020 namespace traccc::host::details {
0021 
0022 /// Templated implementation of the track fitting algorithm.
0023 ///
0024 /// Concrete track fitting algorithms can use this function with the appropriate
0025 /// specializations, to fit tracks on top of a specific detector type, magnetic
0026 /// field type, and track fitting configuration.
0027 ///
0028 /// @note The memory resource received by this function is not used thoroughly
0029 ///       for the setup of the output container. Inner vectors in the output's
0030 ///       jagged vector are created using the default memory resource.
0031 ///
0032 /// @tparam fitter_t The fitter type used for the track fitting
0033 ///
0034 /// @param[in] fitter           The fitter object to use on the track candidates
0035 /// @param[in] track_container  All track candidates to fit
0036 /// @param[in] mr               Memory resource to use for the output container
0037 ///
0038 /// @return A container of the fitted track states
0039 ///
0040 template <typename algebra_t, typename fitter_t>
0041 typename edm::track_container<algebra_t>::host kalman_fitting(
0042     fitter_t& fitter,
0043     const typename edm::track_container<algebra_t>::const_view& tracks_view,
0044     vecmem::memory_resource& mr, vecmem::copy& copy) {
0045   // Create the input container(s).
0046   const typename edm::track_container<algebra_t>::const_device tracks{
0047       tracks_view};
0048 
0049   // Create the output containers.
0050   typename edm::track_container<algebra_t>::host result{
0051       mr, tracks_view.measurements};
0052 
0053   // Iterate over the tracks,
0054   for (unsigned int i = 0; i < tracks.tracks.size(); ++i) {
0055     // Create the objects that will describe this track fit.
0056     result.tracks.push_back({});
0057     edm::track fitted_track = result.tracks.at(result.tracks.size() - 1);
0058     for (const edm::track_constituent_link& link :
0059          tracks.tracks.constituent_links().at(i)) {
0060       assert(link.type == edm::track_constituent_link::measurement);
0061       fitted_track.constituent_links().push_back(
0062           {edm::track_constituent_link::track_state,
0063            static_cast<unsigned int>(result.states.size())});
0064       result.states.push_back(
0065           edm::make_track_state<algebra_t>(tracks.measurements, link.index));
0066     }
0067 
0068     vecmem::data::vector_buffer<typename fitter_t::surface_type> seqs_buffer{
0069         static_cast<vecmem::data::vector_buffer<
0070             typename fitter_t::surface_type>::size_type>(
0071             std::max(static_cast<unsigned int>(
0072                          fitted_track.constituent_links().size()) *
0073                          fitter.config().surface_sequence_size_factor,
0074                      fitter.config().min_surface_sequence_capacity)),
0075         mr, vecmem::data::buffer_type::resizable};
0076     copy.setup(seqs_buffer)->wait();
0077 
0078     // Make a fitter state
0079     typename edm::track_collection<algebra_t>::data result_tracks_data =
0080         vecmem::get_data(result.tracks);
0081     typename edm::track_collection<algebra_t>::device result_tracks_device{
0082         result_tracks_data};
0083     typename fitter_t::state fitter_state(
0084         result_tracks_device.at(result_tracks_device.size() - 1),
0085         typename edm::track_state_collection<algebra_t>::device{
0086             vecmem::get_data(result.states)},
0087         tracks.measurements, seqs_buffer, fitter.config().propagation,
0088         fitter.config().meas_calibration);
0089 
0090     // Run the fitter. The status that it returns is not used here. The main
0091     // failure modes are saved onto the fitted track itself. Not sure what
0092     // we may want to do with the more detailed status codes in the future.
0093     (void)fitter.fit(tracks.tracks.params().at(i), fitter_state);
0094   }
0095 
0096   // Return the fitted track states.
0097   return result;
0098 }
0099 
0100 }  // namespace traccc::host::details