1 #ifndef UtilAlgos_PhysObjectMatcher_h
2 #define UtilAlgos_PhysObjectMatcher_h
32 const C1&
c1,
const C2& c2) :
35 const std::pair<size_t,size_t>&
p2)
const {
55 template<
typename C1,
typename C2,
typename S,
90 template<
typename C1,
typename C2,
typename S,
typename D,
typename Q>
93 src_(cfg.
template getParameter<edm::InputTag>(
"src")),
94 matched_(cfg.
template getParameter<edm::InputTag>(
"matched")),
95 resolveAmbiguities_(cfg.
template getParameter<bool>(
"resolveAmbiguities")),
96 resolveByMatchQuality_(cfg.
template getParameter<bool>(
"resolveByMatchQuality")),
97 select_(
reco::modules::
make<S>(cfg)),
100 produces<MatchMap>();
105 template<
typename C1,
typename C2,
typename S,
typename D,
typename Q>
108 template<
typename C1,
typename C2,
typename S,
typename D,
typename Q>
112 typedef std::pair<size_t, size_t>
IndexPair;
120 auto_ptr<MatchMap> matchMap(
new MatchMap(matched));
121 size_t size = cands->size();
126 Q comparator(config_,*cands,*matched);
129 vector<int> indices(master.
size(), -1);
130 vector<bool> mLock(matched->size(),
false);
133 for(
size_t c = 0;
c !=
size; ++
c) {
134 const T1 & cand = (*cands)[
c];
136 if ( !resolveByMatchQuality_ ) matchPairs.clear();
138 for(
size_t m = 0;
m != matched->size(); ++
m) {
141 if ( !mLock[
m] &&
select(cand, match)) {
147 if ( distance_(cand,match) ) matchPairs.push_back(make_pair(
c,
m));
151 if ( matchPairs.size()>0 && !resolveByMatchQuality_ ) {
154 assert(idx < indices.size());
155 size_t index = min_element(matchPairs.begin(), matchPairs.end(), comparator)->
second;
159 if ( resolveAmbiguities_ ) mLock[
index] =
true;
169 if ( resolveByMatchQuality_ ) {
171 sort(matchPairs.begin(),matchPairs.end(),comparator);
172 vector<bool> cLock(master.
size(),
false);
174 for ( MatchContainer::const_iterator
i=matchPairs.begin();
175 i!=matchPairs.end(); ++
i ) {
176 size_t c = (*i).first;
177 size_t m = (*i).second;
180 if ( mLock[m] || cLock[c] )
continue;
183 assert(idx < indices.size());
189 filler.
insert(master.
get(), indices.begin(), indices.end());
const edm::Handle< C1 > & get() const
std::vector< IndexPair > MatchContainer
bool select(const T1 &c1, const T2 &c2) const
edm::ParameterSet config_
S make(const edm::ParameterSet &cfg)
void insert(const H &h, I begin, I end)
Default class for ranking matches: sorting by smaller distance.
void produce(edm::Event &, const edm::EventSetup &) override
edm::Association< C2 > MatchMap
U second(std::pair< T, U > const &p)
PhysObjectMatcher(const edm::ParameterSet &cfg)
bool resolveByMatchQuality_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
size_t index(size_t i) const
LessByMatchDistance(const edm::ParameterSet &cfg, const C1 &c1, const C2 &c2)
Container::value_type value_type
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
std::pair< size_t, size_t > IndexPair
bool operator()(const std::pair< size_t, size_t > &p1, const std::pair< size_t, size_t > &p2) const
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
DecomposeProduct< arg, typename Div::arg > D
tuple size
Write out results.