File indexing completed on 2024-09-28 07:02:56
0001
0002
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
0026 trace("{:=^70}", " call MergeTracks::AlgorithmProcess ");
0027
0028
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
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
0048 auto out_track = out_tracks->create();
0049 std::vector<edm4eic::TrackPoint> out_track_points;
0050
0051
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
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
0063 for (const auto& point : out_track_points)
0064 out_track.addToPoints(point);
0065
0066
0067
0068
0069
0070 }
0071 }
0072
0073 }