Belle II Software  release-06-01-15
TrackCandidateResultRefiner.cc
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/TrackCandidateResultRefiner.h>
9 #include <framework/core/ModuleParamList.h>
10 #include <framework/core/ModuleParamList.templateDetails.h>
11 #include <framework/geometry/BFieldManager.h>
12 #include <tracking/spacePointCreation/SpacePointTrackCand.h>
13 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorCircleFit.h>
14 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorMC.h>
15 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorRiemannHelixFit.h>
16 #include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorTripletFit.h>
17 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
18 
19 using namespace Belle2;
20 using namespace TrackFindingCDC;
21 using namespace vxdHoughTracking;
22 
23 TrackCandidateResultRefiner::~TrackCandidateResultRefiner() = default;
24 
25 
26 TrackCandidateResultRefiner::TrackCandidateResultRefiner() : Super()
27 {
29 }
30 
31 void TrackCandidateResultRefiner::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
32 {
33  Super::exposeParameters(moduleParamList, prefix);
34 
35  m_overlapResolver.exposeParameters(moduleParamList, TrackFindingCDC::prefixed(prefix, "refinerOverlapResolver"));
36 
37  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "trackQualityEstimationMethod"), m_param_EstimationMethod,
38  "Identifier which estimation method to use. Valid identifiers are: [mcInfo, circleFit, tripletFit, helixFit]",
40  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "MCRecoTracksStoreArrayName"), m_param_MCRecoTracksStoreArrayName,
41  "Only required for MCInfo method. Name of StoreArray containing MCRecoTracks.",
43  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "MCStrictQualityEstimator"), m_param_MCStrictQualityEstimator,
44  "Only required for MCInfo method. If false combining several MCTracks is allowed.",
46 
47  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "minQualitiyIndicatorSize3"), m_param_minQualitiyIndicatorSize3,
48  "Cut on quality indicator value for track candidates of size 3. Only accept SpacePointTrackCands with QI above this value.",
50  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "minQualitiyIndicatorSize4"), m_param_minQualitiyIndicatorSize4,
51  "Cut on quality indicator value for track candidates of size 4. Only accept SpacePointTrackCands with QI above this value.",
53  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "minQualitiyIndicatorSize5"), m_param_minQualitiyIndicatorSize5,
54  "Cut on quality indicator value for track candidates of size 5. Only accept SpacePointTrackCands with QI above this value.",
56 
57  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "maxNumberOfEachPathLength"), m_param_maxNumberOfEachPathLength,
58  "Maximum number of SpacePointTrackCands with a length of 3, 4, 5, or 6 each.",
60 }
61 
63 {
65 
66  // create pointer to chosen estimator
67  if (m_param_EstimationMethod == "mcInfo") {
69  } else if (m_param_EstimationMethod == "tripletFit") {
70  m_estimator = std::make_unique<QualityEstimatorTripletFit>();
71  } else if (m_param_EstimationMethod == "circleFit") {
72  m_estimator = std::make_unique<QualityEstimatorCircleFit>();
73  } else if (m_param_EstimationMethod == "helixFit") {
74  m_estimator = std::make_unique<QualityEstimatorRiemannHelixFit>();
75  }
76  B2ASSERT("QualityEstimator could not be initialized with method: " << m_param_EstimationMethod, m_estimator);
77 }
78 
80 {
82 
83  // BField is required by all QualityEstimators
84  double bFieldZ = BFieldManager::getField(0, 0, 0).Z() / Unit::T;
85  m_estimator->setMagneticFieldStrength(bFieldZ);
86 
87  if (m_param_EstimationMethod == "mcInfo") {
88  StoreArray<RecoTrack> mcRecoTracks;
90  std::string svdClustersName = ""; std::string pxdClustersName = "";
91 
92  if (mcRecoTracks.getEntries() > 0) {
93  svdClustersName = mcRecoTracks[0]->getStoreArrayNameOfSVDHits();
94  pxdClustersName = mcRecoTracks[0]->getStoreArrayNameOfPXDHits();
95  } else {
96  B2WARNING("No Entries in mcRecoTracksStoreArray: using empty cluster name for svd and pxd");
97  }
98 
99  QualityEstimatorMC* MCestimator = static_cast<QualityEstimatorMC*>(m_estimator.get());
100  MCestimator->setClustersNames(svdClustersName, pxdClustersName);
101  }
102 }
103 
104 void TrackCandidateResultRefiner::apply(std::vector<SpacePointTrackCand>& unrefinedResults,
105  std::vector<SpacePointTrackCand>& refinedResults)
106 {
107  refinedResults.clear();
108  std::vector<SpacePointTrackCand> selectedResults;
109  selectedResults.reserve(unrefinedResults.size());
110  // assign a QI computed using the selected QualityEstimator for each given SpacePointTrackCand
111  for (SpacePointTrackCand& aTrackCandidate : unrefinedResults) {
112  double qi = m_estimator->estimateQuality(aTrackCandidate.getSortedHits());
113  aTrackCandidate.setQualityIndicator(qi);
114 
115  // Track candidates of size >= 6 are very rare. If the track candidate already is quite long (>= 6 hits),
116  // it's very likely it's a valid track anyway, so QI is not checked.
117  if ((aTrackCandidate.getNHits() == 3 and qi >= m_param_minQualitiyIndicatorSize3) or
118  (aTrackCandidate.getNHits() == 4 and qi >= m_param_minQualitiyIndicatorSize4) or
119  (aTrackCandidate.getNHits() == 5 and qi >= m_param_minQualitiyIndicatorSize5) or
120  (aTrackCandidate.getNHits() >= 6)) {
121  selectedResults.emplace_back(aTrackCandidate);
122  }
123  }
124 
125  // return early if nothing to do
126  if (selectedResults.size() <= 1) {
127  std::swap(selectedResults, refinedResults);
128  return;
129  }
130 
131  // sort by number of hits in the track candidate and by the QI
132  std::sort(selectedResults.begin(), selectedResults.end(),
133  [](const SpacePointTrackCand & a, const SpacePointTrackCand & b) {
134  return ((a.getNHits() > b.getNHits()) or
135  (a.getNHits() == b.getNHits() and a.getQualityIndicator() > b.getQualityIndicator()));
136  });
137 
138  std::array<uint, 8> numberOfHitsInCheckedSPTCs{{0, 0, 0, 0, 0, 0, 0, 0}};
139  refinedResults.reserve(selectedResults.size());
140  for (auto& currentSPTC : selectedResults) {
141  if (numberOfHitsInCheckedSPTCs[currentSPTC.size()] < m_param_maxNumberOfEachPathLength) {
142  numberOfHitsInCheckedSPTCs[currentSPTC.size()] += 1;
143  refinedResults.emplace_back(currentSPTC);
144  }
145  }
146 
147  m_overlapResolver.apply(refinedResults);
148 }
The Module parameter list class.
Class implementing the algorithm used for the MC based quality estimation.
void setClustersNames(const std::string &svdClustersName, const std::string &pxdClustersName)
Setter for StoreArray names of SVD and PXD clusters.
Storage for (VXD) SpacePoint-based track candidates.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
void initialize() override
Receive and dispatch signal before the start of the event processing.
void beginRun() override
Receive and dispatch signal for the beginning of a new run.
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
virtual void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix)
Forward prefixed parameters of this findlet to the module parameter list.
Definition: Findlet.h:69
Interface for an algorithm part that needs to receive the module processing signals.
static const double T
[tesla]
Definition: Unit.h:120
void apply(std::vector< SpacePointTrackCand > &spacePointTrackCandsToResolve) override
Reject bad SpacePointTrackCands and bad hits inside the remaining.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the sub findlets.
double m_param_minQualitiyIndicatorSize5
Cut on the quality estimator and only further propagate SPTCs with five hits that are above this valu...
std::string m_param_EstimationMethod
Identifier which estimation method to use.
bool m_param_MCStrictQualityEstimator
Only required for MCInfo method.
double m_param_minQualitiyIndicatorSize4
Cut on the quality estimator and only further propagate SPTCs with four hits that are above this valu...
double m_param_minQualitiyIndicatorSize3
Cut on the quality estimator and only further propagate SPTCs with three hits that are above this val...
void apply(std::vector< SpacePointTrackCand > &unrefinedResults, std::vector< SpacePointTrackCand > &refinedResults) override
Reject bad SpacePointTrackCands and bad hits inside the remaining.
void beginRun() override
End run and write Root file.
TrackCandidateOverlapResolver m_overlapResolver
Resolve hit overlaps in track candidates.
std::string m_param_MCRecoTracksStoreArrayName
sets the name of the expected StoreArray containing MCRecoTracks. Only required for MCInfo method
std::unique_ptr< QualityEstimatorBase > m_estimator
pointer to the selected QualityEstimator
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the sub findlets.
uint m_param_maxNumberOfEachPathLength
Accept nHits for each size at maximum.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Abstract base class for different kinds of events.