Belle II Software  release-08-01-10
Phi0CurvTanL.test.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <tracking/trackFindingCDC/testFixtures/TrackFindingCDCTestWithSimpleSimulation.h>
9 
10 #include <tracking/trackFindingCDC/hough/perigee/SimpleRLTaggedWireHitHoughTree.h>
11 #include <tracking/trackFindingCDC/hough/perigee/SimpleSegmentHoughTree.h>
12 #include <tracking/trackFindingCDC/hough/perigee/StandardBinSpec.h>
13 
14 #include <tracking/trackFindingCDC/hough/algorithms/InPhi0CurvTanLBox.h>
15 
16 #include <vector>
17 
18 using namespace Belle2;
19 using namespace TrackFindingCDC;
20 using namespace PerigeeBinSpec;
21 
22 namespace {
23 
24  // /// Hough tree depth and divisions
25  const int maxLevel = 13;
26 
27  // Phi0
29  const int phi0Divisions = 2;
30  const int discretePhi0Overlap = 4;
31  const int discretePhi0Width = 5;
32  const int nPhi0Bins = std::pow(phi0Divisions, maxLevel);
33  const Phi0BinsSpec phi0BinsSpec(nPhi0Bins,
34  discretePhi0Overlap,
35  discretePhi0Width);
36 
37 
38  // Curv
40  const int curvDivisions = 2;
41  const double maxCurv = 0.13;
42  const double minCurv = -0.018;
43  const double maxCurvAcceptance = 0.13;
44 
45  const int discreteCurvOverlap = 4;
46  const int discreteCurvWidth = 5;
47  const int nCurvBins = std::pow(curvDivisions, maxLevel);
48  const CurvBinsSpec curvBinsSpec(minCurv,
49  maxCurv,
50  nCurvBins,
51  discreteCurvOverlap,
52  discreteCurvWidth);
53 
54 
55  // TanL
57  const int tanLDivisions = 2;
58  const double maxTanL = 3.27;
59  const double minTanL = -1.73;
60 
61  const int discreteTanLOverlap = 1;
62  const int discreteTanLWidth = 2;
63  const int nTanLBins = std::pow(tanLDivisions, maxLevel);
64  ImpactBinsSpec tanLBinsSpec(minTanL,
65  maxTanL,
66  nTanLBins,
67  discreteTanLOverlap,
68  discreteTanLWidth);
69 
70  const double curlCurv = 0.018;
71 
72  // cppcheck-suppress syntaxError
73  TEST_F(TrackFindingCDCTestWithSimpleSimulation, hough_perigee_phi0_curv_tanl_hits)
74  {
75  std::string svgFileName = "phi0_curv_tanl_hits.svg";
76 
77  Helix lowerCurvOriginHelix(0.015, 2.52033, 0, 1, 0);
78  Helix higherCurvOriginHelix(0.020, 3.0718, 0, -0.2, 0);
79 
80  // Helix lowerCurvOriginHelix(0.012, 1.4, 0, 1, 0);
81  // Helix higherCurvOriginHelix(0.027, 3.0718, 0, 0.95, 0);
82 
83  simulate({lowerCurvOriginHelix, higherCurvOriginHelix});
84  saveDisplay(svgFileName);
85 
86  using SimpleRLTaggedWireHitPhi0CurvHough =
88  SimpleRLTaggedWireHitPhi0CurvHough houghTree(maxLevel, curlCurv);
89  using HoughBox = SimpleRLTaggedWireHitPhi0CurvHough::HoughBox;
90 
91  const double minWeight = 50.0;
92 
93  houghTree.assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
94  // houghTree.assignArray<DiscreteCurv>(curvBinsSpec.constructArray(),
95  // curvBinsSpec.getNOverlap());
96  houghTree.assignArray<DiscreteCurvWithArcLength2DCache>(curvBinsSpec.constructCacheArray(),
97  curvBinsSpec.getNOverlap());
98 
99  houghTree.assignArray<ContinuousTanL>({{minTanL, maxTanL}}, tanLBinsSpec.getOverlap());
100  //houghTree.assignArray<ContinuousTanL>({{0.0, 0.0}}, 0.0);
101  houghTree.initialize();
102 
103  // Execute the finding a couple of time to find a stable execution time.
104  std::vector< std::pair<HoughBox, std::vector<CDCRLWireHit> > > candidates;
105 
106  // Is this still C++? Looks like JavaScript to me :-).
107  TimeItResult timeItResult = timeIt(1, true, [&]() {
108  houghTree.fell();
109  //houghTree.seed(m_axialWireHits);
110  houghTree.seed(m_wireHits);
111 
112  // candidates = houghTree.find(minWeight, maxCurvAcceptance);
113  candidates = houghTree.findBest(minWeight, maxCurvAcceptance);
114 
115  ASSERT_EQ(m_mcTracks.size(), candidates.size());
116  // Check for the parameters of the track candidates
117  // The actual hit numbers are more than 30, but this is somewhat a lower bound
118  for (size_t iCand = 0; iCand < candidates.size(); ++iCand) {
119  EXPECT_GE(candidates[iCand].second.size(), 30);
120  }
121  });
122 
124  std::size_t nNodes = houghTree.getTree()->getNNodes();
125  B2DEBUG(100, "Tree generated " << nNodes << " nodes");
126  houghTree.fell();
127  houghTree.raze();
128 
129  int iColor = 0;
130  for (std::pair<HoughBox, std::vector<CDCRLWireHit> >& candidate : candidates) {
131  const HoughBox& houghBox = candidate.first;
132  const std::vector<CDCRLWireHit>& taggedHits = candidate.second;
133 
134  B2DEBUG(100, "Candidate");
135  B2DEBUG(100, "size " << taggedHits.size());
136 
137  B2DEBUG(100, "Lower Phi0 " << houghBox.getLowerBound<DiscretePhi0>()->phi());
138  B2DEBUG(100, "Upper Phi0 " << houghBox.getUpperBound<DiscretePhi0>()->phi());
139  B2DEBUG(100, "Lower Curv " << houghBox.getLowerBound<DiscreteCurvWithArcLength2DCache>());
140  B2DEBUG(100, "Upper Curv " << houghBox.getUpperBound<DiscreteCurvWithArcLength2DCache>());
141  B2DEBUG(100, "Lower TanL " << houghBox.getLowerBound<ContinuousTanL>());
142  B2DEBUG(100, "Upper TanL " << houghBox.getUpperBound<ContinuousTanL>());
143  B2DEBUG(100, "Tags of the hits");
144  for (const CDCRLWireHit& rlTaggedWireHit : taggedHits) {
145  B2DEBUG(100, " " <<
146  "rl = " << static_cast<int>(rlTaggedWireHit.getRLInfo()) << " " <<
147  "dl = " << rlTaggedWireHit.getRefDriftLength());
148  }
149 
150  for (const CDCRLWireHit& rlTaggedWireHit : taggedHits) {
151  const CDCWireHit& wireHit = rlTaggedWireHit.getWireHit();
152  std::string color = "blue";
153  if (rlTaggedWireHit.getRLInfo() == ERightLeft::c_Right) {
154  color = "green";
155  } else if (rlTaggedWireHit.getRLInfo() == ERightLeft::c_Left) {
156  color = "red";
157  }
158  //EventDataPlotter::AttributeMap strokeAttr {{"stroke", color}};
159  EventDataPlotter::AttributeMap strokeAttr {{"stroke", m_colors[iColor % m_colors.size()] }};
160  draw(wireHit, strokeAttr);
161  }
162  ++iColor;
163  }
164 
165  saveDisplay(svgFileName);
166 
167  timeItResult.printSummary();
168  }
169 
170  TEST_F(TrackFindingCDCTestWithSimpleSimulation, hough_perigee_phi0_curv_tanl_segments)
171  {
172  std::string svgFileName = "phi0_curv_tanl_segments.svg";
173 
174  Helix lowerCurvOriginHelix(0.015, 2.52033, 0, 1, 0);
175  Helix higherCurvOriginHelix(0.020, 3.0718, 0, -0.2, 0);
176 
177  simulate({lowerCurvOriginHelix, higherCurvOriginHelix});
178  saveDisplay(svgFileName);
179 
180  using SimpleSegmentPhi0CurvHoughTree =
182  SimpleSegmentPhi0CurvHoughTree houghTree(maxLevel, curlCurv);
183  using HoughBox = SimpleSegmentPhi0CurvHoughTree::HoughBox;
184 
185  const double minWeight = 50.0;
186 
187  houghTree.assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
188  houghTree.assignArray<DiscreteCurvWithArcLength2DCache>(curvBinsSpec.constructCacheArray(),
189  curvBinsSpec.getNOverlap());
190 
191  houghTree.assignArray<ContinuousTanL>({{minTanL, maxTanL}}, tanLBinsSpec.getOverlap());
192  houghTree.initialize();
193 
194  // Obtain the segments as pointers.
195  std::vector<const CDCSegment2D*> m_ptrSegment2Ds;
196  m_ptrSegment2Ds.reserve(m_mcSegment2Ds.size());
197  for (const CDCSegment2D& segment2D : m_mcSegment2Ds) {
198  m_ptrSegment2Ds.push_back(&segment2D);
199  }
200 
201  // Execute the finding a couple of time to find a stable execution time.
202  std::vector< std::pair<HoughBox, std::vector<const CDCSegment2D*> > > candidates;
203 
204  // Is this still C++? Looks like JavaScript to me :-).
205  TimeItResult timeItResult = timeIt(1, true, [&]() {
206  // Exclude the timing of the resource release for comparision with the legendre test.
207  houghTree.fell();
208  houghTree.seed(m_ptrSegment2Ds);
209 
210  //candidates = houghTree.find(minWeight, maxCurvAcceptance);
211  candidates = houghTree.findBest(minWeight, maxCurvAcceptance);
212 
213  ASSERT_EQ(m_mcTracks.size(), candidates.size());
214 
215  // Check for the parameters of the track candidates
216  // The actual hit numbers are more than 4 segment, but this is somewhat a lower bound
217  for (size_t iCand = 0; iCand < candidates.size(); ++iCand) {
218  EXPECT_GE(candidates[iCand].second.size(), 4);
219  }
220  });
221 
223  int nNodes = houghTree.getTree()->getNNodes();
224  B2INFO("Tree generated " << nNodes << " nodes");
225  houghTree.fell();
226  houghTree.raze();
227 
228  int iColor = 0;
229  for (std::pair<HoughBox, std::vector<const CDCSegment2D*> >& candidate : candidates) {
230  const HoughBox& houghBox = candidate.first;
231  const std::vector<const CDCSegment2D*>& segments = candidate.second;
232 
233  B2DEBUG(100, "Candidate");
234  B2DEBUG(100, "size " << segments.size());
235  B2DEBUG(100, "Lower Phi0 " << houghBox.getLowerBound<DiscretePhi0>()->phi());
236  B2DEBUG(100, "Upper Phi0 " << houghBox.getUpperBound<DiscretePhi0>()->phi());
237  B2DEBUG(100, "Lower Curv " << houghBox.getLowerBound<DiscreteCurvWithArcLength2DCache>());
238  B2DEBUG(100, "Upper Curv " << houghBox.getUpperBound<DiscreteCurvWithArcLength2DCache>());
239  B2DEBUG(100, "Lower TanL " << houghBox.getLowerBound<ContinuousTanL>());
240  B2DEBUG(100, "Upper TanL " << houghBox.getUpperBound<ContinuousTanL>());
241  for (const CDCSegment2D* segment2D : segments) {
242  EventDataPlotter::AttributeMap strokeAttr {{"stroke", m_colors[iColor % m_colors.size()] }};
243  draw(*segment2D, strokeAttr);
244  }
245  ++iColor;
246  }
247  saveDisplay(svgFileName);
248  timeItResult.printSummary();
249  }
250 }
Helix parameter class.
Definition: Helix.h:48
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Definition: CDCRLWireHit.h:41
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:39
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55
Type to have values not based on discrete positions from an array.
Strategy to construct discrete curv points from discrete overlap specifications.
Definition: CurvRep.h:23
DiscreteCurvWithArcLength2DCache::Array constructCacheArray() const
Constuct the array of discrete curv positions including cache for the two dimensional arc length.
Definition: CurvRep.cc:76
int getNOverlap() const
Getter for the overlap in discrete number of positions.
Definition: CurvRep.h:68
Representation for a discrete position in an array of discrete positions.
Definition: DiscreteValue.h:23
PrimitivePlotter::AttributeMap AttributeMap
Forward the Attributre map from the primitive plotter.
Strategy to construct discrete impact points from discrete overlap specifications.
Definition: ImpactRep.h:19
Strategy to construct discrete phi0 points from discrete overlap specifications.
Definition: Phi0Rep.h:20
DiscretePhi0::Array constructArray() const
Constuct the array of discrete phi0 positions.
Definition: Phi0Rep.cc:23
int getNOverlap() const
Getter for the overlap in discrete number of positions.
Definition: Phi0Rep.h:47
A convenience class based on a BoxDivisionHoughTree for "hit-like" classes.
Class to capture the time a repeated execution took.
Definition: TimeIt.h:29
void printSummary() const
Print a summary of the collected time to the console.
Definition: TimeIt.h:57
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
Definition: globalLabel.cc:72
Abstract base class for different kinds of events.