CMS 3D CMS Logo

GenericOverlapFinder.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PatUtils_GenericOverlapFinder_h
2 #define PhysicsTools_PatUtils_GenericOverlapFinder_h
3 
5 
6 #include <memory>
7 #include <vector>
8 #include <algorithm>
9 
10 namespace pat {
11 
15  typedef std::vector<std::pair<size_t, size_t> > OverlapList;
16 
23  template <typename Comparator>
24  struct OverlapDistance {
25  public:
28  template <typename T1, typename T2>
29  double operator()(const T1 &t1, const T2 &t2) const {
30  return 1.0 - comp_(t1, t2);
31  }
32 
33  private:
35  }; //struct
36 
39  struct OverlapByDeltaR {
40  public:
41  OverlapByDeltaR(double deltaR) : scale_(1.0 / (deltaR * deltaR)) {}
42  template <typename T1, typename T2>
43  double operator()(const T1 &t1, const T2 &t2) const {
44  return deltaR2(t1, t2) * scale_;
45  }
46 
47  private:
48  double scale_;
49  }; //struct
50 
51  template <typename Distance>
53  public:
55  GenericOverlapFinder(const Distance &dist) : distance_(dist) {}
56 
60  template <typename Collection, typename OtherCollection>
61  std::unique_ptr<OverlapList> find(const Collection &items, const OtherCollection &other) const;
62 
63  private:
64  Distance distance_;
65 
66  }; // class
67 } // namespace pat
68 
69 template <typename Distance>
70 template <typename Collection, typename OtherCollection>
71 std::unique_ptr<pat::OverlapList> pat::GenericOverlapFinder<Distance>::find(const Collection &items,
72  const OtherCollection &other) const {
73  size_t size = items.size(), size2 = other.size();
74 
75  auto ret = std::make_unique<OverlapList>();
76 
77  for (size_t ie = 0; ie < size; ++ie) {
78  double dmin = 1.0;
79  size_t match = 0;
80 
81  for (size_t je = 0; je < size2; ++je) {
82  double dist = distance_(items[ie], other[je]);
83  if (dist < dmin) {
84  match = je;
85  dmin = dist;
86  }
87  }
88 
89  if (dmin < 1.0) {
90  ret->push_back(std::make_pair(ie, match));
91  }
92  }
93 
94  return ret;
95 }
96 
97 #endif
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
pat::GenericOverlapFinder
Definition: GenericOverlapFinder.h:52
pat::OverlapDistance::operator()
double operator()(const T1 &t1, const T2 &t2) const
Definition: GenericOverlapFinder.h:29
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
mps_monitormerge.items
list items
Definition: mps_monitormerge.py:29
pat::GenericOverlapFinder::GenericOverlapFinder
GenericOverlapFinder()
Definition: GenericOverlapFinder.h:54
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
trackingPlots.other
other
Definition: trackingPlots.py:1460
pat::OverlapByDeltaR
Definition: GenericOverlapFinder.h:39
pat::OverlapDistance::OverlapDistance
OverlapDistance()
Definition: GenericOverlapFinder.h:26
pat::GenericOverlapFinder::find
std::unique_ptr< OverlapList > find(const Collection &items, const OtherCollection &other) const
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
pat::OverlapByDeltaR::scale_
double scale_
Definition: GenericOverlapFinder.h:48
distance_
double distance_
Definition: PFRecoTauChargedHadronFromGenericTrackPlugin.cc:198
pat::GenericOverlapFinder::GenericOverlapFinder
GenericOverlapFinder(const Distance &dist)
Definition: GenericOverlapFinder.h:55
deltaR.h
pat::OverlapDistance::comp_
Comparator comp_
Definition: GenericOverlapFinder.h:34
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
pat
Definition: HeavyIon.h:7
pat::OverlapByDeltaR::OverlapByDeltaR
OverlapByDeltaR(double deltaR)
Definition: GenericOverlapFinder.h:41
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
pat::OverlapByDeltaR::operator()
double operator()(const T1 &t1, const T2 &t2) const
Definition: GenericOverlapFinder.h:43
Comparator
Definition: Comparator.h:15
pat::OverlapList
std::vector< std::pair< size_t, size_t > > OverlapList
Definition: GenericOverlapFinder.h:15
pat::GenericOverlapFinder::distance_
Distance distance_
Definition: GenericOverlapFinder.h:64
pat::OverlapDistance::OverlapDistance
OverlapDistance(const Comparator &comp)
Definition: GenericOverlapFinder.h:27
pat::OverlapDistance
Definition: GenericOverlapFinder.h:24
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443