File indexing completed on 2025-08-06 08:17:54
0001 #include "MvtxHitMap.h"
0002 #include "MvtxPixelDefs.h"
0003
0004 #include <trackbase/MvtxDefs.h>
0005 #include <trackbase/TrkrDefs.h>
0006
0007 #include <ffarawobjects/MvtxRawHit.h>
0008 #include <ffarawobjects/MvtxRawHitv1.h>
0009
0010 #include <algorithm>
0011 #include <iostream>
0012 #include <set>
0013 #include <string>
0014
0015
0016
0017 void MvtxHitMap::add_hit(MvtxPixelDefs::pixelkey key, uint32_t nhits)
0018 {
0019
0020 is_sorted = false;
0021 auto it = std::find_if(m_pixel_hit_vector.begin(), m_pixel_hit_vector.end(), [key](const pixel_hits_pair_t& element)
0022 { return element.first == key; });
0023
0024 if (it != m_pixel_hit_vector.end())
0025 {
0026
0027 it->second += nhits;
0028 }
0029 else
0030 {
0031
0032 m_pixel_hit_vector.emplace_back(key, nhits);
0033 }
0034
0035 return;
0036 }
0037
0038 uint32_t MvtxHitMap::get_nhits(MvtxPixelDefs::pixelkey key) const
0039 {
0040
0041 auto it = std::find_if(m_pixel_hit_vector.begin(), m_pixel_hit_vector.end(), [key](const pixel_hits_pair_t& element)
0042 { return element.first == key; });
0043
0044 if (it != m_pixel_hit_vector.end())
0045 {
0046
0047 return it->second;
0048 }
0049
0050
0051 return 0;
0052 }
0053
0054 MvtxPixelDefs::pixelkey MvtxHitMap::get_most_significant_pixel()
0055 {
0056
0057 if (m_pixel_hit_vector.empty())
0058 {
0059 return MvtxPixelDefs::VOID_PIXEL;
0060 }
0061
0062 sort_by_hits();
0063 auto it = m_pixel_hit_vector.begin();
0064 return it->first;
0065 }
0066
0067 void MvtxHitMap::sort_by_hits()
0068 {
0069
0070 if (is_sorted)
0071 {
0072 return;
0073 }
0074
0075 std::sort(m_pixel_hit_vector.begin(), m_pixel_hit_vector.end(), [](const pixel_hits_pair_t& a, const pixel_hits_pair_t& b)
0076 { return a.second > b.second; });
0077 is_sorted = true;
0078 return;
0079 }
0080
0081 uint32_t MvtxHitMap::sum_hits(unsigned int nmasked)
0082 {
0083
0084 uint32_t sum = 0;
0085 sort_by_hits();
0086
0087 for (auto it = m_pixel_hit_vector.begin() + nmasked; it != m_pixel_hit_vector.end(); ++it)
0088 {
0089 sum += it->second;
0090 }
0091
0092 return sum;
0093 }