Belle II Software development
SPTCSelectorXBestPerFamily.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#pragma once
9
10#include <vector>
11#include <numeric>
12
13#include <tracking/spacePointCreation/SpacePointTrackCand.h>
14#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorBase.h>
15#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorTripletFit.h>
16#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorCircleFit.h>
17#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorRiemannHelixFit.h>
18#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorRandom.h>
19
20
21namespace Belle2 {
30
31 public:
32
38 SPTCSelectorXBestPerFamily(unsigned short xBest = 5, const std::string& estimationMethod = std::string("tripletFit")):
39 m_xBest(xBest)
40 {
41 if (estimationMethod == "tripletFit") {
42 m_estimator = std::make_unique<QualityEstimatorTripletFit>();
43 } else if (estimationMethod == "circleFit") {
44 m_estimator = std::make_unique<QualityEstimatorCircleFit>();
45 } else if (estimationMethod == "helixFit") {
46 m_estimator = std::make_unique<QualityEstimatorRiemannHelixFit>();
47 } else if (estimationMethod == "random") {
48 m_estimator = std::make_unique<QualityEstimatorRandom>();
49 }
50 B2ASSERT("QualityEstimator could not be initialized with method: " << estimationMethod, m_estimator);
51 };
52
55
61 void prepareSelector(unsigned short nFamilies)
62 {
63 m_bestPaths.clear();
64 m_familyToIndex.clear();
65 m_bestPaths.reserve(nFamilies);
66 m_familyToIndex.resize(nFamilies, -1);
67
69 }
70
77 {
78 sptc.setQualityIndicator(m_estimator->estimateQuality(sptc.getSortedHits()));
79 short family = sptc.getFamily();
80
81 if (m_familyToIndex.at(family) == -1) {
82 m_bestPaths.emplace_back(std::multiset<SpacePointTrackCand> { sptc });
85 return;
86 }
87
88 auto& currentSet = m_bestPaths.at(m_familyToIndex[family]);
89
90 if (currentSet.size() == m_xBest) {
91 std::multiset<SpacePointTrackCand>::iterator iter = currentSet.begin();
92 if (sptc.getQualityIndicator() < iter->getQualityIndicator()) {
93 return;
94 }
95 currentSet.erase(iter);
96 }
97 currentSet.emplace_hint(currentSet.cbegin(), sptc);
98 }
99
103 std::vector<SpacePointTrackCand> returnSelection() const
104 {
105 std::vector<SpacePointTrackCand> jointBestPaths;
106 jointBestPaths.reserve(std::accumulate(m_bestPaths.begin(), m_bestPaths.end(), 0,
107 [](int a, auto b) { return a + b.size(); }));
108
109 for (auto&& set : m_bestPaths) {
110 jointBestPaths.insert(jointBestPaths.end(), set.begin(), set.end());
111 }
112
113 return jointBestPaths;
114 }
115
119 void setMagneticFieldForQE(double bFieldZ)
120 {
121 m_estimator->setMagneticFieldStrength(bFieldZ);
122 }
123
124 private:
125
127 std::unique_ptr<QualityEstimatorBase> m_estimator;
128
130 std::vector<std::multiset<SpacePointTrackCand> > m_bestPaths;
131
133 std::vector<short> m_familyToIndex;
134
137 unsigned short m_currentIndex = 0;
138
140 unsigned short m_xBest;
141 };
143}
Algorithm to collect the x best TrackCandidates per family based on a VXD Quality estimator method ou...
std::vector< short > m_familyToIndex
Map of family number to respective index for m_bestPaths.
unsigned short m_xBest
Number of allowed best SPTCs per family.
~SPTCSelectorXBestPerFamily()=default
Destructor.
unsigned short m_currentIndex
Counter for current index used for m_familyToIndex.
void prepareSelector(unsigned short nFamilies)
Preparation of Best Candidate Selector by resetting the vectors.
std::vector< SpacePointTrackCand > returnSelection() const
Return vector containing the best SPTCs; maximal m_xBest per family.
std::unique_ptr< QualityEstimatorBase > m_estimator
Pointer to the Quality Estimator used to evaluate the SPTCs to find the best.
void setMagneticFieldForQE(double bFieldZ)
Setting magnetic field for the quality estimator.
SPTCSelectorXBestPerFamily(unsigned short xBest=5, const std::string &estimationMethod=std::string("tripletFit"))
Constructor for the selection of the x best candidates for each family based on the quality index.
void testNewSPTC(SpacePointTrackCand &sptc)
Test new SPTC if it is better than the least best of the current x best SPTCs of its respective famil...
std::vector< std::multiset< SpacePointTrackCand > > m_bestPaths
Vector containing one vector of the best SPTCs per family.
Storage for (VXD) SpacePoint-based track candidates.
short getFamily() const
return family identifier
double getQualityIndicator() const
returns the current status of the estimated quality of this track candidate.
const std::vector< const Belle2::SpacePoint * > getSortedHits() const
get hits (space points) sorted by their respective sorting parameter
void setQualityIndicator(const double newIndicator)
sets the new status of the estimated quality of this track candidate.
Abstract base class for different kinds of events.