Belle II Software development
SVDOverlapResolverModule.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
9#include <tracking/modules/trackSetEvaluatorVXD/SVDOverlapResolverModule.h>
10
11#include <framework/logging/Logger.h>
12
13
14#include <tracking/spacePointCreation/SpacePoint.h>
15
16#include <tracking/trackFindingVXD/trackSetEvaluator/OverlapMatrixCreator.h>
17#include <tracking/trackFindingVXD/trackSetEvaluator/HopfieldNetwork.h>
18#include <tracking/trackFindingVXD/trackSetEvaluator/Scrooge.h>
19#include <tracking/trackFindingVXD/trackSetEvaluator/OverlapResolverNodeInfo.h>
20
21#include <vxd/geometry/SensorInfoBase.h>
22
23#include <vector>
24
25using namespace Belle2;
26
27REG_MODULE(SVDOverlapResolver);
28
30{
31 setDescription("Module checks for overlaps of SpacePointTrackCands");
33
34 addParam("NameSpacePointTrackCands", m_nameSpacePointTrackCands, "Name of expected StoreArray.", std::string(""));
35
36 addParam("NameSVDClusters", m_nameSVDClusters, "Name of expected StoreArray.", std::string(""));
37
38 addParam("ResolveMethod", m_resolveMethod, "Strategy used to resolve overlaps. Currently implemented are \"greedy\" and "
39 " \"hopfield\" ", std::string("greedy"));
40
41 addParam("minActivityState", m_minActivityState, "Sets the minimal value of activity for acceptance. (0,1)",
42 float(0.7));
43}
44
45
47{
50
51 B2ASSERT("ResolveMethod has to be either 'greedy' or 'hopfield'. Selected ResolveMethod: " << m_resolveMethod,
52 m_resolveMethod == "greedy" || m_resolveMethod == "hopfield");
53}
54
56{
57
58 //Create matrix[svdCluster][track]
59 unsigned short nHits = m_svdClusters.getEntries();
60
61 //Create subset of active Candidates
62 std::vector<SpacePointTrackCand*> activeCandidates;
63 auto requiredSpace = m_spacePointTrackCands.getEntries();
65 requiredSpace = m_estimatedActiveCandidates;
66 }
67 activeCandidates.reserve(requiredSpace);
69 if (sptc.hasRefereeStatus(SpacePointTrackCand::c_isActive)) activeCandidates.push_back(&sptc);
70 }
71 unsigned short const nActiveCandidates = activeCandidates.size();
72 if (nActiveCandidates < 2) {
73 B2DEBUG(29, "Less than 2 active SPTC. No reason to do SVDOverlapResolver!");
74 return;
75 }
76
77 //now fill the cluster/track matrix:
78 std::vector<std::vector<unsigned short> > svdHitRelatedTracks(nHits);
79 //TODO: Check if one saves time by reserving some space for each single of those vectors;
80 for (unsigned short iCand = 0; iCand < nActiveCandidates; ++iCand) {
81
82 for (const SpacePoint* spacePointPointer : activeCandidates.at(iCand)->getHits()) {
83 //only SVD is handled with this algorithm
84 if (spacePointPointer->getType() != VXD::SensorInfoBase::SensorType::SVD) continue;
85
86 //at the position of the svdCluster Index, the track index is pushed back;
87 RelationVector<SVDCluster> svdClusterRelations = spacePointPointer->getRelationsTo<SVDCluster>(m_nameSVDClusters);
88 for (SVDCluster const& svdClusterPointer : svdClusterRelations) {
89 svdHitRelatedTracks[svdClusterPointer.getArrayIndex()].push_back(iCand);
90 }
91 }
92 }
93
94 //Create the overlap matrix and store it into the OverlapNetwork
95 OverlapMatrixCreator overlapMatrixCreator(svdHitRelatedTracks, nActiveCandidates);
96 auto overlapMatrix = overlapMatrixCreator.getOverlapMatrix();
97
98 //Resolve overlap
99 //Create an empty object of the type,
100 //that needs to be given to Scrooge.
101 std::vector<OverlapResolverNodeInfo> qiTrackOverlap;
102 qiTrackOverlap.reserve(nActiveCandidates);
103
104 //fill this object with the necessary information:
105 for (unsigned short iCand = 0; iCand < nActiveCandidates; ++iCand) {
106 qiTrackOverlap.emplace_back(
107 activeCandidates[iCand]->getQualityIndicator(),
108 iCand,
109 overlapMatrix.at(iCand),
110 1);
111 }
112
113 if (m_resolveMethod == "greedy") {
114 //make a Scrooge and udpate the activity
115 Scrooge scrooge;
116 scrooge.performSelection(qiTrackOverlap);
117
118 } else if (m_resolveMethod == "hopfield") {
119 //Performs the actual HNN.
120 //As the parameter is taken as reference, the values are changed and can be reused below.
121 HopfieldNetwork hopfieldNetwork;
122 unsigned maxIterations = 20;
123 if (hopfieldNetwork.doHopfield(qiTrackOverlap, maxIterations) == maxIterations) {
124 B2WARNING("Hopfield Network failed converge.");
125 }
126 }
127
128 for (auto&& track : qiTrackOverlap) {
129 if (track.activityState < m_minActivityState) {
130 activeCandidates[track.trackIndex]->removeRefereeStatus(SpacePointTrackCand::c_isActive);
131 }
132 }
133}
Hopfield Algorithm with number based inputs.
unsigned short doHopfield(std::vector< OverlapResolverNodeInfo > &overlapResolverNodeInfos, unsigned short nIterations=20)
Performance of the actual algorithm.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
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
void initialize() override final
State requirements of SpacePointTrackCands, SVDClusters, registers OverlapNetworks.
float m_minActivityState
Minimum of activityState of candidate required to be accepted by the algorithm.
StoreArray< SVDCluster > m_svdClusters
Stay connected to the DataStore for timing improvement.
std::string m_resolveMethod
Strategy used to resolve overlaps.
SVDOverlapResolverModule()
Constructor of the module.
void event() override final
Checks for overlaps and fills the OverlapNetwork.
unsigned short m_estimatedActiveCandidates
Estimated amount of active candidates used to reserve enough space.
std::string m_nameSVDClusters
Name of array of SVDCluster.
StoreArray< SpacePointTrackCand > m_spacePointTrackCands
Stay connected to the DataStore for timing improvement.
std::string m_nameSpacePointTrackCands
Name of array of SpacePointTrackCand.
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
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.