Belle II Software development
RelationFilterUtil Struct Reference

name Structured creation of neighborhoods More...

#include <RelationFilterUtil.h>

Static Public Member Functions

template<class AObject , class ARelationFilter >
static void appendUsing (ARelationFilter &relationFilter, const std::vector< AObject * > &froms, const std::vector< AObject * > &tos, std::vector< WeightedRelation< AObject > > &weightedRelations, unsigned int maximumNumberOfRelations=std::numeric_limits< unsigned int >::max())
 Appends relations between elements in the given AItems using the ARelationFilter.
 
template<class AObject , class ARelationFilter >
static void appendUsing (ARelationFilter &relationFilter, const std::vector< AObject * > &objects, std::vector< WeightedRelation< AObject > > &weightedRelations)
 Shortcut for applying appendUsing with froms=tos.
 

Detailed Description

name Structured creation of neighborhoods

Often one faces the problem of having to build a graph between elements of the
same kind. To find suitable neighbors in a general container it would take an amount of time
proportional to n*n to compare all available elements to each other, which is often to long.
However if we can sort the sequence we can improve look up speed to an element by a great deal.
All tracking hits / segments / tracks for which we want to build graphs are therefore made sortable.
But the improved look up speed only helps if the neighbors are not scattered around randomly over
the sorted range but are close together in a specific section of the range. The time complexity drops
than to n*log n + n * m, where n is the number of elements in the collection and m the expected number
of neighbors.

Since we already sorted out the arrangement of hits / segments / tracks during their creation, we have to define
the region where to look for neighbors. We keep the general logic for look up the same
but vary the definition of what a neighborhood is supposed to be we factor the later out into
a strategy object called the RelationFilter with the following interface methods :

  • getPossibleNeighbors(item, itBegin, itEnd) returns a range iterable object of items which are possible neighbors
  • operator(Relation<AItem>) checks every neighboring object and returns a weight to indicate the quality of the neighbor.
    It returns NaN in case the neighbor is invalid and shall not be saved.

Definition at line 59 of file RelationFilterUtil.h.

Member Function Documentation

◆ appendUsing() [1/2]

static void appendUsing ( ARelationFilter &  relationFilter,
const std::vector< AObject * > &  froms,
const std::vector< AObject * > &  tos,
std::vector< WeightedRelation< AObject > > &  weightedRelations,
unsigned int  maximumNumberOfRelations = std::numeric_limits<unsigned int>::max() 
)
inlinestatic

Appends relations between elements in the given AItems using the ARelationFilter.

Definition at line 63 of file RelationFilterUtil.h.

68 {
69 for (AObject* from : froms) {
70 StoreObjPtr<EventLevelTrackingInfo> m_eventLevelTrackingInfo;
71
72 std::vector<AObject*> possibleTos = relationFilter.getPossibleTos(from, tos);
73
74 for (AObject* to : possibleTos) {
75 if (from == to) continue;
76 Relation<AObject> relation(from, to);
77 Weight weight = relationFilter(relation);
78 if (std::isnan(weight)) continue;
79 weightedRelations.emplace_back(from, weight, to);
80
81 if (weightedRelations.size() == maximumNumberOfRelations) {
82 B2WARNING("Relations Creator reached maximal number of items: skipping the event.");
83 if (m_eventLevelTrackingInfo.isValid()) {
84 if (std::is_base_of<AObject, CKFToPXDState>::value) {
85 m_eventLevelTrackingInfo->setPXDCKFAbortionFlag();
86 } else if (std::is_base_of<AObject, CKFToSVDState>::value) {
87 m_eventLevelTrackingInfo->setSVDCKFAbortionFlag();
88 } else if (std::is_base_of<AObject, vxdHoughTracking::VXDHoughState>::value) {
89 B2INFO("Skipping processing VXDHoughTracking track candidate, not setting AbortionFlag.");
90 } else {
91 B2WARNING("Undefined class used for CKFStates. Could not set AbortionFlag.");
92 }
93 }
94
95 weightedRelations.clear();
96 return;
97 }
98 }
99 }
100 // sort everything afterwards
101 std::sort(std::begin(weightedRelations), std::end(weightedRelations));
102 }

◆ appendUsing() [2/2]

static void appendUsing ( ARelationFilter &  relationFilter,
const std::vector< AObject * > &  objects,
std::vector< WeightedRelation< AObject > > &  weightedRelations 
)
inlinestatic

Shortcut for applying appendUsing with froms=tos.

Definition at line 107 of file RelationFilterUtil.h.

110 {
111 appendUsing(relationFilter, objects, objects, weightedRelations);
112 };
static void appendUsing(ARelationFilter &relationFilter, const std::vector< AObject * > &froms, const std::vector< AObject * > &tos, std::vector< WeightedRelation< AObject > > &weightedRelations, unsigned int maximumNumberOfRelations=std::numeric_limits< unsigned int >::max())
Appends relations between elements in the given AItems using the ARelationFilter.

The documentation for this struct was generated from the following file: