CMS 3D CMS Logo

ClusterTPAssociation.h
Go to the documentation of this file.
1 #ifndef SimTracker_TrackerHitAssociation_ClusterTPAssociation_h
2 #define SimTracker_TrackerHitAssociation_ClusterTPAssociation_h
3 
10 
11 #include <vector>
12 #include <utility>
13 #include <algorithm>
14 
22 public:
25  using value_type = std::pair<key_type, mapped_type>;
26  using map_type = std::vector<value_type>;
27  using const_iterator = typename map_type::const_iterator;
28  using range = std::pair<const_iterator, const_iterator>;
29 
31  explicit ClusterTPAssociation(const edm::HandleBase& mappedHandle): ClusterTPAssociation(mappedHandle.id()) {}
32  explicit ClusterTPAssociation(const edm::ProductID& mappedProductId): mappedProductId_(mappedProductId) {}
33 
34  void emplace_back(const OmniClusterRef& cluster, const TrackingParticleRef& tp) {
36  auto foundKeyID = std::find(std::begin(keyProductIDs_), std::end(keyProductIDs_), cluster.id());
37  if(foundKeyID == std::end(keyProductIDs_)) {
38  keyProductIDs_.emplace_back(cluster.id());
39  }
40  map_.emplace_back(cluster, tp);
41  }
42  void sortAndUnique() {
43  std::sort(map_.begin(), map_.end(), compareSort);
44  auto last = std::unique(map_.begin(), map_.end());
45  map_.erase(last, map_.end());
46  map_.shrink_to_fit();
47  }
49  map_.swap(other.map_);
51  }
52 
53  bool empty() const { return map_.empty(); }
54  size_t size() const { return map_.size(); }
55 
56  const_iterator begin() const { return map_.begin(); }
57  const_iterator cbegin() const { return map_.cbegin(); }
58  const_iterator end() const { return map_.end(); }
59  const_iterator cend() const { return map_.end(); }
60 
62  checkKeyProductID(key);
63  return std::equal_range(map_.begin(), map_.end(), value_type(key, TrackingParticleRef()), compare);
64  }
65 
66  const map_type& map() const { return map_; }
67 
68  void checkKeyProductID(const OmniClusterRef& key) const { checkKeyProductID(key.id()); }
69  void checkKeyProductID(const edm::ProductID& id) const;
70 
71  void checkMappedProductID(const edm::HandleBase& mappedHandle) const { checkMappedProductID(mappedHandle.id()); }
73  void checkMappedProductID(const edm::ProductID& id) const;
74 
75 private:
76  static bool compare(const value_type& i, const value_type& j) {
77  return i.first.rawIndex() > j.first.rawIndex();
78  }
79 
80  static bool compareSort(const value_type& i, const value_type& j) {
81  // For sorting compare also TrackingParticle keys in order to
82  // remove duplicate matches
83  return compare(i, j) || (i.first.rawIndex() == j.first.rawIndex() && i.second.key() > j.second.key());
84  }
85 
89 };
90 
91 #endif
const_iterator cbegin() const
ProductID id() const
Definition: HandleBase.cc:15
void checkMappedProductID(const TrackingParticleRef &tp) const
void checkKeyProductID(const OmniClusterRef &key) const
const_iterator begin() const
typename map_type::const_iterator const_iterator
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void swap(ProductID &other)
Definition: ProductID.cc:17
void emplace_back(Args &&...args)
Definition: VecArray.h:92
edm::ProductID mappedProductId_
ProductID id() const
Accessor for product ID.
Definition: Ref.h:259
const_iterator end() const
const_iterator cend() const
def unique(seq, keepstr=True)
Definition: tier0.py:25
static bool compareSort(const value_type &i, const value_type &j)
range equal_range(const OmniClusterRef &key) const
#define end
Definition: vmac.h:39
static bool compare(const value_type &i, const value_type &j)
std::vector< value_type > map_type
ClusterTPAssociation(const edm::HandleBase &mappedHandle)
void swap(ClusterTPAssociation &other)
void checkMappedProductID(const edm::HandleBase &mappedHandle) const
#define begin
Definition: vmac.h:32
edm::ProductID id() const
std::pair< const_iterator, const_iterator > range
const map_type & map() const
edm::VecArray< edm::ProductID, 2 > keyProductIDs_
std::pair< key_type, mapped_type > value_type
edm::Ref< TrackingParticleCollection > TrackingParticleRef
void emplace_back(const OmniClusterRef &cluster, const TrackingParticleRef &tp)
ClusterTPAssociation(const edm::ProductID &mappedProductId)