1 #ifndef CandUtils_CandMatcher_h
2 #define CandUtils_CandMatcher_h
16 template<
typename C1,
typename C2 = C1>
49 const std::vector<const map_type *> &
maps()
const {
return maps_; }
52 std::vector<const map_type *>
maps_;
56 typedef std::map<const reco::Candidate *, reference_type>
CandRefMap;
69 template<
typename C1,
typename C2 = C1>
89 template<
typename C1,
typename C2>
91 matched_ = maps_.front()->refProd().val;
92 for(
typename map_vector::const_iterator
m = maps_.begin() + 1;
93 m != maps_.end(); ++
m ) {
94 if( (*m)->refProd().val != matched_ )
96 <<
"Multiple match maps specified matching different MC truth collections.\n"
97 <<
"Please, specify maps all matching to the same MC truth collection.\n"
98 <<
"In most of the cases you may want to match to genParticleCandidate.";
102 template<
typename C1,
typename C2>
108 template<
typename C1,
typename C2>
114 template<
typename C1,
typename C2>
116 for(
typename map_vector::const_iterator
m = maps_.begin();
117 m != maps_.end(); ++
m ) {
119 for(
size_t i = 0;
i < cands->size(); ++
i ) {
120 candRefs_[ & (*cands)[
i ] ] = reference_type( cands,
i );
122 const C2 & matched = * matched_;
123 size_t matchedSize = matched.size();
124 for(
size_t i = 0;
i < matchedSize; ++
i )
125 matchedRefs_[ & matched[
i ] ] = ref_type( matched_,
i );
126 matchedMothers_.resize( matchedSize );
127 for(
size_t i = 0;
i < matchedSize; ++
i ) {
129 for( Candidate::const_iterator d = c.begin(); d != c.end(); ++ d ) {
130 std;:vector<const Candidate *> daus =
getDaughters( & * d );
131 for(
size_t j = 0;
j < daus.size(); ++
j ) {
133 typename MatchedRefMap::const_iterator
f = matchedRefs_.find( daughter );
134 if ( f == matchedRefs_.end() )
continue;
135 size_t k = f->second.key();
136 assert( k < matchedMothers_.size() );
137 matchedMothers_[
k ].insert(
i );
144 template<
typename C1,
typename C2>
148 template<
typename C1,
typename C2>
153 const C2 & matched = * matched_;
157 std::set<size_t> momsIntersection, momDaughters,
tmp;
158 for( Candidate::const_iterator d = c.
begin(); d != c.
end(); ++ d ) {
160 ref_type
m = (*this)( * d );
162 if ( m.isNull() )
return ref_type();
164 const set<size_t> & allMomDaughters = matchedMothers_[ m.key() ];
165 momDaughters.clear();
166 for( std::set<size_t>::const_iterator
k = allMomDaughters.begin();
167 k != allMomDaughters.end(); ++
k ) {
169 if( compositePreselect( c, matched[ m ] ) )
170 momDaughters.insert( m );
173 if ( momDaughters.size() == 0 )
return ref_type();
175 if ( momsIntersection.size() == 0 ) momsIntersection = momDaughters;
178 set_intersection( momsIntersection.begin(), momsIntersection.end(),
179 momDaughters.begin(), momDaughters.end(),
180 inserter( tmp, tmp.begin() ) );
181 swap( momsIntersection, tmp );
183 if ( momsIntersection.size() == 0 )
return ref_type();
186 if ( momsIntersection.size() > 1 )
return ref_type();
188 return ref_type( matched_, * momsIntersection.begin() );
192 for(
typename std::vector<const map_type *>::const_iterator m = maps_.begin();
193 m != maps_.end(); ++
m ) {
194 typename CandRefMap::const_iterator f = candRefs_.find( & c );
195 if ( f != candRefs_.end() ) {
196 reference_type ref = f->second;
197 typename map_type::const_iterator f = (*m)->find( ref );
198 if ( f != (*m)->end() ) {
207 template<
typename C1,
typename C2>
213 template<
typename C1,
typename C2>
219 template<
typename C1,
typename C2>
223 template<
typename C1,
typename C2>
225 std::vector<const reco::Candidate *>
v;
230 template<
typename C1,
typename C2>
void swap(ora::Record &rh, ora::Record &lh)
void init()
init at constructor
std::vector< const map_type * > map_vector
map vector
std::map< const reco::Candidate *, reference_type > CandRefMap
pointer map type
virtual bool compositePreselect(const reco::Candidate &c, const reco::Candidate &m) const
composite candidate preselection
reference_type::value_type value_type
concrete candidate reference type
reco::helper::CandRefTrait< C2 >::refProd_type refProd_type
refProd type
CandRefMap candRefs_
pointer map of candidates (e.g.: reco)
virtual ~CandMatcherBase()
destructor
Tag::key_type key_type
insert key type
std::vector< const map_type * > maps_
pointers to stored maps
refProd_type matched_
reference to matched collectino
std::map< const reco::Candidate *, ref_type > MatchedRefMap
pointer map type
const std::vector< const map_type * > & maps() const
reco::helper::CandRefTrait< C2 >::ref_type ref_type
ref type
virtual size_type numberOfDaughters() const =0
number of daughters
virtual bool hasMasterClone() const =0
reco::helper::CandMapTrait< C1, C2 >::type map_type
map type
virtual const_iterator end() const =0
last daughter const_iterator
std::vector< std::set< size_t > > matchedMothers_
mother + n.daughters indices from matched
MatchedRefMap matchedRefs_
pointer map of matched candidates (e.g.: MC truth)
CandMatcher(const typename CandMatcherBase< C1, C2 >::map_vector &maps)
constructor
CandMatcherBase(const map_vector &maps)
constructor
virtual ~CandMatcher()
destructor
Container::value_type value_type
ref_type operator()(const reco::Candidate &) const
get match from transient reference
virtual std::vector< const reco::Candidate * > getDaughters(const reco::Candidate *) const
get ultimate daughter (get all in the general case)
std::vector< std::vector< double > > tmp
virtual const_iterator begin() const =0
first daughter const_iterator
map_type::key_type reference_type
concrete candidate reference type
std::vector< SimpleParticle > * getDaughters(HepMC::GenParticle *x)
virtual std::vector< const reco::Candidate * > getDaughters(const reco::Candidate *) const =0
get ultimate daughter (can skip status = 3 in MC)
virtual bool compositePreselect(const reco::Candidate &c, const reco::Candidate &m) const =0
composite candidate preselection
virtual const CandidateBaseRef & masterClone() const =0