Belle II Software  release-06-02-00
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 
18 using namespace std;
19 using namespace Belle2;
20 
21 REG_MODULE(TrackFinderVXDBasicPathFinder)
22 
23 
25 {
26  //Set module properties
27  setDescription("The TrackFinderVXD BasicPathFinder module."
28  "\n It uses the output produced by the SegmentNetworkProducerModule to create"
29  "SpacePointTrackCands by simply storing all possible paths stored in the SegmentNetwork.");
30  setPropertyFlags(c_ParallelProcessingCertified);
31 
32 
33  addParam("NetworkName",
34  m_PARAMNetworkName,
35  "name for StoreObjPtr< DirectedNodeNetwork> which contains the networks needed.",
36  string(""));
37 
38  addParam("EventLevelTrackingInfoName",
39  m_PARAMEventLevelTrackingInfoName,
40  "Name of the EventLevelTrackingInfo that should be used (different one for ROI-finding).",
41  string("EventLevelTrackingInfo"));
42 
43  addParam("SpacePointTrackCandArrayName",
44  m_PARAMSpacePointTrackCandArrayName,
45  "name for StoreArray< SpacePointTrackCand> to be filled.",
46  string(""));
47 
48  addParam("printNetworks",
49  m_PARAMprintNetworks,
50  "If true for each event and each network created a file with a graph is created.", bool(false));
51 
52  addParam("strictSeeding",
53  m_PARAMstrictSeeding,
54  "Regulates if every node with enough notes below it is used as a seed or only the outermost nodes.",
55  bool(true));
56 
57  addParam("storeSubsets",
58  m_PARAMstoreSubsets,
59  "Regulates if every subset of sufficient length of a path shall be collected as separate path or not.",
60  bool(false));
61 
62  addParam("setFamilies",
63  m_PARAMsetFamilies,
64  "Additionally assign a common family identifier to all Tracks that are share a node.",
65  bool(false));
66 
67  addParam("selectBestPerFamily",
68  m_PARAMselectBestPerFamily,
69  "Select only the best track candidates for each family.",
70  bool(false));
71 
72  addParam("xBestPerFamily",
73  m_PARAMxBestPerFamily,
74  "Number of best track candidates to be created per family.",
75  m_PARAMxBestPerFamily);
76 
77  addParam("maxFamilies",
78  m_PARAMmaxFamilies,
79  "Maximal number of families allowed in an event; if exceeded, the event execution will be skipped.",
80  m_PARAMmaxFamilies);
81 
82  addParam("maxPaths",
83  m_PARAMmaxPaths,
84  "Maximal number of paths per an event; if exceeded, the event execution will be skipped.",
85  m_PARAMmaxPaths);
86 }
87 
88 
89 void TrackFinderVXDBasicPathFinderModule::initialize()
90 {
91  m_network.isRequired(m_PARAMNetworkName);
92  m_TCs.registerInDataStore(m_PARAMSpacePointTrackCandArrayName, DataStore::c_DontWriteOut | DataStore::c_ErrorIfAlreadyRegistered);
93 
94  if (m_PARAMselectBestPerFamily) {
95  m_sptcSelector = std::make_unique<SPTCSelectorXBestPerFamily>(m_PARAMxBestPerFamily);
96  }
97 
98  m_eventLevelTrackingInfo.isRequired(m_PARAMEventLevelTrackingInfoName);
99 }
100 
101 
102 void TrackFinderVXDBasicPathFinderModule::beginRun()
103 {
104  if (m_PARAMselectBestPerFamily) {
105  // BField is required by all QualityEstimators
106  double bFieldZ = BFieldManager::getFieldInTesla({0, 0, 0}).Z();
107  m_sptcSelector->setMagneticFieldForQE(bFieldZ);
108  }
109 }
110 
111 
112 void TrackFinderVXDBasicPathFinderModule::event()
113 {
114  m_eventCounter++;
115 
116  DirectedNodeNetwork< Segment<TrackNode>, CACell >& segmentNetwork = m_network->accessSegmentNetwork();
117 
118  if (m_PARAMprintNetworks) {
119  std::string fileName = m_PARAMsecMapName + "_BasicPF_Ev" + std::to_string(m_eventCounter);
120  DNN::printCANetwork<Segment< Belle2::TrackNode>>(segmentNetwork, fileName);
121  }
122 
124  int nRounds = m_cellularAutomaton.apply(segmentNetwork);
125  if (nRounds < 0) {
126  B2WARNING("Basic Path Finder failed, skipping event!");
127  m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
128  return;
129  }
130 
132  unsigned int nSeeds = 0;
133  for (auto* aNode : segmentNetwork) {
134  if (m_PARAMstrictSeeding && !(aNode->getOuterNodes().empty())) {
135  continue;
136  }
137  if (aNode->getInnerNodes().empty()) {
138  continue;
139  }
140 
141  // Mark as seed, if node has got an inner node.
142  aNode->getMetaInfo().setSeed(true);
143  nSeeds++;
144  }
145 
146  if (nSeeds == 0) {
147  B2WARNING("In Event: " << m_eventCounter << " no seed could be found -> no TCs created!");
148  return;
149  }
150 
152  if (m_PARAMsetFamilies) {
153  unsigned short nFamilies = m_familyDefiner.defineFamilies(segmentNetwork);
154  B2DEBUG(10, "Number of families in the network: " << nFamilies);
155  if (nFamilies > m_PARAMmaxFamilies) {
156  B2WARNING("Maximal number of track canidates per event was exceeded: " << LogVar(" Number of Families", nFamilies)
157  << LogVar("Max number of families", m_PARAMmaxFamilies));
158  m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
159  return;
160  }
161  m_sptcSelector->prepareSelector(nFamilies);
162  }
164  m_collectedPaths.clear();
165  if (not m_pathCollector.findPaths(segmentNetwork, m_collectedPaths, m_PARAMmaxPaths, m_PARAMstoreSubsets)) {
166  B2WARNING("VXDBasicPathFinder got signal to abort the event.");
167  m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
168  m_network->set_collectedPaths(m_collectedPaths.size());
169  return;
170  }
171 
172  m_network->set_collectedPaths(m_collectedPaths.size());
173 
176  for (auto& aPath : m_collectedPaths) {
178 
179  if (m_PARAMselectBestPerFamily) {
180  m_sptcSelector->testNewSPTC(sptc);
181  } else {
182  std::vector<const SpacePoint*> path = sptc.getHits();
183  m_sptcCreator.createSPTC(m_TCs, path, sptc.getFamily());
184  }
185  }
186 
188  if (m_PARAMselectBestPerFamily) {
189  std::vector<SpacePointTrackCand> bestPaths = m_sptcSelector->returnSelection();
190  for (unsigned short iCand = 0; iCand < bestPaths.size(); iCand++) {
191  SpacePointTrackCand cand = bestPaths.at(iCand);
192  std::vector<const SpacePoint*> path = cand.getHits();
193  m_sptcCreator.createSPTC(m_TCs, path, cand.getFamily());
194  }
195  }
196 }
The CACell class This Class stores all relevant information one wants to have stored in a cell for a ...
Definition: CACell.h:20
Network of directed nodes of the type EntryType.
Base class for Modules.
Definition: Module.h:72
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
The TrackFinderVXDBasicPathFinder is a low momentum Si-only trackfinder.
Class to store variables with their name which were sent to the logging service.
#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.