Belle II Software development
TrackFinderVXDBasicPathFinderModule.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 <framework/logging/Logger.h>
10
11#include <framework/geometry/BFieldManager.h>
12
13#include <tracking/modules/vxdtfRedesign/TrackFinderVXDBasicPathFinderModule.h>
14#include <tracking/trackFindingVXD/algorithms/NetworkPathConversion.h>
15#include <tracking/trackFindingVXD/segmentNetwork/NodeNetworkHelperFunctions.h>
16
17
18using namespace Belle2;
19
20REG_MODULE(TrackFinderVXDBasicPathFinder);
21
22
24{
25 //Set module properties
26 setDescription("The TrackFinderVXD BasicPathFinder module."
27 "\n It uses the output produced by the SegmentNetworkProducerModule to create"
28 "SpacePointTrackCands by simply storing all possible paths stored in the SegmentNetwork.");
30
31
32 addParam("NetworkName",
34 "name for StoreObjPtr< DirectedNodeNetwork> which contains the networks needed.",
35 std::string(""));
36
37 addParam("EventLevelTrackingInfoName",
39 "Name of the EventLevelTrackingInfo that should be used (different one for ROI-finding).",
40 std::string("EventLevelTrackingInfo"));
41
42 addParam("SpacePointTrackCandArrayName",
44 "name for StoreArray< SpacePointTrackCand> to be filled.",
45 std::string(""));
46
47 addParam("printNetworks",
49 "If true for each event and each network created a file with a graph is created.", bool(false));
50
51 addParam("strictSeeding",
53 "Regulates if every node with enough notes below it is used as a seed or only the outermost nodes.",
54 bool(true));
55
56 addParam("storeSubsets",
58 "Regulates if every subset of sufficient length of a path shall be collected as separate path or not.",
59 bool(false));
60
61 addParam("setFamilies",
63 "Additionally assign a common family identifier to all Tracks that are share a node.",
64 bool(false));
65
66 addParam("selectBestPerFamily",
68 "Select only the best track candidates for each family.",
69 bool(false));
70
71 addParam("xBestPerFamily",
73 "Number of best track candidates to be created per family.",
75
76 addParam("maxFamilies",
78 "Maximal number of families allowed in an event; if exceeded, the event execution will be skipped.",
80
81 addParam("maxPaths",
83 "Maximal number of paths per an event; if exceeded, the event execution will be skipped.",
85}
86
87
89{
92
94 m_sptcSelector = std::make_unique<SPTCSelectorXBestPerFamily>(m_PARAMxBestPerFamily);
95 }
96
98}
99
100
102{
104 // BField is required by all QualityEstimators
105 double bFieldZ = BFieldManager::getFieldInTesla({0, 0, 0}).Z();
106 m_sptcSelector->setMagneticFieldForQE(bFieldZ);
107 }
108}
109
110
112{
114
116
118 std::string fileName = m_PARAMsecMapName + "_BasicPF_Ev" + std::to_string(m_eventCounter);
119 DNN::printCANetwork<Segment< Belle2::TrackNode>>(segmentNetwork, fileName);
120 }
121
123 int nRounds = m_cellularAutomaton.apply(segmentNetwork);
124 if (nRounds < 0) {
125 B2WARNING("Basic Path Finder failed, skipping event!");
126 m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
127 return;
128 }
129
131 unsigned int nSeeds = 0;
132 for (auto* aNode : segmentNetwork) {
133 if (m_PARAMstrictSeeding && !(aNode->getOuterNodes().empty())) {
134 continue;
135 }
136 if (aNode->getInnerNodes().empty()) {
137 continue;
138 }
139
140 // Mark as seed, if node has got an inner node.
141 aNode->getMetaInfo().setSeed(true);
142 nSeeds++;
143 }
144
145 if (nSeeds == 0) {
146 B2WARNING("In Event: " << m_eventCounter << " no seed could be found -> no TCs created!");
147 return;
148 }
149
151 if (m_PARAMsetFamilies) {
152 unsigned short nFamilies = m_familyDefiner.defineFamilies(segmentNetwork);
153 B2DEBUG(20, "Number of families in the network: " << nFamilies);
154 if (nFamilies > m_PARAMmaxFamilies) {
155 B2WARNING("Maximal number of track candidates per event was exceeded: " << LogVar(" Number of Families", nFamilies)
156 << LogVar("Max number of families", m_PARAMmaxFamilies));
157 m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
158 return;
159 }
160 m_sptcSelector->prepareSelector(nFamilies);
161 }
163 m_collectedPaths.clear();
164 if (not m_pathCollector.findPaths(segmentNetwork, m_collectedPaths, m_PARAMmaxPaths, m_PARAMstoreSubsets)) {
165 B2WARNING("VXDBasicPathFinder got signal to abort the event.");
166 m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
168 return;
169 }
170
172
175 for (auto& aPath : m_collectedPaths) {
177
179 m_sptcSelector->testNewSPTC(sptc);
180 } else {
181 std::vector<const SpacePoint*> path = sptc.getHits();
182 m_sptcCreator.createSPTC(m_TCs, path, sptc.getFamily());
183 }
184 }
185
188 std::vector<SpacePointTrackCand> bestPaths = m_sptcSelector->returnSelection();
189 for (unsigned short iCand = 0; iCand < bestPaths.size(); iCand++) {
190 SpacePointTrackCand cand = bestPaths.at(iCand);
191 std::vector<const SpacePoint*> path = cand.getHits();
192 m_sptcCreator.createSPTC(m_TCs, path, cand.getFamily());
193 }
194 }
195}
static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector &pos)
return the magnetic field at a given position in Tesla.
Definition: BFieldManager.h:61
The CACell class This Class stores all relevant information one wants to have stored in a cell for a ...
Definition: CACell.h:20
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:71
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:72
DirectedNodeNetwork< Belle2::Segment< Belle2::TrackNode >, Belle2::CACell > & accessSegmentNetwork()
Returns reference to the SegmentNetwork stored in this container, intended for read and write access.
void set_collectedPaths(int in)
Sets number of paths found.
Network of directed nodes of the type EntryType.
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
Storage for (VXD) SpacePoint-based track candidates.
short getFamily() const
return family identifier
const std::vector< const Belle2::SpacePoint * > & getHits() const
get hits (space points) of track candidate
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
SpacePointTrackCandCreator< StoreArray< Belle2::SpacePointTrackCand > > m_sptcCreator
Tool for creating SPTCs, which fills storeArray directly.
bool m_PARAMprintNetworks
If true for each event and each network created a file with a graph is created.
PathCollectorRecursive< NodeNetworkType, NodeType, Path, Belle2::NodeCompatibilityCheckerBase< NodeType > > m_pathCollector
Algorithm for finding paths of segments.
std::unique_ptr< SPTCSelectorXBestPerFamily > m_sptcSelector
Pointer to SPTC selector class which performs the x best candidate selection.
StoreObjPtr< EventLevelTrackingInfo > m_eventLevelTrackingInfo
Access to the EventLevelTrackingInfo object in the datastore.
std::string m_PARAMEventLevelTrackingInfoName
Name of the EventLevelTrackingInfo that should be used (different one for ROI-finding)
CellularAutomaton< NodeNetworkType, Belle2::CAValidator< Belle2::CACell > > m_cellularAutomaton
member variables
StoreArray< Belle2::SpacePointTrackCand > m_TCs
output containers
StoreObjPtr< Belle2::DirectedNodeNetworkContainer > m_network
input containers
unsigned short m_PARAMmaxFamilies
Maximal number of families in event; if exceeded, the execution of the trackfinder will be stopped.
NodeFamilyDefiner< NodeNetworkType, NodeType, Path > m_familyDefiner
Class to evaluate connected nodes, in this case for the directed node network, and assigns a family t...
std::string m_PARAMsecMapName
the name of the SectorMap used for this instance.
bool m_PARAMsetFamilies
If true additionally assign a common family identifier to all Tracks that are share a node.
std::vector< Path > m_collectedPaths
Path collection obtained from evaluation of the provided segment network.
bool m_PARAMstoreSubsets
Regulates if every subset of sufficient length of a path shall be collected as separate path or not.
unsigned int m_PARAMmaxPaths
Maximal number of paths per event; if exceeded, the execution of the trackfinder will be stopped.
std::string m_PARAMNetworkName
name for StoreObjPtr<DirectedNodeNetwork> which contains the networks needed
bool m_PARAMselectBestPerFamily
If true create track candidate only for the best candidate of a family.
bool m_PARAMstrictSeeding
Regulates if every node with enough nodes below it is used as a seed or only the outermost nodes.
unsigned short m_PARAMxBestPerFamily
Maximal number of best candidates to be created per family.
Class to store variables with their name which were sent to the logging service.
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
SpacePointTrackCand convertNetworkPath(NetworkPath networkPath)
Create new SPTC from network path.
Abstract base class for different kinds of events.