Belle II Software development
AxialLegendreLeafProcessor< ANode > Class Template Reference

Predicate class that is feed the nodes in a WeightedHoughTree walk It decides if a node should be further expanded and extracts items from nodes that are considered as leafs to build tracks. More...

#include <AxialLegendreLeafProcessor.h>

Public Types

using Candidate = std::pair<TrackingUtilities::CDCTrajectory2D, std::vector<TrackingUtilities::CDCRLWireHit> >
 Preliminary structure to save found hits and trajectory information.
 

Public Member Functions

 AxialLegendreLeafProcessor (int maxLevel)
 Initialize a new processor with the maximum level.
 
bool operator() (ANode *node)
 Entry point for the WeightedHoughTree walk to ask if a node is a leaf that should not be further divided into sub nodes.
 
bool skip (const ANode *node)
 Decide if the node should be expanded further or marks an end point of the depth search.
 
bool isLeaf (const ANode *node)
 Decide when a leaf node is reached that should be processed further.
 
void processLeaf (ANode *leaf)
 A valuable leaf has been found in the hough tree walk.
 
std::vector< WithSharedMark< TrackingUtilities::CDCRLWireHit > > searchRoad (const ANode &node, const TrackingUtilities::CDCTrajectory2D &trajectory2D)
 Look for more hits near a ftted trajectory from hits available in the give node.
 
std::vector< CandidategetCandidates () const
 Getter for the candidates structure still used in some tests.
 
const std::vector< TrackingUtilities::CDCTrack > & getTracks () const
 Getter for the tracks.
 
void clear ()
 Clear the found candidates.
 
void setAxialWireHits (std::vector< const TrackingUtilities::CDCWireHit * > axialWireHits)
 Set the pool of all axial wire hits to be used in the postprocessing.
 
void exposeParameters (ModuleParamList *moduleParamList, const std::string &prefix)
 Expose the parameters as a module parameter list.
 
void beginWalk ()
 Function to notify the leaf processor about changes in parameters before a new walk.
 

Public Attributes

int m_nNodes = 0
 Statistic: Number received node.
 
int m_nSkippedNodes = 0
 Statistic: Number of skipped nodes.
 
int m_nLeafs = 0
 Statistic: Number processed leaf.
 

Private Attributes

int m_param_maxLevel = 1
 Memory for the maximal level of the tree.
 
double m_param_minWeight = 0
 Memory for the minimal weight threshold for following the children of a node.
 
double m_param_maxCurv = NAN
 Memory for the maximal curvature that should be searched in the current walk.
 
double m_param_curlCurv = 0.018
 Memory for the curvature of a curler in the CDC.
 
int m_param_nRoadSearches = 0
 Memory for the number of repeated road searches.
 
int m_param_roadLevel = 0
 Memory for the tree node level which should be the source of hits for the road searches. Defaults to the top most node.
 
std::string m_param_curvResolution = "const"
 Memory for the name of the resolution function to be used. Valid values are 'none', 'const', 'basic', 'origin', 'offOrigin'.
 
std::function< double(double)> m_curvResolution
 Memory for the freely defined curvature resolution function.
 
std::vector< TrackingUtilities::CDCTrackm_tracks
 Memory for found trajectories.
 
std::vector< const TrackingUtilities::CDCWireHit * > m_axialWireHits
 Memory for the pool of axial wire hits to can be used in the post processing.
 

Detailed Description

template<class ANode>
class Belle2::TrackFindingCDC::AxialLegendreLeafProcessor< ANode >

Predicate class that is feed the nodes in a WeightedHoughTree walk It decides if a node should be further expanded and extracts items from nodes that are considered as leafs to build tracks.

It accumulates the tracks in a member vector from where they can be taken after the walk over the tree has been completed.

Definition at line 36 of file AxialLegendreLeafProcessor.h.

Member Typedef Documentation

◆ Candidate

template<class ANode>
using Candidate = std::pair<TrackingUtilities::CDCTrajectory2D, std::vector<TrackingUtilities::CDCRLWireHit> >

Preliminary structure to save found hits and trajectory information.

Definition at line 40 of file AxialLegendreLeafProcessor.h.

Constructor & Destructor Documentation

◆ AxialLegendreLeafProcessor()

template<class ANode>
AxialLegendreLeafProcessor ( int maxLevel)
inlineexplicit

Initialize a new processor with the maximum level.

Definition at line 44 of file AxialLegendreLeafProcessor.h.

45 : m_param_maxLevel(maxLevel)
46 {}

Member Function Documentation

◆ beginWalk()

template<class ANode>
void beginWalk ( )

Function to notify the leaf processor about changes in parameters before a new walk.

Definition at line 235 of file AxialLegendreLeafProcessor.icc.h.

236 {
237 // Setup the requested precision function
238 if (m_param_curvResolution == "none") {
239 m_curvResolution = [](double curv __attribute__((unused))) { return NAN; };
240 } else if (m_param_curvResolution == "const") {
241 m_curvResolution = [](double curv __attribute__((unused))) { return 0.0008; };
242 } else if (m_param_curvResolution == "basic") {
243 m_curvResolution = &PrecisionUtil::getBasicCurvPrecision;
244 } else if (m_param_curvResolution == "origin") {
245 m_curvResolution = &PrecisionUtil::getOriginCurvPrecision;
246 } else if (m_param_curvResolution == "nonOrigin") {
247 m_curvResolution = &PrecisionUtil::getNonOriginCurvPrecision;
248 } else {
249 B2WARNING("Unknown curvature resolution function " << m_param_curvResolution);
250 m_curvResolution = [](double curv __attribute__((unused))) { return NAN; };
251 }
252 }

◆ clear()

template<class ANode>
void clear ( )
inline

Clear the found candidates.

Definition at line 117 of file AxialLegendreLeafProcessor.h.

118 {
119 m_tracks.clear();
120 m_axialWireHits.clear();
121 }

◆ exposeParameters()

template<class ANode>
void exposeParameters ( ModuleParamList * moduleParamList,
const std::string & prefix )

Expose the parameters as a module parameter list.

Definition at line 194 of file AxialLegendreLeafProcessor.icc.h.

196 {
197 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "maxLevel"),
198 m_param_maxLevel,
199 "Level of divisions in the hough space at which a leaf is reached",
200 m_param_maxLevel);
201
202 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "minWeight"),
203 m_param_minWeight,
204 "Minimal exceptable weight of a leaf to be considered",
205 m_param_minWeight);
206
207 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "maxCurv"),
208 m_param_maxCurv,
209 "Maximal curvature of a leaf to be considered",
210 m_param_maxCurv);
211
212 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "curlCurv"),
213 m_param_curlCurv,
214 "Curvature below which hits on both arms of the trajectory are allowed",
215 m_param_curlCurv);
216
217 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "nRoadSearches"),
218 m_param_nRoadSearches,
219 "How often the road search should be performed to find new hits",
220 m_param_nRoadSearches);
221
222 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "roadLevel"),
223 m_param_roadLevel,
224 "Level of the read from which additional hits in the road search can be taken",
225 m_param_roadLevel);
226
227 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "curvResolution"),
228 m_param_curvResolution,
229 "The name of the resolution function to be used. "
230 "Valid values are 'none', 'const', 'basic', 'origin', 'nonOrigin'",
231 m_param_curvResolution);
232 }

◆ getCandidates()

template<class ANode>
std::vector< typename AxialLegendreLeafProcessor< ANode >::Candidate > getCandidates ( ) const

Getter for the candidates structure still used in some tests.

Definition at line 179 of file AxialLegendreLeafProcessor.icc.h.

180 {
181 std::vector<Candidate> result;
182 for (const TrackingUtilities::CDCTrack& track : m_tracks) {
183 std::vector<TrackingUtilities::CDCRLWireHit> rlWireHits;
184 for (const TrackingUtilities::CDCRecoHit3D& recoHit3D : track) {
185 rlWireHits.push_back(recoHit3D.getRLWireHit());
186 }
187 TrackingUtilities::CDCTrajectory2D trajectory2D = track.getStartTrajectory3D().getTrajectory2D();
188 result.emplace_back(std::move(trajectory2D), std::move(rlWireHits));
189 }
190 return result;
191 }

◆ getTracks()

template<class ANode>
const std::vector< TrackingUtilities::CDCTrack > & getTracks ( ) const
inline

Getter for the tracks.

Definition at line 111 of file AxialLegendreLeafProcessor.h.

112 {
113 return m_tracks;
114 }

◆ isLeaf()

template<class ANode>
bool isLeaf ( const ANode * node)
inline

Decide when a leaf node is reached that should be processed further.

Definition at line 78 of file AxialLegendreLeafProcessor.h.

79 {
80 //if (node->getLevel() <= 6) return false;
81 if (node->getLevel() >= m_param_maxLevel) return true;
82
83 // Compare the resolution at the mean curvature to the resolution defined by the resolution function
84 std::array<DiscreteCurv, 2> curvs = node->template getBounds<DiscreteCurv>();
85 float lowerCurv = *(curvs[0]);
86 float upperCurv = *(curvs[1]);
87 float curvWidth = std::fabs(upperCurv - lowerCurv);
88 double curvRes = m_curvResolution((lowerCurv + upperCurv) / 2.0);
89 if (curvRes >= curvWidth) return true;
90 return false;
91 }

◆ operator()()

template<class ANode>
bool operator() ( ANode * node)
inline

Entry point for the WeightedHoughTree walk to ask if a node is a leaf that should not be further divided into sub nodes.

Definition at line 53 of file AxialLegendreLeafProcessor.h.

54 {
55 ++m_nNodes;
56 if (skip(node)) {
57 ++m_nSkippedNodes;
58 return true;
59 } else if (isLeaf(node)) {
60 ++m_nLeafs;
61 processLeaf(node);
62 return true;
63 } else {
64 return false;
65 }
66 }

◆ processLeaf()

template<class ANode>
void processLeaf ( ANode * leaf)

A valuable leaf has been found in the hough tree walk.

Extract its content! It may pull more hits from the whole tree by looking at the top node.

Definition at line 40 of file AxialLegendreLeafProcessor.icc.h.

41 {
42 // Special post processing looking for more hits
43 // Start off by fitting the items of the leaf with a general trajectory
44 // that may have a distinct impact != 0
46 auto fitPos = EFitPos::c_RecoPos;
47 auto fitVariance = EFitVariance::c_DriftLength;
48 // Other combinations of fit information
49 // EFitPos::c_RLDriftCircle x EFitVariance::(c_Nominal, c_Pseudo, c_Proper)
50 // have been tried, but found to be worse, which is
51 // not intuitive. Probably the perfect circle trajectory
52 // is not as good of a model on the full CDC volume.
53 CDCObservations2D observations2D(fitPos, fitVariance);
54
55 CDCKarimakiFitter fitter;
56 // Tested alternative CDCRiemannFitter with only marginal differences;
57
58 std::vector<WithSharedMark<TrackingUtilities::CDCRLWireHit>> hits(leaf->begin(), leaf->end());
59 std::sort(hits.begin(), hits.end()); // Hits should be naturally sorted
60 observations2D.appendRange(hits);
61 TrackingUtilities::CDCTrajectory2D trajectory2D = fitter.fit(observations2D);
62 {
63 const double curv = trajectory2D.getCurvature();
64 std::array<DiscreteCurv, 2> curvs = leaf->template getBounds<DiscreteCurv>();
65
66 float lowerCurv = *(curvs[0]);
67 float upperCurv = *(curvs[1]);
68 if (static_cast<double>(TrackingUtilities::ESignUtil::common(lowerCurv, upperCurv)) * curv < 0) {
69 trajectory2D.reverse();
70 }
71 }
72 trajectory2D.setLocalOrigin(ROOT::Math::XYVector(0, 0));
73
74 // Look for more hits near the found trajectory
76 if (m_param_nRoadSearches > 0) {
77 // Acquire all available items in some parent node for the road search
78 // Somewhat bypasses the logic of the tree walk - Must handle with care!
79 ANode* roadNode = leaf;
80 while (roadNode->getParent() and roadNode->getLevel() > m_param_roadLevel) {
81 roadNode = roadNode->getParent();
82 }
83
84 for (int iRoadSearch = 0; iRoadSearch < m_param_nRoadSearches; ++iRoadSearch) {
85 // Use a road search to find new hits from the trajectory
86 // hits = this->searchRoad(*roadNode, trajectory2D); // In case you only want the road hits
87 // if (hits.size() < 5) return;
88
89 // Second version always holding on to the originally found hits
90 int nHitsBefore = hits.size();
91 std::vector<WithSharedMark<TrackingUtilities::CDCRLWireHit>> roadHits = this->searchRoad(*roadNode, trajectory2D);
92 std::sort(roadHits.begin(), roadHits.end());
93 hits.insert(hits.end(), roadHits.begin(), roadHits.end());
94 std::inplace_merge(hits.begin(), hits.begin() + nHitsBefore, hits.end());
95 hits.erase(std::unique(hits.begin(), hits.end()), hits.end());
96
97 // Update the current fit
98 observations2D.clear();
99 observations2D.appendRange(hits);
100 trajectory2D = fitter.fit(observations2D);
101 trajectory2D.setLocalOrigin(ROOT::Math::XYVector(0.0, 0.0));
102 }
103 }
104
105 // Mark found hit as used and safe them with the trajectory
107 std::vector<const TrackingUtilities::CDCWireHit*> foundWireHits;
108 for (TrackingUtilities::CDCRLWireHit& rlWireHit : hits) {
109 foundWireHits.push_back(&rlWireHit.getWireHit());
110 }
111
112 AxialTrackUtil::addCandidateFromHits(foundWireHits, m_axialWireHits, m_tracks, true);
113
114 // Sync up the marks with the used hits
115 for (WithSharedMark<TrackingUtilities::CDCRLWireHit>& markableRLWireHit : leaf->getTree()->getTopNode()) {
116 const TrackingUtilities::AutomatonCell& automatonCell = markableRLWireHit.getWireHit().getAutomatonCell();
117 if (automatonCell.hasTakenFlag() or automatonCell.hasMaskedFlag()) {
118 markableRLWireHit.mark();
119 } else {
120 markableRLWireHit.unmark();
121 }
122 }
123 }

◆ searchRoad()

template<class ANode>
std::vector< WithSharedMark< TrackingUtilities::CDCRLWireHit > > searchRoad ( const ANode & node,
const TrackingUtilities::CDCTrajectory2D & trajectory2D )

Look for more hits near a ftted trajectory from hits available in the give node.

Definition at line 127 of file AxialLegendreLeafProcessor.icc.h.

128 {
129 const TrackingUtilities::PerigeeCircle& circle = trajectory2D.getGlobalCircle();
130 const ROOT::Math::XYVector& support = trajectory2D.getGlobalPerigee();
131 const float curv = circle.curvature();
132 const float phi0 = circle.phi0();
133
134 StereoHitContained<OffOrigin<InPhi0ImpactCurvBox> > hitInPhi0CurvBox(m_param_curlCurv);
135 hitInPhi0CurvBox.setLocalOrigin(support);
136 using RoadHoughBox = StereoHitContained<OffOrigin<InPhi0ImpactCurvBox> >::HoughBox;
137
138 // Determine a precision that we expect to achieve at the fitted momentum
139 // There certainly is some optimizsation potential here.
140 // Spread in the impact parameter is made available here but is not activated yet.
141 const float levelPrecision = 9.0;
142 // Earlier version
143 // const float levelPrecision = 10.5 - 0.24 * exp(-4.13118 * PrecisionUtil::convertRhoToPt(curv) + 2.74);
144 const float phi0Precision = M_PI / std::pow(2.0, levelPrecision + 1.0);
145 const float impactPrecision = 0.0 * std::sqrt(TrackingUtilities::CDCWireHit::c_simpleDriftLengthVariance);
146 const float curvPrecision = 0.15 / std::pow(2.0, levelPrecision);
147
148 DiscreteCurv::Array curvBounds{{curv - curvPrecision, curv + curvPrecision}};
149 ContinuousImpact::Array impactBounds{{ -impactPrecision, impactPrecision}};
150 DiscretePhi0::Array phi0Bounds{{VectorUtil::Phi(phi0 - phi0Precision), VectorUtil::Phi(phi0 + phi0Precision)}};
151 RoadHoughBox precisionPhi0CurvBox(DiscretePhi0::getRange(phi0Bounds),
152 ContinuousImpact::getRange(impactBounds),
153 DiscreteCurv::getRange(curvBounds));
154
155 std::vector<WithSharedMark<TrackingUtilities::CDCRLWireHit>> hitsInPrecisionBox;
156
157 // Explicitly making a copy here to ensure that we do not change the node content
158 for (WithSharedMark<TrackingUtilities::CDCRLWireHit> markableRLWireHit : node) {
159 // Skip marked hits
160 if (markableRLWireHit.isMarked()) continue;
161 TrackingUtilities::Weight weight = hitInPhi0CurvBox(markableRLWireHit, &precisionPhi0CurvBox);
162 if (not std::isnan(weight)) hitsInPrecisionBox.push_back(markableRLWireHit);
163 }
164
165 return hitsInPrecisionBox;
166 }

◆ setAxialWireHits()

template<class ANode>
void setAxialWireHits ( std::vector< const TrackingUtilities::CDCWireHit * > axialWireHits)
inline

Set the pool of all axial wire hits to be used in the postprocessing.

Definition at line 124 of file AxialLegendreLeafProcessor.h.

125 {
126 m_axialWireHits = std::move(axialWireHits);
127 }

◆ skip()

template<class ANode>
bool skip ( const ANode * node)
inline

Decide if the node should be expanded further or marks an end point of the depth search.

Definition at line 69 of file AxialLegendreLeafProcessor.h.

70 {
71 bool tooLowWeight = not(node->getWeight() >= m_param_minWeight);
72 bool tooHighCurvature = (static_cast<float>(node->template getLowerBound<DiscreteCurv>()) > m_param_maxCurv or
73 - static_cast<float>(node->template getUpperBound<DiscreteCurv>()) > m_param_maxCurv);
74 return tooLowWeight or tooHighCurvature;
75 }

Member Data Documentation

◆ m_axialWireHits

template<class ANode>
std::vector<const TrackingUtilities::CDCWireHit*> m_axialWireHits
private

Memory for the pool of axial wire hits to can be used in the post processing.

Definition at line 183 of file AxialLegendreLeafProcessor.h.

◆ m_curvResolution

template<class ANode>
std::function<double(double)> m_curvResolution
private

Memory for the freely defined curvature resolution function.

Definition at line 177 of file AxialLegendreLeafProcessor.h.

◆ m_nLeafs

template<class ANode>
int m_nLeafs = 0

Statistic: Number processed leaf.

Definition at line 144 of file AxialLegendreLeafProcessor.h.

◆ m_nNodes

template<class ANode>
int m_nNodes = 0

Statistic: Number received node.

Definition at line 138 of file AxialLegendreLeafProcessor.h.

◆ m_nSkippedNodes

template<class ANode>
int m_nSkippedNodes = 0

Statistic: Number of skipped nodes.

Definition at line 141 of file AxialLegendreLeafProcessor.h.

◆ m_param_curlCurv

template<class ANode>
double m_param_curlCurv = 0.018
private

Memory for the curvature of a curler in the CDC.

Definition at line 157 of file AxialLegendreLeafProcessor.h.

◆ m_param_curvResolution

template<class ANode>
std::string m_param_curvResolution = "const"
private

Memory for the name of the resolution function to be used. Valid values are 'none', 'const', 'basic', 'origin', 'offOrigin'.

Definition at line 166 of file AxialLegendreLeafProcessor.h.

◆ m_param_maxCurv

template<class ANode>
double m_param_maxCurv = NAN
private

Memory for the maximal curvature that should be searched in the current walk.

Definition at line 154 of file AxialLegendreLeafProcessor.h.

◆ m_param_maxLevel

template<class ANode>
int m_param_maxLevel = 1
private

Memory for the maximal level of the tree.

Definition at line 148 of file AxialLegendreLeafProcessor.h.

◆ m_param_minWeight

template<class ANode>
double m_param_minWeight = 0
private

Memory for the minimal weight threshold for following the children of a node.

Definition at line 151 of file AxialLegendreLeafProcessor.h.

◆ m_param_nRoadSearches

template<class ANode>
int m_param_nRoadSearches = 0
private

Memory for the number of repeated road searches.

Definition at line 160 of file AxialLegendreLeafProcessor.h.

◆ m_param_roadLevel

template<class ANode>
int m_param_roadLevel = 0
private

Memory for the tree node level which should be the source of hits for the road searches. Defaults to the top most node.

Definition at line 163 of file AxialLegendreLeafProcessor.h.

◆ m_tracks

template<class ANode>
std::vector<TrackingUtilities::CDCTrack> m_tracks
private

Memory for found trajectories.

Definition at line 180 of file AxialLegendreLeafProcessor.h.


The documentation for this class was generated from the following files: