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/trackFindingCDC/utilities/WeightedRelation.h>
11#include <tracking/trackFindingCDC/utilities/Relation.h>
12#include <tracking/trackFindingCDC/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 TrackFindingCDC {
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 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 }
103 /* *@}*/
104
106 template <class AObject, class ARelationFilter>
107 static void appendUsing(ARelationFilter& relationFilter,
108 const std::vector<AObject*>& objects,
109 std::vector<WeightedRelation<AObject>>& weightedRelations)
110 {
111 appendUsing(relationFilter, objects, objects, weightedRelations);
112 };
113 };
114 }
116}
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
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.