CMS 3D CMS Logo

FastCandMatcher.h
Go to the documentation of this file.
1 #ifndef CandUtils_FastCandMatcher_h
2 #define CandUtils_FastCandMatcher_h
3 /* class CandMatcher
4  *
5  * \author Luca Lista, INFN
6  *
7  */
8 #include <set>
13 
14 template<typename C>
16 public:
20  typedef std::vector<const map_type *> map_vector;
22  explicit FastCandMatcher( const map_vector & maps );
24  explicit FastCandMatcher( const map_type & map );
26  const reco::Candidate * operator()( const reco::Candidate & ) const;
27 
28 protected:
29  const std::vector<const map_type *> & maps() const { return maps_; }
30 private:
32  std::vector<const map_type *> maps_;
33 };
34 
35 template<typename C>
37  maps_( maps ) {
38 }
39 
40 template<typename C>
42  maps_( 1, & map ) {
43 }
44 
45 template<typename C>
47  using namespace reco;
48  using namespace std;
49  if ( c.hasMasterClone() )
50  return (*this)( * c.masterClone() );
51  unsigned int nDau = c.numberOfDaughters();
52  if ( nDau > 0 ) {
53  // check for composite candidate c
54  // navigate to daughters and find parent matches
55  set<const reco::Candidate *> momsIntersection, momDaughters, tmp;
56  for( Candidate::const_iterator dau = c.begin(); dau != c.end(); ++ dau ) {
57  // check here generically if status == 3, then descend down to one more level
58  const Candidate * dauMatch = (*this)( * dau );
59  // if a daughter does not match, return a null ref.
60  if ( dauMatch == 0 ) return 0;
61  // get matched mothers
62  size_t mothers = dauMatch->numberOfMothers();
63  for( size_t i = 0; i < mothers; ++ i ) {
64  const reco::Candidate * mom = dauMatch->mother( i );
65  if ( mom != 0 && mom->pdgId() == dauMatch->pdgId() &&
66  mom->status() == 3 && dauMatch->status() == 1 ) {
67  // assume a single mother at this point...
68  mom = mom->mother( 0 );
69  }
70  momDaughters.insert( mom );
71  }
72  // if no mother was found return null reference
73  if ( momDaughters.size() == 0 ) return 0;
74  // the first time, momsIntersection is set to momDaughters
75  if ( momsIntersection.size() == 0 ) momsIntersection = momDaughters;
76  else {
77  tmp.clear();
78  set_intersection( momsIntersection.begin(), momsIntersection.end(),
79  momDaughters.begin(), momDaughters.end(),
80  inserter( tmp, tmp.begin() ) );
81  swap( momsIntersection, tmp );
82  }
83  if ( momsIntersection.size() == 0 ) return 0;
84  }
85  // if multiple mothers are found, return a null reference
86  if ( momsIntersection.size() > 1 ) return 0;
87  // return a reference to the unique mother
88  return * momsIntersection.begin();
89  } else {
90  // check for non-composite (leaf) candidate
91  // if one of the maps contains the candidate c
92  for( typename std::vector<const map_type *>::const_iterator m = maps_.begin();
93  m != maps_.end(); ++ m ) {
94  for( typename map_type::const_iterator i = (*m)->begin(); i != (*m)->end(); ++ i ) {
95  if ( & * i->key == & c )
96  return & * i->val;
97  }
98  }
99  return 0;
100  }
101 }
102 
103 #endif
mps_fire.i
i
Definition: mps_fire.py:428
AssociationMap.h
FastCandMatcher::maps_
std::vector< const map_type * > maps_
pointers to stored maps
Definition: FastCandMatcher.h:32
reco::candidate::const_iterator
Definition: const_iterator.h:14
OneToOne.h
FastCandMatcher::map_vector
std::vector< const map_type * > map_vector
map vector
Definition: FastCandMatcher.h:20
reco::Candidate::status
virtual int status() const =0
status word
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
reco::Candidate::mother
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
EDMException.h
reco::Candidate::numberOfMothers
virtual size_type numberOfMothers() const =0
number of mothers (zero or one in most of but not all the cases)
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
FastCandMatcher::operator()
const reco::Candidate * operator()(const reco::Candidate &) const
get match from transient reference
Definition: FastCandMatcher.h:46
FastCandMatcher::map_type
edm::AssociationMap< edm::OneToOne< C, reco::CandidateCollection > > map_type
map type
Definition: FastCandMatcher.h:18
FastCandMatcher::FastCandMatcher
FastCandMatcher(const map_vector &maps)
constructor
edm::AssociationMap
Definition: AssociationMap.h:48
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
reco::Candidate::pdgId
virtual int pdgId() const =0
PDG identifier.
FastCandMatcher::maps
const std::vector< const map_type * > & maps() const
Definition: FastCandMatcher.h:29
reco::Candidate
Definition: Candidate.h:27
std
Definition: JetResolutionObject.h:76
FastCandMatcher
Definition: FastCandMatcher.h:15
reco::swap
void swap(reco::ClusterRemovalInfo &cri1, reco::ClusterRemovalInfo &cri2)
Definition: ClusterRemovalInfo.cc:12
Candidate.h
genParticles_cff.map
map
Definition: genParticles_cff.py:11
edm::AssociationMap::const_iterator
const iterator
Definition: AssociationMap.h:76