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