CbmRoot
Loading...
Searching...
No Matches
CaMcMatch.h
Go to the documentation of this file.
1/* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#ifndef CaMcMatch_h
11#define CaMcMatch_h 1
12
13#include "CaDefs.h"
14
15#include <boost/functional/hash.hpp>
16
17#include <string>
18
19namespace cbm::algo::ca
20{
21 struct McMatch {
22
23 public:
25 McMatch() = default;
26
28 McMatch(const McMatch&) = default;
29
31 McMatch(McMatch&&) = default;
32
34 McMatch& operator=(const McMatch&) = default;
35
37 McMatch& operator=(McMatch&&) = default;
38
40 ~McMatch() = default;
41
45 void AddLink(int linkIndex, float linkWeight)
46 {
47 if (fNofLinks < 5 && linkWeight > 0.f && linkIndex >= 0) {
48 fLinks[fNofLinks] = linkIndex;
49 fLinkWeights[fNofLinks] = linkWeight;
52 }
53 ++fNofLinks;
54 }
55 }
56
59 int GetNofLinks() const { return fNofLinks; }
60
63 int GetBestLinkIndex() const { return fBestLinkIndex; }
64
68 int GetLink(int i) const
69 {
70 if (i >= 0 && i < fNofLinks) {
71 return fLinks[i];
72 }
73 return -1;
74 }
75
79 float GetLinkWeight(int i) const
80 {
81 if (i >= 0 && i < fNofLinks) {
82 return fLinkWeights[i];
83 }
84 return 0.f;
85 }
86
87 bool IsEmpty() const { return fNofLinks == 0; }
88
89 void Clear()
90 {
91 fNofLinks = 0;
92 fBestLinkIndex = -1;
93 fLinks.fill(-1);
94 fLinkWeights.fill(0.f);
95 }
96
97 bool operator==(const McMatch& other) const
98 {
99 for (int i = 0; i < fNofLinks; ++i) {
100 if (fLinkWeights[i] <= 0.f) {
101 continue;
102 }
103 for (int j = 0; j < other.fNofLinks; ++j) {
104 if (other.fLinkWeights[j] <= 0.f) {
105 continue;
106 }
107 if (fLinks[i] == other.fLinks[j]) {
108 return true;
109 }
110 }
111 }
112 return false;
113 }
114
115 bool operator!=(const McMatch& other) const { return !(*this == other); }
116
117 std::string ToString() const
118 {
119 std::ostringstream out;
120 out << "McMatch: NofLinks = " << fNofLinks << ", BestLinkIndex = " << fBestLinkIndex << '\n';
121 for (int i = 0; i < fNofLinks; ++i) {
122 out << " Link[" << i << "] = " << fLinks[i] << ", Weight = " << fLinkWeights[i] << '\n';
123 }
124 return out.str();
125 }
126
127 private:
128 int fNofLinks = 0;
129 std::array<int, 5> fLinks = {-1, -1, -1, -1, -1};
130 std::array<float, 5> fLinkWeights = {0, 0, 0, 0, 0};
131 int fBestLinkIndex = -1;
132 };
133} // namespace cbm::algo::ca
134
135#endif // CaMcMatch_h
Compile-time constants definition for the CA tracking algorithm.
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14
~McMatch()=default
Destructor.
int GetNofLinks() const
Definition CaMcMatch.h:59
McMatch(McMatch &&)=default
Move constructor.
float GetLinkWeight(int i) const
Definition CaMcMatch.h:79
int GetLink(int i) const
Definition CaMcMatch.h:68
std::array< float, 5 > fLinkWeights
Array of matched link weights.
Definition CaMcMatch.h:130
std::string ToString() const
Definition CaMcMatch.h:117
int GetBestLinkIndex() const
Definition CaMcMatch.h:63
McMatch & operator=(const McMatch &)=default
Copy assignment operator.
bool IsEmpty() const
Definition CaMcMatch.h:87
void AddLink(int linkIndex, float linkWeight)
Definition CaMcMatch.h:45
bool operator!=(const McMatch &other) const
Definition CaMcMatch.h:115
int fBestLinkIndex
Index of the best link in fLinks array.
Definition CaMcMatch.h:131
McMatch & operator=(McMatch &&)=default
Move assignment operator.
int fNofLinks
Number of matched links.
Definition CaMcMatch.h:128
McMatch(const McMatch &)=default
Copy constructor.
bool operator==(const McMatch &other) const
Definition CaMcMatch.h:97
std::array< int, 5 > fLinks
Array of matched link indices.
Definition CaMcMatch.h:129
McMatch()=default
Default constructor.