CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes
CandMatcherBase< C1, C2 > Class Template Referenceabstract

#include <CandMatcher.h>

Inheritance diagram for CandMatcherBase< C1, C2 >:
CandMatcher< C1, C2 > CandMatcher< C1, C2 >

Public Types

typedef
reco::helper::CandMapTrait< C1,
C2 >::type 
map_type
 map type More...
 
typedef
reco::helper::CandMapTrait< C1,
C2 >::type 
map_type
 map type More...
 
typedef std::vector< const
map_type * > 
map_vector
 map vector More...
 
typedef std::vector< const
map_type * > 
map_vector
 map vector More...
 
typedef
reco::helper::CandRefTrait< C2 >
::ref_type 
ref_type
 ref type More...
 
typedef
reco::helper::CandRefTrait< C2 >
::ref_type 
ref_type
 ref type More...
 
typedef map_type::key_type reference_type
 concrete candidate reference type More...
 
typedef map_type::key_type reference_type
 concrete candidate reference type More...
 
typedef
reco::helper::CandRefTrait< C2 >
::refProd_type 
refProd_type
 refProd type More...
 
typedef
reco::helper::CandRefTrait< C2 >
::refProd_type 
refProd_type
 refProd type More...
 
typedef reference_type::value_type value_type
 concrete candidate reference type More...
 
typedef reference_type::value_type value_type
 concrete candidate reference type More...
 

Public Member Functions

 CandMatcherBase (const map_vector &maps)
 constructor More...
 
 CandMatcherBase (const map_vector &maps)
 constructor More...
 
 CandMatcherBase (const map_type &map)
 constructor More...
 
 CandMatcherBase (const map_type &map)
 constructor More...
 
ref_type operator() (const reco::Candidate &) const
 get match from transient reference More...
 
ref_type operator() (const reco::Candidate &) const
 get match from transient reference More...
 
virtual ~CandMatcherBase ()
 destructor More...
 
virtual ~CandMatcherBase ()
 destructor More...
 

Protected Member Functions

virtual bool compositePreselect (const reco::Candidate &c, const reco::Candidate &m) const =0
 composite candidate preselection More...
 
virtual bool compositePreselect (const reco::Candidate &c, const reco::Candidate &m) const =0
 composite candidate preselection More...
 
virtual std::vector< const
reco::Candidate * > 
getDaughters (const reco::Candidate *) const =0
 get ultimate daughter (can skip status = 3 in MC) More...
 
virtual std::vector< const
reco::Candidate * > 
getDaughters (const reco::Candidate *) const =0
 get ultimate daughter (can skip status = 3 in MC) More...
 
void initMaps ()
 init maps More...
 
void initMaps ()
 init maps More...
 
const std::vector< const
map_type * > & 
maps () const
 
const std::vector< const
map_type * > & 
maps () const
 

Private Types

typedef std::map< const
reco::Candidate
*, reference_type
CandRefMap
 pointer map type More...
 
typedef std::map< const
reco::Candidate
*, reference_type
CandRefMap
 pointer map type More...
 
typedef std::map< const
reco::Candidate *, ref_type
MatchedRefMap
 pointer map type More...
 
typedef std::map< const
reco::Candidate *, ref_type
MatchedRefMap
 pointer map type More...
 

Private Member Functions

void init ()
 init at constructor More...
 
void init ()
 init at constructor More...
 

Private Attributes

CandRefMap candRefs_
 pointer map of candidates (e.g.: reco) More...
 
std::vector< const map_type * > maps_
 pointers to stored maps More...
 
refProd_type matched_
 reference to matched collectino More...
 
std::vector< std::set< size_t > > matchedMothers_
 mother + n.daughters indices from matched More...
 
MatchedRefMap matchedRefs_
 pointer map of matched candidates (e.g.: MC truth) More...
 

Detailed Description

template<typename C1, typename C2 = C1>
class CandMatcherBase< C1, C2 >

Definition at line 16 of file CandMatcher.h.

Member Typedef Documentation

template<typename C1, typename C2 = C1>
typedef std::map<const reco::Candidate *, reference_type> CandMatcherBase< C1, C2 >::CandRefMap
private

pointer map type

Definition at line 55 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef std::map<const reco::Candidate *, reference_type> CandMatcherBase< C1, C2 >::CandRefMap
private

pointer map type

Definition at line 56 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef reco::helper::CandMapTrait<C1, C2>::type CandMatcherBase< C1, C2 >::map_type

map type

Definition at line 19 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef reco::helper::CandMapTrait<C1, C2>::type CandMatcherBase< C1, C2 >::map_type

map type

Definition at line 20 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef std::vector<const map_type *> CandMatcherBase< C1, C2 >::map_vector

map vector

Definition at line 25 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef std::vector<const map_type *> CandMatcherBase< C1, C2 >::map_vector

map vector

Definition at line 26 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef std::map<const reco::Candidate *, ref_type> CandMatcherBase< C1, C2 >::MatchedRefMap
private

pointer map type

Definition at line 57 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef std::map<const reco::Candidate *, ref_type> CandMatcherBase< C1, C2 >::MatchedRefMap
private

pointer map type

Definition at line 58 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef reco::helper::CandRefTrait<C2>::ref_type CandMatcherBase< C1, C2 >::ref_type

ref type

Definition at line 21 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef reco::helper::CandRefTrait<C2>::ref_type CandMatcherBase< C1, C2 >::ref_type

ref type

Definition at line 22 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef map_type::key_type CandMatcherBase< C1, C2 >::reference_type

concrete candidate reference type

Definition at line 27 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef map_type::key_type CandMatcherBase< C1, C2 >::reference_type

concrete candidate reference type

Definition at line 28 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef reco::helper::CandRefTrait<C2>::refProd_type CandMatcherBase< C1, C2 >::refProd_type

refProd type

Definition at line 23 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef reco::helper::CandRefTrait<C2>::refProd_type CandMatcherBase< C1, C2 >::refProd_type

refProd type

Definition at line 24 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef reference_type::value_type CandMatcherBase< C1, C2 >::value_type

concrete candidate reference type

Definition at line 29 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
typedef reference_type::value_type CandMatcherBase< C1, C2 >::value_type

concrete candidate reference type

Definition at line 30 of file CandMatcher.h.

Constructor & Destructor Documentation

template<typename C1, typename C2 = C1>
CandMatcherBase< C1, C2 >::CandMatcherBase ( const map_vector maps)
explicit

constructor

template<typename C1, typename C2 = C1>
CandMatcherBase< C1, C2 >::CandMatcherBase ( const map_type map)
explicit

constructor

template<typename C1 , typename C2 >
CandMatcherBase< C1, C2 >::~CandMatcherBase ( )
virtual

destructor

Definition at line 146 of file CandMatcher.h.

146  {
147 }
template<typename C1, typename C2 = C1>
CandMatcherBase< C1, C2 >::CandMatcherBase ( const map_vector maps)
explicit

constructor

template<typename C1, typename C2 = C1>
CandMatcherBase< C1, C2 >::CandMatcherBase ( const map_type map)
explicit

constructor

template<typename C1, typename C2 = C1>
virtual CandMatcherBase< C1, C2 >::~CandMatcherBase ( )
virtual

destructor

Member Function Documentation

template<typename C1, typename C2 = C1>
virtual bool CandMatcherBase< C1, C2 >::compositePreselect ( const reco::Candidate c,
const reco::Candidate m 
) const
protectedpure virtual

composite candidate preselection

Implemented in CandMatcher< C1, C2 >, and CandMatcher< C1, C2 >.

template<typename C1, typename C2 = C1>
virtual bool CandMatcherBase< C1, C2 >::compositePreselect ( const reco::Candidate c,
const reco::Candidate m 
) const
protectedpure virtual

composite candidate preselection

Implemented in CandMatcher< C1, C2 >, and CandMatcher< C1, C2 >.

template<typename C1, typename C2 = C1>
virtual std::vector<const reco::Candidate *> CandMatcherBase< C1, C2 >::getDaughters ( const reco::Candidate ) const
protectedpure virtual

get ultimate daughter (can skip status = 3 in MC)

Implemented in CandMatcher< C1, C2 >, and CandMatcher< C1, C2 >.

template<typename C1, typename C2 = C1>
virtual std::vector<const reco::Candidate *> CandMatcherBase< C1, C2 >::getDaughters ( const reco::Candidate ) const
protectedpure virtual

get ultimate daughter (can skip status = 3 in MC)

Implemented in CandMatcher< C1, C2 >, and CandMatcher< C1, C2 >.

template<typename C1 , typename C2 >
void CandMatcherBase< C1, C2 >::init ( void  )
private

init at constructor

Definition at line 89 of file CandMatcher.h.

References edm::errors::InvalidReference, and visualization-live-secondInstance_cfg::m.

89  {
90  matched_ = maps_.front()->refProd().val;
91  for( typename map_vector::const_iterator m = maps_.begin() + 1;
92  m != maps_.end(); ++ m ) {
93  if( (*m)->refProd().val != matched_ )
95  << "Multiple match maps specified matching different MC truth collections.\n"
96  << "Please, specify maps all matching to the same MC truth collection.\n"
97  << "In most of the cases you may want to match to genParticleCandidate.";
98  }
99 }
std::vector< const map_type * > maps_
pointers to stored maps
Definition: CandMatcher.h:51
refProd_type matched_
reference to matched collectino
Definition: CandMatcher.h:53
template<typename C1, typename C2 = C1>
void CandMatcherBase< C1, C2 >::init ( )
private

init at constructor

template<typename C1 , typename C2 >
void CandMatcherBase< C1, C2 >::initMaps ( )
protected

init maps

Definition at line 114 of file CandMatcher.h.

References assert(), reco::Candidate::begin(), EnergyCorrector::c, ztail::d, reco::Candidate::end(), f, getDaughters(), i, j, relval_steps::k, visualization-live-secondInstance_cfg::m, and dt_dqm_sourceclient_common_cff::reco.

Referenced by CandMatcher< C1, C2 >::CandMatcher().

114  {
115  using namespace reco;
116  using namespace std;
117  for( typename map_vector::const_iterator m = maps_.begin();
118  m != maps_.end(); ++ m ) {
119  typename CandMatcherBase<C1, C2>::map_type::ref_type::key_type cands = (*m)->refProd().key;
120  for( size_t i = 0; i < cands->size(); ++ i ) {
121  candRefs_[ & (*cands)[ i ] ] = reference_type( cands, i );
122  }
123  const C2 & matched = * matched_;
124  size_t matchedSize = matched.size();
125  for( size_t i = 0; i < matchedSize; ++ i )
126  matchedRefs_[ & matched[ i ] ] = ref_type( matched_, i );
127  matchedMothers_.resize( matchedSize );
128  for( size_t i = 0; i < matchedSize; ++ i ) {
129  const Candidate & c = matched[ i ];
130  for( Candidate::const_iterator d = c.begin(); d != c.end(); ++ d ) {
131  vector<const Candidate *> daus = getDaughters( & * d );
132  for( size_t j = 0; j < daus.size(); ++ j ) {
133  const Candidate * daughter = daus[ j ];
134  typename MatchedRefMap::const_iterator f = matchedRefs_.find( daughter );
135  if ( f == matchedRefs_.end() ) continue;
136  size_t k = f->second.key();
137  assert( k < matchedMothers_.size() );
138  matchedMothers_[ k ].insert( i );
139  }
140  }
141  }
142  }
143 }
int i
Definition: DBlmapReader.cc:9
assert(m_qm.get())
CandRefMap candRefs_
pointer map of candidates (e.g.: reco)
Definition: CandMatcher.h:59
Tag::key_type key_type
insert key type
std::vector< const map_type * > maps_
pointers to stored maps
Definition: CandMatcher.h:51
refProd_type matched_
reference to matched collectino
Definition: CandMatcher.h:53
tuple d
Definition: ztail.py:151
reco::helper::CandRefTrait< C2 >::ref_type ref_type
ref type
Definition: CandMatcher.h:21
std::vector< std::set< size_t > > matchedMothers_
mother + n.daughters indices from matched
Definition: CandMatcher.h:63
MatchedRefMap matchedRefs_
pointer map of matched candidates (e.g.: MC truth)
Definition: CandMatcher.h:61
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:146
int j
Definition: DBlmapReader.cc:9
double f[11][100]
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:144
map_type::key_type reference_type
concrete candidate reference type
Definition: CandMatcher.h:27
virtual std::vector< const reco::Candidate * > getDaughters(const reco::Candidate *) const =0
get ultimate daughter (can skip status = 3 in MC)
template<typename C1, typename C2 = C1>
void CandMatcherBase< C1, C2 >::initMaps ( )
protected

init maps

template<typename C1, typename C2 = C1>
const std::vector<const map_type *>& CandMatcherBase< C1, C2 >::maps ( ) const
inlineprotected

Definition at line 48 of file CandMatcher.h.

References CandMatcherBase< C1, C2 >::maps_.

48 { return maps_; }
std::vector< const map_type * > maps_
pointers to stored maps
Definition: CandMatcher.h:51
template<typename C1, typename C2 = C1>
const std::vector<const map_type *>& CandMatcherBase< C1, C2 >::maps ( ) const
inlineprotected

Definition at line 49 of file CandMatcher.h.

References CandMatcherBase< C1, C2 >::maps_.

49 { return maps_; }
std::vector< const map_type * > maps_
pointers to stored maps
Definition: CandMatcher.h:51
template<typename C1 , typename C2 >
CandMatcherBase< C1, C2 >::ref_type CandMatcherBase< C1, C2 >::operator() ( const reco::Candidate c) const

get match from transient reference

Definition at line 150 of file CandMatcher.h.

References reco::Candidate::begin(), ztail::d, reco::Candidate::end(), f, reco::Candidate::hasMasterClone(), edm::Ref< C, T, F >::isNull(), relval_steps::k, edm::Ref< C, T, F >::key(), visualization-live-secondInstance_cfg::m, reco::Candidate::masterClone(), reco::Candidate::numberOfDaughters(), dt_dqm_sourceclient_common_cff::reco, reco::swap(), tmp, and edm::helpers::KeyVal< K, V >::val.

150  {
151  using namespace reco;
152  using namespace std;
153  if ( c.hasMasterClone() )
154  return (*this)( * c.masterClone() );
155  unsigned int nDau = c.numberOfDaughters();
156  const C2 & matched = * matched_;
157  if ( nDau > 0 ) {
158  // check for composite candidate c
159  // navigate to daughters and find parent matches
160  set<size_t> momsIntersection, momDaughters, tmp;
161  for( Candidate::const_iterator d = c.begin(); d != c.end(); ++ d ) {
162  // check here generically if status == 3, then descend down to one more level
163  ref_type m = (*this)( * d );
164  // if a daughter does not match, return a null ref.
165  if ( m.isNull() ) return ref_type();
166  // get matched mother indices (fetched previously)
167  const set<size_t> & allMomDaughters = matchedMothers_[ m.key() ];
168  momDaughters.clear();
169  for( set<size_t>::const_iterator k = allMomDaughters.begin();
170  k != allMomDaughters.end(); ++ k ) {
171  size_t m = * k;
172  if( compositePreselect( c, matched[ m ] ) )
173  momDaughters.insert( m );
174  }
175  // if no mother was found return null reference
176  if ( momDaughters.size() == 0 ) return ref_type();
177  // the first time, momsIntersection is set to momDaughters
178  if ( momsIntersection.size() == 0 ) momsIntersection = momDaughters;
179  else {
180  tmp.clear();
181  set_intersection( momsIntersection.begin(), momsIntersection.end(),
182  momDaughters.begin(), momDaughters.end(),
183  inserter( tmp, tmp.begin() ) );
184  swap( momsIntersection, tmp );
185  }
186  if ( momsIntersection.size() == 0 ) return ref_type();
187  }
188  // if multiple mothers are found, return a null reference
189  if ( momsIntersection.size() > 1 ) return ref_type();
190  // return a reference to the unique mother
191  return ref_type( matched_, * momsIntersection.begin() );
192  } else {
193  // check for non-composite (leaf) candidate
194  // if one of the maps contains the candidate c
195  for( typename std::vector<const map_type *>::const_iterator m = maps_.begin();
196  m != maps_.end(); ++ m ) {
197  typename CandRefMap::const_iterator f = candRefs_.find( & c );
198  if ( f != candRefs_.end() ) {
199  reference_type ref = f->second;
200  typename map_type::const_iterator f = (*m)->find( ref );
201  if ( f != (*m)->end() ) {
202  return f->val;
203  }
204  }
205  }
206  return ref_type();
207  }
208 }
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:70
friend struct const_iterator
CandRefMap candRefs_
pointer map of candidates (e.g.: reco)
Definition: CandMatcher.h:59
std::vector< const map_type * > maps_
pointers to stored maps
Definition: CandMatcher.h:51
refProd_type matched_
reference to matched collectino
Definition: CandMatcher.h:53
tuple d
Definition: ztail.py:151
reco::helper::CandRefTrait< C2 >::ref_type ref_type
ref type
Definition: CandMatcher.h:21
virtual size_type numberOfDaughters() const =0
number of daughters
virtual bool hasMasterClone() const =0
std::vector< std::set< size_t > > matchedMothers_
mother + n.daughters indices from matched
Definition: CandMatcher.h:63
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:146
double f[11][100]
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:144
map_type::key_type reference_type
concrete candidate reference type
Definition: CandMatcher.h:27
virtual bool compositePreselect(const reco::Candidate &c, const reco::Candidate &m) const =0
composite candidate preselection
virtual const CandidateBaseRef & masterClone() const =0
template<typename C1, typename C2 = C1>
ref_type CandMatcherBase< C1, C2 >::operator() ( const reco::Candidate ) const

get match from transient reference

Member Data Documentation

template<typename C1, typename C2 = C1>
CandRefMap CandMatcherBase< C1, C2 >::candRefs_
private

pointer map of candidates (e.g.: reco)

Definition at line 59 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
std::vector< const map_type * > CandMatcherBase< C1, C2 >::maps_
private

pointers to stored maps

Definition at line 51 of file CandMatcher.h.

Referenced by CandMatcherBase< C1, C2 >::maps().

template<typename C1, typename C2 = C1>
refProd_type CandMatcherBase< C1, C2 >::matched_
private

reference to matched collectino

Definition at line 53 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
std::vector< std::set< size_t > > CandMatcherBase< C1, C2 >::matchedMothers_
private

mother + n.daughters indices from matched

Definition at line 63 of file CandMatcher.h.

template<typename C1, typename C2 = C1>
MatchedRefMap CandMatcherBase< C1, C2 >::matchedRefs_
private

pointer map of matched candidates (e.g.: MC truth)

Definition at line 61 of file CandMatcher.h.