Belle II Software development
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/trackingUtilities/eventdata/tracks/CDCTrack.h>
16#include <tracking/trackingUtilities/eventdata/segments/CDCSegment2D.h>
17
18#include <tracking/trackingUtilities/utilities/StringManipulation.h>
19
20#include <framework/core/ModuleParamList.templateDetails.h>
21
22using namespace Belle2;
23using namespace CDC;
24using namespace TrackFindingCDC;
25using namespace TrackingUtilities;
26
28{
29 return "Generates axial tracks from segments using a hough space over phi0 impact and curvature for the spares case.";
30}
31
33 const std::string& prefix)
34{
35 moduleParamList->addParameter(prefixed(prefix, "minNHits"),
37 "Absolute minimal number of hits to make an axial track.",
39
40 moduleParamList->addParameter(prefixed(prefix, "minFractionNHits"),
42 "Minimal number of hits as a fraction of the total hits in the event.",
44
45 moduleParamList->addParameter(prefixed(prefix, "maxLevel"),
47 "Level of divisions in the hough space.",
49
50 moduleParamList->addParameter(prefixed(prefix, "curvBounds"),
52 "Curvature bounds of the hough space.",
54
55 moduleParamList->addParameter(prefixed(prefix, "impactBounds"),
57 "Impact parameter bounds of the hough space.",
59
60 moduleParamList->addParameter(prefixed(prefix, "discretePhi0Width"),
62 "Width of the phi0 bins at the lowest level of the hough space.",
64
65 moduleParamList->addParameter(prefixed(prefix, "discretePhi0Overlap"),
67 "Overlap of the phi0 bins at the lowest level of the hough space.",
69
70 moduleParamList->addParameter(prefixed(prefix, "discreteImpactWidth"),
72 "Width of the impact bins at the lowest level of the hough space.",
74
75 moduleParamList->addParameter(prefixed(prefix, "discreteImpactOverlap"),
77 "Overlap of the impact bins at the lowest level of the hough space.",
79
80 moduleParamList->addParameter(prefixed(prefix, "discreteCurvWidth"),
82 "Width of the curvature bins at the lowest level of the hough space.",
84
85 moduleParamList->addParameter(prefixed(prefix, "discreteCurvOverlap"),
87 "Overlap of the curvature bins at the lowest level of the hough space.",
89
90}
91
93{
95
96 B2ASSERT("Need exactly two curv bound", m_param_curvBounds.size() == 2);
97 B2ASSERT("Need exactly two impact bound", m_param_impactBounds.size() == 2);
98
99 const size_t nPhi0Bins = std::pow(c_phi0Divisions, m_param_maxLevel);
100 const Phi0BinsSpec phi0BinsSpec(nPhi0Bins,
103
104 std::array<double, 2> impactBounds{{m_param_impactBounds.front(), m_param_impactBounds.back()}};
105 const size_t nImpactBins = std::pow(c_impactDivisions, m_param_maxLevel);
106 const ImpactBinsSpec impactBinsSpec(impactBounds[0],
107 impactBounds[1],
108 nImpactBins,
111
112 std::array<double, 2> curvBounds{{m_param_curvBounds.front(), m_param_curvBounds.back()}};
113 const size_t nCurvBins = std::pow(c_curvDivisions, m_param_maxLevel);
114 const CurvBinsSpec curvBinsSpec(curvBounds[0],
115 curvBounds[1],
116 nCurvBins,
119
120 m_houghTree = std::make_unique<SimpleSegmentPhi0ImpactCurvHoughTree>(m_param_maxLevel);
121 m_houghTree->assignArray<DiscretePhi0>(phi0BinsSpec.constructArray(), phi0BinsSpec.getNOverlap());
122 m_houghTree->assignArray<ContinuousImpact>(impactBounds, impactBinsSpec.getOverlap()); // Continuous
123 m_houghTree->assignArray<DiscreteCurv>(curvBinsSpec.constructArray(), curvBinsSpec.getNOverlap());
124 m_houghTree->initialize();
125}
126
127void AxialTrackCreatorSegmentHough::apply(const std::vector<CDCSegment2D>& segments,
128 std::vector<CDCTrack>& tracks)
129{
130 m_houghTree->fell();
131
132 size_t nAxialHits = 0;
133 std::vector<const CDCSegment2D*> ptrAxialSegments;
134 ptrAxialSegments.reserve(segments.size());
135
136 for (const CDCSegment2D& segment : segments) {
137 if (segment.getStereoKind() == EStereoKind::c_Axial) {
138 ptrAxialSegments.push_back(&segment);
139 nAxialHits += segment.size();
140 }
141 }
142
143 m_houghTree->seed(ptrAxialSegments);
145
146 Weight minWeight = std::min(m_param_minNHits, nAxialHits * m_param_minFractionNHits);
147
148 using Candidate = std::pair<HoughBox, std::vector<const CDCSegment2D*> >;
149 std::vector<Candidate> candidates = m_houghTree->findBest(minWeight);
150
151 for (const Candidate& candidate : candidates) {
153 CDCObservations2D observations;
154
155 const HoughBox& foundHoughBox = candidate.first;
156 const std::vector<const CDCSegment2D*>& foundSegments = candidate.second;
157 for (const CDCSegment2D* segment : foundSegments) {
158 observations.appendRange(*segment);
159 }
160 CDCTrajectory2D trajectory2D = fitter.fit(observations);
161
162 // Check if the circle has been fitted reverse to the hough box by accident
163 {
164 double curv = trajectory2D.getCurvature();
165 const std::array<DiscreteCurv, 2>& curvs = foundHoughBox.getBounds<DiscreteCurv>();
166 float lowerCurv = *(curvs[0]);
167 float upperCurv = *(curvs[1]);
168 if (static_cast<double>(ESignUtil::common(lowerCurv, upperCurv)) * curv < 0) {
169 trajectory2D.reverse();
170 }
171 }
172
173 CDCTrack track;
174 for (const CDCSegment2D* segment : foundSegments) {
175 for (const CDCRecoHit2D& recoHit2D : *segment) {
176 track.push_back(CDCRecoHit3D::reconstruct(recoHit2D, trajectory2D));
177 }
178 }
179 track.sortByArcLength2D();
180
182 if (track.empty()) continue;
183 const CDCRecoHit3D& startRecoHit3D = track.front();
184 CDCTrajectory3D startTrajectory3D(trajectory2D);
185 startTrajectory3D.setLocalOrigin(startRecoHit3D.getRecoPos3D());
186 track.setStartTrajectory3D(startTrajectory3D);
187
188 const CDCRecoHit3D& endRecoHit3D = track.back();
189 CDCTrajectory3D endTrajectory3D(trajectory2D);
190 endTrajectory3D.setLocalOrigin(endRecoHit3D.getRecoPos3D());
191 track.setEndTrajectory3D(endTrajectory3D);
192
193 tracks.push_back(std::move(track));
194 }
195}
196
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.
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.
void apply(const std::vector< TrackingUtilities::CDCSegment2D > &segments, std::vector< TrackingUtilities::CDCTrack > &tracks) final
Generates the tracks from the given segments into the output argument.
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 TrackingUtilities::CDCSegment2D &segment2D)
Appends all reconstructed hits from the two dimensional segment.
Class implementing the Riemann fit for two dimensional trajectory circle.
static const CDCRiemannFitter & getFitter()
Static getter for a general Riemann fitter.
Strategy to construct discrete curve points from discrete overlap specifications.
Definition CurvRep.h:23
DiscreteCurv::Array constructArray() const
Construct the array of discrete curve positions.
Definition CurvRep.h:40
int getNOverlap() const
Getter for the overlap in discrete number of positions.
Definition CurvRep.h:68
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:46
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:24
int getNOverlap() const
Getter for the overlap in discrete number of positions.
Definition Phi0Rep.h:47
Class representing a two dimensional reconstructed hit in the central drift chamber.
Class representing a three dimensional reconstructed hit.
const Vector3D & getRecoPos3D() const
Getter for the 3d position of the hit.
static CDCRecoHit3D reconstruct(const CDCRecoHit2D &recoHit2D, const CDCTrajectory2D &trajectory2D)
Reconstructs the three dimensional hit from the two dimensional and the two dimensional trajectory.
A reconstructed sequence of two dimensional hits in one super layer.
Class representing a sequence of three dimensional reconstructed hits.
Definition CDCTrack.h:39
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 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.