1 #ifndef CandUtils_CandMatcher_h
2 #define CandUtils_CandMatcher_h
15 template<
typename C1,
typename C2 = C1>
48 const std::vector<const map_type *> &
maps()
const {
return maps_; }
51 std::vector<const map_type *>
maps_;
55 typedef std::map<const reco::Candidate *, reference_type>
CandRefMap;
68 template<
typename C1,
typename C2 = C1>
88 template<
typename C1,
typename C2>
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.";
101 template<
typename C1,
typename C2>
107 template<
typename C1,
typename C2>
113 template<
typename C1,
typename C2>
115 using namespace reco;
117 for(
typename map_vector::const_iterator
m = maps_.begin();
118 m != maps_.end(); ++
m ) {
120 for(
size_t i = 0;
i <
cands->size(); ++
i ) {
123 const C2 &
matched = * matched_;
124 size_t matchedSize =
matched.size();
125 for(
size_t i = 0;
i < matchedSize; ++
i )
127 matchedMothers_.resize( matchedSize );
128 for(
size_t i = 0;
i < matchedSize; ++
i ) {
132 for(
size_t j = 0;
j < daus.size(); ++
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 );
145 template<
typename C1,
typename C2>
149 template<
typename C1,
typename C2>
151 using namespace reco;
153 if (
c.hasMasterClone() )
154 return (*
this)( *
c.masterClone() );
155 unsigned int nDau =
c.numberOfDaughters();
156 const C2 &
matched = * matched_;
160 set<size_t> momsIntersection, momDaughters,
tmp;
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 ) {
172 if( compositePreselect(
c,
matched[
m ] ) )
173 momDaughters.insert(
m );
176 if ( momDaughters.size() == 0 )
return ref_type();
178 if ( momsIntersection.size() == 0 ) momsIntersection = momDaughters;
181 set_intersection( momsIntersection.begin(), momsIntersection.end(),
182 momDaughters.begin(), momDaughters.end(),
183 inserter(
tmp,
tmp.begin() ) );
186 if ( momsIntersection.size() == 0 )
return ref_type();
189 if ( momsIntersection.size() > 1 )
return ref_type();
191 return ref_type( matched_, * momsIntersection.begin() );
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() ) {
201 if (
f != (*m)->end() ) {
210 template<
typename C1,
typename C2>
216 template<
typename C1,
typename C2>
222 template<
typename C1,
typename C2>
226 template<
typename C1,
typename C2>
228 std::vector<const reco::Candidate *>
v;
233 template<
typename C1,
typename C2>
236 return(
c.numberOfDaughters() ==
m.numberOfDaughters() );