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 "\n This module takes a given sectorMap and storeArrays of spacePoints and creates a "
25 "activeSectorNetwork, a trackNodeNetwork and a segmentNetwork."
26 "These are filled and stored in a StoreObjPtr of DirectedNodeNetworkContainer:\n");
31 "List of SpacePoint StoreArray names to be evaluated.",
36 "Unique name for the DirectedNodeNetworkContainer Store Object Pointer created and filled by this module.",
39 addParam(
"EventLevelTrackingInfoName",
41 "Name of the EventLevelTrackingInfo that should be used (different one for ROI-finding).",
42 std::string(
"EventLevelTrackingInfo"));
46 "Whether to add a SpacePoint for a virtual interaction point to be considered by the network creation.",
51 "Coordinates as list [x,z,y] to be used for the virtual interaction point SpacePoint, if turned on.",
56 "Errors on coordinates as list [Ex,Ez,Ey] to be used for the virtual interaction point SpacePoint, if turned on.",
61 "Name of the SectorMap to be used by this instance.",
66 "If true for each event and each network a file containing the networks as graphs is created.",
69 addParam(
"printNetworkToMathematica",
71 "If true a file containing Mathematica code to generate a graph of the segment network is created.",
76 "For debugging purposes: if true, all filters are deactivated for all hit-combinations and therefore all combinations are accepted.",
81 "Maximal size of the SegmentNetwork; if exceeded, the event execution will be skipped.",
86 "Maximal number of Segment connections; if exceeded, the event execution will be skipped.",
91 "Maximal number of added Segment connections; if exceeded, the event execution will be skipped.",
96 "Maximal number of Hit connections; if exceeded, the event execution will be skipped.",
101 "Maximal number of added Hit connections; if exceeded, the event execution will be skipped.",
108 B2FATAL(
"Parameters for virtualIP are wrong!");
114 if (filters ==
nullptr) {
115 B2FATAL(
"Requested secMapName '" <<
m_PARAMsecMapName <<
"' does not exist! Can not continue...");
146 B2FATAL(
"Requested secMapName '" <<
m_PARAMsecMapName <<
"' does not exist! Can not continue...");
157 m_network->set_activeSectorConnections(0);
159 m_network->set_trackNodeAddedConnections(0);
160 m_network->set_activeSectorAddedConnections(0);
161 m_network->set_segmentAddedConnections(0);
167 if (not buildTrackNodeNetwork<VoidObserver>()) {
171 buildSegmentNetwork<VoidObserver>();
177 std::vector<RawSectorData> collectedData;
178 std::deque<TrackNode>& trackNodes =
m_network->accessTrackNodes();
184 if (aSP.getAssignmentState()) {
190 if (sectorFound ==
nullptr) {
191 B2WARNING(
"SpacePoint in sensor " << aSP.getVxdID() <<
" no sector found, SpacePoint discarded!");
195 trackNodes.emplace_back(&aSP);
200 std::vector<RawSectorData>::iterator iter =
201 std::find_if(collectedData.begin(), collectedData.end(),
202 [&](
const RawSectorData & entry) ->
bool { return entry.secID == foundSecID; }
206 if (iter == collectedData.end()) {
207 collectedData.push_back({ foundSecID,
false,
nullptr, sectorFound, { & (trackNodes.back())}});
210 iter->hits.push_back(&(trackNodes.back()));
221 collectedData.push_back({
FullSecID(),
false,
nullptr, sectorFound, {vIP}});
224 m_network->set_trackNodesCollected(nCollected);
225 return collectedData;
236 std::deque<ActiveSector<StaticSectorType, TrackNode>>& activeSectors =
m_network->accessActiveSectors();
237 unsigned int nLinked = 0, nAdded = 0;
242 std::int32_t outerEntryID = outerSector.
getID();
245 bool wasAnythingFoundSoFar =
false;
249 for (
const FullSecID& innerSecID : innerSecIDs) {
250 std::int32_t innerEntryID = innerSecID;
251 std::vector<RawSectorData>::iterator innerRawSecPos =
252 std::find_if(collectedData.begin(), collectedData.end(),
253 [&](
const RawSectorData & entry) ->
bool { return (entry.secID == innerSecID); }
257 if (innerRawSecPos == collectedData.end()) {
262 if (!innerRawSecPos->wasCreated) {
263 activeSectors.emplace_back(innerRawSecPos->staticSector);
264 innerRawSecPos->wasCreated =
true;
265 innerRawSecPos->sector = &activeSectors.back();
267 hit->m_sector = &activeSectors.back();
270 activeSectors.back().addHits(innerRawSecPos->hits);
271 activeSectorNetwork.
addNode(innerEntryID, activeSectors.back());
275 if (!wasAnythingFoundSoFar) {
276 activeSectors.push_back(outerSector);
277 outerSectorData.wasCreated =
true;
278 outerSectorData.sector = &activeSectors.back();
280 hit->m_sector = &activeSectors.back();
283 activeSectors.back().addHits(outerSectorData.hits);
284 activeSectorNetwork.
addNode(outerEntryID, activeSectors.back());
286 if (activeSectorNetwork.
linkNodes(outerEntryID, innerEntryID)) {
287 wasAnythingFoundSoFar =
true;
299 m_network->set_activeSectorConnections(nLinked);
300 m_network->set_activeSectorAddedConnections(nAdded);
304 DNN::printNetwork<ActiveSector<StaticSectorType, TrackNode>,
VoidMetaInfo>(activeSectorNetwork, fileName);
309template <
class ObserverType>
316 unsigned int nLinked = 0, nAdded = 0;
319 for (
auto* outerSector : activeSectorNetwork.
getNodes()) {
320 if (outerSector->getInnerNodes().empty()) {
323 const std::vector<TrackNode*>& outerHits = outerSector->getEntry().getHits();
324 if (outerHits.empty()) {
329 const StaticSectorType* outerStaticSector = outerSector->getEntry().getAttachedStaticSector();
331 if (outerStaticSector ==
nullptr) {
332 B2WARNING(
"Static sector not found. This should not happen!");
337 for (
auto* innerSector : outerSector->getInnerNodes()) {
338 const std::vector<TrackNode*>& innerHits = innerSector->getEntry().getHits();
339 if (innerHits.empty()) {
344 const auto* filter2sp = outerStaticSector->
getFilter2sp(innerSector->getEntry().getFullSecID());
345 if (filter2sp ==
nullptr) {
351 bool wasAnythingFoundSoFar =
false;
353 std::int32_t outerNodeID =
outerHit->getID();
359 bool accepted = (filter2sp->observe(ObserverType())).accept(
outerHit->getHit(), innerHit->getHit());
367 std::int32_t innerNodeID = innerHit->getID();
368 hitNetwork.
addNode(innerNodeID, *innerHit);
370 if (!wasAnythingFoundSoFar) {
371 if (hitNetwork.
linkNodes(outerNodeID, innerNodeID)) {
374 wasAnythingFoundSoFar =
true;
384 <<
"! The event will be skipped and not be processed. The number of connections was = " << nLinked);
386 m_network->set_trackNodeConnections(nLinked);
387 m_network->set_trackNodeAddedConnections(nAdded);
392 <<
"! The event will be skipped and not be processed. The number of connections was = " << nAdded);
394 m_network->set_trackNodeConnections(nLinked);
395 m_network->set_trackNodeAddedConnections(nAdded);
402 m_network->set_trackNodeConnections(nLinked);
403 m_network->set_trackNodeAddedConnections(nAdded);
407 DNN::printNetwork<Belle2::TrackNode, VoidMetaInfo>(hitNetwork, fileName);
414template <
class ObserverType>
419 std::deque<Belle2::Segment<Belle2::TrackNode>>& segments =
m_network->accessSegments();
420 unsigned int nLinked = 0, nAdded = 0;
423 const std::vector<DirectedNode<TrackNode, VoidMetaInfo>*>& centerHits =
outerHit->getInnerNodes();
425 if (centerHits.empty()) {
432 if (outerStaticSector ==
nullptr) {
433 B2WARNING(
"Static sector not found. This should not happen!");
438 const std::vector<DirectedNode<TrackNode, VoidMetaInfo>*>& innerHits = centerHit->getInnerNodes();
439 if (innerHits.empty()) {
444 bool wasAnythingFoundSoFar =
false;
448 const auto* filter3sp = outerStaticSector->
getFilter3sp(centerHit->getEntry().m_sector->getFullSecID(),
449 innerHit->getEntry().m_sector->getFullSecID());
450 if (filter3sp ==
nullptr) {
456 bool accepted =
false;
459 accepted = (filter3sp->observe(ObserverType())).accept(
outerHit->getEntry().getHit(),
460 centerHit->getEntry().getHit(),
461 innerHit->getEntry().getHit());
463 B2WARNING(
"SegmentNetworkProducerModule: exception caught thrown by one of the three hit filters");
472 std::int64_t innerSegmentID =
static_cast<std::int64_t
>(centerHit->getEntry().getID()) << 32 |
static_cast<std::int64_t
>
473 (innerHit->getEntry().getID());
477 segments.emplace_back(centerHit->getEntry().m_sector->getFullSecID(),
478 innerHit->getEntry().m_sector->getFullSecID(),
479 ¢erHit->getEntry(),
480 &innerHit->getEntry());
481 segmentNetwork.
addNode(innerSegmentID, segments.back());
484 std::int64_t outerSegmentID =
static_cast<std::int64_t
>(
outerHit->getEntry().getID()) << 32 |
static_cast<std::int64_t
>
485 (centerHit->getEntry().getID());
487 segments.emplace_back(
outerHit->getEntry().m_sector->getFullSecID(),
488 centerHit->getEntry().m_sector->getFullSecID(),
490 ¢erHit->getEntry());
491 segmentNetwork.
addNode(outerSegmentID, segments.back());
495 if (!wasAnythingFoundSoFar) {
496 if (segmentNetwork.
linkNodes(outerSegmentID, innerSegmentID)) {
499 wasAnythingFoundSoFar =
true;
509 <<
". VXDTF2 will skip the event and the SegmentNetwork is cleared.");
511 m_network->set_segmentConnections(nLinked);
512 m_network->set_segmentAddedConnections(nAdded);
518 <<
". VXDTF2 will skip the event and the SegmentNetwork is cleared.");
520 m_network->set_segmentConnections(nLinked);
521 m_network->set_segmentAddedConnections(nAdded);
527 <<
". Network size is " << segmentNetwork.
size()
528 <<
". VXDTF2 will skip the event and the SegmentNetwork is cleared.");
530 m_network->set_segmentConnections(nLinked);
531 m_network->set_segmentAddedConnections(nAdded);
538 m_network->set_segmentConnections(nLinked);
539 m_network->set_segmentAddedConnections(nAdded);
543 DNN::printNetwork<Segment<Belle2::TrackNode>,
CACell>(segmentNetwork, fileName);
544 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 ...
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
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.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
bool m_PARAMprintNetworks
If true for each event and each network a file with a graph of the network is created.
unsigned int m_eventCounter
Counters.
void buildSegmentNetwork()
Use connected SpacePoints to form segments which will stored and linked in a DirectedNodeNetwork<Segm...
unsigned short m_PARAMmaxNetworkSize
Maximal size of SegmentNetwork; if exceeded, filling of SegmentNetwork will be stopped and the event ...
std::string m_PARAMNetworkOutputName
Name for network container data store object created by this module.
void initialize() override
Module initialization: performing checks on input parameter and registration of network container in ...
unsigned int m_PARAMmaxSegmentConnections
Maximal number of Segment connections; if exceeded, filling of SegmentNetwork will be stopped and the...
StoreObjPtr< EventLevelTrackingInfo > m_eventLevelTrackingInfo
Access to the EventLevelTrackingInfo object in the datastore.
void buildActiveSectorNetwork(std::vector< RawSectorData > &collectedData)
Builds a DirectedNodeNetwork<ActiveSector>, containing ActiveSectors which have SpacePoints and compa...
void event() override
Event function.
std::vector< double > m_PARAMVirtualIPCoordinates
Coordinates for virtual interaction point SpacePoint.
std::string m_PARAMEventLevelTrackingInfoName
Name of the EventLevelTrackingInfo that should be used (different one for ROI-finding)
StoreObjPtr< DirectedNodeNetworkContainer > m_network
Access to the DirectedNodeNetwork, which will be produced by this module.
unsigned int m_PARAMmaxTrackNodeAddedConnections
Maximal number of added hit connections; if exceeded, filling of HitNetwork will be stopped and the e...
std::vector< StoreArray< Belle2::SpacePoint > > m_spacePoints
Contains all SPacePoint storeArrays to be evaluated.
SegmentNetworkProducerModule()
Constructor of the module.
unsigned int m_PARAMmaxSegmentAddedConnections
Maximal number of added Segment connections; if exceeded, filling of SegmentNetwork will be stopped a...
std::vector< RawSectorData > matchSpacePointToSectors()
Create TrackNodes from SpacePoints and collect fullSecIDs of 'active' sectors with SpacePoints for th...
VXDTFFilters< SpacePoint > * m_vxdtfFilters
Pointer to the current filters, contains all sectorCombinations and Filters including cuts.
std::vector< double > m_PARAMVirtualIPErrors
Errors on coordinates for virtual interaction point SpacePoint.
std::string m_PARAMsecMapName
Name of SectorMap used for this instance.
FiltersContainer< SpacePoint > & m_filtersContainer
Reference to container which contains all the sector to filter maps and with it the VXDTFFilters.
bool m_PARAMallFiltersOff
If true, all filters are deactivated for all hit-combinations and therefore all combinations are acce...
const StaticSectorType * findSectorForSpacePoint(const SpacePoint &aSP)
Returns pointer to static sector of a provided SpacePoint; returns nullptr if no sector could be foun...
B2Vector3D m_virtualIPCoordinates
Member Variables.
unsigned short m_PARAMmaxTrackNodeConnections
Maximal number of hit connections; if exceeded, filling of HitNetwork will be stopped and the event s...
bool m_PARAMprintToMathematica
If true a file containing Mathematica code to generate a graph of the segment network is created.
bool buildTrackNodeNetwork()
Evaluate TrackNodes in the ActiveSectors and link them if they fulfill the filter criteria of the Sec...
std::vector< std::string > m_PARAMSpacePointsArrayNames
Module Parameters.
B2Vector3D m_virtualIPErrors
Vector for errors on coordinates of virtual IP.
bool m_PARAMAddVirtualIP
Boolean to set whether to add an additional SpacePoint as a virtual interaction point.
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
class to describe a static sector of the sector map.
const Filter3sp * getFilter3sp(const FullSecID ¢erID, const FullSecID &innerID) const
Get the pointer to the 3 Space Point filter assigned to the friendship relation among this sector; wi...
FullSecID getFullSecID() const
returns FullSecID of this sector
const Filter2sp * getFilter2sp(FullSecID innerSector) const
Get the pointer to the 2 Space Point filter assigned to the friendship relation among this sector; wi...
Accessor to arrays stored in the data store.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
B2Vector3< double > B2Vector3D
typedef for common usage with double
B2Vector3D outerHit(0, 0, 0)
testing out of range behavior
void printStaticSectorRelations(const VXDTFFilters< HitType > &filters, const std::string &configName, unsigned int nHitCombinations=2, bool print2File=true, bool suppressDeadSectors=true)
TODO dot-compatible version of printStaticSectorRelations:
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.