Belle II Software  release-06-01-15
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 
17 using namespace std;
18 using namespace Belle2;
19 
20 REG_MODULE(TrackFinderVXDCellOMat)
21 
22 
24 {
26  setDescription("The TrackFinderVXD Cell-O-Mat module."
27  "\n It uses the output produced by the SegmentNetworkProducerModule to create"
28  "SpacePointTrackCands using a Cellular Automaton algorithm implementation.");
29  setPropertyFlags(c_ParallelProcessingCertified);
30 
31 
32  addParam("NetworkName",
33  m_PARAMNetworkName,
34  "name for StoreObjPtr< DirectedNodeNetwork> which contains the networks needed.",
35  string(""));
36 
37  addParam("SpacePointTrackCandArrayName",
38  m_PARAMSpacePointTrackCandArrayName,
39  "name for StoreArray< SpacePointTrackCand> to be filled.",
40  string(""));
41 
42  addParam("EventLevelTrackingInfoName",
43  m_PARAMEventLevelTrackingInfoName,
44  "Name of the EventLevelTrackingInfo that should be used (different one for ROI-finding).",
45  string("EventLevelTrackingInfo"));
46 
47  addParam("printNetworks",
48  m_PARAMprintNetworks,
49  "If true for each event and each network created a file with a graph is created.", bool(false));
50 
51  addParam("strictSeeding",
52  m_PARAMstrictSeeding,
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",
57  m_PARAMstoreSubsets,
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",
62  m_PARAMsetFamilies,
63  "Additionally assign a common family identifier to all Tracks that are share a node.",
64  bool(false));
65 
66  addParam("selectBestPerFamily",
67  m_PARAMselectBestPerFamily,
68  "Select only the best track candidate for each family.",
69  bool(false));
70 
71  addParam("xBestPerFamily",
72  m_PARAMxBestPerFamily,
73  "Number of best track candidates to be created per family.",
74  m_PARAMxBestPerFamily);
75 
76  addParam("maxFamilies",
77  m_PARAMmaxFamilies,
78  "Maximal number of families allowed in an event; if exceeded, the event execution will be skipped.",
79  m_PARAMmaxFamilies);
80 
81  addParam("maxPaths",
82  m_PARAMmaxPaths,
83  "Maximal number of paths per an event; if exceeded, the event execution will be skipped.",
84  m_PARAMmaxPaths);
85 }
86 
87 
88 void TrackFinderVXDCellOMatModule::initialize()
89 {
90  m_network.isRequired(m_PARAMNetworkName);
91  m_TCs.registerInDataStore(m_PARAMSpacePointTrackCandArrayName, DataStore::c_DontWriteOut | DataStore::c_ErrorIfAlreadyRegistered);
92 
93  if (m_PARAMselectBestPerFamily) {
94  m_sptcSelector = std::make_unique<SPTCSelectorXBestPerFamily>(m_PARAMxBestPerFamily);
95  }
96 
97  m_eventLevelTrackingInfo.isRequired(m_PARAMEventLevelTrackingInfoName);
98 }
99 
100 
101 void TrackFinderVXDCellOMatModule::beginRun()
102 {
103  if (m_PARAMselectBestPerFamily) {
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 
111 void TrackFinderVXDCellOMatModule::event()
112 {
113  m_eventCounter++;
114 
115  DirectedNodeNetwork< Segment<TrackNode>, CACell >& segmentNetwork = m_network->accessSegmentNetwork();
116 
118  int nRounds = m_cellularAutomaton.apply(segmentNetwork);
119  if (nRounds < 0) {
120  B2ERROR("Cellular Automaton failed, skipping event!");
121  return;
122  }
123 
124  if (m_PARAMprintNetworks) {
125  std::string fileName = m_PARAMNetworkName + "_CA_Ev" + std::to_string(m_eventCounter);
126  DNN::printCANetwork<Segment< Belle2::TrackNode>>(segmentNetwork, fileName);
127  }
128 
130  unsigned int nSeeds = m_cellularAutomaton.findSeeds(segmentNetwork, m_PARAMstrictSeeding);
131  if (nSeeds == 0) {
132  return;
133  }
134 
136  if (m_PARAMsetFamilies) {
137  unsigned short nFamilies = m_familyDefiner.defineFamilies(segmentNetwork);
138  if (nFamilies > m_PARAMmaxFamilies) {
139  B2WARNING("Maximal number of track canidates per event was exceeded: Number of Families = " << nFamilies);
140  m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
141  return;
142  }
143  m_sptcSelector->prepareSelector(nFamilies);
144  }
145 
147  m_collectedPaths.clear();
148  if (not m_pathCollector.findPaths(segmentNetwork, m_collectedPaths, m_PARAMmaxPaths, m_PARAMstoreSubsets)) {
149  B2WARNING("Received signal to skip the event and not processing it.");
150  m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
151  m_network->set_collectedPaths(m_collectedPaths.size());
152  return;
153  }
154 
155  m_network->set_collectedPaths(m_collectedPaths.size());
156 
159  for (auto& aPath : m_collectedPaths) {
161 
162  if (m_PARAMselectBestPerFamily) {
163  m_sptcSelector->testNewSPTC(sptc);
164  } else {
165  std::vector<const SpacePoint*> path = sptc.getHits();
166  m_sptcCreator.createSPTC(m_TCs, path, sptc.getFamily());
167  }
168  }
169 
171  if (m_PARAMselectBestPerFamily) {
172  std::vector<SpacePointTrackCand> bestPaths = m_sptcSelector->returnSelection();
173  for (unsigned short iCand = 0; iCand < bestPaths.size(); iCand++) {
174  SpacePointTrackCand cand = bestPaths.at(iCand);
175  std::vector<const SpacePoint*> path = cand.getHits();
176  m_sptcCreator.createSPTC(m_TCs, path, cand.getFamily());
177  }
178  }
179 }
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 TrackFinderVXDCellOMatModule 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.