CMS 3D CMS Logo

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 >

Public Types

typedef reco::helper::CandMapTrait< C1, C2 >::type map_type
 map type 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 map_type::key_type reference_type
 concrete candidate reference 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...
 

Public Member Functions

 CandMatcherBase (const map_type &map)
 constructor More...
 
 CandMatcherBase (const map_vector &maps)
 constructor More...
 
ref_type operator() (const reco::Candidate &) const
 get match from transient reference 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 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...
 
const std::vector< const map_type * > & maps () const
 

Private Types

typedef std::map< const reco::Candidate *, reference_typeCandRefMap
 pointer map type More...
 
typedef std::map< const reco::Candidate *, ref_typeMatchedRefMap
 pointer map type More...
 

Private Member Functions

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

◆ CandRefMap

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.

◆ map_type

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.

◆ map_vector

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.

◆ MatchedRefMap

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.

◆ ref_type

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.

◆ reference_type

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.

◆ refProd_type

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.

◆ value_type

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.

Constructor & Destructor Documentation

◆ CandMatcherBase() [1/2]

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

constructor

◆ CandMatcherBase() [2/2]

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

constructor

◆ ~CandMatcherBase()

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

destructor

Definition at line 146 of file CandMatcher.h.

146  {
147 }

Member Function Documentation

◆ compositePreselect()

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 >.

◆ getDaughters()

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 >.

◆ init()

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

init at constructor

Definition at line 89 of file CandMatcher.h.

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 }

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

◆ initMaps()

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

init maps

Definition at line 114 of file CandMatcher.h.

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 }

References cms::cuda::assert(), c, HLT_FULL_cff::cands, ztail::d, f, getDaughters(), mps_fire::i, dqmiolumiharvest::j, dqmdumpme::k, visualization-live-secondInstance_cfg::m, and muonTagProbeFilters_cff::matched.

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

◆ 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.

48 { return maps_; }

References CandMatcherBase< C1, C2 >::maps_.

◆ operator()()

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.

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 }

References c, ztail::d, f, dqmdumpme::k, visualization-live-secondInstance_cfg::m, muonTagProbeFilters_cff::matched, reco::swap(), and createJobs::tmp.

Member Data Documentation

◆ candRefs_

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.

◆ maps_

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().

◆ matched_

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.

◆ matchedMothers_

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.

◆ matchedRefs_

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.

muonTagProbeFilters_cff.matched
matched
Definition: muonTagProbeFilters_cff.py:62
mps_fire.i
i
Definition: mps_fire.py:428
CandMatcherBase::reference_type
map_type::key_type reference_type
concrete candidate reference type
Definition: CandMatcher.h:27
CandMatcherBase::maps_
std::vector< const map_type * > maps_
pointers to stored maps
Definition: CandMatcher.h:51
edm::errors::InvalidReference
Definition: EDMException.h:39
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
CandMatcherBase::compositePreselect
virtual bool compositePreselect(const reco::Candidate &c, const reco::Candidate &m) const =0
composite candidate preselection
CandMatcherBase::matchedRefs_
MatchedRefMap matchedRefs_
pointer map of matched candidates (e.g.: MC truth)
Definition: CandMatcher.h:61
edm::swap
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
reco::candidate::const_iterator
Definition: const_iterator.h:14
cms::cuda::assert
assert(be >=bs)
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
CandMatcherBase::ref_type
reco::helper::CandRefTrait< C2 >::ref_type ref_type
ref type
Definition: CandMatcher.h:21
CandMatcherBase::getDaughters
virtual std::vector< const reco::Candidate * > getDaughters(const reco::Candidate *) const =0
get ultimate daughter (can skip status = 3 in MC)
edm::Exception
Definition: EDMException.h:77
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::AssociationMap::const_iterator
friend struct const_iterator
Definition: AssociationMap.h:274
CandMatcherBase::candRefs_
CandRefMap candRefs_
pointer map of candidates (e.g.: reco)
Definition: CandMatcher.h:59
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15146
reco::Candidate
Definition: Candidate.h:27
std
Definition: JetResolutionObject.h:76
edm::AssociationMap::key_type
Tag::key_type key_type
insert key type
Definition: AssociationMap.h:59
ztail.d
d
Definition: ztail.py:151
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
CandMatcherBase::matched_
refProd_type matched_
reference to matched collectino
Definition: CandMatcher.h:53
CandMatcherBase::matchedMothers_
std::vector< std::set< size_t > > matchedMothers_
mother + n.daughters indices from matched
Definition: CandMatcher.h:63