ATLAS Offline Software
ObjectMatching.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef OBJECT_MATCHING_H
6 #define OBJECT_MATCHING_H
7 
9 
11 #include "CxxUtils/fpcompare.h"
12 
13 #include <vector>
14 
21 
22  public:
23 
24  ObjectMatching() { ; };
25  virtual ~ObjectMatching() { ; };
26 
31  template <typename T, typename U>
32  float distance(
33  const T *t,
34  const U *u,
35  const DistanceFunctor<T, U> *metric) const;
36 
37  // default metric version - uses deltaR matching and so no metric
38  // need be supplied
39  template <typename T, typename U>
40  float distance(
41  const T *t,
42  const U *u) const;
49  template <typename T, typename U>
50  std::vector<const T*> matchToObjects(
51  const U* matchObject,
52  const std::vector<const T*> &targetObjects,
53  float maxDistance,
54  const DistanceFunctor<T, U> *metric) const;
55 
56  // default metric version - uses deltaR matching and so no metric
57  // need be supplied
58  template <typename T, typename U>
59  std::vector<const T*> matchToObjects(
60  const U* matchObject,
61  const std::vector<const T*> &targetObjects,
62  float maxDistance = 0.1) const;
63 
64  // similar matching functions for data vectors instead of std vectors
65  template <typename T, typename U>
66  std::vector<const T*> matchToObjects(
67  const U* matchObject,
68  const DataVector<T> &targetObjects,
69  float maxDistance,
70  const DistanceFunctor<T, U> *metric) const;
71 
72  template <typename T, typename U>
73  std::vector<const T*> matchToObjects(
74  const U* matchObject,
75  const DataVector<T> &targetObjects,
76  float maxDistance = 0.1) const;
77 
78  template <typename T, typename U>
79  bool anyMatch(
80  const U* matchObject,
81  const std::vector<const T*> &targetObjects,
82  float maxDistance,
83  const DistanceFunctor<T, U> *metric) const;
84 
85  template <typename T, typename U>
86  bool anyMatch(
87  const U* matchObject,
88  const std::vector<const T*> &targetObjects,
89  float maxDistance) const;
90 
98  template <typename T, typename U>
99  const T* matchToObject(
100  const U *matchObject,
101  const std::vector<const T*> &targetObjects,
102  float maxDistance,
103  const DistanceFunctor<T, U> *metric) const;
104 
105  // default metric version - uses deltaR matching and so no metric
106  // need be supplied
107  template <typename T, typename U>
108  const T* matchToObject(
109  const U *matchObject,
110  const std::vector<const T*> &targetObjects,
111  float maxDistance = 0.1) const;
112 
113  // similar functions for data vectors rather than std::vectors
114  template <typename T, typename U>
115  const T* matchToObject(
116  const U *matchObject,
117  const DataVector<T> &targetObjects,
118  float maxDistance,
119  const DistanceFunctor<T, U> *metric) const;
120 
121  template <typename T, typename U>
122  const T* matchToObject(
123  const U *matchObject,
124  const DataVector<T> &targetObjects,
125  float maxDistance = 0.1) const;
126 
127  protected:
128 
129  // returns factory held default metric (deltaR)
130  template <typename T, typename U>
132 
133  private:
134 
135  // functor for sorting by distance relative to a base object
136  // with a given metric
137  template <typename T, typename U>
139  public:
140  DistanceCompare(const U *baseObject, const DistanceFunctor<T, U> *m) {
141  m_metric = m;
142  m_baseObject = baseObject;
143  }
144  virtual bool operator()(const T *x, const T *y) {
145  // see Control/CxxUtils/fpcompare.h for explanation of
146  // why this is required
148  (*m_metric)(y,m_baseObject));
149  };
150  private:
151  const U *m_baseObject;
153  };
154 
155 
156 }; // end ObjectMatching declaration
157 
159 
160 #endif
ObjectMatching::matchToObjects
std::vector< const T * > matchToObjects(const U *matchObject, const DataVector< T > &targetObjects, float maxDistance=0.1) const
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
ObjectMatching::distance
float distance(const T *t, const U *u, const DistanceFunctor< T, U > *metric) const
distance returns the distance between the two supplied objects using metric, if available,...
ObjectMatching.icc
ObjectMatching::DistanceCompare
Definition: ObjectMatching.h:138
ObjectMatching::matchToObject
const T * matchToObject(const U *matchObject, const DataVector< T > &targetObjects, float maxDistance, const DistanceFunctor< T, U > *metric) const
ObjectMatching::DistanceCompare::DistanceCompare
DistanceCompare(const U *baseObject, const DistanceFunctor< T, U > *m)
Definition: ObjectMatching.h:140
ObjectMatching::ObjectMatching
ObjectMatching()
Definition: ObjectMatching.h:24
ObjectMatching::DistanceCompare::operator()
virtual bool operator()(const T *x, const T *y)
Definition: ObjectMatching.h:144
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
x
#define x
ObjectMatching::DistanceCompare::m_metric
const DistanceFunctor< T, U > * m_metric
Definition: ObjectMatching.h:152
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
ObjectMatching
ObjectMatching is a base class that performs generic matching of objects using the distance functor f...
Definition: ObjectMatching.h:20
ObjectMatching::matchToObject
const T * matchToObject(const U *matchObject, const DataVector< T > &targetObjects, float maxDistance=0.1) const
fpcompare.h
Workaround x86 precision issues for FP inequality comparisons.
ObjectMatching::anyMatch
bool anyMatch(const U *matchObject, const std::vector< const T * > &targetObjects, float maxDistance, const DistanceFunctor< T, U > *metric) const
DistanceFunctor
Definition: DistanceFunctor.h:11
DataVector< T >
ObjectMatching::matchToObject
const T * matchToObject(const U *matchObject, const std::vector< const T * > &targetObjects, float maxDistance=0.1) const
ObjectMatching::matchToObjects
std::vector< const T * > matchToObjects(const U *matchObject, const std::vector< const T * > &targetObjects, float maxDistance, const DistanceFunctor< T, U > *metric) const
matchToObjects returns the objects of type T from the supplied vector that match to matchObject,...
ObjectMatching::DistanceCompare::m_baseObject
const U * m_baseObject
Definition: ObjectMatching.h:149
ObjectMatching::matchToObject
const T * matchToObject(const U *matchObject, const std::vector< const T * > &targetObjects, float maxDistance, const DistanceFunctor< T, U > *metric) const
matchToObject returns the object of type T from the suppled vector that best matches matchObject acco...
CxxUtils::fpcompare::less
bool less(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition: fpcompare.h:166
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
y
#define y
DistanceFunctor.h
ObjectMatching::~ObjectMatching
virtual ~ObjectMatching()
Definition: ObjectMatching.h:25
ObjectMatching::matchToObjects
std::vector< const T * > matchToObjects(const U *matchObject, const DataVector< T > &targetObjects, float maxDistance, const DistanceFunctor< T, U > *metric) const
ObjectMatching::anyMatch
bool anyMatch(const U *matchObject, const std::vector< const T * > &targetObjects, float maxDistance) const
ObjectMatching::matchToObjects
std::vector< const T * > matchToObjects(const U *matchObject, const std::vector< const T * > &targetObjects, float maxDistance=0.1) const
ObjectMatching::distance
float distance(const T *t, const U *u) const
ObjectMatching::prepareMetric
const DistanceFunctor< T, U > * prepareMetric() const
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35