Belle II Software  release-05-02-19
RelationFilterUtil.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
13 #include <tracking/trackFindingCDC/utilities/Relation.h>
14 #include <tracking/trackFindingCDC/numerics/Weight.h>
15 
16 #include <framework/datastore/StoreObjPtr.h>
17 #include <mdst/dataobjects/EventLevelTrackingInfo.h>
18 
19 #include <tracking/ckf/pxd/entities/CKFToPXDState.h>
20 #include <tracking/ckf/svd/entities/CKFToSVDState.h>
21 
22 #include <framework/logging/Logger.h>
23 
24 #include <vector>
25 #include <limits>
26 #include <algorithm>
27 
28 namespace Belle2 {
33  namespace TrackFindingCDC {
34 
59  struct RelationFilterUtil {
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. Aborting");
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 {
89  B2WARNING("Undefined class used for CKFStates. Could not set AbortionFlag.");
90  }
91  }
92 
93  weightedRelations.clear();
94  return;
95  }
96  }
97  }
98  // sort everything afterwards
99  std::sort(std::begin(weightedRelations), std::end(weightedRelations));
100  }
101  /* *@}*/
102 
104  template <class AObject, class ARelationFilter>
105  static void appendUsing(ARelationFilter& relationFilter,
106  const std::vector<AObject*>& objects,
107  std::vector<WeightedRelation<AObject>>& weightedRelations)
108  {
109  appendUsing(relationFilter, objects, objects, weightedRelations);
110  };
111  };
112  }
114 }
Belle2::TrackFindingCDC::Relation
Type for two related objects.
Definition: CDCSegment2D.h:37
Belle2::TrackFindingCDC::RelationFilterUtil::appendUsing
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.
Definition: RelationFilterUtil.h:71
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::StoreObjPtr::isValid
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:120