CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes

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

#include <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)

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_.

                                                                                   :
    config_(cfg),
    src_(cfg.template getParameter<edm::InputTag>("src")),
    matched_(cfg.template getParameter<edm::InputTag>("matched")), 
    resolveAmbiguities_(cfg.template getParameter<bool>("resolveAmbiguities")),
    resolveByMatchQuality_(cfg.template getParameter<bool>("resolveByMatchQuality")),
    select_(reco::modules::make<S>(cfg)), 
    distance_(reco::modules::make<D>(cfg)) {
    // definition of the product
    produces<MatchMap>();
    // set resolveByMatchQuality only if ambiguities are to be resolved
    resolveByMatchQuality_ = resolveByMatchQuality_ && resolveAmbiguities_;
  }
template<typename C1 , typename C2 , typename S , typename D , typename Q >
reco::PhysObjectMatcher< C1, C2, S, D, Q >::~PhysObjectMatcher ( )

Definition at line 106 of file PhysObjectMatcher.h.

{ }

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  
) [private, virtual]

Implements edm::EDProducer.

Definition at line 109 of file PhysObjectMatcher.h.

References trackerHits::c, edm::helper::Filler< Map >::fill(), edm::Event::getByLabel(), i, UserOptions_cff::idx, getHLTprescales::index, edm::helper::Filler< Map >::insert(), m, funct::master(), match(), edm::Event::put(), edm::second(), benchmark_cfg::select, findQualityFiles::size, and python::multivaluedict::sort().

                                                                                      {
    using namespace edm;
    using namespace std;
    typedef std::pair<size_t, size_t> IndexPair;
    typedef std::vector<IndexPair> MatchContainer;
    // get collections from event
    Handle<C2> matched;  
    evt.getByLabel(matched_, matched);
    Handle<C1> cands;  
    evt.getByLabel(src_, cands);
    // create product
    auto_ptr<MatchMap> matchMap(new MatchMap(matched));
    size_t size = cands->size();
    if( size != 0 ) {
      //
      // create helpers
      //
      Q comparator(config_,*cands,*matched);
      typename MatchMap::Filler filler(*matchMap);
      ::helper::MasterCollection<C1> master(cands);
      vector<int> indices(master.size(), -1);      // result: indices in target collection
      vector<bool> mLock(matched->size(),false);   // locks in target collection
      MatchContainer matchPairs;                   // container of matched pairs
      // loop over candidates
      for(size_t c = 0; c != size; ++ c) {
        const T1 & cand = (*cands)[c];
        // no global comparison of match quality -> reset the container for each candidate
        if ( !resolveByMatchQuality_ )  matchPairs.clear();
        // loop over target collection
        for(size_t m = 0; m != matched->size(); ++m) {
          const T2 & match = (* matched)[m];
          // check lock and preselection
          if ( !mLock[m] && select(cand, match)) {
//          double dist = testDR_(cand,match);
//          cout << "dist between c = " << c << " and m = "
//               << m << " is " << dist << " at pts of "
//               << cand.pt() << " " << match.pt() << endl;
            // matching requirement fulfilled -> store pair of indices
            if ( distance_(cand,match) )  matchPairs.push_back(make_pair(c,m));
          }
        }
        // if match(es) found and no global ambiguity resolution requested
        if ( matchPairs.size()>0 && !resolveByMatchQuality_ ) {
          // look for and store best match
          size_t idx = master.index(c);
          assert(idx < indices.size());
          size_t index = min_element(matchPairs.begin(), matchPairs.end(), comparator)->second;
          indices[idx] = index;
          // if ambiguity resolution by order of (reco) candidates:
          //   lock element in target collection
          if ( resolveAmbiguities_ )  mLock[index] = true;
//        {
//          MatchContainer::const_iterator i = min_element(matchPairs.begin(), matchPairs.end(), comparator);
//          cout << "smallest distance for c = " << c << " is " 
//               << testDR_((*cands)[(*i).first],
//                          (*matched)[(*i).second]) << endl;
//        }
        }
      }
      // ambiguity resolution by global match quality (if requested)
      if ( resolveByMatchQuality_ ) {
        // sort container of all matches by quality
        sort(matchPairs.begin(),matchPairs.end(),comparator);
        vector<bool> cLock(master.size(),false);
        // loop over sorted container
        for ( MatchContainer::const_iterator i=matchPairs.begin();
              i!=matchPairs.end(); ++i ) {
          size_t c = (*i).first;
          size_t m = (*i).second;
//        cout << "rel dp = " << ((*cands)[c].pt()-(*matched)[m].pt())/(*matched)[m].pt() << endl;
          // accept only pairs without any lock
          if ( mLock[m] || cLock[c] )  continue;
          // store index to target collection and lock the two items
          size_t idx = master.index(c);
          assert(idx < indices.size());
          indices[idx] = m;
          mLock[m] = true;
          cLock[c] = true;
        }
      }
      filler.insert(master.get(), indices.begin(), indices.end());
      filler.fill();
    }
    evt.put(matchMap);
  }    
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_.

                                                    { 
      return select_(c1, c2); 
    }

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.

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.

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.

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]
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]
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]
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.