Belle II Software  release-05-01-25
Phi0ImpactCurv.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/InPhi0ImpactCurvBox.h>
17 
18 #include <vector>
19 
20 using namespace Belle2;
21 using namespace TrackFindingCDC;
22 using namespace PerigeeBinSpec;
23 
24 namespace {
25 
26  TEST_F(TrackFindingCDCTestWithSimpleSimulation, hough_perigee_SimpleHitBasedHough_phi0_impact_curv_onHits)
27  {
28  std::string svgFileName = "phi0_impact_curv_on_hits.svg";
29 
30  Helix lowerCurvHelix(0.015, 2.52033, -20, 0, 0);
31  Helix higherCurvHelix(0.027, 3.0718, 20, 0, 0);
32 
33  // Helix lowerCurvHelix(0.015, 2.52033, 0, 0, 0);
34  // Helix higherCurvHelix(0.027, 3.0718, 0, 0, 0);
35 
36 
37  simulate({lowerCurvHelix, higherCurvHelix});
38  saveDisplay(svgFileName);
39 
40  using SimpleWireHitPhi0ImpactCurvHoughTree =
41  SimpleRLTaggedWireHitHoughTree<InPhi0ImpactCurvBox, phi0Divisions, impactDivisions, curvDivisions>;
42 
43  SimpleWireHitPhi0ImpactCurvHoughTree houghTree(maxLevel, curlCurv);
44  using HoughBox = SimpleWireHitPhi0ImpactCurvHoughTree::HoughBox;
45 
46  const double minWeight = 70.0;
47 
48  houghTree.assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
49  //houghTree.assignArray<DiscreteImpact>(impactBinsSpec.constructArray(), impactBinsSpec.getNOverlap()); // Discrete
50  houghTree.assignArray<ContinuousImpact>({{minImpact, maxImpact}}, impactBinsSpec.getOverlap()); // Continuous
51  houghTree.assignArray<DiscreteCurv>(curvBinsSpec.constructArray(), curvBinsSpec.getNOverlap());
52  houghTree.initialize();
53 
54  // Execute the finding a couple of time to find a stable execution time.
55  std::vector< std::pair<HoughBox, std::vector<CDCRLWireHit> > > candidates;
56 
57  // Is this still C++? Looks like JavaScript to me :-).
58  TimeItResult timeItResult = timeIt(100, true, [&]() {
59  houghTree.fell();
60  houghTree.seed(m_axialWireHits);
61 
62  candidates = houghTree.find(minWeight, maxCurvAcceptance);
63  // candidates = houghTree.findBest(minWeight, maxCurvAcceptance);
64 
65  ASSERT_EQ(m_mcTracks.size(), candidates.size());
66  // Check for the parameters of the track candidates
67  // The actual hit numbers are more than 30, but this is somewhat a lower bound
68  for (size_t iCand = 0; iCand < candidates.size(); ++iCand) {
69  EXPECT_GE(candidates[iCand].second.size(), 30);
70  }
71  });
72 
73  std::size_t nNodes = houghTree.getTree()->getNNodes();
74  B2INFO("Tree generated " << nNodes << " nodes");
75  houghTree.fell();
76  houghTree.raze();
77 
78 
79  size_t iColor = 0;
80  for (std::pair<HoughBox, std::vector<CDCRLWireHit> >& candidate : candidates) {
81  const HoughBox& houghBox = candidate.first;
82  const std::vector<CDCRLWireHit>& taggedHits = candidate.second;
83 
84  B2DEBUG(100, "Candidate");
85  B2DEBUG(100, "size " << taggedHits.size());
86  B2DEBUG(100, "Phi0 " << houghBox.getLowerBound<DiscretePhi0>()->phi());
87  B2DEBUG(100, "Curv " << houghBox.getLowerBound<DiscreteCurv>());
88  B2DEBUG(100, "Impact " << houghBox.getLowerBound<ContinuousImpact>());
89 
90  B2DEBUG(100, "Tags of the hits");
91  for (const CDCRLWireHit& rlTaggedWireHit : taggedHits) {
92  B2DEBUG(100, " " <<
93  "rl = " << static_cast<int>(rlTaggedWireHit.getRLInfo()) << " " <<
94  "dl = " << rlTaggedWireHit.getRefDriftLength());
95  }
96 
97  for (const CDCRLWireHit& rlTaggedWireHit : taggedHits) {
98  const CDCWireHit& wireHit = rlTaggedWireHit.getWireHit();
99  std::string color = "blue";
100  if (rlTaggedWireHit.getRLInfo() == ERightLeft::c_Right) {
101  color = "green";
102  } else if (rlTaggedWireHit.getRLInfo() == ERightLeft::c_Left) {
103  color = "red";
104  }
105  //EventDataPlotter::AttributeMap strokeAttr {{"stroke", color}};
106  EventDataPlotter::AttributeMap strokeAttr {{"stroke", m_colors[iColor % m_colors.size()] }};
107  draw(wireHit, strokeAttr);
108  }
109  ++iColor;
110  }
111  saveDisplay(svgFileName);
112 
113  timeItResult.printSummary();
114  }
115 }
116 
117 namespace {
118  TEST_F(TrackFindingCDCTestWithSimpleSimulation, hough_perigee_SimpleHitBasedHough_phi0_impact_curv_onSegment)
119  {
120  std::string svgFileName = "phi0_impact_curv_on_segments.svg";
121 
122  Helix lowerCurvHelix(0.015, 2.52033, -20, 0, 0);
123  Helix higherCurvHelix(0.027, 3.0718, 20, 0, 0);
124 
125  simulate({lowerCurvHelix, higherCurvHelix});
126  saveDisplay(svgFileName);
127 
128  using SimpleSegmentPhi0ImpactCurvHoughTree =
129  SimpleSegmentHoughTree<InPhi0ImpactCurvBox, phi0Divisions, impactDivisions, curvDivisions>;
130 
131  SimpleSegmentPhi0ImpactCurvHoughTree houghTree(maxLevel, curlCurv);
132  using HoughBox = SimpleSegmentPhi0ImpactCurvHoughTree::HoughBox;
133 
134  const double minWeight = 70.0;
135 
136  houghTree.assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
137  //houghTree.assignArray<DiscreteImpact>(impactBinsSpec.constructArray(), impactBinsSpec.getNOverlap()); // Discrete
138  houghTree.assignArray<ContinuousImpact>({{minImpact, maxImpact}}, impactBinsSpec.getOverlap()); // Continuous
139  houghTree.assignArray<DiscreteCurv>(curvBinsSpec.constructArray(), curvBinsSpec.getNOverlap());
140  houghTree.initialize();
141 
142  // Execute the finding a couple of time to find a stable execution time.
143  std::vector< std::pair<HoughBox, std::vector<const CDCSegment2D*> > > candidates;
144 
145  // Is this still C++? Looks like JavaScript to me :-).
146  TimeItResult timeItResult = timeIt(100, true, [&]() {
147  // Exclude the timing of the resource release for comparision with the legendre test.
148  houghTree.fell();
149 
150  houghTree.seed(m_mcAxialSegment2Ds);
151 
152  candidates = houghTree.find(minWeight, maxCurvAcceptance);
153  // candidates = houghTree.findBest(minWeight, maxCurvAcceptance);
154 
155  ASSERT_EQ(m_mcTracks.size(), candidates.size());
156 
157  // Check for the parameters of the track candidates
158  // The actual hit numbers are more than 4 segment, but this is somewhat a lower bound
159  for (size_t iCand = 0; iCand < candidates.size(); ++iCand) {
160  EXPECT_GE(candidates[iCand].second.size(), 4);
161  }
162  });
163 
165  std::size_t nNodes = houghTree.getTree()->getNNodes();
166  B2INFO("Tree generated " << nNodes << " nodes");
167  houghTree.fell();
168  houghTree.raze();
169 
170  size_t iColor = 0;
171  for (std::pair<HoughBox, std::vector<const CDCSegment2D*> >& candidate : candidates) {
172  const HoughBox& houghBox = candidate.first;
173  const std::vector<const CDCSegment2D*>& segments = candidate.second;
174 
175  B2DEBUG(100, "Candidate");
176  B2DEBUG(100, "size " << segments.size());
177  B2DEBUG(100, "Phi0 " << houghBox.getLowerBound<DiscretePhi0>()->phi());
178  B2DEBUG(100, "Curv " << houghBox.getLowerBound<DiscreteCurv>());
179  B2DEBUG(100, "Impact " << houghBox.getLowerBound<ContinuousImpact>());
180 
181  for (const CDCSegment2D* segment2D : segments) {
182  EventDataPlotter::AttributeMap strokeAttr {{"stroke", m_colors[iColor % m_colors.size()] }};
183  draw(*segment2D, strokeAttr);
184  }
185  ++iColor;
186  }
187  saveDisplay(svgFileName);
188  timeItResult.printSummary();
189  }
190 
191 
192  TEST_F(TrackFindingCDCTestWithSimpleSimulation, hough_perigee_phi0_impact_curv_prepared_event_segments)
193  {
194  std::string svgFileName = "phi0_impact_curv_on_prepared_event_segments.svg";
195  loadPreparedEvent();
196  saveDisplay(svgFileName);
197 
198  using SimpleSegmentPhi0ImpactCurvHoughTree =
199  SimpleSegmentHoughTree<InPhi0ImpactCurvBox, phi0Divisions, impactDivisions, curvDivisions>;
200 
201  using HoughBox = SimpleSegmentPhi0ImpactCurvHoughTree::HoughBox;
202  SimpleSegmentPhi0ImpactCurvHoughTree houghTree(maxLevel);
203 
204  houghTree.assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(),
205  phi0BinsSpec.getNOverlap());
206  houghTree.assignArray<ContinuousImpact>({{minImpact, maxImpact}},
207  impactBinsSpec.getOverlap()); // Continuous
208  houghTree.assignArray<DiscreteCurv>(curvBinsSpec.constructArray(),
209  curvBinsSpec.getNOverlap());
210 
211  houghTree.initialize();
212  const double minWeight = 30.0;
213 
214  // Execute the finding a couple of time to find a stable execution time.
215  std::vector< std::pair<HoughBox, std::vector<const CDCSegment2D*> > > candidates;
216 
217  // Is this still C++? Looks like JavaScript to me :-).
218  TimeItResult timeItResult = timeIt(1, true, [&]() {
219  // Exclude the timing of the resource release for comparision with the legendre test.
220  houghTree.fell();
221  houghTree.seed(m_mcAxialSegment2Ds);
222 
223  // candidates = houghTree.find(minWeight, maxCurvAcceptance);
224  candidates = houghTree.findBest(minWeight, maxCurvAcceptance);
225 
226  ASSERT_EQ(m_mcTracks.size(), candidates.size());
227  // Check for the parameters of the track candidates
228  // The actual hit numbers are more than 30, but this is somewhat a lower bound
229  for (size_t iCand = 0; iCand < candidates.size(); ++iCand) {
230  EXPECT_GE(candidates[iCand].second.size(), 3);
231  }
232  });
233 
235  std::size_t nNodes = houghTree.getTree()->getNNodes();
236  B2DEBUG(100, "Tree generated " << nNodes << " nodes");
237  houghTree.fell();
238  houghTree.raze();
239 
240  size_t iColor = 0;
241  for (std::pair<HoughBox, std::vector<const CDCSegment2D*> >& candidate : candidates) {
242  const HoughBox& houghBox = candidate.first;
243  const std::vector<const CDCSegment2D*>& segments = candidate.second;
244 
245  B2DEBUG(100, "Candidate");
246  B2DEBUG(100, "size " << segments.size());
247  B2DEBUG(100, "Phi0 " << houghBox.getLowerBound<DiscretePhi0>()->phi());
248  B2DEBUG(100, "Curv " << houghBox.getLowerBound<DiscreteCurv>());
249  B2DEBUG(100, "Impact " << houghBox.getLowerBound<ContinuousImpact>());
250 
251  for (const CDCSegment2D* segment2D : segments) {
252  EventDataPlotter::AttributeMap strokeAttr {{"stroke", m_colors[iColor % m_colors.size()] }};
253  draw(*segment2D, strokeAttr);
254  }
255  ++iColor;
256  }
257  saveDisplay(svgFileName);
258  timeItResult.printSummary();
259  }
260 
261 }
Belle2::TrackFindingCDC::Phi0BinsSpec::getNOverlap
int getNOverlap() const
Getter for the overlap in discrete number of positions.
Definition: Phi0Rep.h:57
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::TrackFindingCDC::CurvBinsSpec::constructArray
DiscreteCurv::Array constructArray() const
Constuct the array of discrete curv positions.
Definition: CurvRep.h:50
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::ImpactBinsSpec::getOverlap
double getOverlap() const
Getter for the overlap in real impact to investigate the value that results from the discrete overlap...
Definition: ImpactRep.cc:47
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