Belle II Software  release-05-02-19
DATCONTrackingPurifierFunctions.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Michael Schnell, Christian Wessel *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <tracking/modules/DATCON/DATCONTrackingModule.h>
12 
13 using namespace std;
14 using namespace Belle2;
15 
16 
17 /*
18 * TODO
19 */
20 void
21 DATCONTrackingModule::purifyTrackCandsList()
22 {
23  vector<unsigned int> merged_idList;
24  unsigned int cand_cnt = 0;
25  double x = 0, y = 0;
26  double x_tolerance = 0.2;
27  vector<DATCONHoughCand> cpyCand;
28  bool useMerger = false;
29 
32  cpyCand = vHoughCand;
33  sort(cpyCand.begin(), cpyCand.end());
34  for (auto it = cpyCand.begin(); it != cpyCand.end(); ++it) {
35  vector<unsigned int> idList = it->getIdList();
36  coord2dPair hc = it->getCoord();
37  if (it == cpyCand.begin()) {
38  x = hc.first.X() + hc.second.X();
39  y = hc.first.Y() + hc.second.Y();
40  merged_idList = idList;
41  cand_cnt = 1;
42  } else if (compareList(idList, merged_idList) && fabs(x / (2.0 * cand_cnt) - hc.first.X()) < x_tolerance
43  && it != cpyCand.end()) {
44  x += hc.first.X() + hc.second.X();
45  y += hc.first.Y() + hc.second.Y();
46  ++cand_cnt;
47  if (useMerger) {
48  mergeIdList(merged_idList, idList);
49  } else {
50  merged_idList = idList;
51  }
52  } else {
53  if (it != cpyCand.begin()) {
54  x /= (2.0 * ((double) cand_cnt));
55  y /= (2.0 * ((double) cand_cnt));
56  vTrackCand.push_back(DATCONTrackCand(merged_idList, TVector2(x, y)));
57  }
58  x = hc.first.X() + hc.second.X();
59  y = hc.first.Y() + hc.second.Y();
60  cand_cnt = 1;
61  merged_idList = idList;
62  }
63  }
64 
65  if (cpyCand.size() > 0) {
66  x /= (2.0 * ((double) cand_cnt));
67  y /= (2.0 * ((double) cand_cnt));
68  vTrackCand.push_back(DATCONTrackCand(merged_idList, TVector2(x, y)));
69  }
70 
75  cpyCand = uHoughCand;
76  sort(cpyCand.begin(), cpyCand.end());
77  for (auto it = cpyCand.begin(); it != cpyCand.end(); ++it) {
78  vector<unsigned int> idList = it->getIdList();
79  coord2dPair hc = it->getCoord();
80  if (it == cpyCand.begin()) {
81  x = hc.first.X() + hc.second.X();
82  y = hc.first.Y() + hc.second.Y();
83  cand_cnt = 1;
84  merged_idList = idList;
85  } else if (compareList(idList, merged_idList) && fabs(x / (2.0 * cand_cnt) - hc.first.X()) < x_tolerance
86  && it != cpyCand.end()) {
87  x += hc.first.X() + hc.second.X();
88  y += hc.first.Y() + hc.second.Y();
89  ++cand_cnt;
90  if (useMerger) {
91  mergeIdList(merged_idList, idList);
92  } else {
93  merged_idList = idList;
94  }
95  } else {
96  if (it != cpyCand.begin()) {
97  x /= (2.0 * ((double) cand_cnt));
98  y /= (2.0 * ((double) cand_cnt));
99  uTrackCand.push_back(DATCONTrackCand(merged_idList, TVector2(x, y)));
100  }
101  x = hc.first.X() + hc.second.X();
102  y = hc.first.Y() + hc.second.Y();
103  cand_cnt = 1;
104  merged_idList = idList;
105  }
106  }
107 
108  if (cpyCand.size() > 0) {
109  x /= (2.0 * ((double) cand_cnt));
110  y /= (2.0 * ((double) cand_cnt));
111  uTrackCand.push_back(DATCONTrackCand(merged_idList, TVector2(x, y)));
112  }
113 
116 }
117 
118 /*
119 * Function to compare the hit list.
120 * Returns "true", if the IDs of two hits in the two lists are equal and if a hit on at least m_minimumLines is found.
121 */
122 bool
123 DATCONTrackingModule::compareList(std::vector<unsigned int>& aList, std::vector<unsigned int>& bList)
124 {
125  unsigned int countLayer = 0;
126  bool foundLayer[4] = {false};
127 
128  for (auto ita = aList.begin(); ita != aList.end(); ++ita) {
129  for (auto itb = bList.begin(); itb != bList.end(); ++itb) {
130  int hitIDa = (int)(*ita) - (((int)(*ita) / 10000) * 10000);
131  int hitIDb = (int)(*itb) - (((int)(*itb) / 10000) * 10000);
132  int layera = (int)(*ita) / 10000000;
133  if (hitIDa == hitIDb && !foundLayer[layera - 3]) {
134  foundLayer[layera - 3] = true;
135  ++countLayer;
136  }
137  }
138  }
139 
140  if (countLayer >= m_minimumLines) {
141  return (true);
142  } else {
143  return (false);
144  }
145  return (true);
146 }
147 
148 
149 /*
150 * Merge Id lists.
151 */
152 void
153 DATCONTrackingModule::mergeIdList(std::vector<unsigned int>& mergedList, std::vector<unsigned int>& mergeme)
154 {
155  for (auto& mergemeit : mergeme) {
156  bool found = false;
157  for (auto& mergedit : mergedList) {
158  if (mergedit == mergemeit) {
159  found = true;
160  break;
161  }
162  }
163  if (!found) {
164  mergedList.push_back(mergemeit);
165  }
166  }
167 }
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::coord2dPair
std::pair< TVector2, TVector2 > coord2dPair
Typedef for the coord2dPair, which represents the DATCONHoughCand.
Definition: DATCONHoughCand.h:32
Belle2::DATCONTrackCand
The DATCONTrackCand represents the candidates of tracks found by the DATCON algoritms for u-side and ...
Definition: DATCONTrackCand.h:38