Belle II Software  release-05-01-25
Phi0TanL.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 
15 #include <tracking/trackFindingCDC/hough/algorithms/InPhi0TanLBox.h>
16 
17 #include <tracking/trackFindingCDC/hough/perigee/Phi0Rep.h>
18 #include <tracking/trackFindingCDC/hough/axes/StandardAxes.h>
19 #include <tracking/trackFindingCDC/hough/perigee/ImpactRep.h>
20 
21 #include <vector>
22 
23 using namespace Belle2;
24 using namespace TrackFindingCDC;
25 
26 namespace {
27  // const int maxLevel = 7;
28  // const int phi0Divisions = 7;
29  // const int tanLDivisions = 3;
30 
31  // const int maxLevel = 5;
32  // const int phi0Divisions = 7;
33  // const int tanLDivisions = 6;
34 
35  // const int maxLevel = 9;
36  // const int phi0Divisions = 3;
37  // const int tanLDivisions = 2;
38 
39 
40  // const int maxLevel = 13;
41  // const int phi0Divisions = 2;
42  // const int tanLDivisions = 2;
43 
44  // const int maxLevel = 8;
45  // const int phi0Divisions = 3;
46  // const int tanLDivisions = 3;
47 
48  // const int maxLevel = 7;
49  // const int phi0Divisions = 4;
50  // const int tanLDivisions = 3;
51 
52  // const int discretePhi0Overlap = 4;
53  // const int discretePhi0Width = 5;
54 
55  const int maxLevel = 13;
56  const int phi0Divisions = 2;
57  const int tanLDivisions = 2;
58 
59  const int discretePhi0Overlap = 4;
60  const int discretePhi0Width = 5;
61 
62  const int nPhi0Bins = std::pow(phi0Divisions, maxLevel);
63  Phi0BinsSpec phi0BinsSpec(nPhi0Bins,
64  discretePhi0Overlap,
65  discretePhi0Width);
66 
67  const double maxTanL = 3.27;
68  const double minTanL = -1.73;
69 
70  const int discreteTanLOverlap = 1;
71  const int discreteTanLWidth = 2;
72  const int nTanLBins = std::pow(tanLDivisions, maxLevel);
73  ImpactBinsSpec tanLBinsSpec(minTanL,
74  maxTanL,
75  nTanLBins,
76  discreteTanLOverlap,
77  discreteTanLWidth);
78 
79  const double curlCurv = 0.018;
80 
81 
82  TEST_F(TrackFindingCDCTestWithSimpleSimulation, hough_perigee_phi0_tanl_on_hits)
83  {
84  std::string svgFileName = "phi0_tanl_on_hits.svg";
85 
86  Helix originLine0(0.0, -1.0, 0, 0.2, 0);
87  Helix originLine1(0.0, 1.0, 0, -0.5, 0);
88 
89  simulate({originLine0, originLine1});
90  saveDisplay(svgFileName);
91 
92  using SimpleRLTaggedWireHitPhi0TanLHoughTree =
93  SimpleRLTaggedWireHitHoughTree< InPhi0TanLBox, phi0Divisions, tanLDivisions>;
94 
95  SimpleRLTaggedWireHitPhi0TanLHoughTree houghTree(maxLevel, 0.018);
96  using HoughBox = SimpleRLTaggedWireHitPhi0TanLHoughTree::HoughBox;
97 
98  houghTree.assignArray<ContinuousTanL>({{minTanL, maxTanL}}, tanLBinsSpec.getOverlap());
99  houghTree.assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
100 
101  houghTree.initialize();
102 
103  std::vector<CDCRLWireHit> mcTaggedWireHits;
104  for (const CDCTrack& mcTrack : m_mcTracks) {
105  for (const CDCRecoHit3D& recoHit3D : mcTrack) {
106  const CDCWireHit& wireHit = recoHit3D.getWireHit();
107  mcTaggedWireHits.emplace_back(&wireHit);
108  mcTaggedWireHits.back().setRLInfo(recoHit3D.getRLInfo());
109  }
110  }
111 
112  // Execute the finding a couple of time to find a stable execution time.
113  std::vector< std::pair<HoughBox, std::vector<CDCRLWireHit> > > candidates;
114 
115  // Is this still C++? Looks like JavaScript to me :-).
116  TimeItResult timeItResult = timeIt(100, true, [&]() {
117  houghTree.fell();
118 
119  //houghTree.seed(m_wireHits);
120  houghTree.seed(mcTaggedWireHits);
121 
122  const double minWeight = 50.0;
123  // candidates = houghTree.find(minWeight);
124  candidates = houghTree.findBest(minWeight);
125 
126  ASSERT_EQ(m_mcTracks.size(), candidates.size());
127  // Check for the parameters of the track candidates
128  // The actual hit numbers are more than 30, but this is somewhat a lower bound
129  for (size_t iCand = 0; iCand < candidates.size(); ++iCand) {
130  EXPECT_GE(candidates[iCand].second.size(), 30);
131  }
132  });
133 
134  std::size_t nNodes = houghTree.getTree()->getNNodes();
135  B2INFO("Tree generated " << nNodes << " nodes");
136  houghTree.fell();
137  houghTree.raze();
138 
139 
140  int iColor = 0;
141  for (std::pair<HoughBox, std::vector<CDCRLWireHit> >& candidate : candidates) {
142  const HoughBox& houghBox = candidate.first;
143  const std::vector<CDCRLWireHit>& taggedHits = candidate.second;
144 
145  B2DEBUG(100, "Candidate");
146  B2DEBUG(100, "size " << taggedHits.size());
147  B2DEBUG(100, "Lower Phi0 " << houghBox.getLowerBound<DiscretePhi0>()->phi());
148  B2DEBUG(100, "Upper Phi0 " << houghBox.getUpperBound<DiscretePhi0>()->phi());
149  B2DEBUG(100, "Lower TanL " << houghBox.getLowerBound<ContinuousTanL>());
150  B2DEBUG(100, "Upper TanL " << houghBox.getUpperBound<ContinuousTanL>());
151 
152 
153  B2DEBUG(100, "Tags of the hits");
154  for (const CDCRLWireHit& rlTaggedWireHit : taggedHits) {
155  B2DEBUG(100, " " <<
156  "rl = " << static_cast<int>(rlTaggedWireHit.getRLInfo()) << " " <<
157  "dl = " << rlTaggedWireHit.getRefDriftLength());
158  }
159 
160  for (const CDCRLWireHit& rlTaggedWireHit : taggedHits) {
161  const CDCWireHit& wireHit = rlTaggedWireHit.getWireHit();
162  std::string color = "blue";
163  if (rlTaggedWireHit.getRLInfo() == ERightLeft::c_Right) {
164  color = "green";
165  } else if (rlTaggedWireHit.getRLInfo() == ERightLeft::c_Left) {
166  color = "red";
167  }
168  //EventDataPlotter::AttributeMap strokeAttr {{"stroke", color}};
169  EventDataPlotter::AttributeMap strokeAttr {{"stroke", m_colors[iColor % m_colors.size()] }};
170  draw(wireHit, strokeAttr);
171  }
172  ++iColor;
173  }
174  saveDisplay(svgFileName);
175 
176  timeItResult.printSummary();
177  }
178 
179  TEST_F(TrackFindingCDCTestWithSimpleSimulation, hough_perigee_phi0_tanl_on_segments)
180  {
181  std::string svgFileName = "phi0_tanl_on_segments.svg";
182 
183  Helix originLine0(0.0, -1.0, 0, 0.2, 0);
184  Helix originLine1(0.0, 1.0, 0, -0.5, 0);
185 
186  simulate({originLine0, originLine1});
187  saveDisplay(svgFileName);
188 
189  using SimpleSegmentPhi0TanLHoughTree =
190  SimpleSegmentHoughTree<InPhi0TanLBox, phi0Divisions, tanLDivisions>;
191 
192  SimpleSegmentPhi0TanLHoughTree houghTree(maxLevel, curlCurv);
193  using HoughBox = SimpleSegmentPhi0TanLHoughTree::HoughBox;
194 
195  houghTree.assignArray<ContinuousTanL>({{minTanL, maxTanL}}, tanLBinsSpec.getOverlap());
196  houghTree.assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
197 
198  houghTree.initialize();
199 
200  // Obtain the segments as pointers.
201  std::vector<const CDCSegment2D*> m_ptrSegment2Ds;
202  m_ptrSegment2Ds.reserve(m_mcSegment2Ds.size());
203  for (const CDCSegment2D& segment2D : m_mcSegment2Ds) {
204  m_ptrSegment2Ds.push_back(&segment2D);
205  }
206 
207  // Execute the finding a couple of time to find a stable execution time.
208  std::vector< std::pair<HoughBox, std::vector<const CDCSegment2D*> > > candidates;
209 
210  // Is this still C++? Looks like JavaScript to me :-).
211  TimeItResult timeItResult = timeIt(100, true, [&]() {
212  // Exclude the timing of the resource release for comparision with the legendre test.
213  houghTree.fell();
214  houghTree.seed(m_ptrSegment2Ds);
215 
216  const double minWeight = 50.0;
217  // candidates = houghTree.find(minWeight);
218  candidates = houghTree.findBest(minWeight);
219 
220  ASSERT_EQ(m_mcTracks.size(), candidates.size());
221 
222  // Check for the parameters of the track candidates
223  // The actual hit numbers are more than 4 segment, but this is somewhat a lower bound
224  for (size_t iCand = 0; iCand < candidates.size(); ++iCand) {
225  EXPECT_GE(candidates[iCand].second.size(), 7);
226  }
227  });
228 
230  std::size_t nNodes = houghTree.getTree()->getNNodes();
231  B2INFO("Tree generated " << nNodes << " nodes");
232  houghTree.fell();
233  houghTree.raze();
234 
235  int iColor = 0;
236  for (std::pair<HoughBox, std::vector<const CDCSegment2D*> >& candidate : candidates) {
237  const HoughBox& houghBox = candidate.first;
238  const std::vector<const CDCSegment2D*>& segments = candidate.second;
239 
240  B2DEBUG(100, "Candidate");
241  B2DEBUG(100, "size " << segments.size());
242  B2DEBUG(100, "Lower Phi0 " << houghBox.getLowerBound<DiscretePhi0>()->phi());
243  B2DEBUG(100, "Upper Phi0 " << houghBox.getUpperBound<DiscretePhi0>()->phi());
244  B2DEBUG(100, "Lower TanL " << houghBox.getLowerBound<ContinuousTanL>());
245  B2DEBUG(100, "Upper TanL " << houghBox.getUpperBound<ContinuousTanL>());
246 
247  for (const CDCSegment2D* segment2D : segments) {
248  EventDataPlotter::AttributeMap strokeAttr {{"stroke", m_colors[iColor % m_colors.size()] }};
249  draw(*segment2D, strokeAttr);
250  }
251  ++iColor;
252  }
253  saveDisplay(svgFileName);
254  timeItResult.printSummary();
255  }
256 }
Belle2::TrackFindingCDC::Phi0BinsSpec::getNOverlap
int getNOverlap() const
Getter for the overlap in discrete number of positions.
Definition: Phi0Rep.h:57
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