Belle II Software development
RelationFilterUtil.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <tracking/trackingUtilities/utilities/WeightedRelation.h>
11#include <tracking/trackingUtilities/utilities/Relation.h>
12#include <tracking/trackingUtilities/numerics/Weight.h>
13
14#include <framework/datastore/StoreObjPtr.h>
15#include <mdst/dataobjects/EventLevelTrackingInfo.h>
16
17#include <tracking/ckf/pxd/entities/CKFToPXDState.h>
18#include <tracking/ckf/svd/entities/CKFToSVDState.h>
19
20#include <tracking/vxdHoughTracking/entities/VXDHoughState.h>
21
22#include <framework/logging/Logger.h>
23
24#include <vector>
25#include <limits>
26#include <algorithm>
27
28namespace Belle2 {
33 namespace TrackingUtilities {
34
60 /* *@{*/
62 template <class AObject, class ARelationFilter>
63 static void appendUsing(ARelationFilter& relationFilter,
64 const std::vector<AObject*>& froms,
65 const std::vector<AObject*>& tos,
66 std::vector<WeightedRelation<AObject>>& weightedRelations,
67 unsigned int maximumNumberOfRelations = std::numeric_limits<unsigned int>::max())
68 {
69 for (AObject* from : froms) {
70 std::vector<AObject*> possibleTos = relationFilter.getPossibleTos(from, tos);
71
72 for (AObject* to : possibleTos) {
73 if (from == to) continue;
74 Relation<AObject> relation(from, to);
75 Weight weight = relationFilter(relation);
76 if (std::isnan(weight)) continue;
77 weightedRelations.emplace_back(from, weight, to);
78
79 if (weightedRelations.size() == maximumNumberOfRelations) {
80 B2WARNING("Relations Creator reached maximal number of items: skipping the event.");
81 // Constructing a StoreObjPtr on every iteration of an hot loop is not cheap:
82 // let's do it only if we need to set an AbortionFlag.
83 StoreObjPtr<EventLevelTrackingInfo> eventLevelTrackingInfo;
84 if (eventLevelTrackingInfo.isValid()) {
85 if (std::is_base_of<AObject, CKFToPXDState>::value) {
86 eventLevelTrackingInfo->setPXDCKFAbortionFlag();
87 } else if (std::is_base_of<AObject, CKFToSVDState>::value) {
88 eventLevelTrackingInfo->setSVDCKFAbortionFlag();
89 } else if (std::is_base_of<AObject, vxdHoughTracking::VXDHoughState>::value) {
90 B2INFO("Skipping processing VXDHoughTracking track candidate, not setting AbortionFlag.");
91 } else {
92 B2WARNING("Undefined class used for CKFStates. Could not set AbortionFlag.");
93 }
94 }
95
96 weightedRelations.clear();
97 return;
98 }
99 }
100 }
101 // sort everything afterwards
102 std::sort(std::begin(weightedRelations), std::end(weightedRelations));
103 }
104 /* *@}*/
105
107 template <class AObject, class ARelationFilter>
108 static void appendUsing(ARelationFilter& relationFilter,
109 const std::vector<AObject*>& objects,
110 std::vector<WeightedRelation<AObject>>& weightedRelations)
111 {
112 appendUsing(relationFilter, objects, objects, weightedRelations);
113 };
114 };
115 }
117}
virtual void clear()
Clear contents of this object.
Type-safe access to single objects in the data store.
Definition StoreObjPtr.h:96
bool isValid() const
Check whether the object was created.
Type for two related objects.
Definition Relation.h:21
Type for two related objects with a weight.
Abstract base class for different kinds of events.
name Structured creation of neighborhoods
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.
static void appendUsing(ARelationFilter &relationFilter, const std::vector< AObject * > &objects, std::vector< WeightedRelation< AObject > > &weightedRelations)
Shortcut for applying appendUsing with froms=tos.