11 #ifndef RecoJets_FFTJetAlgorithms_matchOneToOne_h
12 #define RecoJets_FFTJetAlgorithms_matchOneToOne_h
37 template <
class T1,
class T2,
class DistanceCalculator>
39 const std::vector<T2>& v2,
40 const DistanceCalculator& calc,
41 std::vector<int>* matchFrom1To2,
42 const double maxMatchingDistance = 1.0e300) {
44 matchFrom1To2->clear();
46 const unsigned n1 = v1.size();
48 matchFrom1To2->reserve(n1);
49 for (
unsigned i1 = 0;
i1 < n1; ++
i1)
50 matchFrom1To2->push_back(-1);
52 const unsigned n2 = v2.size();
54 const unsigned nmatches = n1 * n2;
55 std::vector<Private::matchOneToOne_MatchInfo> distanceTable(nmatches);
56 std::vector<int> taken2(n2);
58 for (
unsigned i2 = 0;
i2 < n2; ++
i2)
62 for (
unsigned i1 = 0;
i1 < n1; ++
i1)
63 for (
unsigned i2 = 0;
i2 < n2; ++
i2) {
64 m = &distanceTable[
i1 * n2 +
i2];
65 m->distance = calc(v1[
i1], v2[
i2]);
70 std::sort(distanceTable.begin(), distanceTable.end());
71 for (
unsigned i = 0;
i < nmatches && nused < n1 && nused < n2; ++
i) {
72 m = &distanceTable[
i];
73 if (
m->distance > maxMatchingDistance)
75 if ((*matchFrom1To2)[
m->i1] < 0 && !taken2[
m->i2]) {
76 (*matchFrom1To2)[
m->i1] = static_cast<int>(
m->i2);
88 #endif // RecoJets_FFTJetAlgorithms_matchOneToOne_h