ECCE @ EIC 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 "TrkrClusterv2.h"
10 #include "TrkrDefs.h"
11 
12 #include <cstdlib>
13 
14 namespace
15 {
16  TrkrClusterContainer::Map dummy_map;
17 }
18 
19 //_________________________________________________________________
21 {
22  for(unsigned int layer = 0;layer < max_layer; layer++)
23  for(unsigned int phi_segment = 0;phi_segment < max_phisegment;phi_segment++)
24  for(unsigned int z_segment = 0; z_segment < max_zsegment; z_segment++)
25  {
26  for( const auto& pair:m_clusmap[layer][phi_segment][z_segment] )
27  { delete pair.second; }
28 
29  m_clusmap[layer][phi_segment][z_segment].clear();
30  }
31 }
32 
33 //_________________________________________________________________
34 void TrkrClusterContainerv2::identify(std::ostream& os) const
35 {
36  os << "-----TrkrClusterContainerv2-----" << std::endl;
37  os << "Number of clusters: " << size() << std::endl;
38 
39  for(unsigned int layer = 0;layer < max_layer; layer++)
40  for(unsigned int phi_segment = 0;phi_segment < max_phisegment;phi_segment++)
41  for(unsigned int z_segment = 0; z_segment < max_zsegment; z_segment++)
42  {
43  const auto iter = m_clusmap[layer][phi_segment][z_segment].begin();
44  const int flayer = TrkrDefs::getLayer(iter->first);
45  const unsigned int fsector = TrkrDefs::getPhiElement(iter->first);
46  const unsigned int fside = TrkrDefs::getZElement(iter->first);
47  std::cout << "layer: " << layer << " | " << flayer
48  << " phi_seg: " << phi_segment << " | " << fsector
49  << " z_seg: " << z_segment << " | " << fside
50  << " nclu: " << m_clusmap[layer][phi_segment][z_segment].size()
51  << std::endl;
52 
53  for( const auto& pair:m_clusmap[layer][phi_segment][z_segment] )
54  {
55  int layer = TrkrDefs::getLayer(pair.first);
56  os << "clus key " << pair.first << " layer " << layer << std::endl;
57  (pair.second)->identify();
58  }
59  }
60 
61  os << "------------------------------" << std::endl;
62 }
63 
64 //_________________________________________________________________
66 {
67  unsigned int layer = TrkrDefs::getLayer(key);
68  unsigned int sector = TrkrDefs::getPhiElement(key);
69  unsigned int side = TrkrDefs::getZElement(key);
70 
71  // bound check
72  if( layer < max_layer && sector < max_phisegment && side < max_zsegment )
73  {
74 
75  m_clusmap[layer][sector][side].erase(key);
76 
77  } else {
78 
79  std::cout
80  << "TrkrClusterContainerv2::removeCluster - out of range access."
81  << " layer: " << layer
82  << " sector: " << sector
83  << " side: " << side
84  << std::endl;
85 
86  }
87 }
88 
89 //_________________________________________________________________
91 { removeCluster( clus->getClusKey() ); }
92 
93 //_________________________________________________________________
96 { return addClusterSpecifyKey(newclus->getClusKey(), newclus); }
97 
98 //_________________________________________________________________
101 {
102  unsigned int layer = TrkrDefs::getLayer(key);
103  unsigned int sector = TrkrDefs::getPhiElement(key);
104  unsigned int side = TrkrDefs::getZElement(key);
105 
106  // bound check
107  if( layer < max_layer && sector < max_phisegment && side < max_zsegment )
108  {
109 
110  auto ret = m_clusmap[layer][sector][side].insert(std::make_pair(key, newclus));
111  if ( !ret.second )
112  {
113  std::cout << "TrkrClusterContainerv2::AddClusterSpecifyKey: duplicate key: " << key << " exiting now" << std::endl;
114  exit(1);
115  } else {
116  ret.first->second->setClusKey( key );
117  return ret.first;
118  }
119 
120  } else {
121 
122  std::cout
123  << "TrkrClusterContainerv2::addClusterSpecifyKey - out of range access."
124  << " layer: " << layer
125  << " sector: " << sector
126  << " side: " << side
127  << std::endl;
128 
129  return dummy_map.begin();
130 
131  }
132 
133 }
134 
135 //_________________________________________________________________
138 {
139  const unsigned int layer = TrkrDefs::getLayer(hitsetkey);
140  const unsigned int sector= TrkrDefs::getPhiElement(hitsetkey);
141  const unsigned int side = TrkrDefs::getZElement(hitsetkey);
142 
143  // bound check
144  if( layer < max_layer && sector < max_phisegment && side < max_zsegment )
145  {
146  return std::make_pair( m_clusmap[layer][sector][side].cbegin(), m_clusmap[layer][sector][side].cend() );
147  } else {
148  std::cout
149  << "TrkrClusterContainerv2::getClusters - out of range access."
150  << " layer: " << layer
151  << " sector: " << sector
152  << " side: " << side
153  << std::endl;
154 
155  return std::make_pair( dummy_map.cbegin(), dummy_map.cend() );
156  }
157 }
158 
159 //_________________________________________________________________
162 {
163  const unsigned int layer = TrkrDefs::getLayer(hitsetkey);
164  const unsigned int sector= TrkrDefs::getPhiElement(hitsetkey);
165  const unsigned int side = TrkrDefs::getZElement(hitsetkey);
166 
167  // bound check
168  if( layer < max_layer && sector < max_phisegment && side < max_zsegment )
169  {
170  return &m_clusmap[layer][sector][side];
171  } else {
172  std::cout
173  << "TrkrClusterContainerv2::getClusterMap - out of range access."
174  << " layer: " << layer
175  << " sector: " << sector
176  << " side: " << side
177  << std::endl;
178 
179  return nullptr;
180  }
181 }
182 
183 //_________________________________________________________________
186 {
187  const unsigned int layer = TrkrDefs::getLayer(key);
188  const unsigned int sector= TrkrDefs::getPhiElement(key);
189  const unsigned int side = TrkrDefs::getZElement(key);
190 
191  // bound check
192  if( layer < max_layer && sector < max_phisegment && side < max_zsegment )
193  {
194  auto it = m_clusmap[layer][sector][side].lower_bound(key);
195  if( it == m_clusmap[layer][sector][side].end() || (key < it->first) )
196  {
197  // add new cluster and set its key
198  it = m_clusmap[layer][sector][side].insert(it, std::make_pair(key, new TrkrClusterv2()));
199  it->second->setClusKey( key );
200  }
201  return it;
202  } else {
203  std::cout
204  << "TrkrClusterContainerv2::findOrAddCluster - out of range access."
205  << " layer: " << layer
206  << " sector: " << sector
207  << " side: " << side
208  << std::endl;
209 
210  return dummy_map.begin();
211  }
212 
213 }
214 
215 //_________________________________________________________________
217 {
218  const unsigned int layer = TrkrDefs::getLayer(key);
219  const unsigned int sector= TrkrDefs::getPhiElement(key);
220  const unsigned int side = TrkrDefs::getZElement(key);
221 
222  // bound check
223  if( layer < max_layer && sector < max_phisegment && side < max_zsegment )
224  {
225 
226  auto it = m_clusmap[layer][sector][side].find(key);
227  if (it != m_clusmap[layer][sector][side].end())
228  {
229  return it->second;
230  } else {
231  return nullptr;
232  }
233 
234  } else {
235  std::cout
236  << "TrkrClusterContainerv2::findOrAddCluster - out of range access."
237  << " layer: " << layer
238  << " sector: " << sector
239  << " side: " << side
240  << std::endl;
241  return nullptr;
242  }
243 }
244 
245 //_________________________________________________________________
246 unsigned int TrkrClusterContainerv2::size() const
247 {
248  unsigned int size = 0;
249  for(unsigned layer = 0;layer < max_layer; layer++)
250  for(unsigned phi_segment = 0;phi_segment < max_phisegment;phi_segment++)
251  for(unsigned z_segment = 0; z_segment < max_zsegment; z_segment++)
252  {
253  size += m_clusmap[layer][phi_segment][z_segment].size();
254  }
255 
256  return size;
257 }