Belle II Software development
TrackFinderVXDCellOMatModule.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#include <framework/geometry/BFieldManager.h>
11
12#include <tracking/modules/vxdtfRedesign/TrackFinderVXDCellOMatModule.h>
13#include <tracking/trackFindingVXD/algorithms/NetworkPathConversion.h>
14#include <tracking/trackFindingVXD/segmentNetwork/NodeNetworkHelperFunctions.h>
15
16
17using namespace Belle2;
18
19REG_MODULE(TrackFinderVXDCellOMat);
20
21
23{
25 setDescription("The TrackFinderVXD Cell-O-Mat module."
26 "\n It uses the output produced by the SegmentNetworkProducerModule to create"
27 "SpacePointTrackCands using a Cellular Automaton algorithm implementation.");
29
30
31 addParam("NetworkName",
33 "name for StoreObjPtr< DirectedNodeNetwork> which contains the networks needed.",
34 std::string(""));
35
36 addParam("SpacePointTrackCandArrayName",
38 "name for StoreArray< SpacePointTrackCand> to be filled.",
39 std::string(""));
40
41 addParam("EventLevelTrackingInfoName",
43 "Name of the EventLevelTrackingInfo that should be used (different one for ROI-finding).",
44 std::string("EventLevelTrackingInfo"));
45
46 addParam("printNetworks",
48 "If true for each event and each network created a file with a graph is created.", bool(false));
49
50 addParam("strictSeeding",
52 "Regulates if every node with enough notes below it is used as a seed or only the outermost nodes.",
53 bool(true));
54
55 addParam("storeSubsets",
57 "Regulates if every subset of sufficient length of a path shall be collected as separate path or not.",
58 bool(false));
59
60 addParam("setFamilies",
62 "Additionally assign a common family identifier to all Tracks that are share a node.",
63 bool(false));
64
65 addParam("selectBestPerFamily",
67 "Select only the best track candidate for each family.",
68 bool(false));
69
70 addParam("xBestPerFamily",
72 "Number of best track candidates to be created per family.",
74
75 addParam("maxFamilies",
77 "Maximal number of families allowed in an event; if exceeded, the event execution will be skipped.",
79
80 addParam("maxPaths",
82 "Maximal number of paths per an event; if exceeded, the event execution will be skipped.",
84}
85
86
88{
91
93 m_sptcSelector = std::make_unique<SPTCSelectorXBestPerFamily>(m_PARAMxBestPerFamily);
94 }
95
97}
98
99
101{
103 // BField is required by all QualityEstimators
104 double bFieldZ = BFieldManager::getFieldInTesla({0, 0, 0}).Z();
105 m_sptcSelector->setMagneticFieldForQE(bFieldZ);
106 }
107}
108
109
111{
113
115
117 int nRounds = m_cellularAutomaton.apply(segmentNetwork);
118 if (nRounds < 0) {
119 B2ERROR("Cellular Automaton failed, skipping event!");
120 return;
121 }
122
124 std::string fileName = m_PARAMNetworkName + "_CA_Ev" + std::to_string(m_eventCounter);
125 DNN::printCANetwork<Segment< Belle2::TrackNode>>(segmentNetwork, fileName);
126 }
127
129 unsigned int nSeeds = m_cellularAutomaton.findSeeds(segmentNetwork, m_PARAMstrictSeeding);
130 if (nSeeds == 0) {
131 return;
132 }
133
135 if (m_PARAMsetFamilies) {
136 unsigned short nFamilies = m_familyDefiner.defineFamilies(segmentNetwork);
137 if (nFamilies > m_PARAMmaxFamilies) {
138 B2WARNING("Maximal number of track candidates per event was exceeded: Number of Families = " << nFamilies);
139 m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
140 return;
141 }
142 m_sptcSelector->prepareSelector(nFamilies);
143 }
144
146 m_collectedPaths.clear();
147 if (not m_pathCollector.findPaths(segmentNetwork, m_collectedPaths, m_PARAMmaxPaths, m_PARAMstoreSubsets)) {
148 B2WARNING("Received signal to skip the event and not processing it.");
149 m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
151 return;
152 }
153
155
158 for (auto& aPath : m_collectedPaths) {
160
162 m_sptcSelector->testNewSPTC(sptc);
163 } else {
164 std::vector<const SpacePoint*> path = sptc.getHits();
165 m_sptcCreator.createSPTC(m_TCs, path, sptc.getFamily());
166 }
167 }
168
171 std::vector<SpacePointTrackCand> bestPaths = m_sptcSelector->returnSelection();
172 for (unsigned short iCand = 0; iCand < bestPaths.size(); iCand++) {
173 SpacePointTrackCand cand = bestPaths.at(iCand);
174 std::vector<const SpacePoint*> path = cand.getHits();
175 m_sptcCreator.createSPTC(m_TCs, path, cand.getFamily());
176 }
177 }
178}
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.
unsigned int m_eventCounter
Event number counter.
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...
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.
std::string m_PARAMSpacePointTrackCandArrayName
module parameters
bool m_PARAMstrictSeeding
Regulates if every node with enough notes below it is used as a seed or only the outermost nodes.
PathCollectorRecursive< NodeNetworkType, NodeType, Path, Belle2::NodeCompatibilityCheckerPathCollector< NodeType > > m_pathCollector
Algorithm for finding paths of segments.
unsigned short m_PARAMxBestPerFamily
Maximal number of best candidates to be created per family.
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.