/
MatchCandidate.cxx
210 lines (167 loc) · 6.06 KB
/
MatchCandidate.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//
// AYK (ayk@bnl.gov)
//
// Match candidate (possible track) class;
//
// Initial port from OLYMPUS sources: Oct'2015;
//
#include <MatchCandidate.h>
#include <HoughTree.h>
// ---------------------------------------------------------------------------------------
void MatchCandidate::ResetToTheVirginState()
{
ResetOkGroupCounter();
// THINK: this is in fact needed on highest resolution level only; overhead is small though;
if (mGdim)
for(unsigned gr=0; gr<mGdim; gr++)
ResetMemberCount(gr);
mActive = mGrouped = false;
} // MatchCandidate::ResetToTheVirginState()
// ---------------------------------------------------------------------------------------
MatchCandidate::MatchCandidate(const HoughTree *tree):
mActive(false),
mGrouped(false),
//mAccountedAsGoodTrack(false),
mOkGroupCounter(0),
mGdim(0),
mId(0),
mMemberCount(0),
#ifdef _USE_ALL_MEMBERS_VECTOR_
mAllMembers(0),
#endif
mSelMembers(0)
{
if (tree) {
mGdim = tree->GetGdim();
mId = new unsigned[tree->GetDdim()];
mMemberCount = new unsigned[mGdim];
#ifdef _USE_ALL_MEMBERS_VECTOR_
mAllMembers = new std::vector<GroupMember*>[mGdim];
#endif
mSelMembers = new std::vector<GroupMember*>[mGdim];
} //if
} // MatchCandidate::MatchCandidate()
// ---------------------------------------------------------------------------------------
void MatchCandidate::ShapeItUpForInspection(const HoughTree *tree, const unsigned id[])
{
mActive = true;
for(unsigned iq=0; iq<tree->GetDdim(); iq++)
mId[iq] = id[iq];
for(unsigned gr=0; gr<GetGdim(); gr++) {
for(unsigned mm=0; mm<GetLinearMemberCount(gr); mm++) {
GroupMember *member = GetSelMember(gr,mm);
// Here all pointers should be non-zero I believe?;
assert(member);
member->InsertMatchCandidate(this);
//printf("A: gr=%2d, mm=%2d -> %p hit sharing: %3d\n", gr, mm, hit, hit->mMatchCandidates.size());
//member->SetBusyFlag();
} //for mm
} //for gr
} // MatchCandidate::ShapeItUpForInspection()
// ---------------------------------------------------------------------------------------
void MatchCandidate::AddMember(unsigned gr, GroupMember *member) {
// Allocate yet another entry if needed;
if (mMemberCount[gr] == mSelMembers[gr].size()) {
#ifdef _USE_ALL_MEMBERS_VECTOR_
mAllMembers[gr].push_back(member);
#endif
mSelMembers[gr].push_back(member);
} else {
#ifdef _USE_ALL_MEMBERS_VECTOR_
mAllMembers[gr][mMemberCount[gr]] = member;
#endif
mSelMembers[gr][mMemberCount[gr]] = member;
} //if
mMemberCount[gr]++;
} // MatchCandidate::AddMember()
// ---------------------------------------------------------------------------------------
bool MatchCandidate::IsSubset(const HoughTree *tree, const MatchCandidate *reference) const
{
for(int gr=0; gr<tree->GetGdim(); gr++) {
#if 1
// Well, if this present candidate has MORE hits than the
// reference one, it can not be a subset, right?;
if (GetAliveMemberCount(gr) > reference->GetAliveMemberCount(gr)) return false;
// Current track candidate has LESS hits; need to check
// that they are ALL listed in the reference one, then (and
// only then) it is a true subset;
#endif
#ifdef _USE_ALL_MEMBERS_VECTOR_
// THINK: better use AllMembers[] here?;
#endif
for(unsigned mm=0; mm<mMemberCount[gr]; mm++) {
// Skip 0 pointers;
if (!mSelMembers[gr][mm]) continue;
bool found = false;
for(unsigned qm=0; qm<reference->mMemberCount[gr]; qm++)
if (mSelMembers[gr][mm] == reference->mSelMembers[gr][qm]) {
found = true;
break;
} //for qm .. if
if (!found) return false;
} //for mm
} //for gr
// Ok, a subset in all hit groups -> return success;
return true;
} // MatchCandidate::IsSubset()
// ---------------------------------------------------------------------------------------
__u64 MatchCandidate::Ambiguity() const
{
__u64 ret = 1;
// THINK: no active flag checks, etc?; FIXME: may want to check on non-zero
// member pointers (this is what will happen after the clean up pass);
for(int gr=0; gr<GetGdim(); gr++) {
__u64 multi = 0;
for(unsigned mm=0; mm<mMemberCount[gr]; mm++)
if (mSelMembers[gr][mm])
multi++;
// THINK: this can probably happen after final smoother pass; anyway,
// want to account here only those nodes which have >1 hits;
assert(multi);
if (multi) ret *= multi;
} //for gr
return ret;
} // MatchCandidate::Ambiguity()
// ---------------------------------------------------------------------------------------
bool MatchCandidate::HasAmbiguousHits() const
{
return (Ambiguity() != 1);
} // MatchCandidate::HasAmbiguousHits()
// ---------------------------------------------------------------------------------------
bool MatchCandidate::SiamGroupCandidate(unsigned minHitCount)
{
unsigned hCounters[2] = {0, 0}, toggle = 0;
for(int gr=0; gr<GetGdim(); gr++) {
#if _OLD_
__u64 multi = 0;
for(unsigned mm=0; mm<mMemberCount[gr]; mm++)
if (mMembers[gr][mm])
multi++;
#else
unsigned multi = GetAliveMemberCount(gr);
#endif
// The idea is clear: if >1 hit in this plane, both potential
// tracks can be happy; otherwise alternate, this obviously gives
// highest possible hit count per track;
if (multi == 1) {
hCounters[toggle]++;
toggle = (toggle+1)%2;
} else if (multi >= 2) {
hCounters[0]++;
hCounters[1]++;
} //if
} //for gr
//printf("Double counts: %2d %2d\n", hCounters[0], hCounters[1]);
return (hCounters[0] >= minHitCount && hCounters[1] >= minHitCount);
} // MatchCandidate::SiamGroupCandidate()
// ---------------------------------------------------------------------------------------
#if _LATER_
void MatchCandidate::AssertHitActiveFlags(const HoughTree *tree)
{
for(int gr=0; gr<tree->GetGdim(); gr++)
for(unsigned mm=0; mm<mMemberCount[gr]; mm++)
mMembers[gr][mm]->SetActive(true);
} // MatchCandidate::AssertHitActiveFlags()
#endif
// ---------------------------------------------------------------------------------------
ClassImp(MatchCandidate)