Belle II Software development
RawTrackCandCleaner.icc.h
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/vxdHoughTracking/findlets/RawTrackCandCleaner.dcl.h>
9#include <tracking/vxdHoughTracking/utilities/SVDHoughTrackingHelpers.h>
10
11#include <framework/core/ModuleParamList.templateDetails.h>
12#include <tracking/spacePointCreation/SpacePointTrackCand.h>
13#include <tracking/vxdHoughTracking/filters/relations/LayerRelationFilter.icc.h>
14#include <tracking/vxdHoughTracking/findlets/SVDHoughTrackingTreeSearcher.icc.h>
15#include <tracking/trackingUtilities/filters/base/ChooseableFilter.icc.h>
16#include <tracking/trackingUtilities/utilities/StringManipulation.h>
17#include <tracking/trackingUtilities/utilities/Algorithms.h>
18#include <vxd/dataobjects/VxdID.h>
19#include <tracking/dbobjects/SVDHoughParameters.h>
20
21namespace Belle2::vxdHoughTracking {
22
23 template<class AHit>
25
26 template<class AHit>
33
34 template<class AHit>
35 void RawTrackCandCleaner<AHit>::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
36 {
37 Super::exposeParameters(moduleParamList, prefix);
38 m_relationCreator.exposeParameters(moduleParamList, prefix);
39 m_treeSearcher.exposeParameters(moduleParamList, prefix);
40 m_resultRefiner.exposeParameters(moduleParamList, prefix);
42 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "maxRelations"), m_maxRelations,
43 "Maximum number of relations allowed for entering tree search.", m_maxRelations);
44 }
45
46 template<class AHit>
48 {
50 }
51
52 template<class AHit>
54 {
55
57
58 if (!m_SVDHoughParameters.isValid()) {
59 B2FATAL("SVDHough - RawTrackCandCleaner: SVDHoughParameter dbobject not found.");
60 } else {
61 m_maxRelations = m_SVDHoughParameters->getMaxRelations();
62 }
63 m_relationCreator.setMaxRelations(m_maxRelations);
64
65 }
66
67 template<class AHit>
68 void RawTrackCandCleaner<AHit>::apply(std::vector<std::vector<AHit*>>& rawTrackCandidates,
69 std::vector<SpacePointTrackCand>& trackCandidates)
70 {
71
72 uint family = 0; // family of the SpacePointTrackCands
73 for (auto& rawTrackCand : rawTrackCandidates) {
74
75 // If the capacity of a std::vector is too large, start with a fresh one, but only do this if the capacity is too big.
76 // Since std::vector.shrink() or std::vector.shrink_to_fit() not necessarily reduce the capacity in the desired way,
77 // create a temporary vector of the same type and swap them to use the vector at the new location afterwards.
78 if (m_relations.capacity() <= c_MaxAllowedVectorSize) {
79 m_relations.clear();
80 } else {
81 checkResizeClear<TrackingUtilities::WeightedRelation<AHit>>(m_relations, c_MaxAllowedVectorSize);
82 }
83 if (m_results.capacity() <= c_MaxAllowedVectorSize) {
84 m_results.clear();
85 } else {
86 checkResizeClear<Result>(m_results, c_MaxAllowedVectorSize);
87 }
89 m_unfilteredResults.clear();
90 } else {
91 checkResizeClear<SpacePointTrackCand>(m_unfilteredResults, c_MaxAllowedVectorSize);
92 }
93 if (m_filteredResults.capacity() <= c_MaxAllowedVectorSize) {
94 m_filteredResults.clear();
95 } else {
96 checkResizeClear<SpacePointTrackCand>(m_filteredResults, c_MaxAllowedVectorSize);
97 }
98
99 m_relationCreator.apply(rawTrackCand, m_relations);
100
101 // The m_relationCreator stops creating relations at m_maxRelations and clears the m_relations vector
102 // This sets the size of m_relations to 0 and there is nothing more to do for this track candidate.
103 if (m_relations.size() == 0) {
104 continue;
105 }
106
107 m_treeSearcher.apply(rawTrackCand, m_relations, m_results);
108
109 m_unfilteredResults.reserve(m_results.size());
110 for (const std::vector<TrackingUtilities::WithWeight<const AHit*>>& result : m_results) {
111 std::vector<const SpacePoint*> spacePointsInResult;
112 spacePointsInResult.reserve(result.size());
113 for (const TrackingUtilities::WithWeight<const AHit*>& hit : result) {
114 spacePointsInResult.emplace_back(hit->getHit());
115 }
116 std::sort(spacePointsInResult.begin(), spacePointsInResult.end(), [](const SpacePoint * a, const SpacePoint * b) {
117 return
118 (a->getVxdID().getLayerNumber() < b->getVxdID().getLayerNumber()) or
119 (a->getVxdID().getLayerNumber() == b->getVxdID().getLayerNumber()
120 and a->getPosition().Perp() < b->getPosition().Perp());
121 });
122 m_unfilteredResults.emplace_back(spacePointsInResult);
123 }
124
125 for (auto aTC : m_unfilteredResults) {
126 aTC.setFamily(family);
127 }
128
130
131 for (const SpacePointTrackCand& trackCand : m_filteredResults) {
132 trackCandidates.emplace_back(trackCand);
133 }
134
135 family++;
136 }
137 }
138
139}
The Module parameter list class.
Storage for (VXD) SpacePoint-based track candidates.
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition SpacePoint.h:42
virtual void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix)
A mixin class to attach a weight to an object.
Definition WithWeight.h:24
SVDHoughTrackingTreeSearcher< AHit, ChooseablePathFilter, Result > m_treeSearcher
perform a tree search using a cellular automaton for all the hits and relations of each raw track can...
void apply(std::vector< std::vector< AHit * > > &rawTrackCandidates, std::vector< SpacePointTrackCand > &trackCandidates) override
Reject bad SpacePointTrackCands and bad hits inside the remaining.
TrackCandidateResultRefiner m_resultRefiner
sort and refine the results for each raw track cand, performing a fit and a basic overlap check
void initialize() override
Create the store arrays.
TrackingUtilities::Findlet< std::vector< AHit * >, SpacePointTrackCand > Super
Parent class.
std::vector< TrackingUtilities::WeightedRelation< AHit > > m_relations
vector containing the relations between the hits in the raw track candidate
std::vector< SpacePointTrackCand > m_unfilteredResults
vector containing unfiltered results, i.e.
void beginRun() override
Check dbobject validity.
RelationCreator< AHit, ChooseableRelationFilter > m_relationCreator
create relations between the hits in each raw track candidate
RawTrackCandCleaner()
Find intercepts in the 2D Hough space.
std::vector< Result > m_results
vector containing track candidates after tree search
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the sub findlets.
std::vector< SpacePointTrackCand > m_filteredResults
vector containing the filtered and pruned results the filtered results of each raw track candidate wi...
static constexpr ushort c_MaxAllowedVectorSize
maximum allowed size of the vectors before resizing
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.