Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrkrClusterContainerv2.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrkrClusterContainerv2.cc
1 
8 #include "TrkrCluster.h"
9 #include "TrkrDefs.h"
10 
11 #include <cstdlib>
12 
13 namespace
14 {
15  TrkrClusterContainer::Map dummy_map;
16 }
17 
18 //_________________________________________________________________
20 {
21  for (unsigned int layer = 0; layer < max_layer; layer++)
22  {
23  for (unsigned int phi_segment = 0; phi_segment < max_phisegment; phi_segment++)
24  {
25  for (unsigned int z_segment = 0; z_segment < max_zsegment; z_segment++)
26  {
27  for (const auto& pair : m_clusmap[layer][phi_segment][z_segment])
28  {
29  delete pair.second;
30  }
31 
32  m_clusmap[layer][phi_segment][z_segment].clear();
33  }
34  }
35  }
36 }
37 
38 //_________________________________________________________________
39 void TrkrClusterContainerv2::identify(std::ostream& os) const
40 {
41  os << "-----TrkrClusterContainerv2-----" << std::endl;
42  os << "Number of clusters: " << size() << std::endl;
43 
44  for (unsigned int layer = 0; layer < max_layer; layer++)
45  {
46  for (unsigned int phi_segment = 0; phi_segment < max_phisegment; phi_segment++)
47  {
48  for (unsigned int z_segment = 0; z_segment < max_zsegment; z_segment++)
49  {
50  const auto iter = m_clusmap[layer][phi_segment][z_segment].begin();
51  const int flayer = TrkrDefs::getLayer(iter->first);
52  const unsigned int fsector = TrkrDefs::getPhiElement(iter->first);
53  const unsigned int fside = TrkrDefs::getZElement(iter->first);
54  std::cout << "layer: " << layer << " | " << flayer
55  << " phi_seg: " << phi_segment << " | " << fsector
56  << " z_seg: " << z_segment << " | " << fside
57  << " nclu: " << m_clusmap[layer][phi_segment][z_segment].size()
58  << std::endl;
59 
60  for (const auto& pair : m_clusmap[layer][phi_segment][z_segment])
61  {
62  os << "clus key " << pair.first << " layer " << TrkrDefs::getLayer(pair.first) << std::endl;
63  (pair.second)->identify();
64  }
65  }
66  }
67  }
68 
69  os << "------------------------------" << std::endl;
70 }
71 
72 //_________________________________________________________________
74 {
75  unsigned int layer = TrkrDefs::getLayer(key);
76  unsigned int sector = TrkrDefs::getPhiElement(key);
77  unsigned int side = TrkrDefs::getZElement(key);
78 
79  // bound check
80  if (layer < max_layer && sector < max_phisegment && side < max_zsegment)
81  {
82  m_clusmap[layer][sector][side].erase(key);
83  }
84  else
85  {
86  std::cout
87  << "TrkrClusterContainerv2::removeCluster - out of range access."
88  << " layer: " << layer
89  << " sector: " << sector
90  << " side: " << side
91  << std::endl;
92  }
93 }
94 
95 //_________________________________________________________________
97 {
98  unsigned int layer = TrkrDefs::getLayer(key);
99  unsigned int sector = TrkrDefs::getPhiElement(key);
100  unsigned int side = TrkrDefs::getZElement(key);
101 
102  // bound check
103  if (layer < max_layer && sector < max_phisegment && side < max_zsegment)
104  {
105  const auto [iter, success] = m_clusmap[layer][sector][side].insert(std::make_pair(key, newclus));
106  if (!success)
107  {
108  std::cout << "TrkrClusterContainerv2::AddClusterSpecifyKey: duplicate key: " << key << " exiting now" << std::endl;
109  exit(1);
110  }
111  }
112  else
113  {
114  std::cout
115  << "TrkrClusterContainerv2::addClusterSpecifyKey - out of range access."
116  << " layer: " << layer
117  << " sector: " << sector
118  << " side: " << side
119  << std::endl;
120  }
121 }
122 
123 //_________________________________________________________________
126 {
127  const unsigned int layer = TrkrDefs::getLayer(hitsetkey);
128  const unsigned int sector = TrkrDefs::getPhiElement(hitsetkey);
129  const unsigned int side = TrkrDefs::getZElement(hitsetkey);
130 
131  // bound check
132  if (layer < max_layer && sector < max_phisegment && side < max_zsegment)
133  {
134  return std::make_pair(m_clusmap[layer][sector][side].cbegin(), m_clusmap[layer][sector][side].cend());
135  }
136  else
137  {
138  std::cout
139  << "TrkrClusterContainerv2::getClusters - out of range access."
140  << " layer: " << layer
141  << " sector: " << sector
142  << " side: " << side
143  << std::endl;
144 
145  return std::make_pair(dummy_map.cbegin(), dummy_map.cend());
146  }
147 }
148 
149 //_________________________________________________________________
151 {
152  const unsigned int layer = TrkrDefs::getLayer(key);
153  const unsigned int sector = TrkrDefs::getPhiElement(key);
154  const unsigned int side = TrkrDefs::getZElement(key);
155 
156  // bound check
157  if (layer < max_layer && sector < max_phisegment && side < max_zsegment)
158  {
159  auto it = m_clusmap[layer][sector][side].find(key);
160  if (it != m_clusmap[layer][sector][side].end())
161  {
162  return it->second;
163  }
164  else
165  {
166  return nullptr;
167  }
168  }
169  else
170  {
171  std::cout
172  << "TrkrClusterContainerv2::findOrAddCluster - out of range access."
173  << " layer: " << layer
174  << " sector: " << sector
175  << " side: " << side
176  << std::endl;
177  return nullptr;
178  }
179 }
180 
181 //_________________________________________________________________
182 unsigned int TrkrClusterContainerv2::size() const
183 {
184  unsigned int size = 0;
185  for (unsigned layer = 0; layer < max_layer; layer++)
186  {
187  for (unsigned phi_segment = 0; phi_segment < max_phisegment; phi_segment++)
188  {
189  for (unsigned z_segment = 0; z_segment < max_zsegment; z_segment++)
190  {
191  size += m_clusmap[layer][phi_segment][z_segment].size();
192  }
193  }
194  }
195 
196  return size;
197 }