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