1 #ifndef UtilAlgos_Matcher_h
2 #define UtilAlgos_Matcher_h
20 template<
typename C1,
typename C2,
typename M = edm::AssociationMap<edm::OneToOne<C1, C2> > >
37 virtual bool select(
const T1 &,
const T2 & )
const = 0;
40 template<
typename C1,
typename C2,
70 return p1.second < p2.second;
75 template<
typename C1,
typename C2,
typename M>
77 srcToken_( consumes<C1>( cfg.
template getParameter<edm::
InputTag>(
"src" ) ) ),
78 matchedToken_( consumes<C2>( cfg.
template getParameter<edm::
InputTag>(
"matched" ) ) ),
79 distMin_( cfg.
template getParameter<double>(
"distMin" ) ) {
83 template<
typename C1,
typename C2,
typename M>
86 template<
typename C1,
typename C2,
typename M>
94 typedef typename MatchMap::ref_type ref_type;
95 typedef typename ref_type::key_type key_ref_type;
97 auto_ptr<MatchMap> matchMap(
new MatchMap( ref_type( key_ref_type( cands ),
98 value_ref_type( matched ) ) ) );
99 for(
size_t c = 0;
c != cands->size(); ++
c ) {
100 const T1 & cand = (*cands)[
c ];
101 vector<helper::MatchPair>
v;
102 for(
size_t m = 0;
m != matched->size(); ++
m ) {
103 const T2 &
match = ( * matched )[
m ];
104 if (
select( cand, match ) ) {
105 double dist = matchDistance( cand, match );
106 if ( dist < distMin_ ) v.push_back( make_pair(
m, dist ) );
109 if ( v.size() > 0 ) {
111 typedef typename MatchMap::key_type key_type;
112 typedef typename MatchMap::data_type data_type;
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
virtual bool select(const T1 &, const T2 &) const =0
bool getByToken(EDGetToken token, Handle< PROD > &result) const
double matchDistance(const T1 &c1, const T2 &c2) const
Matcher(const edm::ParameterSet &cfg)
S make(const edm::ParameterSet &cfg)
edm::EDGetTokenT< C1 > srcToken_
bool select(const T1 &c1, const T2 &c2) const
MatcherBase< C1, C2, M >::T2 T2
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
virtual double matchDistance(const T1 &, const T2 &) const =0
Container::value_type value_type
DecomposeProduct< arg, typename Div::arg > D
MatcherBase< C1, C2, M >::T1 T1
void produce(edm::Event &, const edm::EventSetup &) override
double S(const TLorentzVector &, const TLorentzVector &)
std::pair< size_t, double > MatchPair
edm::EDGetTokenT< C2 > matchedToken_
bool operator()(const MatchPair &p1, const MatchPair &p2) const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
MatcherBase< C1, C2, M >::MatchMap MatchMap
MatcherBase(const edm::ParameterSet &)