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