CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CandMatcherNew.h
Go to the documentation of this file.
1 #ifndef CandUtils_CandMatcherNew_h
2 #define CandUtils_CandMatcherNew_h
3 /* class CandMatcher
4  *
5  * \author Luca Lista, INFN
6  *
7  */
11 #include <algorithm>
12 #include <iterator>
13 #include <set>
14 
15 namespace reco {
16  namespace utilsNew {
17 
18  template <typename C>
19  class CandMatcher {
20  public:
25  typedef std::vector<const map_type *> map_vector;
27  explicit CandMatcher(const map_vector &maps);
29  explicit CandMatcher(const map_type &map);
31  virtual ~CandMatcher();
35  typename map_type::refprod_type ref() const { return map_.ref(); }
36 
37  protected:
40 
41  private:
42  };
43 
44  template <typename C>
45  CandMatcher<C>::CandMatcher(const typename CandMatcher<C>::map_vector &maps) : map_() {
46  for (typename map_vector::const_iterator i = maps.begin(); i != maps.end(); ++i)
47  map_ += **i;
48  }
49 
50  template <typename C>
51  CandMatcher<C>::CandMatcher(const typename CandMatcher<C>::map_type &map) : map_(map) {}
52 
53  template <typename C>
55 
56  template <typename C>
58  using namespace reco;
59  using namespace std;
60  if (c.hasMasterClone()) {
61  const CandidateBaseRef &master = c.masterClone();
62  return master->numberOfDaughters() == 0 ? map_[master] : (*this)[*master];
63  }
64  size_t nDau = c.numberOfDaughters();
65  if (nDau == 0)
66  return reference_type();
67  set<size_t> momIdx, common, tmp;
68  for (size_t i = 0; i < nDau; ++i) {
69  const Candidate &d = *c.daughter(i);
70  reference_type m = (*this)[d];
71  if (m.isNull())
72  return reference_type();
73  momIdx.clear();
74  while (m->numberOfMothers() == 1) {
75  m = m->motherRef();
76  momIdx.insert(m.key());
77  }
78  if (momIdx.empty())
79  return reference_type();
80  if (common.empty())
81  common = momIdx;
82  else {
83  tmp.clear();
84  set_intersection(common.begin(), common.end(), momIdx.begin(), momIdx.end(), inserter(tmp, tmp.begin()));
85  swap(common, tmp);
86  }
87  if (common.empty())
88  return reference_type();
89  }
90  size_t idx = *max_element(common.begin(), common.end());
91  return reference_type(map_.ref(), idx);
92  }
93 
94  } // namespace utilsNew
95 } // namespace reco
96 
97 #endif
Master< F > master(const F &f)
Definition: FunctClone.h:63
refprod_type ref() const
Definition: Association.h:67
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
const edm::EventSetup & c
CandMatcher(const map_vector &maps)
constructor
std::vector< const map_type * > map_vector
map_type::refprod_type ref() const
reference to matched collection
key_type key() const
Accessor for product key.
Definition: Ref.h:250
tuple d
Definition: ztail.py:151
virtual size_type numberOfDaughters() const =0
number of daughters
virtual bool hasMasterClone() const =0
bool isNull() const
Checks for null.
Definition: Ref.h:235
virtual ~CandMatcher()
destructor
map_type map_
match map at leaf level
reference_type operator[](const reco::Candidate &) const
get match from transient reference
edm::Association< C >::reference_type reference_type
ref type
edm::Association< C > map_type
map type
tmp
align.sh
Definition: createJobs.py:716
void swap(reco::ClusterRemovalInfo &cri1, reco::ClusterRemovalInfo &cri2)
virtual const CandidateBaseRef & masterClone() const =0
std::vector< std::string > set_intersection(std::vector< std::string > const &v1, std::vector< std::string > const &v2)