CMS 3D CMS Logo

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();
33  reference_type operator[](const reco::Candidate &) const;
35  typename map_type::refprod_type ref() const { return map_.ref(); }
36  protected:
38  map_type map_;
39 
40  private:
41  };
42 
43  template<typename C>
45  map_() {
46  for(typename map_vector::const_iterator i = maps.begin(); i != maps.end(); ++ i)
47  map_ += **i;
48  }
49 
50  template<typename C>
52  map_(map) {
53  }
54 
55  template<typename C>
57  }
58 
59  template<typename C>
61  using namespace reco;
62  using namespace std;
63  if (c.hasMasterClone()) {
65  return master->numberOfDaughters() == 0 ? map_[master] : (*this)[*master];
66  }
67  size_t nDau = c.numberOfDaughters();
68  if(nDau == 0) return reference_type();
69  set<size_t> momIdx, common, tmp;
70  for(size_t i = 0; i < nDau; ++ i) {
71  const Candidate & d = * c.daughter(i);
72  reference_type m = (*this)[d];
73  if (m.isNull()) return reference_type();
74  momIdx.clear();
75  while(m->numberOfMothers() == 1) {
76  m = m->motherRef();
77  momIdx.insert(m.key());
78  }
79  if(momIdx.size() == 0) return reference_type();
80  if (common.size() == 0) common = momIdx;
81  else {
82  tmp.clear();
83  set_intersection(common.begin(), common.end(),
84  momIdx.begin(), momIdx.end(),
85  inserter(tmp, tmp.begin()));
86  swap(common, tmp);
87  }
88  if (common.size() == 0) return reference_type();
89  }
90  size_t idx = * max_element(common.begin(), common.end());
91  return reference_type(map_.ref(), idx);
92  }
93 
94  }
95 }
96 
97 #endif
Master< F > master(const F &f)
Definition: FunctClone.h:68
refprod_type ref() const
Definition: Association.h:66
CandMatcher(const map_vector &maps)
constructor
std::vector< const map_type * > map_vector
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
map_type::refprod_type ref() const
reference to matched collection
key_type key() const
Accessor for product key.
Definition: Ref.h:265
virtual ~CandMatcher()
destructor
bool isNull() const
Checks for null.
Definition: Ref.h:250
reference_type operator[](const reco::Candidate &) const
get match from transient reference
virtual const CandidateBaseRef & masterClone() const =0
map_type map_
match map at leaf level
edm::Association< C >::reference_type reference_type
ref type
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
fixed size matrix
edm::Association< C > map_type
map type
virtual size_type numberOfDaughters() const =0
number of daughters
void swap(reco::ClusterRemovalInfo &cri1, reco::ClusterRemovalInfo &cri2)
virtual bool hasMasterClone() const =0