Belle II Software development
|
Class to remember recently assigned clusters This class will remember the current and the last pixel row to allow fast finding of the correct cluster a pixel belongs to. More...
#include <ClusterCache.h>
Public Types | |
enum | { c_defaultNumberColumns = 250 } |
typedef std::deque< ClusterCandidate >::iterator | iterator |
Define iterator type. | |
typedef std::deque< ClusterCandidate >::const_iterator | const_iterator |
Define const iterator type. | |
Public Member Functions | |
ClusterCache (unsigned int maxU=c_defaultNumberColumns) | |
Create a new cache. | |
ClusterCache (const ClusterCache &)=delete | |
No copy construction. | |
ClusterCache & | operator= (const ClusterCache &)=delete |
No operator=. | |
~ClusterCache () | |
Delete the cache and free the memory. | |
void | clear () |
Clear the cache structure. | |
ClusterCandidate & | findCluster (unsigned int u, unsigned int v) |
Find a cluster adjacent to the given coordinates. | |
std::deque< ClusterCandidate >::iterator | begin () |
Return iterator to the begin of of created clusters. | |
std::deque< ClusterCandidate >::iterator | end () |
Return iterator to the end of created clusters. | |
bool | empty () const |
Check if there are any clusters. | |
Private Member Functions | |
ClusterCandidate * | mergeCluster (ClusterCandidate *cls1, ClusterCandidate *cls2) |
Merge two cluster and update the list of cached clusters. | |
void | switchRow (unsigned int v) |
Switch the internal rows. | |
Private Attributes | |
const unsigned int | m_maxU |
number of columns of the cache. | |
unsigned int | m_curV |
current v coordinate, needed to switch top row | |
ClusterCandidate ** | m_clsTop |
cache of the top row | |
ClusterCandidate ** | m_clsCur |
cache of the current row | |
std::deque< ClusterCandidate > | m_clusters |
list of all the clusters created so far | |
std::deque< ClusterCandidate >::iterator | m_currCluster |
iterator to the next free cluster to be used if a new cluster is needed. | |
Class to remember recently assigned clusters This class will remember the current and the last pixel row to allow fast finding of the correct cluster a pixel belongs to.
All hit pixels above noise threshold will be processed sorted, row wise with increasing u (column) and v (row) ids. For each pixel we look at the left neighbor in the same row and the three direct neighbors in the last row. If at least one cluster is found in any of these pixels, all those clusters will be merged and the pixel gets assigned to the existing cluster. Otherwise a new cluster is created. At the end, all clusters will be checked if they satisfy the requirements for a valid cluster (seed and cluster charge) and only valid clusters are kept
Lets assume that we have a hit in the pixel marked with X. If we process the pixels in a sorted way, than we only have to check the pixels marked O to see if this pixel belongs to a cluster. To do this, we cache the top row and the current row. For each pixel, we just have to check the left cluster and three elements of the top row. If we already found a valid left cluster we only have to check the top right position in addition as we are sure that top left and top are already pointing to the same cluster as the left position due to the sorted processing. If we find more than one adjoining cluster (like the clusters 1 and 2 when looking at 3), all those clusters will be merged. After this step the pixels belonging to 2 and 3 will all belong to cluster 1.
We save the row we are currently looking at. Once the v coordinate of the next hit changes we either switch the current row to top row or erase it if the v coordinate changed by more than one (complete row without an hit).
With this algorithm we only have to look at each pixel once and otherwise just update the list of clusters. To further improve performance the number of free/malloc calls is kept to a minimum: The list of clusters is kept in a std::deque (to keep pointer valid at all times) and not cleared between events but reused. Each new cluster keeps the pixel information in a std::vector is constructed with a capacity of 10 pixels so that relocation should only occur in rare cases and the current and top row pointers are kept and reused over the lifetime of the Cache.
* u → → → → → → → → → → * v┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐ * ↓│ │ │O│O│O│ │ │ │ │ │ │ * ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ * ↓│ │ │O│X│ │ │ │ │ │ │ │ * ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ * ↓│ │ │ │ │ │ │ │ │ │ │ │ * ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ * ↓│ │ │1│ │2│2│ │ │ │ │ │ * ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ * ↓│ │ │ │3│ │ │ │ │ │ │ │ * ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ * ↓│ │ │ │ │ │ │ │ │ │ │ │ * └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘ *
Definition at line 77 of file ClusterCache.h.
typedef std::deque<ClusterCandidate>::const_iterator const_iterator |
Define const iterator type.
Definition at line 82 of file ClusterCache.h.
typedef std::deque<ClusterCandidate>::iterator iterator |
Define iterator type.
Definition at line 80 of file ClusterCache.h.
anonymous enum |
Enumerator | |
---|---|
c_defaultNumberColumns | Default maximum number of PIXEL columns the cache can handle. |
Definition at line 84 of file ClusterCache.h.
|
explicit |
Create a new cache.
Definition at line 19 of file ClusterCache.cc.
~ClusterCache | ( | ) |
Delete the cache and free the memory.
Definition at line 26 of file ClusterCache.cc.
|
inline |
Return iterator to the begin of of created clusters.
This list also contains clusters which were already merged with other clusters so one has to check that the cluster size is >0 To loop over all cluster candidates use something like
Definition at line 121 of file ClusterCache.h.
void clear | ( | ) |
Clear the cache structure.
clear the Cache
Definition at line 33 of file ClusterCache.cc.
|
inline |
|
inline |
ClusterCandidate & findCluster | ( | unsigned int | u, |
unsigned int | v | ||
) |
Find a cluster adjacent to the given coordinates.
If no adjacent cluster is found, a new cluster is returned.
u | column id to look for a adjacent clusters |
v | row id to look for adjacent clusters |
If no cluster is found, 0 is returned
Definition at line 42 of file ClusterCache.cc.
|
private |
Merge two cluster and update the list of cached clusters.
Definition at line 85 of file ClusterCache.cc.
|
private |
Switch the internal rows.
Switch current and top row or clear cache.
We always keep current and last row. This method switches these rows and resets the new current row
v | current row id |
Definition at line 95 of file ClusterCache.cc.
|
private |
cache of the current row
Definition at line 147 of file ClusterCache.h.
|
private |
cache of the top row
Definition at line 145 of file ClusterCache.h.
|
private |
list of all the clusters created so far
Definition at line 149 of file ClusterCache.h.
|
private |
iterator to the next free cluster to be used if a new cluster is needed.
The List of clusters is kept between clustering calls to save malloc/free calls. On clear, this iterator will point to the beginning of m_clusters and will be incremented every time a cluster is needed. Once it reaches m_clusters.end(), new clusters will be added to the front of the m_clusters container.
Definition at line 157 of file ClusterCache.h.
|
private |
current v coordinate, needed to switch top row
Definition at line 143 of file ClusterCache.h.
|
private |
number of columns of the cache.
This is the actual number of columns + 2 to get rid of edge effects
Definition at line 141 of file ClusterCache.h.