9 #include <tracking/modules/vxdtfRedesign/SegmentNetworkProducerModule.h>
10 #include <tracking/trackFindingVXD/segmentNetwork/NodeNetworkHelperFunctions.h>
11 #include <tracking/trackFindingVXD/environment/VXDTFFilters.h>
12 #include <tracking/trackFindingVXD/environment/VXDTFFiltersHelperFunctions.h>
14 #include <tracking/trackFindingVXD/filterMap/filterFramework/VoidObserver.h>
24 setDescription(
"The segment network producer module. "
25 "\n This module takes a given sectorMap and storeArrays of spacePoints and creates a "
26 "activeSectorNetwork, a trackNodeNetwork and a segmentNetwork."
27 "These are filled and stored in a StoreObjPtr of DirectedNodeNetworkContainer:\n");
28 setPropertyFlags(c_ParallelProcessingCertified);
30 addParam(
"SpacePointsArrayNames",
31 m_PARAMSpacePointsArrayNames,
32 "List of SpacePoint StoreArray names to be evaluated.",
33 m_PARAMSpacePointsArrayNames);
35 addParam(
"NetworkOutputName",
36 m_PARAMNetworkOutputName,
37 "Unique name for the DirectedNodeNetworkContainer Store Object Pointer created and filled by this module.",
40 addParam(
"EventLevelTrackingInfoName",
41 m_PARAMEventLevelTrackingInfoName,
42 "Name of the EventLevelTrackingInfo that should be used (different one for ROI-finding).",
43 string(
"EventLevelTrackingInfo"));
45 addParam(
"addVirtualIP",
47 "Whether to add a SpacePoint for a virtual interaction point to be considered by the network creation.",
50 addParam(
"virtualIPCoorindates",
51 m_PARAMVirtualIPCoordinates,
52 "Coordinates as list [x,z,y] to be used for the virtual interaction point SpacePoint, if turned on.",
53 m_PARAMVirtualIPCoordinates);
55 addParam(
"virtualIPErrors",
56 m_PARAMVirtualIPErrors,
57 "Errors on coordinates as list [Ex,Ez,Ey] to be used for the virtual interaction point SpacePoint, if turned on.",
58 m_PARAMVirtualIPErrors);
60 addParam(
"sectorMapName",
62 "Name of the SectorMap to be used by this instance.",
65 addParam(
"printNetworks",
67 "If true for each event and each network a file containing the networks as graphs is created.",
68 m_PARAMprintNetworks);
70 addParam(
"printNetworkToMathematica",
71 m_PARAMprintToMathematica,
72 "If true a file containing Mathematica code to generate a graph of the segment network is created.",
73 m_PARAMprintToMathematica);
75 addParam(
"allFiltersOff",
77 "For debugging purposes: if true, all filters are deactivated for all hit-combinations and therefore all combinations are accepted.",
78 m_PARAMallFiltersOff);
80 addParam(
"maxNetworkSize",
81 m_PARAMmaxNetworkSize,
82 "Maximal size of the SegmentNetwork; if exceeded, the event execution will be skipped.",
83 m_PARAMmaxNetworkSize);
85 addParam(
"maxConnections",
86 m_PARAMmaxSegmentConnections ,
87 "Maximal number of Segment connections; if exceeded, the event execution will be skipped.",
88 m_PARAMmaxSegmentConnections);
90 addParam(
"maxAddedConnections",
91 m_PARAMmaxSegmentAddedConnections ,
92 "Maximal number of added Segment connections; if exceeded, the event execution will be skipped.",
93 m_PARAMmaxSegmentAddedConnections);
95 addParam(
"maxHitConnections",
96 m_PARAMmaxTrackNodeConnections,
97 "Maximal number of Hit connections; if exceeded, the event execution will be skipped.",
98 m_PARAMmaxTrackNodeConnections);
100 addParam(
"maxAddedHitConnections",
101 m_PARAMmaxTrackNodeAddedConnections,
102 "Maximal number of added Hit connections; if exceeded, the event execution will be skipped.",
103 m_PARAMmaxTrackNodeAddedConnections);
106 void SegmentNetworkProducerModule::initialize()
108 if (m_PARAMVirtualIPCoordinates.size() != 3 or m_PARAMVirtualIPErrors.size() != 3) {
109 B2FATAL(
"Parameters for virtualIP are wrong!");
114 auto filters = m_filtersContainer.getFilters(m_PARAMsecMapName);
115 if (filters ==
nullptr) {
116 B2FATAL(
"Requested secMapName '" << m_PARAMsecMapName <<
"' does not exist! Can not continue...");
119 m_virtualIPCoordinates =
B2Vector3D(m_PARAMVirtualIPCoordinates.at(0),
120 m_PARAMVirtualIPCoordinates.at(1),
121 m_PARAMVirtualIPCoordinates.at(2));
122 m_virtualIPErrors =
B2Vector3D(m_PARAMVirtualIPErrors.at(0),
123 m_PARAMVirtualIPErrors.at(1),
124 m_PARAMVirtualIPErrors.at(2));
126 if (m_PARAMprintToMathematica) {
127 SecMapHelper::printStaticSectorRelations(*filters, filters->getConfig().secMapName +
"segNetProducer", 2, m_PARAMprintToMathematica,
131 for (std::string& anArrayName : m_PARAMSpacePointsArrayNames) {
133 m_spacePoints.back().isRequired();
136 m_network.registerInDataStore(m_PARAMNetworkOutputName, DataStore::c_DontWriteOut | DataStore::c_ErrorIfAlreadyRegistered);
138 m_eventLevelTrackingInfo.isRequired(m_PARAMEventLevelTrackingInfoName);
142 void SegmentNetworkProducerModule::event()
146 if (m_vxdtfFilters ==
nullptr) {
147 B2FATAL(
"Requested secMapName '" << m_PARAMsecMapName <<
"' does not exist! Can not continue...");
155 vector<RawSectorData> collectedData = matchSpacePointToSectors();
157 m_network->set_trackNodeConnections(0);
158 m_network->set_activeSectorConnections(0);
159 m_network->set_segmentConnections(0);
160 m_network->set_trackNodeAddedConnections(0);
161 m_network->set_activeSectorAddedConnections(0);
162 m_network->set_segmentAddedConnections(0);
163 m_network->set_collectedPaths(0);
166 buildActiveSectorNetwork(collectedData);
168 if (not buildTrackNodeNetwork<VoidObserver>()) {
172 buildSegmentNetwork<VoidObserver>();
176 std::vector<SegmentNetworkProducerModule::RawSectorData> SegmentNetworkProducerModule::matchSpacePointToSectors()
178 std::vector<RawSectorData> collectedData;
179 std::deque<TrackNode>& trackNodes = m_network->accessTrackNodes();
185 if (aSP.getAssignmentState()) {
191 if (sectorFound ==
nullptr) {
192 B2WARNING(
"SpacePoint in sensor " << aSP.getVxdID() <<
" no sector found, SpacePoint discarded!");
196 trackNodes.emplace_back(&aSP);
201 vector<RawSectorData>::iterator iter =
202 std::find_if(collectedData.begin(), collectedData.end(),
203 [&](
const RawSectorData & entry) ->
bool { return entry.secID == foundSecID; }
207 if (iter == collectedData.end()) {
208 collectedData.push_back({ foundSecID ,
false,
nullptr, sectorFound, { & (trackNodes.back())}});
211 iter->hits.push_back(&(trackNodes.back()));
218 if (m_PARAMAddVirtualIP) {
219 m_network->setVirtualInteractionPoint(m_virtualIPCoordinates, m_virtualIPErrors);
220 TrackNode* vIP = m_network->getVirtualInteractionPoint();
222 collectedData.push_back({
FullSecID(),
false,
nullptr, sectorFound, {vIP}});
225 m_network->set_trackNodesCollected(nCollected);
226 return collectedData;
230 void SegmentNetworkProducerModule::buildActiveSectorNetwork(std::vector<SegmentNetworkProducerModule::RawSectorData>&
235 m_network->accessActiveSectorNetwork();
237 std::deque<ActiveSector<StaticSectorType, TrackNode>>& activeSectors = m_network->accessActiveSectors();
238 unsigned int nLinked = 0, nAdded = 0;
243 std::int32_t outerEntryID = outerSector.
getID();
246 bool wasAnythingFoundSoFar =
false;
250 for (
const FullSecID& innerSecID : innerSecIDs) {
251 std::int32_t innerEntryID = innerSecID;
252 vector<RawSectorData>::iterator innerRawSecPos =
253 std::find_if(collectedData.begin(), collectedData.end(),
254 [&](
const RawSectorData & entry) ->
bool { return (entry.secID == innerSecID); }
258 if (innerRawSecPos == collectedData.end()) {
263 if (!innerRawSecPos->wasCreated) {
264 activeSectors.emplace_back(innerRawSecPos->staticSector);
265 innerRawSecPos->wasCreated =
true;
266 innerRawSecPos->sector = &activeSectors.back();
268 hit->m_sector = &activeSectors.back();
271 activeSectors.back().addHits(innerRawSecPos->hits);
272 activeSectorNetwork.
addNode(innerEntryID, activeSectors.back());
276 if (!wasAnythingFoundSoFar) {
277 activeSectors.push_back(outerSector);
278 outerSectorData.wasCreated =
true;
279 outerSectorData.sector = &activeSectors.back();
281 hit->m_sector = &activeSectors.back();
284 activeSectors.back().addHits(outerSectorData.hits);
285 activeSectorNetwork.
addNode(outerEntryID, activeSectors.back());
287 if (activeSectorNetwork.
linkNodes(outerEntryID, innerEntryID)) {
288 wasAnythingFoundSoFar =
true;
300 m_network->set_activeSectorConnections(nLinked);
301 m_network->set_activeSectorAddedConnections(nAdded);
303 if (m_PARAMprintNetworks) {
304 std::string fileName = m_vxdtfFilters->getConfig().secMapName +
"_ActiveSector_Ev" + std::to_string(m_eventCounter);
305 DNN::printNetwork<ActiveSector<StaticSectorType, TrackNode>,
VoidMetaInfo>(activeSectorNetwork, fileName);
310 template <
class ObserverType>
311 bool SegmentNetworkProducerModule::buildTrackNodeNetwork()
314 m_network->accessActiveSectorNetwork();
317 unsigned int nLinked = 0, nAdded = 0;
320 for (
auto* outerSector : activeSectorNetwork.
getNodes()) {
321 if (outerSector->getInnerNodes().empty()) {
324 const vector<TrackNode*>& outerHits = outerSector->getEntry().getHits();
325 if (outerHits.empty()) {
330 const StaticSectorType* outerStaticSector = outerSector->getEntry().getAttachedStaticSector();
332 if (outerStaticSector ==
nullptr) {
333 B2WARNING(
"Static sector not found. This should not happen!");
338 for (
auto* innerSector : outerSector->getInnerNodes()) {
339 const vector<TrackNode*>& innerHits = innerSector->getEntry().getHits();
340 if (innerHits.empty()) {
345 const auto* filter2sp = outerStaticSector->
getFilter2sp(innerSector->getEntry().getFullSecID());
346 if (filter2sp ==
nullptr) {
352 bool wasAnythingFoundSoFar =
false;
354 std::int32_t outerNodeID = outerHit->getID();
355 hitNetwork.
addNode(outerNodeID, *outerHit);
360 bool accepted = (filter2sp->observe(ObserverType())).accept(outerHit->getHit(), innerHit->getHit());
362 if (m_PARAMallFiltersOff) accepted =
true;
368 std::int32_t innerNodeID = innerHit->getID();
369 hitNetwork.
addNode(innerNodeID, *innerHit);
371 if (!wasAnythingFoundSoFar) {
372 if (hitNetwork.
linkNodes(outerNodeID, innerNodeID)) {
375 wasAnythingFoundSoFar =
true;
383 if (nLinked > m_PARAMmaxTrackNodeConnections) {
384 B2WARNING(
"Number of TrackNodeConnections has exceeded maximal size limit of " << m_PARAMmaxTrackNodeConnections
385 <<
"! The event will be skipped and not be processed. The number of connections was = " << nLinked);
386 m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
387 m_network->set_trackNodeConnections(nLinked);
388 m_network->set_trackNodeAddedConnections(nAdded);
391 if (nAdded > m_PARAMmaxTrackNodeAddedConnections) {
392 B2WARNING(
"Number of added TrackNodeConnections has exceeded maximal size limit of " << m_PARAMmaxTrackNodeAddedConnections
393 <<
"! The event will be skipped and not be processed. The number of connections was = " << nAdded);
394 m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
395 m_network->set_trackNodeConnections(nLinked);
396 m_network->set_trackNodeAddedConnections(nAdded);
403 m_network->set_trackNodeConnections(nLinked);
404 m_network->set_trackNodeAddedConnections(nAdded);
406 if (m_PARAMprintNetworks) {
407 std::string fileName = m_vxdtfFilters->getConfig().secMapName +
"_TrackNode_Ev" + std::to_string(m_eventCounter);
408 DNN::printNetwork<Belle2::TrackNode, VoidMetaInfo>(hitNetwork, fileName);
415 template <
class ObserverType>
416 void SegmentNetworkProducerModule::buildSegmentNetwork()
420 std::deque<Belle2::Segment<Belle2::TrackNode>>& segments = m_network->accessSegments();
421 unsigned int nLinked = 0, nAdded = 0;
424 const vector<DirectedNode<TrackNode, VoidMetaInfo>*>& centerHits = outerHit->getInnerNodes();
426 if (centerHits.empty()) {
431 const StaticSectorType* outerStaticSector = outerHit->getEntry().m_sector->getAttachedStaticSector();
433 if (outerStaticSector ==
nullptr) {
434 B2WARNING(
"Static sector not found. This should not happen!");
439 const vector<DirectedNode<TrackNode, VoidMetaInfo>*>& innerHits = centerHit->getInnerNodes();
440 if (innerHits.empty()) {
445 bool wasAnythingFoundSoFar =
false;
449 const auto* filter3sp = outerStaticSector->
getFilter3sp(centerHit->getEntry().m_sector->getFullSecID(),
450 innerHit->getEntry().m_sector->getFullSecID());
451 if (filter3sp ==
nullptr) {
457 bool accepted =
false;
460 accepted = (filter3sp->observe(ObserverType())).accept(outerHit->getEntry().getHit(),
461 centerHit->getEntry().getHit(),
462 innerHit->getEntry().getHit());
464 B2WARNING(
"SegmentNetworkProducerModule: exception caught thrown by one of the three hit filters");
467 if (m_PARAMallFiltersOff) accepted =
true;
473 std::int64_t innerSegmentID =
static_cast<std::int64_t
>(centerHit->getEntry().getID()) << 32 |
static_cast<std::int64_t
>
474 (innerHit->getEntry().getID());
478 segments.emplace_back(centerHit->getEntry().m_sector->getFullSecID(),
479 innerHit->getEntry().m_sector->getFullSecID(),
480 ¢erHit->getEntry(),
481 &innerHit->getEntry());
482 segmentNetwork.
addNode(innerSegmentID, segments.back());
485 std::int64_t outerSegmentID =
static_cast<std::int64_t
>(outerHit->getEntry().getID()) << 32 |
static_cast<std::int64_t
>
486 (centerHit->getEntry().getID());
488 segments.emplace_back(outerHit->getEntry().m_sector->getFullSecID(),
489 centerHit->getEntry().m_sector->getFullSecID(),
490 &outerHit->getEntry(),
491 ¢erHit->getEntry());
492 segmentNetwork.
addNode(outerSegmentID, segments.back());
496 if (!wasAnythingFoundSoFar) {
497 if (segmentNetwork.
linkNodes(outerSegmentID, innerSegmentID)) {
500 wasAnythingFoundSoFar =
true;
508 if (nLinked > m_PARAMmaxSegmentConnections) {
509 B2WARNING(
"Number of SegmentConnections exceeds the limit of " << m_PARAMmaxSegmentConnections
510 <<
". VXDTF2 will skip the event and the SegmentNetwork is cleared.");
511 m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
512 m_network->set_segmentConnections(nLinked);
513 m_network->set_segmentAddedConnections(nAdded);
517 if (nAdded > m_PARAMmaxSegmentAddedConnections) {
518 B2WARNING(
"Number of added SegmentConnections exceeds the limit of " << m_PARAMmaxSegmentAddedConnections
519 <<
". VXDTF2 will skip the event and the SegmentNetwork is cleared.");
520 m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
521 m_network->set_segmentConnections(nLinked);
522 m_network->set_segmentAddedConnections(nAdded);
526 if (segments.size() > m_PARAMmaxNetworkSize) {
527 B2WARNING(
"SegmentNetwork size exceeds the limit of " << m_PARAMmaxNetworkSize
528 <<
". Network size is " << segmentNetwork.
size()
529 <<
". VXDTF2 will skip the event and the SegmentNetwork is cleared.");
530 m_eventLevelTrackingInfo->setVXDTF2AbortionFlag();
531 m_network->set_segmentConnections(nLinked);
532 m_network->set_segmentAddedConnections(nAdded);
539 m_network->set_segmentConnections(nLinked);
540 m_network->set_segmentAddedConnections(nAdded);
542 if (m_PARAMprintNetworks) {
543 std::string fileName = m_vxdtfFilters->getConfig().secMapName +
"_Segment_Ev" + std::to_string(m_eventCounter);
544 DNN::printNetwork<Segment<Belle2::TrackNode>,
CACell>(segmentNetwork, fileName);
545 DNN::printCANetwork<Segment<Belle2::TrackNode>>(segmentNetwork,
"CA" + fileName);
std::int32_t getID() const
************************* PUBLIC MEMBER FUNCTIONS *************************
const std::vector< FullSecID > & getInner2spSecIDs() const
returns all IDs for inner sectors of two-sector-combinations stored in the static SectorMap
The CACell class This Class stores all relevant information one wants to have stored in a cell for a ...
Network of directed nodes of the type EntryType.
std::vector< Node * > & getNodes()
Returns all nodes of the network.
bool addInnerToLastOuterNode(NodeID innerNodeID)
to the last outerNode added, another innerNode will be attached
unsigned int size() const
Returns number of nodes to be found in the network.
bool linkNodes(NodeID outerNodeID, NodeID innerNodeID)
takes two entry IDs and weaves them into the network
bool isNodeInNetwork(const NodeID nodeID) const
Check if a given entry is already in the network.
bool addNode(NodeID nodeID, EntryType &newEntry)
************************* PUBLIC MEMBER FUNCTIONS *************************
Class to identify a sector inside of the VXD.
The Segment Network Producer Module.
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
class to describe a static sector of the sector map.
FullSecID getFullSecID() const
returns FullSecID of this sector
const Filter3sp * getFilter3sp(const FullSecID ¢erID, const FullSecID &innerID) const
Get the pionter to the 3 Space Point filter assigned to the friendship relation among this sector; wi...
const Filter2sp * getFilter2sp(FullSecID innerSector) const
Get the pionter to the 2 Space Point filter assigned to the friendship relation among this sector; wi...
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
B2Vector3< double > B2Vector3D
typedef for common usage with double
Abstract base class for different kinds of events.
Simple struct for collecting raw data for a single sector.
Minimal class to store combination of sector and spacePoint, since SpacePoint can not carry sectorCon...
const SpacePoint & getHit() const
returns reference to hit.