1 #ifndef UtilAlgos_PhysObjectMatcher_h
2 #define UtilAlgos_PhysObjectMatcher_h
29 template <
typename D,
typename C1,
typename C2>
34 bool operator()(
const std::pair<size_t, size_t>&
p1,
const std::pair<size_t, size_t>&
p2)
const {
53 template <
typename C1,
84 template <
typename C1,
typename C2,
typename S,
typename D,
typename Q>
88 matchedToken_(consumes<C2>(cfg.
template getParameter<edm::
InputTag>(
"matched"))),
89 resolveAmbiguities_(cfg.
template getParameter<bool>(
"resolveAmbiguities")),
90 resolveByMatchQuality_(cfg.
template getParameter<bool>(
"resolveByMatchQuality")),
99 template <
typename C1,
typename C2,
typename S,
typename D,
typename Q>
102 template <
typename C1,
typename C2,
typename S,
typename D,
typename Q>
106 typedef std::pair<size_t, size_t>
IndexPair;
114 unique_ptr<MatchMap> matchMap(
new MatchMap(matched));
120 Q comparator(config_, *
cands, *matched);
123 vector<int>
indices(master.size(), -1);
124 vector<bool> mLock(matched->size(),
false);
127 for (
size_t c = 0;
c !=
size; ++
c) {
128 const T1& cand = (*cands)[
c];
130 if (!resolveByMatchQuality_)
133 for (
size_t m = 0;
m != matched->size(); ++
m) {
136 if (!mLock[
m] &&
select(cand, match)) {
143 matchPairs.push_back(make_pair(
c,
m));
147 if (!matchPairs.empty() && !resolveByMatchQuality_) {
149 size_t idx = master.index(
c);
151 size_t index = min_element(matchPairs.begin(), matchPairs.end(), comparator)->
second;
155 if (resolveAmbiguities_)
166 if (resolveByMatchQuality_) {
168 sort(matchPairs.begin(), matchPairs.end(), comparator);
169 vector<bool> cLock(master.size(),
false);
171 for (MatchContainer::const_iterator
i = matchPairs.begin();
i != matchPairs.end(); ++
i) {
172 size_t c = (*i).first;
173 size_t m = (*i).second;
176 if (mLock[m] || cLock[c])
179 size_t idx = master.index(c);
std::vector< IndexPair > MatchContainer
Master< F > master(const F &f)
~PhysObjectMatcher() override
bool select(const T1 &c1, const T2 &c2) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
const edm::EventSetup & c
edm::EDGetTokenT< C2 > matchedToken_
edm::ParameterSet config_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
S make(const edm::ParameterSet &cfg)
void insert(const H &h, I begin, I end)
edm::EDGetTokenT< C1 > srcToken_
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)
Container::value_type value_type
bool resolveByMatchQuality_
LessByMatchDistance(const edm::ParameterSet &cfg, const C1 &c1, const C2 &c2)
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
DecomposeProduct< arg, typename Div::arg > D
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
tuple size
Write out results.