Belle II Software  release-06-00-14
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  B2ERROR("Basic Path Finder failed, skipping event!");
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(10, "Number of families in the network: " << nFamilies);
154  if (nFamilies > m_PARAMmaxFamilies) {
155  B2ERROR("Maximal number of track canidates per event was exceeded: Number of Families = " << nFamilies);
156  m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
157  return;
158  }
159  m_sptcSelector->prepareSelector(nFamilies);
160  }
162  m_collectedPaths.clear();
163  if (not m_pathCollector.findPaths(segmentNetwork, m_collectedPaths, m_PARAMmaxPaths, m_PARAMstoreSubsets)) {
164  B2ERROR("VXDBasicPathFinder got signal to abort the event.");
165  m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
166  m_network->set_collectedPaths(m_collectedPaths.size());
167  return;
168  }
169 
170  m_network->set_collectedPaths(m_collectedPaths.size());
171 
174  for (auto& aPath : m_collectedPaths) {
176 
177  if (m_PARAMselectBestPerFamily) {
178  m_sptcSelector->testNewSPTC(sptc);
179  } else {
180  std::vector<const SpacePoint*> path = sptc.getHits();
181  m_sptcCreator.createSPTC(m_TCs, path, sptc.getFamily());
182  }
183  }
184 
186  if (m_PARAMselectBestPerFamily) {
187  std::vector<SpacePointTrackCand> bestPaths = m_sptcSelector->returnSelection();
188  for (unsigned short iCand = 0; iCand < bestPaths.size(); iCand++) {
189  SpacePointTrackCand cand = bestPaths.at(iCand);
190  std::vector<const SpacePoint*> path = cand.getHits();
191  m_sptcCreator.createSPTC(m_TCs, path, cand.getFamily());
192  }
193  }
194 }
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.
#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.