Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:12

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 <utility>
0017 
0018 namespace ActsFatras {
0019 
0020 /// Generic implementation of a channel merger, currently only additive
0021 /// channel merging.
0022 ///
0023 /// @tparam signal_t The type of signal, needs operator+= to be defined
0024 /// @tparam kSize the dimensonality of the object (cluster)
0025 ///
0026 /// @param channels The channels from one cluster
0027 ///
0028 /// @return A cluster containing the parameter set and cluster size
0029 template <typename signal_t, std::size_t kSize>
0030 const std::vector<Channel<signal_t, kSize>> mergeChannels(
0031     const std::vector<Channel<signal_t, kSize>>& channels) {
0032   using Channel = Channel<signal_t, kSize>;
0033   using ChannelKey = std::array<unsigned int, kSize>;
0034 
0035   // Fill a channel map - use the channel identification
0036   auto extractChannelKey = [&](const Channel& ch) -> ChannelKey {
0037     ChannelKey cKey;
0038     for (unsigned int ik = 0; ik < kSize; ++ik) {
0039       cKey[ik] = ch.cellId[ik].first;
0040     }
0041     return cKey;
0042   };
0043 
0044   std::map<ChannelKey, Channel> channelMap;
0045   for (const auto& ch : channels) {
0046     ChannelKey key = extractChannelKey(ch);
0047     auto chItr = channelMap.find(key);
0048     if (chItr != channelMap.end()) {
0049       chItr->second.value += ch.value;
0050       chItr->second.links.insert(ch.links.begin(), ch.links.end());
0051     } else {
0052       channelMap.insert(std::pair<ChannelKey, Channel>(key, ch));
0053     }
0054   }
0055   // Unroll the channels after merging
0056   std::vector<Channel> mergedChannels;
0057   mergedChannels.reserve(channelMap.size());
0058   for (auto& [key, value] : channelMap) {
0059     mergedChannels.push_back(value);
0060   }
0061   return mergedChannels;
0062 }
0063 
0064 }  // namespace ActsFatras