Belle II Software development
ClusterCandidate.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <pxd/reconstruction/ClusterCandidate.h>
10
11using namespace std;
12
13namespace Belle2 {
19 namespace PXD {
20
22 {
23 //If this cluster has been merged, delegate to the correct cluster
24 if (m_merged) return m_merged->merge(cls);
25 ClusterCandidate* pcls = &cls;
26 //No need to merge with ourselves
27 if (pcls == this) return this;
28 //If the other cluster has been merged, find the parent
29 while (pcls->m_merged != 0) {
30 ClusterCandidate* tmp = pcls->m_merged;
31 if (tmp == this) return this;
32 //Update all merged pointers to point to this cluster
33 pcls->m_merged = this;
34 pcls = tmp;
35 }
36 //Sum charge, set seed and copy pixels
37 m_charge += pcls->m_charge;
38 if (pcls->m_seed.getCharge() > m_seed.getCharge()) {
39 m_seed = pcls->m_seed;
40 }
41 //copy only the smaller vector
42 if (pcls->m_pixels.size() > m_pixels.size()) std::swap(m_pixels, pcls->m_pixels);
43 m_pixels.insert(m_pixels.end(), pcls->m_pixels.begin(), pcls->m_pixels.end());
44 //If the allocated memory is too large, shrink it down to default
45 if (pcls->m_pixels.capacity() > c_maxCapacity) {
46 pcls->m_pixels.resize(c_defaultCapacity);
47 pcls->m_pixels.shrink_to_fit();
48 }
49 //Clear the pixels and charge in the merged cluster
50 pcls->m_pixels.clear();
51 pcls->m_charge = 0;
52 //And set the merge pointer
53 pcls->m_merged = this;
54 return this;
55 }
56
57 void ClusterCandidate::add(const Pixel& pixel)
58 {
59 //Delegate to the correct cluster
60 if (m_merged) {
61 m_merged->add(pixel);
62 return;
63 }
64 //check seed charge
65 float charge = pixel.getCharge();
66 m_charge += charge;
67 if (m_seed.getCharge() < charge) {
68 m_seed = pixel;
69 }
70 //add pixel
71 m_pixels.push_back(pixel);
72 }
73 }
75} //Belle2 namespace
Class representing a possible cluster during clustering of the PXD It supports merging of different c...
Pixel m_seed
Seed pixel of the cluster, i.e.
ClusterCandidate * m_merged
Pointer to the cluster this cluster was merged into.
float m_charge
Charge of the cluster.
std::vector< Pixel > m_pixels
List of all pixels in the cluster.
ClusterCandidate * merge(ClusterCandidate &cls)
Merge the given cluster with this one.
void add(const Pixel &pixel)
Add a Pixel to the current cluster.
@ c_defaultCapacity
Reserve space for this number of pixels on construction.
@ c_maxCapacity
If the capacity exceeds this value, shrink the vector back to c_defaultCapacity after clearing.
Class to represent one pixel, used in clustering for fast access.
Definition: Pixel.h:36
float getCharge() const
Return the Charge of the Pixel.
Definition: Pixel.h:70
Abstract base class for different kinds of events.
STL namespace.