Belle II Software  release-08-01-10
AxialTrackCreatorSegmentHough.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/findlets/minimal/AxialTrackCreatorSegmentHough.h>
9 
10 #include <tracking/trackFindingCDC/hough/perigee/StandardBinSpec.h>
11 
12 #include <tracking/trackFindingCDC/fitting/CDCRiemannFitter.h>
13 #include <tracking/trackFindingCDC/fitting/CDCObservations2D.h>
14 
15 #include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
16 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
17 
18 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
19 
20 #include <framework/core/ModuleParamList.templateDetails.h>
21 
22 using namespace Belle2;
23 using namespace TrackFindingCDC;
24 
26 {
27  return "Generates axial tracks from segments using a hough space over phi0 impact and curvature for the spares case.";
28 }
29 
31  const std::string& prefix)
32 {
33  moduleParamList->addParameter(prefixed(prefix, "minNHits"),
35  "Absolute minimal number of hits to make an axial track.",
37 
38  moduleParamList->addParameter(prefixed(prefix, "minFractionNHits"),
40  "Minimal number of hits as a fraction of the total hits in the event.",
42 
43  moduleParamList->addParameter(prefixed(prefix, "maxLevel"),
45  "Level of divisions in the hough space.",
47 
48  moduleParamList->addParameter(prefixed(prefix, "curvBounds"),
50  "Curvature bounds of the hough space.",
52 
53  moduleParamList->addParameter(prefixed(prefix, "impactBounds"),
55  "Impact parameter bounds of the hough space.",
57 
58  moduleParamList->addParameter(prefixed(prefix, "discretePhi0Width"),
60  "Width of the phi0 bins at the lowest level of the hough space.",
62 
63  moduleParamList->addParameter(prefixed(prefix, "discretePhi0Overlap"),
65  "Overlap of the phi0 bins at the lowest level of the hough space.",
67 
68  moduleParamList->addParameter(prefixed(prefix, "discreteImpactWidth"),
70  "Width of the impact bins at the lowest level of the hough space.",
72 
73  moduleParamList->addParameter(prefixed(prefix, "discreteImpactOverlap"),
75  "Overlap of the impact bins at the lowest level of the hough space.",
77 
78  moduleParamList->addParameter(prefixed(prefix, "discreteCurvWidth"),
80  "Width of the curvature bins at the lowest level of the hough space.",
82 
83  moduleParamList->addParameter(prefixed(prefix, "discreteCurvOverlap"),
85  "Overlap of the curvature bins at the lowest level of the hough space.",
87 
88 }
89 
91 {
93 
94  B2ASSERT("Need exactly two curv bound", m_param_curvBounds.size() == 2);
95  B2ASSERT("Need exactly two impact bound", m_param_impactBounds.size() == 2);
96 
97  const size_t nPhi0Bins = std::pow(c_phi0Divisions, m_param_maxLevel);
98  const Phi0BinsSpec phi0BinsSpec(nPhi0Bins,
101 
102  std::array<double, 2> impactBounds{{m_param_impactBounds.front(), m_param_impactBounds.back()}};
103  const size_t nImpactBins = std::pow(c_impactDivisions, m_param_maxLevel);
104  const ImpactBinsSpec impactBinsSpec(impactBounds[0],
105  impactBounds[1],
106  nImpactBins,
109 
110  std::array<double, 2> curvBounds{{m_param_curvBounds.front(), m_param_curvBounds.back()}};
111  const size_t nCurvBins = std::pow(c_curvDivisions, m_param_maxLevel);
112  const CurvBinsSpec curvBinsSpec(curvBounds[0],
113  curvBounds[1],
114  nCurvBins,
117 
118  m_houghTree = std::make_unique<SimpleSegmentPhi0ImpactCurvHoughTree>(m_param_maxLevel);
119  m_houghTree->assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
120  m_houghTree->assignArray<ContinuousImpact>(impactBounds, impactBinsSpec.getOverlap()); // Continuous
121  m_houghTree->assignArray<DiscreteCurv>(curvBinsSpec.constructArray(), curvBinsSpec.getNOverlap());
122  m_houghTree->initialize();
123 }
124 
125 void AxialTrackCreatorSegmentHough::apply(const std::vector<CDCSegment2D>& segments,
126  std::vector<CDCTrack>& tracks)
127 {
128  m_houghTree->fell();
129 
130  size_t nAxialHits = 0;
131  std::vector<const CDCSegment2D*> ptrAxialSegments;
132  ptrAxialSegments.reserve(segments.size());
133 
134  for (const CDCSegment2D& segment : segments) {
135  if (segment.getStereoKind() == EStereoKind::c_Axial) {
136  ptrAxialSegments.push_back(&segment);
137  nAxialHits += segment.size();
138  }
139  }
140 
141  m_houghTree->seed(ptrAxialSegments);
143 
144  Weight minWeight = std::min(m_param_minNHits, nAxialHits * m_param_minFractionNHits);
145 
146  using Candidate = std::pair<HoughBox, std::vector<const CDCSegment2D*> >;
147  std::vector<Candidate> candidates = m_houghTree->findBest(minWeight);
148 
149  for (const Candidate& candidate : candidates) {
151  CDCObservations2D observations;
152 
153  const HoughBox& foundHoughBox = candidate.first;
154  const std::vector<const CDCSegment2D*>& foundSegments = candidate.second;
155  for (const CDCSegment2D* segment : foundSegments) {
156  observations.appendRange(*segment);
157  }
158  CDCTrajectory2D trajectory2D = fitter.fit(observations);
159 
160  // Check if the circle has been fitted reverse to the hough box by accident
161  {
162  double curv = trajectory2D.getCurvature();
163  const std::array<DiscreteCurv, 2>& curvs = foundHoughBox.getBounds<DiscreteCurv>();
164  float lowerCurv = *(curvs[0]);
165  float upperCurv = *(curvs[1]);
166  if (static_cast<double>(ESignUtil::common(lowerCurv, upperCurv)) * curv < 0) {
167  trajectory2D.reverse();
168  }
169  }
170 
171  CDCTrack track;
172  for (const CDCSegment2D* segment : foundSegments) {
173  for (const CDCRecoHit2D& recoHit2D : *segment) {
174  track.push_back(CDCRecoHit3D::reconstruct(recoHit2D, trajectory2D));
175  }
176  }
177  track.sortByArcLength2D();
178 
180  if (track.empty()) continue;
181  const CDCRecoHit3D& startRecoHit3D = track.front();
182  CDCTrajectory3D startTrajectory3D(trajectory2D);
183  startTrajectory3D.setLocalOrigin(startRecoHit3D.getRecoPos3D());
184  track.setStartTrajectory3D(startTrajectory3D);
185 
186  const CDCRecoHit3D& endRecoHit3D = track.back();
187  CDCTrajectory3D endTrajectory3D(trajectory2D);
188  endTrajectory3D.setLocalOrigin(endRecoHit3D.getRecoPos3D());
189  track.setEndTrajectory3D(endTrajectory3D);
190 
191  tracks.push_back(std::move(track));
192  }
193 }
194 
196 {
197  m_houghTree->raze();
198  m_houghTree.reset();
200 }
The Module parameter list class.
static const int c_curvDivisions
Fixed parameter: Number of divisions in the curv direction.
void initialize() final
Initialize the findlet before event processing.
double m_param_minNHits
Parameter: Absolute minimal number of hits to make an axial track.
void apply(const std::vector< CDCSegment2D > &segments, std::vector< CDCTrack > &tracks) final
Generates the tracks from the given segments into the output argument.
int m_param_discreteImpactWidth
Parameter: Width of the impact bins at the lowest level of the hough space.
std::string getDescription() final
Short description of the findlet.
int m_param_discretePhi0Width
Parameter: Width of the phi0 bins at the lowest level of the hough space.
std::unique_ptr< SimpleSegmentPhi0ImpactCurvHoughTree > m_houghTree
The hough space tree search.
std::vector< float > m_param_curvBounds
Parameter: Curvature bounds of the hough space.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
double m_param_minFractionNHits
Parameter: Minimal number of hits as a fraction of the total hits in the event.
static const int c_impactDivisions
Fixed parameter: Number of divisions in the impact direction.
int m_param_discreteImpactOverlap
Parameter: Overlap of the impact bins at the lowest level of the hough space.
int m_param_discreteCurvOverlap
Parameter: Overlap of the curvature bins at the lowest level of the hough space.
int m_param_maxLevel
Parameter: Level of divisions in the hough space.
static const int c_phi0Divisions
Fixed parameter: Number of divisions in the phi0 direction.
void terminate() final
Cleanup the findlet after event processing.
int m_param_discreteCurvWidth
Parameter: Width of the curvature bins at the lowest level of the hough space.
int m_param_discretePhi0Overlap
Parameter: Overlap of the phi0 bins at the lowest level of the hough space.
std::vector< float > m_param_impactBounds
Parameter: Impact parameter bounds of the hough space.
Class serving as a storage of observed drift circles to present to the Riemann fitter.
std::size_t appendRange(const CDCSegment2D &segment2D)
Appends all reconstructed hits from the two dimensional segment.
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:47
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:52
static CDCRecoHit3D reconstruct(const CDCRecoHit2D &recoHit2D, const CDCTrajectory2D &trajectory2D)
Reconstructs the three dimensional hit from the two dimensional and the two dimensional trajectory.
Definition: CDCRecoHit3D.cc:56
const Vector3D & getRecoPos3D() const
Getter for the 3d position of the hit.
Definition: CDCRecoHit3D.h:285
Class implementing the Riemann fit for two dimensional trajectory circle.
static const CDCRiemannFitter & getFitter()
Static getter for a general Riemann fitter.
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
Particle trajectory as it is seen in xy projection represented as a circle.
void reverse()
Reverses the trajectory in place.
double getCurvature() const
Getter for the curvature as seen from the xy projection.
Particle full three dimensional trajectory.
double setLocalOrigin(const Vector3D &localOrigin)
Setter for the origin of the local coordinate system.
void initialize() override
Receive and dispatch signal before the start of the event processing.
void terminate() override
Receive and dispatch Signal for termination of the event processing.
Type to have values not based on discrete positions from an array.
Strategy to construct discrete curv points from discrete overlap specifications.
Definition: CurvRep.h:23
DiscreteCurv::Array constructArray() const
Constuct the array of discrete curv positions.
Definition: CurvRep.h:40
int getNOverlap() const
Getter for the overlap in discrete number of positions.
Definition: CurvRep.h:68
Representation for a discrete position in an array of discrete positions.
Definition: DiscreteValue.h:23
Strategy to construct discrete impact points from discrete overlap specifications.
Definition: ImpactRep.h:19
double getOverlap() const
Getter for the overlap in real impact to investigate the value that results from the discrete overlap...
Definition: ImpactRep.cc:45
Strategy to construct discrete phi0 points from discrete overlap specifications.
Definition: Phi0Rep.h:20
DiscretePhi0::Array constructArray() const
Constuct 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
typename InBox::HoughBox HoughBox
Type of the hough box.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
static ESign common(ESign n1, ESign n2)
Check if two values have a common sign.
Definition: ESign.h:57
Abstract base class for different kinds of events.