Belle II Software development
ClusterCandidate Class Reference

Class representing a possible cluster during clustering of the PXD It supports merging of different clusters and keeps track of the highest charge inside the cluster. More...

#include <ClusterCandidate.h>

Public Types

enum  {
  c_defaultCapacity = 10 ,
  c_maxCapacity = 4 * c_defaultCapacity
}
 

Public Member Functions

 ClusterCandidate ()
 Constructor to create an empty Cluster.
 
void clear ()
 Clear the Cluster information (to reuse the same cluster instance)
 
ClusterCandidatemerge (ClusterCandidate &cls)
 Merge the given cluster with this one.
 
void add (const Pixel &pixel)
 Add a Pixel to the current cluster.
 
float getCharge () const
 get the charge of the cluster
 
float getSeedCharge () const
 get the seed charge of the cluster
 
const PixelgetSeed () const
 get the seed pixel of the cluster, i.e.
 
size_t size () const
 get the cluster size
 
const std::vector< Pixel > & pixels () const
 get a reference to all pixels in the cluster
 

Protected Attributes

ClusterCandidatem_merged
 Pointer to the cluster this cluster was merged into.
 
float m_charge
 Charge of the cluster.
 
Pixel m_seed
 Seed pixel of the cluster, i.e.
 
std::vector< Pixelm_pixels
 List of all pixels in the cluster.
 

Detailed Description

Class representing a possible cluster during clustering of the PXD It supports merging of different clusters and keeps track of the highest charge inside the cluster.

To save relocation time, each Instance is created with a default capacity of 10 pixels before relocation will occur.

Definition at line 30 of file ClusterCandidate.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
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.

Definition at line 32 of file ClusterCandidate.h.

32 {
37 };
@ 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.

Constructor & Destructor Documentation

◆ ClusterCandidate()

ClusterCandidate ( )
inline

Constructor to create an empty Cluster.

Definition at line 39 of file ClusterCandidate.h.

39 :
40 m_merged(0), m_charge(0), m_seed()
41 {
43 }
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.

Member Function Documentation

◆ add()

void add ( const Pixel pixel)

Add a Pixel to the current cluster.

Increases the charge of the cluster and checks if the seed pixel changes. If this method is called on a cluster which has been merged with another cluster, the add method of the merged cluster will be called,

Parameters
pixelPixel to add to the cluster

Definition at line 57 of file ClusterCandidate.cc.

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();
67 if (m_seed.getCharge() < charge) {
68 m_seed = pixel;
69 }
70 //add pixel
71 m_pixels.push_back(pixel);
72 }
void add(const Pixel &pixel)
Add a Pixel to the current cluster.
float getCharge() const
Return the Charge of the Pixel.
Definition: Pixel.h:70
double charge(int pdgCode)
Returns electric charge of a particle with given pdg code.
Definition: EvtPDLUtil.cc:44

◆ clear()

void clear ( )
inline

Clear the Cluster information (to reuse the same cluster instance)

Definition at line 46 of file ClusterCandidate.h.

47 {
48 m_merged = 0;
49 m_charge = 0;
50 m_seed = Pixel();
51 m_pixels.clear();
52 }

◆ getCharge()

float getCharge ( ) const
inline

get the charge of the cluster

Definition at line 75 of file ClusterCandidate.h.

75{ return m_charge; }

◆ getSeed()

const Pixel & getSeed ( ) const
inline

get the seed pixel of the cluster, i.e.

the pixel with the highes charge

Definition at line 79 of file ClusterCandidate.h.

79{ return m_seed; }

◆ getSeedCharge()

float getSeedCharge ( ) const
inline

get the seed charge of the cluster

Definition at line 77 of file ClusterCandidate.h.

77{ return m_seed.getCharge(); }

◆ merge()

ClusterCandidate * merge ( ClusterCandidate cls)

Merge the given cluster with this one.

This method will remove all pixels from a given cluster and add it to this one. In addition we set a pointer to this instance in the other cluster so that new pixels will be directly added to the correct cluster when add is called on an already merged cluster

Parameters
clsCluster to merge into this one
Returns
the address of the cluster containing all pixels

Definition at line 21 of file ClusterCandidate.cc.

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 }
ClusterCandidate()
Constructor to create an empty Cluster.
ClusterCandidate * merge(ClusterCandidate &cls)
Merge the given cluster with this one.

◆ pixels()

const std::vector< Pixel > & pixels ( ) const
inline

get a reference to all pixels in the cluster

Definition at line 83 of file ClusterCandidate.h.

83{ return m_pixels; }

◆ size()

size_t size ( ) const
inline

get the cluster size

Definition at line 81 of file ClusterCandidate.h.

81{ return m_pixels.size(); }

Member Data Documentation

◆ m_charge

float m_charge
protected

Charge of the cluster.

Definition at line 89 of file ClusterCandidate.h.

◆ m_merged

ClusterCandidate* m_merged
protected

Pointer to the cluster this cluster was merged into.

Definition at line 87 of file ClusterCandidate.h.

◆ m_pixels

std::vector<Pixel> m_pixels
protected

List of all pixels in the cluster.

Definition at line 93 of file ClusterCandidate.h.

◆ m_seed

Pixel m_seed
protected

Seed pixel of the cluster, i.e.

the pixel with the highest charge

Definition at line 91 of file ClusterCandidate.h.


The documentation for this class was generated from the following files: