Belle II Software  release-05-02-19
TrackFinderVXDBasicPathFinderModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jakob Lettenbichler, Jonas Wagner, Felix Metzner *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/logging/Logger.h>
12 
13 #include <framework/geometry/BFieldManager.h>
14 
15 #include <tracking/modules/vxdtfRedesign/TrackFinderVXDBasicPathFinderModule.h>
16 #include <tracking/trackFindingVXD/algorithms/NetworkPathConversion.h>
17 #include <tracking/trackFindingVXD/segmentNetwork/NodeNetworkHelperFunctions.h>
18 
19 
20 using namespace std;
21 using namespace Belle2;
22 
23 REG_MODULE(TrackFinderVXDBasicPathFinder)
24 
25 
27 {
28  //Set module properties
29  setDescription("The TrackFinderVXD BasicPathFinder module."
30  "\n It uses the output produced by the SegmentNetworkProducerModule to create"
31  "SpacePointTrackCands by simply storing all possible paths stored in the SegmentNetwork.");
32  setPropertyFlags(c_ParallelProcessingCertified);
33 
34 
35  addParam("NetworkName",
36  m_PARAMNetworkName,
37  "name for StoreObjPtr< DirectedNodeNetwork> which contains the networks needed.",
38  string(""));
39 
40  addParam("EventLevelTrackingInfoName",
41  m_PARAMEventLevelTrackingInfoName,
42  "Name of the EventLevelTrackingInfo that should be used (different one for ROI-finding).",
43  string("EventLevelTrackingInfo"));
44 
45  addParam("SpacePointTrackCandArrayName",
46  m_PARAMSpacePointTrackCandArrayName,
47  "name for StoreArray< SpacePointTrackCand> to be filled.",
48  string(""));
49 
50  addParam("printNetworks",
51  m_PARAMprintNetworks,
52  "If true for each event and each network created a file with a graph is created.", bool(false));
53 
54  addParam("strictSeeding",
55  m_PARAMstrictSeeding,
56  "Regulates if every node with enough notes below it is used as a seed or only the outermost nodes.",
57  bool(true));
58 
59  addParam("storeSubsets",
60  m_PARAMstoreSubsets,
61  "Regulates if every subset of sufficient length of a path shall be collected as separate path or not.",
62  bool(false));
63 
64  addParam("setFamilies",
65  m_PARAMsetFamilies,
66  "Additionally assign a common family identifier to all Tracks that are share a node.",
67  bool(false));
68 
69  addParam("selectBestPerFamily",
70  m_PARAMselectBestPerFamily,
71  "Select only the best track candidates for each family.",
72  bool(false));
73 
74  addParam("xBestPerFamily",
75  m_PARAMxBestPerFamily,
76  "Number of best track candidates to be created per family.",
77  m_PARAMxBestPerFamily);
78 
79  addParam("maxFamilies",
80  m_PARAMmaxFamilies,
81  "Maximal number of families allowed in an event; if exceeded, the event execution will be skipped.",
82  m_PARAMmaxFamilies);
83 
84  addParam("maxPaths",
85  m_PARAMmaxPaths,
86  "Maximal number of paths per an event; if exceeded, the event execution will be skipped.",
87  m_PARAMmaxPaths);
88 }
89 
90 
91 void TrackFinderVXDBasicPathFinderModule::initialize()
92 {
93  m_network.isRequired(m_PARAMNetworkName);
94  m_TCs.registerInDataStore(m_PARAMSpacePointTrackCandArrayName, DataStore::c_DontWriteOut | DataStore::c_ErrorIfAlreadyRegistered);
95 
96  if (m_PARAMselectBestPerFamily) {
97  m_sptcSelector = std::make_unique<SPTCSelectorXBestPerFamily>(m_PARAMxBestPerFamily);
98  }
99 
100  m_eventLevelTrackingInfo.isRequired(m_PARAMEventLevelTrackingInfoName);
101 }
102 
103 
104 void TrackFinderVXDBasicPathFinderModule::beginRun()
105 {
106  if (m_PARAMselectBestPerFamily) {
107  // BField is required by all QualityEstimators
108  double bFieldZ = BFieldManager::getFieldInTesla({0, 0, 0}).Z();
109  m_sptcSelector->setMagneticFieldForQE(bFieldZ);
110  }
111 }
112 
113 
114 void TrackFinderVXDBasicPathFinderModule::event()
115 {
116  m_eventCounter++;
117 
118  DirectedNodeNetwork< Segment<TrackNode>, CACell >& segmentNetwork = m_network->accessSegmentNetwork();
119 
120  if (m_PARAMprintNetworks) {
121  std::string fileName = m_PARAMsecMapName + "_BasicPF_Ev" + std::to_string(m_eventCounter);
122  DNN::printCANetwork<Segment< Belle2::TrackNode>>(segmentNetwork, fileName);
123  }
124 
126  int nRounds = m_cellularAutomaton.apply(segmentNetwork);
127  if (nRounds < 0) {
128  B2ERROR("Basic Path Finder failed, skipping event!");
129  return;
130  }
131 
133  unsigned int nSeeds = 0;
134  for (auto* aNode : segmentNetwork) {
135  if (m_PARAMstrictSeeding && !(aNode->getOuterNodes().empty())) {
136  continue;
137  }
138  if (aNode->getInnerNodes().empty()) {
139  continue;
140  }
141 
142  // Mark as seed, if node has got an inner node.
143  aNode->getMetaInfo().setSeed(true);
144  nSeeds++;
145  }
146 
147  if (nSeeds == 0) {
148  B2WARNING("In Event: " << m_eventCounter << " no seed could be found -> no TCs created!");
149  return;
150  }
151 
153  if (m_PARAMsetFamilies) {
154  unsigned short nFamilies = m_familyDefiner.defineFamilies(segmentNetwork);
155  B2DEBUG(10, "Number of families in the network: " << nFamilies);
156  if (nFamilies > m_PARAMmaxFamilies) {
157  B2ERROR("Maximal number of track canidates per event was exceeded: Number of Families = " << nFamilies);
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  B2ERROR("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 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::DirectedNodeNetwork
Network of directed nodes of the type EntryType.
Definition: DirectedNodeNetwork.h:38
Belle2::convertNetworkPath
SpacePointTrackCand convertNetworkPath(NetworkPath networkPath)
Create new SPTC from network path.
Definition: NetworkPathConversion.h:34
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::SpacePointTrackCand::getHits
const std::vector< const Belle2::SpacePoint * > & getHits() const
get hits (space points) of track candidate
Definition: SpacePointTrackCand.h:131
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFinderVXDBasicPathFinderModule
The TrackFinderVXDBasicPathFinder is a low momentum Si-only trackfinder.
Definition: TrackFinderVXDBasicPathFinderModule.h:54
Belle2::CACell
The CACell class This Class stores all relevant information one wants to have stored in a cell for a ...
Definition: CACell.h:30
Belle2::SpacePointTrackCand::getFamily
short getFamily() const
return family identifier
Definition: SpacePointTrackCand.h:285
Belle2::SpacePointTrackCand
Storage for (VXD) SpacePoint-based track candidates.
Definition: SpacePointTrackCand.h:51