Belle II Software  release-05-01-25
TrackFinderVXDCellOMatModule.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 #include <framework/geometry/BFieldManager.h>
13 
14 #include <tracking/modules/vxdtfRedesign/TrackFinderVXDCellOMatModule.h>
15 #include <tracking/trackFindingVXD/algorithms/NetworkPathConversion.h>
16 #include <tracking/trackFindingVXD/segmentNetwork/NodeNetworkHelperFunctions.h>
17 
18 
19 using namespace std;
20 using namespace Belle2;
21 
22 REG_MODULE(TrackFinderVXDCellOMat)
23 
24 
26 {
28  setDescription("The TrackFinderVXD Cell-O-Mat module."
29  "\n It uses the output produced by the SegmentNetworkProducerModule to create"
30  "SpacePointTrackCands using a Cellular Automaton algorithm implementation.");
31  setPropertyFlags(c_ParallelProcessingCertified);
32 
33 
34  addParam("NetworkName",
35  m_PARAMNetworkName,
36  "name for StoreObjPtr< DirectedNodeNetwork> which contains the networks needed.",
37  string(""));
38 
39  addParam("SpacePointTrackCandArrayName",
40  m_PARAMSpacePointTrackCandArrayName,
41  "name for StoreArray< SpacePointTrackCand> to be filled.",
42  string(""));
43 
44  addParam("EventLevelTrackingInfoName",
45  m_PARAMEventLevelTrackingInfoName,
46  "Name of the EventLevelTrackingInfo that should be used (different one for ROI-finding).",
47  string("EventLevelTrackingInfo"));
48 
49  addParam("printNetworks",
50  m_PARAMprintNetworks,
51  "If true for each event and each network created a file with a graph is created.", bool(false));
52 
53  addParam("strictSeeding",
54  m_PARAMstrictSeeding,
55  "Regulates if every node with enough notes below it is used as a seed or only the outermost nodes.",
56  bool(true));
57 
58  addParam("storeSubsets",
59  m_PARAMstoreSubsets,
60  "Regulates if every subset of sufficient length of a path shall be collected as separate path or not.",
61  bool(false));
62 
63  addParam("setFamilies",
64  m_PARAMsetFamilies,
65  "Additionally assign a common family identifier to all Tracks that are share a node.",
66  bool(false));
67 
68  addParam("selectBestPerFamily",
69  m_PARAMselectBestPerFamily,
70  "Select only the best track candidate for each family.",
71  bool(false));
72 
73  addParam("xBestPerFamily",
74  m_PARAMxBestPerFamily,
75  "Number of best track candidates to be created per family.",
76  m_PARAMxBestPerFamily);
77 
78  addParam("maxFamilies",
79  m_PARAMmaxFamilies,
80  "Maximal number of families allowed in an event; if exceeded, the event execution will be skipped.",
81  m_PARAMmaxFamilies);
82 
83  addParam("maxPaths",
84  m_PARAMmaxPaths,
85  "Maximal number of paths per an event; if exceeded, the event execution will be skipped.",
86  m_PARAMmaxPaths);
87 }
88 
89 
90 void TrackFinderVXDCellOMatModule::initialize()
91 {
92  m_network.isRequired(m_PARAMNetworkName);
93  m_TCs.registerInDataStore(m_PARAMSpacePointTrackCandArrayName, DataStore::c_DontWriteOut | DataStore::c_ErrorIfAlreadyRegistered);
94 
95  if (m_PARAMselectBestPerFamily) {
96  m_sptcSelector = std::make_unique<SPTCSelectorXBestPerFamily>(m_PARAMxBestPerFamily);
97  }
98 
99  m_eventLevelTrackingInfo.isRequired(m_PARAMEventLevelTrackingInfoName);
100 }
101 
102 
103 void TrackFinderVXDCellOMatModule::beginRun()
104 {
105  if (m_PARAMselectBestPerFamily) {
106  // BField is required by all QualityEstimators
107  double bFieldZ = BFieldManager::getFieldInTesla({0, 0, 0}).Z();
108  m_sptcSelector->setMagneticFieldForQE(bFieldZ);
109  }
110 }
111 
112 
113 void TrackFinderVXDCellOMatModule::event()
114 {
115  m_eventCounter++;
116 
117  DirectedNodeNetwork< Segment<TrackNode>, CACell >& segmentNetwork = m_network->accessSegmentNetwork();
118 
120  int nRounds = m_cellularAutomaton.apply(segmentNetwork);
121  if (nRounds < 0) {
122  B2ERROR("CA failed, skipping event!");
123  return;
124  }
125 
126  if (m_PARAMprintNetworks) {
127  std::string fileName = m_PARAMNetworkName + "_CA_Ev" + std::to_string(m_eventCounter);
128  DNN::printCANetwork<Segment< Belle2::TrackNode>>(segmentNetwork, fileName);
129  }
130 
132  unsigned int nSeeds = m_cellularAutomaton.findSeeds(segmentNetwork, m_PARAMstrictSeeding);
133  if (nSeeds == 0) {
134  return;
135  }
136 
138  if (m_PARAMsetFamilies) {
139  unsigned short nFamilies = m_familyDefiner.defineFamilies(segmentNetwork);
140  if (nFamilies > m_PARAMmaxFamilies) {
141  B2WARNING("Maximal number of track canidates per event was exceeded: Number of Families = " << nFamilies);
142  m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
143  return;
144  }
145  m_sptcSelector->prepareSelector(nFamilies);
146  }
147 
149  m_collectedPaths.clear();
150  if (not m_pathCollector.findPaths(segmentNetwork, m_collectedPaths, m_PARAMmaxPaths, m_PARAMstoreSubsets)) {
151  B2WARNING("VXDCellOMat got signal to abort the event.");
152  m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
153  m_network->set_collectedPaths(m_collectedPaths.size());
154  return;
155  }
156 
157  m_network->set_collectedPaths(m_collectedPaths.size());
158 
161  for (auto& aPath : m_collectedPaths) {
163 
164  if (m_PARAMselectBestPerFamily) {
165  m_sptcSelector->testNewSPTC(sptc);
166  } else {
167  std::vector<const SpacePoint*> path = sptc.getHits();
168  m_sptcCreator.createSPTC(m_TCs, path, sptc.getFamily());
169  }
170  }
171 
173  if (m_PARAMselectBestPerFamily) {
174  std::vector<SpacePointTrackCand> bestPaths = m_sptcSelector->returnSelection();
175  for (unsigned short iCand = 0; iCand < bestPaths.size(); iCand++) {
176  SpacePointTrackCand cand = bestPaths.at(iCand);
177  std::vector<const SpacePoint*> path = cand.getHits();
178  m_sptcCreator.createSPTC(m_TCs, path, cand.getFamily());
179  }
180  }
181 }
Belle2::TrackFinderVXDCellOMatModule
The TrackFinderVXDCellOMatModule is a low momentum Si-only trackfinder.
Definition: TrackFinderVXDCellOMatModule.h:54
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::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