Belle II Software  release-05-01-25
ClusterCandidate.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <pxd/reconstruction/ClusterCandidate.h>
12 
13 using namespace std;
14 
15 namespace Belle2 {
21  namespace PXD {
22 
24  {
25  //If this cluster has been merged, delegate to the correct cluster
26  if (m_merged) return m_merged->merge(cls);
27  ClusterCandidate* pcls = &cls;
28  //No need to merge with ourselves
29  if (pcls == this) return this;
30  //If the other cluster has been merged, find the parent
31  while (pcls->m_merged != 0) {
32  ClusterCandidate* tmp = pcls->m_merged;
33  if (tmp == this) return this;
34  //Update all merged pointers to point to this cluster
35  pcls->m_merged = this;
36  pcls = tmp;
37  }
38  //Sum charge, set seed and copy pixels
39  m_charge += pcls->m_charge;
40  if (pcls->m_seed.getCharge() > m_seed.getCharge()) {
41  m_seed = pcls->m_seed;
42  }
43  //copy only the smaller vector
44  if (pcls->m_pixels.size() > m_pixels.size()) std::swap(m_pixels, pcls->m_pixels);
45  m_pixels.insert(m_pixels.end(), pcls->m_pixels.begin(), pcls->m_pixels.end());
46  //If the allocated memory is too large, shrink it down to default
47  if (pcls->m_pixels.capacity() > c_maxCapacity) {
48  pcls->m_pixels.resize(c_defaultCapacity);
49  pcls->m_pixels.shrink_to_fit();
50  }
51  //Clear the pixels and charge in the merged cluster
52  pcls->m_pixels.clear();
53  pcls->m_charge = 0;
54  //And set the merge pointer
55  pcls->m_merged = this;
56  return this;
57  }
58 
59  void ClusterCandidate::add(const Pixel& pixel)
60  {
61  //Delegate to the correct cluster
62  if (m_merged) {
63  m_merged->add(pixel);
64  return;
65  }
66  //check seed charge
67  float charge = pixel.getCharge();
68  m_charge += charge;
69  if (m_seed.getCharge() < charge) {
70  m_seed = pixel;
71  }
72  //add pixel
73  m_pixels.push_back(pixel);
74  }
75  }
77 } //Belle2 namespace
Belle2::PXD::ClusterCandidate::m_merged
ClusterCandidate * m_merged
Pointer to the cluster this cluster was merged into.
Definition: ClusterCandidate.h:98
Belle2::PXD::Pixel::getCharge
float getCharge() const
Return the Charge of the Pixel.
Definition: Pixel.h:81
Belle2::PXD::ClusterCandidate
Class representing a possible cluster during clustering of the PXD It supports merging of different c...
Definition: ClusterCandidate.h:41
Belle2::PXD::Pixel
Class to represent one pixel, used in clustering for fast access.
Definition: Pixel.h:47
Belle2::merge
std::vector< std::vector< double > > merge(std::vector< std::vector< std::vector< double >>> toMerge)
merge { vector<double> a, vector<double> b} into {a, b}
Definition: tools.h:44
Belle2::PXD::ClusterCandidate::m_pixels
std::vector< Pixel > m_pixels
List of all pixels in the cluster.
Definition: ClusterCandidate.h:104
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PXD::ClusterCandidate::m_seed
Pixel m_seed
Seed pixel of the cluster, i.e.
Definition: ClusterCandidate.h:102
Belle2::PXD::ClusterCandidate::m_charge
float m_charge
Charge of the cluster.
Definition: ClusterCandidate.h:100
Belle2::PXD::ClusterCandidate::add
void add(const Pixel &pixel)
Add a Pixel to the current cluster.
Definition: ClusterCandidate.cc:59