CMS 3D CMS Logo

reco::PhysObjectMatcher< C1, C2, S, D, Q > Class Template Reference

#include <PhysicsTools/UtilAlgos/interface/PhysObjectMatcher.h>

Inheritance diagram for reco::PhysObjectMatcher< C1, C2, S, D, Q >:

edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 PhysObjectMatcher (const edm::ParameterSet &cfg)
 ~PhysObjectMatcher ()

Private Types

typedef std::pair< size_t, size_t > IndexPair
typedef std::vector< IndexPairMatchContainer
typedef edm::Association< C2 > MatchMap
typedef C1::value_type T1
typedef C2::value_type T2

Private Member Functions

void produce (edm::Event &, const edm::EventSetup &)
bool select (const T1 &c1, const T2 &c2) const

Private Attributes

edm::ParameterSet config_
distance_
edm::InputTag matched_
bool resolveAmbiguities_
bool resolveByMatchQuality_
select_
edm::InputTag src_


Detailed Description

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
class reco::PhysObjectMatcher< C1, C2, S, D, Q >

Definition at line 63 of file PhysObjectMatcher.h.


Member Typedef Documentation

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
typedef std::pair<size_t, size_t> reco::PhysObjectMatcher< C1, C2, S, D, Q >::IndexPair [private]

Definition at line 71 of file PhysObjectMatcher.h.

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
typedef std::vector<IndexPair> reco::PhysObjectMatcher< C1, C2, S, D, Q >::MatchContainer [private]

Definition at line 72 of file PhysObjectMatcher.h.

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
typedef edm::Association<C2> reco::PhysObjectMatcher< C1, C2, S, D, Q >::MatchMap [private]

Definition at line 70 of file PhysObjectMatcher.h.

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
typedef C1::value_type reco::PhysObjectMatcher< C1, C2, S, D, Q >::T1 [private]

Definition at line 68 of file PhysObjectMatcher.h.

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
typedef C2::value_type reco::PhysObjectMatcher< C1, C2, S, D, Q >::T2 [private]

Definition at line 69 of file PhysObjectMatcher.h.


Constructor & Destructor Documentation

template<typename C1, typename C2, typename S, typename D, typename Q>
reco::PhysObjectMatcher< C1, C2, S, D, Q >::PhysObjectMatcher ( const edm::ParameterSet cfg  )  [inline]

Definition at line 91 of file PhysObjectMatcher.h.

References reco::PhysObjectMatcher< C1, C2, S, D, Q >::resolveAmbiguities_, and reco::PhysObjectMatcher< C1, C2, S, D, Q >::resolveByMatchQuality_.

00091                                                                                    :
00092     config_(cfg),
00093     src_(cfg.template getParameter<edm::InputTag>("src")),
00094     matched_(cfg.template getParameter<edm::InputTag>("matched")), 
00095     resolveAmbiguities_(cfg.template getParameter<bool>("resolveAmbiguities")),
00096     resolveByMatchQuality_(cfg.template getParameter<bool>("resolveByMatchQuality")),
00097     select_(reco::modules::make<S>(cfg)), 
00098     distance_(reco::modules::make<D>(cfg)) {
00099     // definition of the product
00100     produces<MatchMap>();
00101     // set resolveByMatchQuality only if ambiguities are to be resolved
00102     resolveByMatchQuality_ = resolveByMatchQuality_ && resolveAmbiguities_;
00103   }

template<typename C1, typename C2, typename S, typename D, typename Q>
reco::PhysObjectMatcher< C1, C2, S, D, Q >::~PhysObjectMatcher (  )  [inline]

Definition at line 106 of file PhysObjectMatcher.h.

00106 { }


Member Function Documentation

template<typename C1, typename C2, typename S, typename D, typename Q>
void reco::PhysObjectMatcher< C1, C2, S, D, Q >::produce ( edm::Event evt,
const edm::EventSetup  
) [inline, private, virtual]

Implements edm::EDProducer.

Definition at line 109 of file PhysObjectMatcher.h.

References c, reco::PhysObjectMatcher< C1, C2, S, D, Q >::config_, reco::PhysObjectMatcher< C1, C2, S, D, Q >::distance_, edm::helper::Filler< Map >::fill(), edm::Event::getByLabel(), i, index, edm::helper::Filler< Map >::insert(), m, funct::master(), edm::match(), reco::PhysObjectMatcher< C1, C2, S, D, Q >::matched_, edm::Event::put(), reco::PhysObjectMatcher< C1, C2, S, D, Q >::resolveAmbiguities_, reco::PhysObjectMatcher< C1, C2, S, D, Q >::resolveByMatchQuality_, edm::second(), reco::PhysObjectMatcher< C1, C2, S, D, Q >::select(), size, python::multivaluedict::sort(), reco::PhysObjectMatcher< C1, C2, S, D, Q >::src_, and std.

00109                                                                                       {
00110     using namespace edm;
00111     using namespace std;
00112     typedef std::pair<size_t, size_t> IndexPair;
00113     typedef std::vector<IndexPair> MatchContainer;
00114     // get collections from event
00115     Handle<C2> matched;  
00116     evt.getByLabel(matched_, matched);
00117     Handle<C1> cands;  
00118     evt.getByLabel(src_, cands);
00119     // create product
00120     auto_ptr<MatchMap> matchMap(new MatchMap(matched));
00121     size_t size = cands->size();
00122     if( size != 0 ) {
00123       //
00124       // create helpers
00125       //
00126       Q comparator(config_,*cands,*matched);
00127       typename MatchMap::Filler filler(*matchMap);
00128       ::helper::MasterCollection<C1> master(cands);
00129       vector<int> indices(master.size(), -1);      // result: indices in target collection
00130       vector<bool> mLock(matched->size(),false);   // locks in target collection
00131       MatchContainer matchPairs;                   // container of matched pairs
00132       // loop over candidates
00133       for(size_t c = 0; c != size; ++ c) {
00134         const T1 & cand = (*cands)[c];
00135         // no global comparison of match quality -> reset the container for each candidate
00136         if ( !resolveByMatchQuality_ )  matchPairs.clear();
00137         // loop over target collection
00138         for(size_t m = 0; m != matched->size(); ++m) {
00139           const T2 & match = (* matched)[m];
00140           // check lock and preselection
00141           if ( !mLock[m] && select(cand, match)) {
00142 //          double dist = testDR_(cand,match);
00143 //          cout << "dist between c = " << c << " and m = "
00144 //               << m << " is " << dist << " at pts of "
00145 //               << cand.pt() << " " << match.pt() << endl;
00146             // matching requirement fulfilled -> store pair of indices
00147             if ( distance_(cand,match) )  matchPairs.push_back(make_pair(c,m));
00148           }
00149         }
00150         // if match(es) found and no global ambiguity resolution requested
00151         if ( matchPairs.size()>0 && !resolveByMatchQuality_ ) {
00152           // look for and store best match
00153           size_t idx = master.index(c);
00154           assert(idx < indices.size());
00155           size_t index = min_element(matchPairs.begin(), matchPairs.end(), comparator)->second;
00156           indices[idx] = index;
00157           // if ambiguity resolution by order of (reco) candidates:
00158           //   lock element in target collection
00159           if ( resolveAmbiguities_ )  mLock[index] = true;
00160 //        {
00161 //          MatchContainer::const_iterator i = min_element(matchPairs.begin(), matchPairs.end(), comparator);
00162 //          cout << "smallest distance for c = " << c << " is " 
00163 //               << testDR_((*cands)[(*i).first],
00164 //                          (*matched)[(*i).second]) << endl;
00165 //        }
00166         }
00167       }
00168       // ambiguity resolution by global match quality (if requested)
00169       if ( resolveByMatchQuality_ ) {
00170         // sort container of all matches by quality
00171         sort(matchPairs.begin(),matchPairs.end(),comparator);
00172         vector<bool> cLock(master.size(),false);
00173         // loop over sorted container
00174         for ( MatchContainer::const_iterator i=matchPairs.begin();
00175               i!=matchPairs.end(); ++i ) {
00176           size_t c = (*i).first;
00177           size_t m = (*i).second;
00178 //        cout << "rel dp = " << ((*cands)[c].pt()-(*matched)[m].pt())/(*matched)[m].pt() << endl;
00179           // accept only pairs without any lock
00180           if ( mLock[m] || cLock[c] )  continue;
00181           // store index to target collection and lock the two items
00182           size_t idx = master.index(c);
00183           assert(idx < indices.size());
00184           indices[idx] = m;
00185           mLock[m] = true;
00186           cLock[c] = true;
00187         }
00188       }
00189       filler.insert(master.get(), indices.begin(), indices.end());
00190       filler.fill();
00191     }
00192     evt.put(matchMap);
00193   }    

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
bool reco::PhysObjectMatcher< C1, C2, S, D, Q >::select ( const T1 c1,
const T2 c2 
) const [inline, private]

Definition at line 82 of file PhysObjectMatcher.h.

References reco::PhysObjectMatcher< C1, C2, S, D, Q >::select_.

Referenced by reco::PhysObjectMatcher< C1, C2, S, D, Q >::produce().

00082                                                     { 
00083       return select_(c1, c2); 
00084     }


Member Data Documentation

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
edm::ParameterSet reco::PhysObjectMatcher< C1, C2, S, D, Q >::config_ [private]

Definition at line 74 of file PhysObjectMatcher.h.

Referenced by reco::PhysObjectMatcher< C1, C2, S, D, Q >::produce().

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
D reco::PhysObjectMatcher< C1, C2, S, D, Q >::distance_ [private]

Definition at line 86 of file PhysObjectMatcher.h.

Referenced by reco::PhysObjectMatcher< C1, C2, S, D, Q >::produce().

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
edm::InputTag reco::PhysObjectMatcher< C1, C2, S, D, Q >::matched_ [private]

Definition at line 76 of file PhysObjectMatcher.h.

Referenced by reco::PhysObjectMatcher< C1, C2, S, D, Q >::produce().

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
bool reco::PhysObjectMatcher< C1, C2, S, D, Q >::resolveAmbiguities_ [private]

Definition at line 77 of file PhysObjectMatcher.h.

Referenced by reco::PhysObjectMatcher< C1, C2, S, D, Q >::PhysObjectMatcher(), and reco::PhysObjectMatcher< C1, C2, S, D, Q >::produce().

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
bool reco::PhysObjectMatcher< C1, C2, S, D, Q >::resolveByMatchQuality_ [private]

Definition at line 79 of file PhysObjectMatcher.h.

Referenced by reco::PhysObjectMatcher< C1, C2, S, D, Q >::PhysObjectMatcher(), and reco::PhysObjectMatcher< C1, C2, S, D, Q >::produce().

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
S reco::PhysObjectMatcher< C1, C2, S, D, Q >::select_ [private]

Definition at line 85 of file PhysObjectMatcher.h.

Referenced by reco::PhysObjectMatcher< C1, C2, S, D, Q >::select().

template<typename C1, typename C2, typename S, typename D = reco::MatchByDR<typename C1::value_type, typename C2::value_type>, typename Q = helper::LessByMatchDistance< DeltaR<typename C1::value_type, typename C2::value_type>, C1, C2 >>
edm::InputTag reco::PhysObjectMatcher< C1, C2, S, D, Q >::src_ [private]

Definition at line 75 of file PhysObjectMatcher.h.

Referenced by reco::PhysObjectMatcher< C1, C2, S, D, Q >::produce().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:51:26 2009 for CMSSW by  doxygen 1.5.4