Belle II Software  release-06-02-00
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  TEST_F(TrackFindingCDCTestWithSimpleSimulation, hough_perigee_phi0_curv_tanl_hits)
73  {
74  std::string svgFileName = "phi0_curv_tanl_hits.svg";
75 
76  Helix lowerCurvOriginHelix(0.015, 2.52033, 0, 1, 0);
77  Helix higherCurvOriginHelix(0.020, 3.0718, 0, -0.2, 0);
78 
79  // Helix lowerCurvOriginHelix(0.012, 1.4, 0, 1, 0);
80  // Helix higherCurvOriginHelix(0.027, 3.0718, 0, 0.95, 0);
81 
82  simulate({lowerCurvOriginHelix, higherCurvOriginHelix});
83  saveDisplay(svgFileName);
84 
85  using SimpleRLTaggedWireHitPhi0CurvHough =
87  SimpleRLTaggedWireHitPhi0CurvHough houghTree(maxLevel, curlCurv);
88  using HoughBox = SimpleRLTaggedWireHitPhi0CurvHough::HoughBox;
89 
90  const double minWeight = 50.0;
91 
92  houghTree.assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
93  // houghTree.assignArray<DiscreteCurv>(curvBinsSpec.constructArray(),
94  // curvBinsSpec.getNOverlap());
95  houghTree.assignArray<DiscreteCurvWithArcLength2DCache>(curvBinsSpec.constructCacheArray(),
96  curvBinsSpec.getNOverlap());
97 
98  houghTree.assignArray<ContinuousTanL>({{minTanL, maxTanL}}, tanLBinsSpec.getOverlap());
99  //houghTree.assignArray<ContinuousTanL>({{0.0, 0.0}}, 0.0);
100  houghTree.initialize();
101 
102  // Execute the finding a couple of time to find a stable execution time.
103  std::vector< std::pair<HoughBox, std::vector<CDCRLWireHit> > > candidates;
104 
105  // Is this still C++? Looks like JavaScript to me :-).
106  TimeItResult timeItResult = timeIt(1, true, [&]() {
107  houghTree.fell();
108  //houghTree.seed(m_axialWireHits);
109  houghTree.seed(m_wireHits);
110 
111  // candidates = houghTree.find(minWeight, maxCurvAcceptance);
112  candidates = houghTree.findBest(minWeight, maxCurvAcceptance);
113 
114  ASSERT_EQ(m_mcTracks.size(), candidates.size());
115  // Check for the parameters of the track candidates
116  // The actual hit numbers are more than 30, but this is somewhat a lower bound
117  for (size_t iCand = 0; iCand < candidates.size(); ++iCand) {
118  EXPECT_GE(candidates[iCand].second.size(), 30);
119  }
120  });
121 
123  std::size_t nNodes = houghTree.getTree()->getNNodes();
124  B2DEBUG(100, "Tree generated " << nNodes << " nodes");
125  houghTree.fell();
126  houghTree.raze();
127 
128  int iColor = 0;
129  for (std::pair<HoughBox, std::vector<CDCRLWireHit> >& candidate : candidates) {
130  const HoughBox& houghBox = candidate.first;
131  const std::vector<CDCRLWireHit>& taggedHits = candidate.second;
132 
133  B2DEBUG(100, "Candidate");
134  B2DEBUG(100, "size " << taggedHits.size());
135 
136  B2DEBUG(100, "Lower Phi0 " << houghBox.getLowerBound<DiscretePhi0>()->phi());
137  B2DEBUG(100, "Upper Phi0 " << houghBox.getUpperBound<DiscretePhi0>()->phi());
138  B2DEBUG(100, "Lower Curv " << houghBox.getLowerBound<DiscreteCurvWithArcLength2DCache>());
139  B2DEBUG(100, "Upper Curv " << houghBox.getUpperBound<DiscreteCurvWithArcLength2DCache>());
140  B2DEBUG(100, "Lower TanL " << houghBox.getLowerBound<ContinuousTanL>());
141  B2DEBUG(100, "Upper TanL " << houghBox.getUpperBound<ContinuousTanL>());
142  B2DEBUG(100, "Tags of the hits");
143  for (const CDCRLWireHit& rlTaggedWireHit : taggedHits) {
144  B2DEBUG(100, " " <<
145  "rl = " << static_cast<int>(rlTaggedWireHit.getRLInfo()) << " " <<
146  "dl = " << rlTaggedWireHit.getRefDriftLength());
147  }
148 
149  for (const CDCRLWireHit& rlTaggedWireHit : taggedHits) {
150  const CDCWireHit& wireHit = rlTaggedWireHit.getWireHit();
151  std::string color = "blue";
152  if (rlTaggedWireHit.getRLInfo() == ERightLeft::c_Right) {
153  color = "green";
154  } else if (rlTaggedWireHit.getRLInfo() == ERightLeft::c_Left) {
155  color = "red";
156  }
157  //EventDataPlotter::AttributeMap strokeAttr {{"stroke", color}};
158  EventDataPlotter::AttributeMap strokeAttr {{"stroke", m_colors[iColor % m_colors.size()] }};
159  draw(wireHit, strokeAttr);
160  }
161  ++iColor;
162  }
163 
164  saveDisplay(svgFileName);
165 
166  timeItResult.printSummary();
167  }
168 
169  TEST_F(TrackFindingCDCTestWithSimpleSimulation, hough_perigee_phi0_curv_tanl_segments)
170  {
171  std::string svgFileName = "phi0_curv_tanl_segments.svg";
172 
173  Helix lowerCurvOriginHelix(0.015, 2.52033, 0, 1, 0);
174  Helix higherCurvOriginHelix(0.020, 3.0718, 0, -0.2, 0);
175 
176  simulate({lowerCurvOriginHelix, higherCurvOriginHelix});
177  saveDisplay(svgFileName);
178 
179  using SimpleSegmentPhi0CurvHoughTree =
181  SimpleSegmentPhi0CurvHoughTree houghTree(maxLevel, curlCurv);
182  using HoughBox = SimpleSegmentPhi0CurvHoughTree::HoughBox;
183 
184  const double minWeight = 50.0;
185 
186  houghTree.assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
187  houghTree.assignArray<DiscreteCurvWithArcLength2DCache>(curvBinsSpec.constructCacheArray(),
188  curvBinsSpec.getNOverlap());
189 
190  houghTree.assignArray<ContinuousTanL>({{minTanL, maxTanL}}, tanLBinsSpec.getOverlap());
191  houghTree.initialize();
192 
193  // Obtain the segments as pointers.
194  std::vector<const CDCSegment2D*> m_ptrSegment2Ds;
195  m_ptrSegment2Ds.reserve(m_mcSegment2Ds.size());
196  for (const CDCSegment2D& segment2D : m_mcSegment2Ds) {
197  m_ptrSegment2Ds.push_back(&segment2D);
198  }
199 
200  // Execute the finding a couple of time to find a stable execution time.
201  std::vector< std::pair<HoughBox, std::vector<const CDCSegment2D*> > > candidates;
202 
203  // Is this still C++? Looks like JavaScript to me :-).
204  TimeItResult timeItResult = timeIt(1, true, [&]() {
205  // Exclude the timing of the resource release for comparision with the legendre test.
206  houghTree.fell();
207  houghTree.seed(m_ptrSegment2Ds);
208 
209  //candidates = houghTree.find(minWeight, maxCurvAcceptance);
210  candidates = houghTree.findBest(minWeight, maxCurvAcceptance);
211 
212  ASSERT_EQ(m_mcTracks.size(), candidates.size());
213 
214  // Check for the parameters of the track candidates
215  // The actual hit numbers are more than 4 segment, but this is somewhat a lower bound
216  for (size_t iCand = 0; iCand < candidates.size(); ++iCand) {
217  EXPECT_GE(candidates[iCand].second.size(), 4);
218  }
219  });
220 
222  int nNodes = houghTree.getTree()->getNNodes();
223  B2INFO("Tree generated " << nNodes << " nodes");
224  houghTree.fell();
225  houghTree.raze();
226 
227  int iColor = 0;
228  for (std::pair<HoughBox, std::vector<const CDCSegment2D*> >& candidate : candidates) {
229  const HoughBox& houghBox = candidate.first;
230  const std::vector<const CDCSegment2D*>& segments = candidate.second;
231 
232  B2DEBUG(100, "Candidate");
233  B2DEBUG(100, "size " << segments.size());
234  B2DEBUG(100, "Lower Phi0 " << houghBox.getLowerBound<DiscretePhi0>()->phi());
235  B2DEBUG(100, "Upper Phi0 " << houghBox.getUpperBound<DiscretePhi0>()->phi());
236  B2DEBUG(100, "Lower Curv " << houghBox.getLowerBound<DiscreteCurvWithArcLength2DCache>());
237  B2DEBUG(100, "Upper Curv " << houghBox.getUpperBound<DiscreteCurvWithArcLength2DCache>());
238  B2DEBUG(100, "Lower TanL " << houghBox.getLowerBound<ContinuousTanL>());
239  B2DEBUG(100, "Upper TanL " << houghBox.getUpperBound<ContinuousTanL>());
240  for (const CDCSegment2D* segment2D : segments) {
241  EventDataPlotter::AttributeMap strokeAttr {{"stroke", m_colors[iColor % m_colors.size()] }};
242  draw(*segment2D, strokeAttr);
243  }
244  ++iColor;
245  }
246  saveDisplay(svgFileName);
247  timeItResult.printSummary();
248  }
249 }
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.