Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-27 08:58:02

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Surfaces/Surface.hpp"
0012 #include "Acts/Surfaces/SurfaceError.hpp"
0013 #include "ActsFatras/Digitization/DigitizationData.hpp"
0014 
0015 #include <array>
0016 #include <map>
0017 #include <utility>
0018 
0019 namespace ActsFatras {
0020 
0021 /// Generic implementation of a channel merger, currently only additive
0022 /// channel merging.
0023 ///
0024 /// @tparam signal_t The type of signal, needs operator+= to be defined
0025 /// @tparam kSize the dimensionality of the object (cluster)
0026 ///
0027 /// @param channels The channels from one cluster
0028 ///
0029 /// @return A cluster containing the parameter set and cluster size
0030 template <typename signal_t, std::size_t kSize>
0031 const std::vector<Channel<signal_t, kSize>> mergeChannels(
0032     const std::vector<Channel<signal_t, kSize>>& channels) {
0033   using Channel = Channel<signal_t, kSize>;
0034   using ChannelKey = std::array<unsigned int, kSize>;
0035 
0036   // Fill a channel map - use the channel identification
0037   auto extractChannelKey = [&](const Channel& ch) -> ChannelKey {
0038     ChannelKey cKey;
0039     for (unsigned int ik = 0; ik < kSize; ++ik) {
0040       cKey[ik] = ch.cellId[ik].first;
0041     }
0042     return cKey;
0043   };
0044 
0045   std::map<ChannelKey, Channel> channelMap;
0046   for (const auto& ch : channels) {
0047     ChannelKey key = extractChannelKey(ch);
0048     auto chItr = channelMap.find(key);
0049     if (chItr != channelMap.end()) {
0050       chItr->second.value += ch.value;
0051       chItr->second.links.insert(ch.links.begin(), ch.links.end());
0052     } else {
0053       channelMap.insert(std::pair<ChannelKey, Channel>(key, ch));
0054     }
0055   }
0056   // Unroll the channels after merging
0057   std::vector<Channel> mergedChannels;
0058   mergedChannels.reserve(channelMap.size());
0059   for (auto& [key, value] : channelMap) {
0060     mergedChannels.push_back(value);
0061   }
0062   return mergedChannels;
0063 }
0064 
0065 }  // namespace ActsFatras