Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-27 07:02:59

0001 // Copyright 2023, Christopher Dilks
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 
0004 #include "MergeTracks.h"
0005 
0006 #include <algorithm>
0007 #include <cstddef>
0008 #include <edm4eic/TrackPoint.h>
0009 #include <fmt/core.h>
0010 #include <fmt/format.h>
0011 #include <gsl/pointers>
0012 #include <iterator>
0013 #include <podio/RelationRange.h>
0014 #include <unordered_map>
0015 #include <utility>
0016 
0017 namespace eicrecon {
0018 
0019 void MergeTracks::process(const MergeTracks::Input& input,
0020                           const MergeTracks::Output& output) const {
0021 
0022   const auto [in_track_collections] = input;
0023   auto [out_tracks]                 = output;
0024 
0025   // logging
0026   trace("{:=^70}", " call MergeTracks::AlgorithmProcess ");
0027 
0028   // check that all input collections have the same size
0029   std::unordered_map<std::size_t, std::size_t> in_track_collection_size_distribution;
0030   for (const auto& in_track_collection : in_track_collections) {
0031     ++in_track_collection_size_distribution[in_track_collection->size()];
0032   }
0033   if (in_track_collection_size_distribution.size() != 1) {
0034     std::vector<size_t> in_track_collection_sizes;
0035     std::transform(in_track_collections.begin(), in_track_collections.end(),
0036                    std::back_inserter(in_track_collection_sizes),
0037                    [](const auto& in_track_collection) { return in_track_collection->size(); });
0038     error("cannot merge input track collections with different sizes {}",
0039           fmt::join(in_track_collection_sizes, ", "));
0040     return;
0041   }
0042 
0043   // loop over track collection elements
0044   std::size_t n_tracks = in_track_collection_size_distribution.begin()->first;
0045   for (std::size_t i_track = 0; i_track < n_tracks; i_track++) {
0046 
0047     // create a new output track, and a local container to hold its track points
0048     auto out_track = out_tracks->create();
0049     std::vector<edm4eic::TrackPoint> out_track_points;
0050 
0051     // loop over collections for this track, and add each track's points to `out_track_points`
0052     for (const auto& in_track_collection : in_track_collections) {
0053       const auto& in_track = in_track_collection->at(i_track);
0054       for (const auto& point : in_track.getPoints())
0055         out_track_points.push_back(point);
0056     }
0057 
0058     // sort all `out_track_points` by time
0059     std::sort(out_track_points.begin(), out_track_points.end(),
0060               [](edm4eic::TrackPoint& a, edm4eic::TrackPoint& b) { return a.time < b.time; });
0061 
0062     // add these sorted points to `out_track`
0063     for (const auto& point : out_track_points)
0064       out_track.addToPoints(point);
0065 
0066     /* FIXME: merge other members, such as `length` and `lengthError`;
0067      * currently not needed for RICH tracks, so such members are left as default
0068      */
0069 
0070   } // end loop over tracks
0071 }
0072 
0073 } // namespace eicrecon