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 )
126 matchedRefs_[ & matched[
i ] ] =
ref_type( matched_,
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;
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() ) );
184 swap( momsIntersection, tmp );
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>
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
bool isNull() const
Checks for null.
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)
key_type key() const
Accessor for product key.
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)
void swap(reco::ClusterRemovalInfo &cri1, reco::ClusterRemovalInfo &cri2)
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