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,
60 typename C2::value_type>,
68 typedef typename C1::value_type
T1;
69 typedef typename C2::value_type
T2;
82 bool select(
const T1 &
c1,
const T2 & c2)
const {
83 return select_(c1, c2);
90 template<
typename C1,
typename C2,
typename S,
typename D,
typename Q>
93 srcToken_(consumes<C1>(cfg.
template getParameter<
edm::InputTag>(
"src"))),
94 matchedToken_(consumes<C2>(cfg.
template getParameter<
edm::InputTag>(
"matched"))),
95 resolveAmbiguities_(cfg.
template getParameter<
bool>(
"resolveAmbiguities")),
96 resolveByMatchQuality_(cfg.
template getParameter<
bool>(
"resolveByMatchQuality")),
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 unique_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);
131 MatchContainer matchPairs;
133 for(
size_t c = 0;
c !=
size; ++
c) {
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));
154 assert(idx < indices.size());
155 size_t index = min_element(matchPairs.begin(), matchPairs.end(), comparator)->
second;
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
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.
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_
size_t index(size_t i) const
LessByMatchDistance(const edm::ParameterSet &cfg, const C1 &c1, const C2 &c2)
def template(fileName, svg, replaceme="REPLACEME")
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
double S(const TLorentzVector &, const TLorentzVector &)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.