Belle II Software  release-05-01-25
AxialTrackCreatorSegmentHough.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 *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/findlets/minimal/AxialTrackCreatorSegmentHough.h>
11 
12 #include <tracking/trackFindingCDC/hough/perigee/StandardBinSpec.h>
13 
14 #include <tracking/trackFindingCDC/fitting/CDCRiemannFitter.h>
15 #include <tracking/trackFindingCDC/fitting/CDCObservations2D.h>
16 
17 #include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
18 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
19 
20 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
21 
22 #include <framework/core/ModuleParamList.templateDetails.h>
23 
24 using namespace Belle2;
25 using namespace TrackFindingCDC;
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 
127 void 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 (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 
198 {
199  m_houghTree->raze();
200  m_houghTree.reset();
202 }
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
Definition: AxialTrackCreatorSegmentHough.cc:32
Belle2::TrackFindingCDC::ESignUtil::common
static ESign common(ESign n1, ESign n2)
Check if two values have a common sign.
Definition: ESign.h:67
Belle2::TrackFindingCDC::Phi0BinsSpec::getNOverlap
int getNOverlap() const
Getter for the overlap in discrete number of positions.
Definition: Phi0Rep.h:57
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_param_discretePhi0Width
int m_param_discretePhi0Width
Parameter: Width of the phi0 bins at the lowest level of the hough space.
Definition: AxialTrackCreatorSegmentHough.h:79
Belle2::TrackFindingCDC::CDCRecoHit3D
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:62
Belle2::TrackFindingCDC::CDCRiemannFitter
Class implementing the Riemann fit for two dimensional trajectory circle.
Definition: CDCRiemannFitter.h:34
Belle2::TrackFindingCDC::CDCTrack
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:51
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::c_curvDivisions
static const int c_curvDivisions
Fixed parameter: Number of divisions in the curv direction.
Definition: AxialTrackCreatorSegmentHough.h:103
Belle2::TrackFindingCDC::CDCTrajectory2D::reverse
void reverse()
Reverses the trajectory in place.
Definition: CDCTrajectory2D.cc:97
Belle2::TrackFindingCDC::DiscreteValue
Representation for a discrete position in an array of discrete positions.
Definition: DiscreteValue.h:33
Belle2::TrackFindingCDC::CDCTrajectory3D::setLocalOrigin
double setLocalOrigin(const Vector3D &localOrigin)
Setter for the origin of the local coordinate system.
Definition: CDCTrajectory3D.cc:369
Belle2::TrackFindingCDC::CurvBinsSpec::getNOverlap
int getNOverlap() const
Getter for the overlap in discrete number of positions.
Definition: CurvRep.h:78
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_param_minNHits
double m_param_minNHits
Parameter: Absolute minimal number of hits to make an axial track.
Definition: AxialTrackCreatorSegmentHough.h:64
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_param_curvBounds
std::vector< float > m_param_curvBounds
Parameter: Curvature bounds of the hough space.
Definition: AxialTrackCreatorSegmentHough.h:73
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_param_minFractionNHits
double m_param_minFractionNHits
Parameter: Minimal number of hits as a fraction of the total hits in the event.
Definition: AxialTrackCreatorSegmentHough.h:67
Belle2::TrackFindingCDC::CDCTrajectory2D::getCurvature
double getCurvature() const
Getter for the curvature as seen from the xy projection.
Definition: CDCTrajectory2D.h:432
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_param_maxLevel
int m_param_maxLevel
Parameter: Level of divisions in the hough space.
Definition: AxialTrackCreatorSegmentHough.h:70
Belle2::TrackFindingCDC::ImpactBinsSpec
Strategy to construct discrete impact points from discrete overlap specifications.
Definition: ImpactRep.h:29
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_param_discretePhi0Overlap
int m_param_discretePhi0Overlap
Parameter: Overlap of the phi0 bins at the lowest level of the hough space.
Definition: AxialTrackCreatorSegmentHough.h:82
Belle2::TrackFindingCDC::CDCTrajectory2D
Particle trajectory as it is seen in xy projection represented as a circle.
Definition: CDCTrajectory2D.h:46
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_param_discreteCurvOverlap
int m_param_discreteCurvOverlap
Parameter: Overlap of the curvature bins at the lowest level of the hough space.
Definition: AxialTrackCreatorSegmentHough.h:94
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::initialize
void initialize() override
Receive and dispatch signal before the start of the event processing.
Definition: CompositeProcessingSignalListener.cc:17
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_param_discreteCurvWidth
int m_param_discreteCurvWidth
Parameter: Width of the curvature bins at the lowest level of the hough space.
Definition: AxialTrackCreatorSegmentHough.h:91
Belle2::TrackFindingCDC::CDCObservations2D::appendRange
std::size_t appendRange(const CDCSegment2D &segment2D)
Appends all reconstructed hits from the two dimensional segment.
Definition: CDCObservations2D.cc:242
Belle2::TrackFindingCDC::CurvBinsSpec::constructArray
DiscreteCurv::Array constructArray() const
Constuct the array of discrete curv positions.
Definition: CurvRep.h:50
Belle2::TrackFindingCDC::CDCObservations2D
Class serving as a storage of observed drift circles to present to the Riemann fitter.
Definition: CDCObservations2D.h:53
Belle2::ModuleParamList::addParameter
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Definition: ModuleParamList.templateDetails.h:38
Belle2::TrackFindingCDC::CDCRecoHit2D
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:57
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::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_houghTree
std::unique_ptr< SimpleSegmentPhi0ImpactCurvHoughTree > m_houghTree
The hough space tree search.
Definition: AxialTrackCreatorSegmentHough.h:111
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::terminate
void terminate() override
Receive and dispatch Signal for termination of the event processing.
Definition: CompositeProcessingSignalListener.cc:49
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::apply
void apply(const std::vector< CDCSegment2D > &segments, std::vector< CDCTrack > &tracks) final
Generates the tracks from the given segments into the output argument.
Definition: AxialTrackCreatorSegmentHough.cc:127
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_param_impactBounds
std::vector< float > m_param_impactBounds
Parameter: Impact parameter bounds of the hough space.
Definition: AxialTrackCreatorSegmentHough.h:76
Belle2::TrackFindingCDC::CDCRiemannFitter::getFitter
static const CDCRiemannFitter & getFitter()
Static getter for a general Riemann fitter.
Definition: CDCRiemannFitter.cc:22
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::c_phi0Divisions
static const int c_phi0Divisions
Fixed parameter: Number of divisions in the phi0 direction.
Definition: AxialTrackCreatorSegmentHough.h:97
Belle2::TrackFindingCDC::CDCSegment2D
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:40
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::c_impactDivisions
static const int c_impactDivisions
Fixed parameter: Number of divisions in the impact direction.
Definition: AxialTrackCreatorSegmentHough.h:100
Belle2::TrackFindingCDC::CurvBinsSpec
Strategy to construct discrete curv points from discrete overlap specifications.
Definition: CurvRep.h:33
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::terminate
void terminate() final
Cleanup the findlet after event processing.
Definition: AxialTrackCreatorSegmentHough.cc:197
Belle2::TrackFindingCDC::ContinuousValue
Type to have values not based on discrete positions from an array.
Definition: ContinuousValue.h:31
Belle2::TrackFindingCDC::CDCRecoHit3D::reconstruct
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:58
Belle2::ModuleParamList
The Module parameter list class.
Definition: ModuleParamList.h:46
Belle2::TrackFindingCDC::CDCRecoHit3D::getRecoPos3D
const Vector3D & getRecoPos3D() const
Getter for the 3d position of the hit.
Definition: CDCRecoHit3D.h:295
Belle2::TrackFindingCDC::SimpleHitBasedHoughTree::HoughBox
typename InBox::HoughBox HoughBox
Type of the hough box.
Definition: SimpleHitBasedHoughTree.h:53
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::getDescription
std::string getDescription() final
Short description of the findlet.
Definition: AxialTrackCreatorSegmentHough.cc:27
Belle2::TrackFindingCDC::Phi0BinsSpec
Strategy to construct discrete phi0 points from discrete overlap specifications.
Definition: Phi0Rep.h:30
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_param_discreteImpactWidth
int m_param_discreteImpactWidth
Parameter: Width of the impact bins at the lowest level of the hough space.
Definition: AxialTrackCreatorSegmentHough.h:85
Belle2::TrackFindingCDC::CDCTrajectory3D
Particle full three dimensional trajectory.
Definition: CDCTrajectory3D.h:47
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::m_param_discreteImpactOverlap
int m_param_discreteImpactOverlap
Parameter: Overlap of the impact bins at the lowest level of the hough space.
Definition: AxialTrackCreatorSegmentHough.h:88
Belle2::TrackFindingCDC::AxialTrackCreatorSegmentHough::initialize
void initialize() final
Initialize the findlet before event processing.
Definition: AxialTrackCreatorSegmentHough.cc:92