Belle II Software  release-05-02-19
DATCONTrackingHoughSpaceClusterFinder.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 void
17 DATCONTrackingModule::FindHoughSpaceCluster(bool uSide)
18 {
19 
20  int vertSectors = 1;
21  int angleSectors = 1;
22  int minimumClusterSize = 1;
23  int maximumClusterSize = 1000;
24  double unitX = 0., unitY = 0.;
25  double angleRange = 0., vertRange = 0.;
26  double left = 0., right = 0., up = 0., down = 0.;
27  vector<DATCONHoughSpaceClusterCand> HoughSpaceClusterCandCopy;
28  vector<unsigned int> idList;
29  vector<unsigned int> mergedList;
30  TVector2 CandidateCoordinates;
31 
32  int** ArrayOfActiveHoughSpaceSectors;
33 
34  if (m_usePhase2Simulation) {
35  B2WARNING("This mode is not yet implemented, nothing will happen! Return...");
36  return;
37  } else {
38  if (uSide) {
39  angleSectors = m_nAngleSectorsU;
40  vertSectors = m_nVertSectorsU;
41  HoughSpaceClusterCandCopy = uHoughSpaceClusterCand;
42  ArrayOfActiveHoughSpaceSectors = ArrayOfActiveSectorsPhiHS;
43  minimumClusterSize = m_MinimumPhiHSClusterSize;
44  maximumClusterSize = m_MaximumPhiHSClusterSize;
45  left = -M_PI;
46  right = M_PI;
47  up = m_rectSizeU;
48  down = -m_rectSizeU;
49  } else {
50  angleSectors = m_nAngleSectorsV;
51  vertSectors = m_nVertSectorsV;
52  HoughSpaceClusterCandCopy = vHoughSpaceClusterCand;
53  ArrayOfActiveHoughSpaceSectors = ArrayOfActiveSectorsThetaHS;
54  minimumClusterSize = m_MinimumThetaHSClusterSize;
55  maximumClusterSize = m_MaximumThetaHSClusterSize;
56  left = -M_PI;
57  right = 0.;
58  up = m_rectSizeV;
59  down = -m_rectSizeV;
60  }
61  }
62 
63  angleRange = (right - left);
64  vertRange = (up - down);
65  unitX = angleRange / (double)(angleSectors);
66  unitY = vertRange / (double)(vertSectors);
67 
68  // cell content meanings:
69  // -1 : active sector, not yet visited
70  // 0 : non-active sector (will never be visited, only checked)
71  // 1,2,3...: index of the clusters
72 
73  m_clusterCount = 1;
74 
75  for (auto it = HoughSpaceClusterCandCopy.begin(); it != HoughSpaceClusterCandCopy.end(); it++) {
76  idList = it->getIdList();
77  mergedList = idList;
78  CandidateCoordinates = it->getCoord();
79  int actualPositionX = (int)CandidateCoordinates.X();
80  int actualPositionY = (int)CandidateCoordinates.Y();
81  if (ArrayOfActiveHoughSpaceSectors[actualPositionY][actualPositionX] == -1) {
82  m_clusterInitialPosition.Set((double)actualPositionX, (double)actualPositionY);
83  m_clusterCenterOfGravity.Set((double)actualPositionX, (double)actualPositionY);
84  m_clusterSize = 1;
85  DepthFirstSearch(uSide, ArrayOfActiveHoughSpaceSectors, angleSectors, vertSectors,
86  actualPositionX, actualPositionY, mergedList);
87  m_clusterCount++;
88  if (m_clusterSize >= minimumClusterSize && m_clusterSize <= maximumClusterSize) {
89  double CoGX = left + unitX * (((double)m_clusterCenterOfGravity.X() / (double)(m_clusterSize)) + 0.5);
90  double CoGY = up - unitY * (((double)m_clusterCenterOfGravity.Y() / (double)(m_clusterSize)) + 0.5);
91  if (uSide) {
92  uTrackCand.push_back(DATCONTrackCand(mergedList, TVector2(CoGX, CoGY)));
93  } else {
94  vTrackCand.push_back(DATCONTrackCand(mergedList, TVector2(CoGX, CoGY)));
95  }
96  }
97  }
98  }
99 }
100 
101 void
102 DATCONTrackingModule::DepthFirstSearch(bool uSide, int** ArrayOfActiveHoughSpaceSectors, int angleSectors, int vertSectors,
103  int actualPositionX, int actualPositionY, vector<unsigned int>& mergedList)
104 {
105  vector<unsigned int> mergeMeIDList;
106  int maximumClusterSize;
107  int maximumClusterSizeX;
108  int maximumClusterSizeY;
109  vector<DATCONHoughSpaceClusterCand> HoughSpaceClusterCandCopy;
110  TVector2 CandidateCoordinates;
111 
112  if (uSide) {
113  HoughSpaceClusterCandCopy = uHoughSpaceClusterCand;
114  maximumClusterSize = m_MaximumPhiHSClusterSize;
115  maximumClusterSizeX = m_MaximumPhiHSClusterSizeX;
116  maximumClusterSizeY = m_MaximumPhiHSClusterSizeY;
117  } else {
118  HoughSpaceClusterCandCopy = vHoughSpaceClusterCand;
119  maximumClusterSize = m_MaximumThetaHSClusterSize;
120  maximumClusterSizeX = m_MaximumThetaHSClusterSizeX;
121  maximumClusterSizeY = m_MaximumThetaHSClusterSizeY;
122  }
123 
124  ArrayOfActiveHoughSpaceSectors[actualPositionY][actualPositionX] = m_clusterCount;
125  for (int k = actualPositionY; k >= actualPositionY - 1; k--) {
126  for (int l = actualPositionX; l <= actualPositionX + 1; l++) {
127  if (k >= 0 && k < vertSectors && l >= 0 && l < angleSectors) {
128  if (ArrayOfActiveHoughSpaceSectors[k][l] == -1) {
129  for (auto it = HoughSpaceClusterCandCopy.begin(); it != HoughSpaceClusterCandCopy.end(); it++) {
130  mergeMeIDList = it->getIdList();
131  CandidateCoordinates = it->getCoord();
132  int j = (int)CandidateCoordinates.X();
133  int i = (int)CandidateCoordinates.Y();
134  if (j == l && i == k) {
135  break;
136  }
137  }
138  mergeIdList(mergedList, mergeMeIDList);
139 
140  m_clusterCenterOfGravity += TVector2(l, k);
141  m_clusterSize++;
142  if (m_clusterSize >= maximumClusterSize || abs((int)m_clusterInitialPosition.X() - actualPositionX) >= maximumClusterSizeX
143  || abs((int)m_clusterInitialPosition.Y() - actualPositionY) >= maximumClusterSizeY) {
144  return;
145  }
146  DepthFirstSearch(uSide, ArrayOfActiveHoughSpaceSectors, angleSectors, vertSectors, l, k, mergedList);
147  }
148  }
149  }
150  }
151 }
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DATCONTrackCand
The DATCONTrackCand represents the candidates of tracks found by the DATCON algoritms for u-side and ...
Definition: DATCONTrackCand.h:38