Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrkrClusterContainerv3.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrkrClusterContainerv3.cc
1 
8 #include "TrkrCluster.h"
9 #include "TrkrDefs.h"
10 
11 #include <algorithm>
12 
13 namespace
14 {
15  TrkrClusterContainer::Map dummy_map;
16 }
17 
18 //_________________________________________________________________
20 {
21  // delete all clusters
22  for (auto&& [key, map] : m_clusmap)
23  {
24  for (auto&& [cluskey, cluster] : map)
25  {
26  delete cluster;
27  }
28  }
29 
30  // clear the maps
31  /* using swap ensures that the memory is properly de-allocated */
32  std::map<TrkrDefs::hitsetkey, Map> empty;
33  m_clusmap.swap(empty);
34 }
35 
36 //_________________________________________________________________
37 void TrkrClusterContainerv3::identify(std::ostream& os) const
38 {
39  os << "-----TrkrClusterContainerv3-----" << std::endl;
40  os << "Number of clusters: " << size() << std::endl;
41 
42  for (const auto& [hitsetkey, map] : m_clusmap)
43  {
44  const unsigned int layer = TrkrDefs::getLayer(hitsetkey);
45  os << "layer: " << layer << " hitsetkey: " << hitsetkey << std::endl;
46  for (const auto& [cluskey, cluster] : map)
47  {
48  os << "clus key " << cluskey << " layer " << TrkrDefs::getLayer(cluskey) << std::endl;
49  cluster->identify();
50  }
51  }
52 
53  os << "------------------------------" << std::endl;
54 }
55 
56 //_________________________________________________________________
58 {
59  // get hitset key from cluster
61 
62  // find relevant cluster map if any and remove corresponding cluster
63  auto iter = m_clusmap.find(hitsetkey);
64  if (iter != m_clusmap.end())
65  {
66  TrkrCluster* clus = findCluster(key);
67  delete clus;
68  iter->second.erase(key);
69  }
70 }
71 
72 //_________________________________________________________________
74 {
75  // get hitsetkey from cluster
77 
78  // find relevant cluster map or create one if not found
79  Map& map = m_clusmap[hitsetkey];
80  const auto [iter, success] = map.insert(std::make_pair(key, newclus));
81  if (!success)
82  {
83  std::cout << "TrkrClusterContainerv3::AddClusterSpecifyKey: duplicate key: " << key << " exiting now" << std::endl;
84  exit(1);
85  }
86 }
87 
88 //_________________________________________________________________
91 {
92  // find relevant association map
93  const auto iter = m_clusmap.find(hitsetkey);
94  if (iter != m_clusmap.end())
95  {
96  return std::make_pair(iter->second.cbegin(), iter->second.cend());
97  }
98  else
99  {
100  return std::make_pair(dummy_map.cbegin(), dummy_map.cend());
101  }
102 }
103 
104 //_________________________________________________________________
106 {
107  // get hitsetkey from cluster
109 
110  const auto map_iter = m_clusmap.find(hitsetkey);
111  if (map_iter != m_clusmap.end())
112  {
113  const auto clus_iter = map_iter->second.find(key);
114  if (clus_iter != map_iter->second.end())
115  {
116  return clus_iter->second;
117  }
118  else
119  {
120  return nullptr;
121  }
122  }
123  else
124  {
125  return nullptr;
126  }
127 }
128 
129 //_________________________________________________________________
131 {
133  out.reserve(m_clusmap.size());
135  m_clusmap.begin(), m_clusmap.end(), std::back_inserter(out),
136  [](const std::pair<TrkrDefs::hitsetkey, Map>& pair)
137  { return pair.first; });
138  return out;
139 }
140 
141 //_________________________________________________________________
143 {
144  /* copy the logic from TrkrHitSetContainerv1::getHitSets */
145  const TrkrDefs::hitsetkey keylo = TrkrDefs::getHitSetKeyLo(trackerid);
146  const TrkrDefs::hitsetkey keyhi = TrkrDefs::getHitSetKeyHi(trackerid);
147 
148  // get relevant range in map
149  const auto begin = m_clusmap.lower_bound(keylo);
150  const auto end = m_clusmap.upper_bound(keyhi);
151 
152  // transform to a vector
154  out.reserve(m_clusmap.size());
156  begin, end, std::back_inserter(out),
157  [](const std::pair<TrkrDefs::hitsetkey, Map>& pair)
158  { return pair.first; });
159  return out;
160 }
161 
162 //_________________________________________________________________
164 {
165  /* copy the logic from TrkrHitSetContainerv1::getHitSets */
166  TrkrDefs::hitsetkey keylo = TrkrDefs::getHitSetKeyLo(trackerid, layer);
167  TrkrDefs::hitsetkey keyhi = TrkrDefs::getHitSetKeyHi(trackerid, layer);
168 
169  // get relevant range in map
170  const auto begin = m_clusmap.lower_bound(keylo);
171  const auto end = m_clusmap.upper_bound(keyhi);
172 
173  // transform to a vector
175  out.reserve(m_clusmap.size());
177  begin, end, std::back_inserter(out),
178  [](const std::pair<TrkrDefs::hitsetkey, Map>& pair)
179  { return pair.first; });
180  return out;
181 }
182 
183 //_________________________________________________________________
184 unsigned int TrkrClusterContainerv3::size() const
185 {
186  unsigned int size = 0;
187  for (const auto& map_pair : m_clusmap)
188  {
189  size += map_pair.second.size();
190  }
191 
192  return size;
193 }