Belle II Software  release-05-01-25
Phi0Impact.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/InPhi0ImpactBox.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_onHits)
27  {
28  std::string svgFileName = "phi0_impact_on_hits.svg";
29 
30  Helix lowerHelix(0.00, 2.52033, -20, 0, 0);
31  Helix higherHelix(0.00, 3.0718, 20, 0, 0);
32 
33  simulate({lowerHelix, higherHelix});
34  saveDisplay(svgFileName);
35 
36  using SimpleRLTaggedWireHitHoughTree =
37  SimpleRLTaggedWireHitHoughTree<InPhi0ImpactBox, phi0Divisions, impactDivisions>;
38 
39  SimpleRLTaggedWireHitHoughTree houghTree(maxLevel);
41 
42  houghTree.assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
43  //houghTree.assignArray<DiscreteImpact>(impactBinsSpec.constructArray(), impactBinsSpec.getNOverlap()); // Discrete
44  houghTree.assignArray<ContinuousImpact>({{minImpact, maxImpact}}, impactBinsSpec.getOverlap()); // Continuous
45  houghTree.initialize();
46 
47  // Execute the finding a couple of time to find a stable execution time.
48  std::vector< std::pair<HoughBox, std::vector<CDCRLWireHit> > > candidates;
49 
50  // Is this still C++? Looks like JavaScript to me :-).
51  TimeItResult timeItResult = timeIt(100, true, [&]() {
52  houghTree.fell();
53  houghTree.seed(m_axialWireHits);
54 
55  const double minWeight = 30.0;
56  candidates = houghTree.find(minWeight);
57  // candidates = houghTree.findBest(minWeight);
58 
59  ASSERT_EQ(m_mcTracks.size(), candidates.size());
60  // Check for the parameters of the track candidates
61  // The actual hit numbers are more than 30, but this is somewhat a lower bound
62  for (size_t iCand = 0; iCand < candidates.size(); ++iCand) {
63  EXPECT_GE(candidates[iCand].second.size(), 30);
64  }
65  });
66 
67  std::size_t nNodes = houghTree.getTree()->getNNodes();
68  B2INFO("Tree generated " << nNodes << " nodes");
69  houghTree.fell();
70  houghTree.raze();
71 
72 
73  size_t iColor = 0;
74  for (std::pair<HoughBox, std::vector<CDCRLWireHit> >& candidate : candidates) {
75  const HoughBox& houghBox = candidate.first;
76  const std::vector<CDCRLWireHit>& taggedHits = candidate.second;
77 
78  B2DEBUG(100, "Candidate");
79  B2DEBUG(100, "size " << taggedHits.size());
80  B2DEBUG(100, "Phi0 " << houghBox.getLowerBound<DiscretePhi0>()->phi());
81  B2DEBUG(100, "Impact " << houghBox.getLowerBound<ContinuousImpact>());
82 
83  B2DEBUG(100, "Tags of the hits");
84  for (const CDCRLWireHit& rlTaggedWireHit : taggedHits) {
85  B2DEBUG(100, " " <<
86  "rl = " << static_cast<int>(rlTaggedWireHit.getRLInfo()) << " " <<
87  "dl = " << rlTaggedWireHit.getRefDriftLength());
88  }
89 
90  for (const CDCRLWireHit& rlTaggedWireHit : taggedHits) {
91  const CDCWireHit& wireHit = rlTaggedWireHit.getWireHit();
92  std::string color = "blue";
93  if (rlTaggedWireHit.getRLInfo() == ERightLeft::c_Right) {
94  color = "green";
95  } else if (rlTaggedWireHit.getRLInfo() == ERightLeft::c_Left) {
96  color = "red";
97  }
98  //EventDataPlotter::AttributeMap strokeAttr {{"stroke", color}};
99  EventDataPlotter::AttributeMap strokeAttr {{"stroke", m_colors[iColor % m_colors.size()] }};
100  draw(wireHit, strokeAttr);
101  }
102  ++iColor;
103  }
104  saveDisplay(svgFileName);
105 
106  timeItResult.printSummary();
107  }
108 }
109 
110 
111 namespace {
112  TEST_F(TrackFindingCDCTestWithSimpleSimulation, hough_perigee_SimpleHitBasedHough_phi0_impact_onSegment)
113  {
114  std::string svgFileName = "phi0_impact_on_segments.svg";
115 
116  Helix lowerHelix(0.00, 2.52033, -20, 0, 0);
117  Helix higherHelix(0.00, 3.0718, 20, 0, 0);
118 
119  simulate({lowerHelix, higherHelix});
120  saveDisplay(svgFileName);
121 
122  using SimpleSegmentPhi0ImpactHoughTree =
123  SimpleSegmentHoughTree<InPhi0ImpactBox, phi0Divisions, impactDivisions>;
124  SimpleSegmentPhi0ImpactHoughTree houghTree(maxLevel);
125 
126  using HoughBox = SimpleSegmentPhi0ImpactHoughTree::HoughBox;
127 
128  B2INFO("yes");
129  houghTree.assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
130  //houghTree.assignArray<DiscreteImpact>(impactBinsSpec.constructArray(), impactBinsSpec.getNOverlap()); // Discrete
131  houghTree.assignArray<ContinuousImpact>({{minImpact, maxImpact}}, impactBinsSpec.getOverlap()); // Continuous
132  houghTree.initialize();
133 
134  // Execute the finding a couple of time to find a stable execution time.
135  std::vector< std::pair<HoughBox, std::vector<const CDCSegment2D*> > > candidates;
136 
137  // Is this still C++? Looks like JavaScript to me :-).
138  TimeItResult timeItResult = timeIt(100, true, [&]() {
139  // Exclude the timing of the resource release for comparision with the legendre test.
140  houghTree.fell();
141 
142  houghTree.seed(m_mcAxialSegment2Ds);
143 
144  const double minWeight = 40.0;
145  candidates = houghTree.find(minWeight);
146  // candidates = houghTree.findBest(minWeight);
147 
148  ASSERT_EQ(m_mcTracks.size(), candidates.size());
149 
150  // Check for the parameters of the track candidates
151  // The actual hit numbers are more than 4 segment, but this is somewhat a lower bound
152  for (size_t iCand = 0; iCand < candidates.size(); ++iCand) {
153  EXPECT_GE(candidates[iCand].second.size(), 4);
154  }
155  });
156 
158  std::size_t nNodes = houghTree.getTree()->getNNodes();
159  B2INFO("Tree generated " << nNodes << " nodes");
160  houghTree.fell();
161  houghTree.raze();
162 
163  size_t iColor = 0;
164  for (std::pair<HoughBox, std::vector<const CDCSegment2D*> >& candidate : candidates) {
165  const HoughBox& houghBox = candidate.first;
166  const std::vector<const CDCSegment2D*>& segments = candidate.second;
167 
168  B2DEBUG(100, "Candidate");
169  B2DEBUG(100, "size " << segments.size());
170  B2DEBUG(100, "Phi0 " << houghBox.getLowerBound<DiscretePhi0>()->phi());
171  B2DEBUG(100, "Impact " << houghBox.getLowerBound<ContinuousImpact>());
172 
173  for (const CDCSegment2D* segment2D : segments) {
174  EventDataPlotter::AttributeMap strokeAttr {{"stroke", m_colors[iColor % m_colors.size()] }};
175  draw(*segment2D, strokeAttr);
176  }
177  ++iColor;
178  }
179  saveDisplay(svgFileName);
180  timeItResult.printSummary();
181  }
182 }
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::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
Belle2::TrackFindingCDC::SimpleHitBasedHoughTree::HoughBox
typename InBox::HoughBox HoughBox
Type of the hough box.
Definition: SimpleHitBasedHoughTree.h:53