Belle II Software development
OverlapMatrixCreator Class Reference

Creates a vector of vectors, that knows which track is conflicting with which other. More...

#include <OverlapMatrixCreator.h>

Public Member Functions

 OverlapMatrixCreator (std::vector< std::vector< unsigned short > > const &hitRelatedTracks, unsigned short nSpacePointTrackCandidates)
 Constructor taking information necessary to perform algorithm.
 
std::vector< std::vector< unsigned short > > getOverlapMatrix (unsigned allowedOverlaps=0)
 Fills and returns the overlap matrix.
 

Private Attributes

std::vector< std::vector< unsigned short > > const & m_hitRelatedTracks
 Input information, see constructor.
 
std::vector< std::vector< unsigned short > > m_overlapMatrix
 Output information, see getOverlapMatrix.
 

Detailed Description

Creates a vector of vectors, that knows which track is conflicting with which other.

Definition at line 19 of file OverlapMatrixCreator.h.

Constructor & Destructor Documentation

◆ OverlapMatrixCreator()

OverlapMatrixCreator ( std::vector< std::vector< unsigned short > > const &  hitRelatedTracks,
unsigned short  nSpacePointTrackCandidates 
)
inline

Constructor taking information necessary to perform algorithm.

The index of the first vector of hitRelatedTracks is the hit index. The vector at that place holds all tracks, that are connected to that index. m_overlapMatrix is the output and needs to know for how many tracks overlaps need to be saved, hence the second parameter.

Definition at line 28 of file OverlapMatrixCreator.h.

29 :
30 m_hitRelatedTracks(hitRelatedTracks), m_overlapMatrix(nSpacePointTrackCandidates)
31 {}
std::vector< std::vector< unsigned short > > const & m_hitRelatedTracks
Input information, see constructor.
std::vector< std::vector< unsigned short > > m_overlapMatrix
Output information, see getOverlapMatrix.

Member Function Documentation

◆ getOverlapMatrix()

std::vector< std::vector< unsigned short > > getOverlapMatrix ( unsigned  allowedOverlaps = 0)
inline

Fills and returns the overlap matrix.

It is fairly easily possible to extend the algorithm to allow a number of overlaps without telling the tracks to be in conflict.

Definition at line 38 of file OverlapMatrixCreator.h.

39 {
40 //Loop over all the hits and make corresponding connections for the tracks
41 //This yields unordered indices of tracks, one for each shared hit.
42 for (auto&& tracks : m_hitRelatedTracks) {
43 for (unsigned short ii = 0; ii < tracks.size(); ii++) {
44 for (unsigned short jj = ii + 1; jj < tracks.size(); jj++) {
45 m_overlapMatrix[tracks[ii]].push_back(tracks[jj]);
46 m_overlapMatrix[tracks[jj]].push_back(tracks[ii]);
47 }
48 }
49 }
50
51 //If it makes sense to have this can be explored by Jonas and Felix...
52 //... so let's start with something that works, not necessarily what is fastest.
53 //This is probably slower then the version below for 0 overlaps, but shall work with
54 //any number of allowed overlaps.
55 if (allowedOverlaps) {
56 std::vector <unsigned short> overlapChache;
57
58 for (auto&& overlapTracks : m_overlapMatrix) {
59 std::sort(overlapTracks.begin(), overlapTracks.end());
60
61 auto endIter = overlapTracks.end();
62 auto cacheIter = overlapTracks.begin();
63 for (auto iter = overlapTracks.begin(); iter != endIter; iter++) {
64 if (*iter != *cacheIter) {
65 cacheIter = iter;
66 } else if (iter - cacheIter == allowedOverlaps) {
67 overlapChache.push_back(*iter);
68 }
69 }
70 overlapTracks = overlapChache;
71 overlapChache.clear();
72 }
73 return m_overlapMatrix;
74 }
75
76 //sort and erase duplicate overlaps
77 //TODO: Check in realistic situation alternative approach:
78 //see http://stackoverflow.com/questions/1041620/whats-the-most-efficient-way-to-erase-duplicates-and-sort-a-vector
79 for (auto&& overlapTracks : m_overlapMatrix) {
80 std::sort(overlapTracks.begin(), overlapTracks.end());
81 overlapTracks.erase(std::unique(overlapTracks.begin(), overlapTracks.end()), overlapTracks.end());
82 }
83
84 return m_overlapMatrix;
85 }

Member Data Documentation

◆ m_hitRelatedTracks

std::vector<std::vector <unsigned short> > const& m_hitRelatedTracks
private

Input information, see constructor.

Definition at line 88 of file OverlapMatrixCreator.h.

◆ m_overlapMatrix

std::vector<std::vector <unsigned short> > m_overlapMatrix
private

Output information, see getOverlapMatrix.

Definition at line 89 of file OverlapMatrixCreator.h.


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