11 #ifndef RecoJets_FFTJetAlgorithms_matchOneToOne_h
12 #define RecoJets_FFTJetAlgorithms_matchOneToOne_h
40 template <
class T1,
class T2,
class DistanceCalculator>
41 unsigned matchOneToOne(
const std::vector<T1>& v1,
const std::vector<T2>& v2,
42 const DistanceCalculator& calc,
43 std::vector<int>* matchFrom1To2,
44 const double maxMatchingDistance = 1.0e300)
47 matchFrom1To2->clear();
49 const unsigned n1 = v1.size();
52 matchFrom1To2->reserve(n1);
53 for (
unsigned i1=0; i1<n1; ++i1)
54 matchFrom1To2->push_back(-1);
56 const unsigned n2 = v2.size();
59 const unsigned nmatches = n1*n2;
60 std::vector<Private::matchOneToOne_MatchInfo> distanceTable(nmatches);
61 std::vector<int> taken2(n2);
63 for (
unsigned i2=0; i2<n2; ++i2)
67 for (
unsigned i1=0; i1<n1; ++i1)
68 for (
unsigned i2=0; i2<n2; ++i2)
70 m = &distanceTable[i1*n2+i2];
76 std::sort(distanceTable.begin(), distanceTable.end());
77 for (
unsigned i=0;
i<nmatches && nused<n1 && nused<n2; ++
i)
79 m = &distanceTable[
i];
80 if (m->
distance > maxMatchingDistance)
82 if ((*matchFrom1To2)[m->
i1] < 0 && !taken2[m->
i2])
84 (*matchFrom1To2)[m->
i1] =
static_cast<int>(m->
i2);
96 #endif // RecoJets_FFTJetAlgorithms_matchOneToOne_h
unsigned matchOneToOne(const std::vector< T1 > &v1, const std::vector< T2 > &v2, const DistanceCalculator &calc, std::vector< int > *matchFrom1To2, const double maxMatchingDistance=1.0e300)
bool operator<(const matchOneToOne_MatchInfo &r) const
bool operator>(const matchOneToOne_MatchInfo &r) const