Belle II Software prerelease-11-00-00a
TrackCandidateOverlapResolver.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/TrackCandidateOverlapResolver.h>
9#include <framework/core/ModuleParamList.h>
10#include <tracking/spacePointCreation/SpacePointTrackCand.h>
11#include <tracking/spacePointCreation/SpacePoint.h>
12#include <tracking/trackFindingVXD/trackSetEvaluator/OverlapMatrixCreator.h>
13#include <tracking/trackFindingVXD/trackSetEvaluator/HopfieldNetwork.h>
14#include <tracking/trackFindingVXD/trackSetEvaluator/Scrooge.h>
15#include <tracking/trackFindingVXD/trackSetEvaluator/OverlapResolverNodeInfo.h>
16#include <tracking/trackingUtilities/utilities/StringManipulation.h>
17#include <tracking/dbobjects/SVDHoughParameters.h>
18#include <svd/dataobjects/SVDCluster.h>
19
20using namespace Belle2;
21using namespace TrackingUtilities;
22using namespace vxdHoughTracking;
23
25
26
30
31void TrackCandidateOverlapResolver::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
32{
33 Super::exposeParameters(moduleParamList, prefix);
34
35 m_prefix = prefix;
36
37 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "ResolveMethod"), m_resolveMethod,
38 "Strategy used to resolve overlaps. Currently implemented are \"greedy\" and \"hopfield\".",
40 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "NameSVDClusters"), m_nameSVDClusters,
41 "Name of expected SVDClusters StoreArray.", m_nameSVDClusters);
42
43 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "minActivityState"), m_minActivityState,
44 "Sets the minimal value of activity for acceptance. [0,1]", m_minActivityState);
45}
46
47
49{
51
53
54 B2ASSERT("ResolveMethod has to be either 'greedy' or 'hopfield'. Selected ResolveMethod: " << m_resolveMethod,
55 m_resolveMethod == "greedy" || m_resolveMethod == "hopfield");
56
57}
58
60{
61 if (!m_SVDHoughParameters.isValid()) {
62 B2FATAL("SVDHough - TrackCandidateOverlapResolver: SVDHoughParameter dbobject not found, using default parameters.");
63 } else {
64 if (m_prefix == "finalOverlapResolver") {
65 m_minActivityState = m_SVDHoughParameters->getFinalOverlapResolverMinActivityState();
66 } else if (m_prefix == "refinerOverlapResolver") {
67 m_minActivityState = m_SVDHoughParameters->getRefinerOverlapResolverMinActivityState();
68 }
69 }
70}
71
72void TrackCandidateOverlapResolver::apply(std::vector<SpacePointTrackCand>& spacePointTrackCandsToResolve)
73{
74 //Create matrix[svdCluster][track]
75 unsigned short nHits = m_svdClusters.getEntries();
76
77 //Create subset of active Candidates
78 std::vector<SpacePointTrackCand*> activeCandidates;
79 auto requiredSpace = spacePointTrackCandsToResolve.size();
80 activeCandidates.reserve(requiredSpace);
81 for (SpacePointTrackCand& sptc : spacePointTrackCandsToResolve) {
82 if (sptc.hasRefereeStatus(SpacePointTrackCand::c_isActive)) activeCandidates.push_back(&sptc);
83 }
84 unsigned short const nActiveCandidates = activeCandidates.size();
85 if (nActiveCandidates < 2) {
86 B2DEBUG(29, "Less than 2 active SPTC. No reason to do SVDOverlapResolver!");
87 return;
88 }
89
90 //now fill the cluster/track matrix:
91 std::vector<std::vector<unsigned short> > svdHitRelatedTracks(nHits);
92 //TODO: Check if one saves time by reserving some space for each single of those vectors;
93 for (unsigned short iCand = 0; iCand < nActiveCandidates; ++iCand) {
94
95 for (const SpacePoint* spacePointPointer : activeCandidates.at(iCand)->getHits()) {
96 //only SVD is handled with this algorithm
97 if (spacePointPointer->getType() != VXD::SensorInfoBase::SensorType::SVD) continue;
98
99 //at the position of the svdCluster Index, the track index is pushed back;
100 RelationVector<SVDCluster> svdClusterRelations = spacePointPointer->getRelationsTo<SVDCluster>(m_nameSVDClusters);
101 for (SVDCluster const& svdClusterPointer : svdClusterRelations) {
102 svdHitRelatedTracks[svdClusterPointer.getArrayIndex()].push_back(iCand);
103 }
104 }
105 }
106
107 //Create the overlap matrix and store it into the OverlapNetwork
108 OverlapMatrixCreator overlapMatrixCreator(svdHitRelatedTracks, nActiveCandidates);
109 auto overlapMatrix = overlapMatrixCreator.getOverlapMatrix();
110
111 //Resolve overlap
112 //Create an empty object of the type,
113 //that needs to be given to Scrooge.
114 std::vector<OverlapResolverNodeInfo> qiTrackOverlap;
115 qiTrackOverlap.reserve(nActiveCandidates);
116
117 //fill this object with the necessary information:
118 for (unsigned short iCand = 0; iCand < nActiveCandidates; ++iCand) {
119 qiTrackOverlap.emplace_back(
120 activeCandidates[iCand]->getQualityIndicator(),
121 iCand,
122 overlapMatrix.at(iCand),
123 1);
124 }
125
126 if (m_resolveMethod == "greedy") {
127 //make a Scrooge and update the activity
128 Scrooge scrooge;
129 scrooge.performSelection(qiTrackOverlap);
130
131 } else if (m_resolveMethod == "hopfield") {
132 //Performs the actual HNN.
133 //As the parameter is taken as reference, the values are changed and can be reused below.
134 HopfieldNetwork hopfieldNetwork;
135 unsigned maxIterations = 20;
136 if (hopfieldNetwork.doHopfield(qiTrackOverlap, maxIterations) == maxIterations) {
137 B2WARNING("Hopfield Network failed converge.");
138 }
139 }
140
141 for (auto&& track : qiTrackOverlap) {
142 if (track.activityState < m_minActivityState) {
143 activeCandidates[track.trackIndex]->removeRefereeStatus(SpacePointTrackCand::c_isActive);
144 }
145 }
146}
Hopfield Algorithm with number based inputs.
unsigned short doHopfield(std::vector< OverlapResolverNodeInfo > &overlapResolverNodeInfos, unsigned short nIterations=20)
Performance of the actual algorithm.
The Module parameter list class.
Creates a vector of vectors, that knows which track is conflicting with which other.
std::vector< std::vector< unsigned short > > getOverlapMatrix(unsigned allowedOverlaps=0)
Fills and returns the overlap matrix.
Class for type safe access to objects that are referred to in relations.
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition SVDCluster.h:29
Executes greedy algorithm for vector of QITrackOverlap structs.
Definition Scrooge.h:26
void performSelection(std::vector< OverlapResolverNodeInfo > &overlapResolverNodeInfo)
Sets the isActive flag in m_qiTrackOverlap to false, for killed tracks.
Definition Scrooge.h:33
Storage for (VXD) SpacePoint-based track candidates.
@ c_isActive
bit 11: SPTC is active (i.e.
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition SpacePoint.h:42
virtual void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix)
TrackingUtilities::Findlet< SpacePointTrackCand > Super
Parent class.
void apply(std::vector< SpacePointTrackCand > &spacePointTrackCandsToResolve) override
Reject bad SpacePointTrackCands and bad hits inside the remaining.
StoreArray< SVDCluster > m_svdClusters
Stay connected to the DataStore for timing improvement.
std::string m_prefix
parameters prefix (finalOverlapResolver, refinerOverlapResolver)
DBObjPtr< SVDHoughParameters > m_SVDHoughParameters
DB object containing the SVDHough parameters.
std::string m_resolveMethod
Strategy used to resolve overlaps.
double m_minActivityState
Minimum of activityState of candidate required to be accepted by the algorithm.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the sub findlets.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.