Belle II Software  release-05-02-19
TrackSetEvaluatorHopfieldNNDEVModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2011 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jakob Lettenbichler *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include "tracking/modules/trackSetEvaluatorVXD/TrackSetEvaluatorHopfieldNNDEVModule.h"
12 
13 #include "tracking/trackFindingVXD/trackSetEvaluator/HopfieldNetwork.h"
14 
15 using namespace Belle2;
16 
17 
18 REG_MODULE(TrackSetEvaluatorHopfieldNNDEV)
19 
21 {
22  setDescription("This module expects a container of SpacePointTrackCandidates and an OverlapNetwork\
23  and thenselects a subset of non-overlapping TCs determined using a neural network of Hopfield type.");
24 
25  setPropertyFlags(c_ParallelProcessingCertified);
26 
27  addParam("NameSpacePointTrackCands", m_PARAMtcArrayName, "Sets the name of expected StoreArray with SpacePointTrackCand in it.",
28  std::string(""));
29  addParam("NameOverlapNetworks", m_PARAMtcNetworkName, "Sets the name of expected StoreArray<OverlapNetwork>.",
30  std::string(""));
31  addParam("minActivityState", m_minActivityState, "Sets the minimal value of activity (Neuron Value) for acceptance.",
32  float(0.7));
33 }
34 
35 
37 {
39  //If no SpacePointTrackCands are available, later algorithms may crash.
41  return;
42  }
44 
45  //Prepare the information for the actual HNN.
46  std::vector<OverlapResolverNodeInfo> overlapResolverNodeInfos;
47  overlapResolverNodeInfos.reserve(m_spacePointTrackCands.getEntries());
48 
49  for (const SpacePointTrackCand& sPTC : m_spacePointTrackCands) {
50  overlapResolverNodeInfos.emplace_back(sPTC.getQualityIndicator(), sPTC.getArrayIndex(),
51  m_overlapNetworks[0]->getOverlapForTrackIndex(sPTC.getArrayIndex()), 1.0);
52  }
53 
54  //Performs the actual HNN.
55  //As the parameter is taken as reference, the values are changed and can be reused below.
56  HopfieldNetwork hopfieldNetwork;
57  unsigned maxIterations = 20;
58  if (hopfieldNetwork.doHopfield(overlapResolverNodeInfos, maxIterations) == maxIterations) {
59  B2INFO("Hopfield Network failed converge.");
61  }
62 
63  //Update tcs and kill those which were rejected by the Hopfield algorithm
64  unsigned int nSurvivors = 0;
65  for (const auto& overlapResolverNodeInfo : overlapResolverNodeInfos) {
66  if (overlapResolverNodeInfo.activityState > m_minActivityState) {
67  nSurvivors++;
68  continue;
69  }
70  m_spacePointTrackCands[overlapResolverNodeInfo.trackIndex]->removeRefereeStatus(SpacePointTrackCand::c_isActive);
71  }
72 
73  //Reporting stuff.
74  if (nSurvivors == 0) {
75  B2WARNING("Hopfield network - had no survivors!");
76  }
77 
78  m_nFinalTCs += nSurvivors;
79 }
80 
81 
83 {
84  if (m_eventCounter == 0) { m_eventCounter++; } // prevents division by zero
85  double invEvents = 1. / m_eventCounter;
86 
87  B2INFO("TrackSetEvaluatorHopfieldNNDEVModule-endRun: " <<
88  " nTCs per event: " << float(m_nTCsTotal)*invEvents <<
89  " nFinalTCs per event: " << float(m_nFinalTCs)*invEvents <<
90  "\n nTCs total: " << m_nTCsTotal <<
91  ", nFinalTCs total: " << m_nFinalTCs <<
92  ", number of times Hopfield did not succeed: " << m_nHopfieldFails);
93 
94  //After having evaluated the counters, we reset them to zero.
95  m_eventCounter = 0;
96  m_nTCsTotal = 0;
97  m_nFinalTCs = 0;
98  m_nHopfieldFails = 0;
99 }
Belle2::TrackSetEvaluatorHopfieldNNDEVModule::endRun
void endRun() override final
Report on performance.
Definition: TrackSetEvaluatorHopfieldNNDEVModule.cc:82
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::TrackSetEvaluatorHopfieldNNDEVModule::m_nFinalTCs
unsigned int m_nFinalTCs
number of TCs found for final sets of non-overlapping TCs so far.
Definition: TrackSetEvaluatorHopfieldNNDEVModule.h:101
Belle2::TrackSetEvaluatorHopfieldNNDEVModule::event
void event() override final
Applies the Hopfield neural network algorithm at given sets of SpacePointTrackCandidates.
Definition: TrackSetEvaluatorHopfieldNNDEVModule.cc:36
Belle2::SpacePointTrackCand::c_isActive
@ c_isActive
bit 11: SPTC is active (i.e.
Definition: SpacePointTrackCand.h:94
Belle2::TrackSetEvaluatorHopfieldNNDEVModule::m_eventCounter
unsigned int m_eventCounter
knows current event number.
Definition: TrackSetEvaluatorHopfieldNNDEVModule.h:95
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::TrackSetEvaluatorHopfieldNNDEVModule
The Hopfield algoritm Trackset Evaluator.
Definition: TrackSetEvaluatorHopfieldNNDEVModule.h:55
Belle2::TrackSetEvaluatorHopfieldNNDEVModule::m_minActivityState
float m_minActivityState
************************************** Member variables *********************************************...
Definition: TrackSetEvaluatorHopfieldNNDEVModule.h:86
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::HopfieldNetwork
Hopfield Algorithm with number based inputs.
Definition: HopfieldNetwork.h:46
Belle2::TrackSetEvaluatorHopfieldNNDEVModule::m_nTCsTotal
unsigned int m_nTCsTotal
total number of TCs evaluated so far.
Definition: TrackSetEvaluatorHopfieldNNDEVModule.h:98
Belle2::HopfieldNetwork::doHopfield
unsigned short doHopfield(std::vector< OverlapResolverNodeInfo > &overlapResolverNodeInfos, unsigned short nIterations=20)
Performance of the actual algorithm.
Definition: HopfieldNetwork.cc:21
Belle2::TrackSetEvaluatorHopfieldNNDEVModule::m_overlapNetworks
StoreArray< OverlapNetwork > m_overlapNetworks
access to tcNetwork, which will be produced by this module.
Definition: TrackSetEvaluatorHopfieldNNDEVModule.h:92
Belle2::TrackSetEvaluatorHopfieldNNDEVModule::m_spacePointTrackCands
StoreArray< SpacePointTrackCand > m_spacePointTrackCands
the storeArray for SpacePointTrackCands as member, is faster than recreating link for each event.
Definition: TrackSetEvaluatorHopfieldNNDEVModule.h:89
Belle2::TrackSetEvaluatorHopfieldNNDEVModule::m_nHopfieldFails
unsigned int m_nHopfieldFails
counts number of times when Hopfield was not able to clean overlaps.
Definition: TrackSetEvaluatorHopfieldNNDEVModule.h:104
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226
Belle2::SpacePointTrackCand
Storage for (VXD) SpacePoint-based track candidates.
Definition: SpacePointTrackCand.h:51