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< CDCTrajectory2D, std::vector< 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< CDCRLWireHit > > searchRoad (const ANode &node, const 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< CDCTrack > & getTracks () const
 Getter for the tracks.
 
void clear ()
 Clear the found candidates.
 
void setAxialWireHits (std::vector< const 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::vector< CDCTrackm_tracks
 Memory for found trajectories.
 
std::vector< const CDCWireHit * > m_axialWireHits
 Memory for the pool of axial wire hits to can be used in the post processing.
 
std::function< double(double)> m_curvResolution
 Memory for the freely defined curvature resolution function.
 

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

using Candidate = std::pair<CDCTrajectory2D, std::vector<CDCRLWireHit> >

Preliminary structure to save found hits and trajectory information.

Definition at line 40 of file AxialLegendreLeafProcessor.h.

Constructor & Destructor Documentation

◆ AxialLegendreLeafProcessor()

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 {}
int m_param_maxLevel
Memory for the maximal level of the tree.

Member Function Documentation

◆ beginWalk()

void beginWalk

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

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

233 {
234 // Setup the requested precision function
235 if (m_param_curvResolution == "none") {
236 m_curvResolution = [](double curv __attribute__((unused))) { return NAN; };
237 } else if (m_param_curvResolution == "const") {
238 m_curvResolution = [](double curv __attribute__((unused))) { return 0.0008; };
239 } else if (m_param_curvResolution == "basic") {
241 } else if (m_param_curvResolution == "origin") {
243 } else if (m_param_curvResolution == "nonOrigin") {
245 } else {
246 B2WARNING("Unknown curvature resolution function " << m_param_curvResolution);
247 m_curvResolution = [](double curv __attribute__((unused))) { return NAN; };
248 }
249 }
std::string m_param_curvResolution
Memory for the name of the resolution function to be used. Valid values are 'none',...
std::function< double(double)> m_curvResolution
Memory for the freely defined curvature resolution function.
static double getOriginCurvPrecision(double curv)
Function which estimates desired curvature resolution of quadtree node in the given pt region paramet...
Definition: PrecisionUtil.h:65
static double getNonOriginCurvPrecision(double curv)
Function which estimates desired curvature resolution of quadtree node in the given pt region paramet...
Definition: PrecisionUtil.h:90
static double getBasicCurvPrecision(double curv)
Basic function to estimate the curvature precision Takes a curvature value and returns a width that.
Definition: PrecisionUtil.h:49

◆ clear()

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 }
std::vector< const CDCWireHit * > m_axialWireHits
Memory for the pool of axial wire hits to can be used in the post processing.
std::vector< CDCTrack > m_tracks
Memory for found trajectories.

◆ exposeParameters()

void exposeParameters ( ModuleParamList moduleParamList,
const std::string &  prefix 
)

Expose the parameters as a module parameter list.

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

193 {
194 moduleParamList->addParameter(prefixed(prefix, "maxLevel"),
196 "Level of divisions in the hough space at which a leaf is reached",
198
199 moduleParamList->addParameter(prefixed(prefix, "minWeight"),
201 "Minimal exceptable weight of a leaf to be considered",
203
204 moduleParamList->addParameter(prefixed(prefix, "maxCurv"),
206 "Maximal curvature of a leaf to be considered",
208
209 moduleParamList->addParameter(prefixed(prefix, "curlCurv"),
211 "Curvature below which hits on both arms of the trajectory are allowed",
213
214 moduleParamList->addParameter(prefixed(prefix, "nRoadSearches"),
216 "How often the road search should be performed to find new hits",
218
219 moduleParamList->addParameter(prefixed(prefix, "roadLevel"),
221 "Level of the read from which additional hits in the road search can be taken",
223
224 moduleParamList->addParameter(prefixed(prefix, "curvResolution"),
226 "The name of the resolution function to be used. "
227 "Valid values are 'none', 'const', 'basic', 'origin', 'nonOrigin'",
229 }
int m_param_roadLevel
Memory for the tree node level which should be the source of hits for the road searches....
double m_param_curlCurv
Memory for the curvature of a curler in the CDC.
double m_param_maxCurv
Memory for the maximal curvature that should be searched in the current walk.
double m_param_minWeight
Memory for the minimal weight threshold for following the children of a node.
int m_param_nRoadSearches
Memory for the number of repeated road searches.

◆ getCandidates()

std::vector< typename AxialLegendreLeafProcessor< ANode >::Candidate > getCandidates

Getter for the candidates structure still used in some tests.

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

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

◆ getTracks()

const std::vector< CDCTrack > & getTracks ( ) const
inline

Getter for the tracks.

Definition at line 111 of file AxialLegendreLeafProcessor.h.

112 {
113 return m_tracks;
114 }

◆ isLeaf()

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()()

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)) {
58 return true;
59 } else if (isLeaf(node)) {
60 ++m_nLeafs;
61 processLeaf(node);
62 return true;
63 } else {
64 return false;
65 }
66 }
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.
bool skip(const ANode *node)
Decide if the node should be expanded further or marks an end point of the depth search.

◆ processLeaf()

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 37 of file AxialLegendreLeafProcessor.icc.h.

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

◆ searchRoad()

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

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

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

125 {
126 PerigeeCircle circle = trajectory2D.getGlobalCircle();
127 Vector2D support = trajectory2D.getGlobalPerigee();
128 const float curv = circle.curvature();
129 const float phi0 = circle.phi0();
130
131 StereoHitContained<OffOrigin<InPhi0ImpactCurvBox> > hitInPhi0CurvBox(m_param_curlCurv);
132 hitInPhi0CurvBox.setLocalOrigin(support);
133 using RoadHoughBox = StereoHitContained<OffOrigin<InPhi0ImpactCurvBox> >::HoughBox;
134
135 // Determine a precision that we expect to achieve at the fitted momentum
136 // There certainly is some optimizsation potential here.
137 // Spread in the impact parameter is made available here but is not activated yet.
138 const float levelPrecision = 9.0;
139 // Earlier version
140 // const float levelPrecision = 10.5 - 0.24 * exp(-4.13118 * PrecisionUtil::convertRhoToPt(curv) + 2.74);
141 const float phi0Precision = 3.1415 / std::pow(2.0, levelPrecision + 1.0);
142 const float impactPrecision = 0.0 * std::sqrt(CDCWireHit::c_simpleDriftLengthVariance);
143 const float curvPrecision = 0.15 / std::pow(2.0, levelPrecision);
144
145 DiscreteCurv::Array curvBounds{{curv - curvPrecision, curv + curvPrecision}};
146 ContinuousImpact::Array impactBounds{{ -impactPrecision, impactPrecision}};
147 DiscretePhi0::Array phi0Bounds{{Vector2D::Phi(phi0 - phi0Precision), Vector2D::Phi(phi0 + phi0Precision)}};
148 RoadHoughBox precisionPhi0CurvBox(DiscretePhi0::getRange(phi0Bounds),
149 ContinuousImpact::getRange(impactBounds),
150 DiscreteCurv::getRange(curvBounds));
151
152 std::vector<WithSharedMark<CDCRLWireHit>> hitsInPrecisionBox;
153
154 // Explicitly making a copy here to ensure that we do not change the node content
155 for (WithSharedMark<CDCRLWireHit> markableRLWireHit : node) {
156 // Skip marked hits
157 if (markableRLWireHit.isMarked()) continue;
158 Weight weight = hitInPhi0CurvBox(markableRLWireHit, &precisionPhi0CurvBox);
159 if (not std::isnan(weight)) hitsInPrecisionBox.push_back(markableRLWireHit);
160 }
161
162 return hitsInPrecisionBox;
163 }
static constexpr const double c_simpleDriftLengthVariance
A default value for the drift length variance if no variance from the drift length translation is ava...
Definition: CDCWireHit.h:64
std::array< T, 2 > Array
Mock array type to be a drop in replacement for the discrete values.
static std::array< This, 2 > getRange(const Array &bounds)
Extract the range from an array providing the discrete values.
static std::array< This, 2 > getRange(Array &values)
Extract the range from an array providing the discrete values.
Definition: DiscreteValue.h:59
std::vector< T > Array
The type of the array which contains the underlying values.
Definition: DiscreteValue.h:55
static Vector2D Phi(const double phi)
Constructs a unit vector with azimuth angle equal to phi.
Definition: Vector2D.h:62

◆ setAxialWireHits()

void setAxialWireHits ( std::vector< const 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()

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

std::vector<const CDCWireHit*> m_axialWireHits
private

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

Definition at line 180 of file AxialLegendreLeafProcessor.h.

◆ m_curvResolution

std::function<double(double)> m_curvResolution
private

Memory for the freely defined curvature resolution function.

Definition at line 183 of file AxialLegendreLeafProcessor.h.

◆ m_nLeafs

int m_nLeafs = 0

Statistic: Number processed leaf.

Definition at line 144 of file AxialLegendreLeafProcessor.h.

◆ m_nNodes

int m_nNodes = 0

Statistic: Number received node.

Definition at line 138 of file AxialLegendreLeafProcessor.h.

◆ m_nSkippedNodes

int m_nSkippedNodes = 0

Statistic: Number of skipped nodes.

Definition at line 141 of file AxialLegendreLeafProcessor.h.

◆ m_param_curlCurv

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

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

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

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

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

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

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

std::vector<CDCTrack> m_tracks
private

Memory for found trajectories.

Definition at line 177 of file AxialLegendreLeafProcessor.h.


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