CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | 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::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 PhysObjectMatcher (const edm::ParameterSet &cfg)
 
 ~PhysObjectMatcher ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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 &) override
 
bool select (const T1 &c1, const T2 &c2) const
 

Private Attributes

edm::ParameterSet config_
 
distance_
 
edm::EDGetTokenT< C2 > matchedToken_
 
bool resolveAmbiguities_
 
bool resolveByMatchQuality_
 
S select_
 
edm::EDGetTokenT< C1 > srcToken_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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

91  :
92  config_(cfg),
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")),
97  select_(reco::modules::make<S>(cfg)),
98  distance_(reco::modules::make<D>(cfg)) {
99  // definition of the product
100  produces<MatchMap>();
101  // set resolveByMatchQuality only if ambiguities are to be resolved
102  resolveByMatchQuality_ = resolveByMatchQuality_ && resolveAmbiguities_;
103  }
edm::EDGetTokenT< C2 > matchedToken_
edm::ParameterSet config_
edm::EDGetTokenT< C1 > srcToken_
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.

106 { }

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  
)
overrideprivatevirtual

Implements edm::EDProducer.

Definition at line 109 of file PhysObjectMatcher.h.

References assert(), EnergyCorrector::c, distance_, edm::helper::Filler< Map >::fill(), helper::MasterCollection< C1 >::get(), edm::Event::getByToken(), i, customizeTrackingMonitorSeedNumber::idx, helper::MasterCollection< C1 >::index(), cmsHarvester::index, edm::helper::Filler< Map >::insert(), visualization-live-secondInstance_cfg::m, autoMagneticFieldProducer_cfi::master, match(), edm::Event::put(), class-composition::Q, edm::second(), benchmark_cfg::select, helper::MasterCollection< C1 >::size(), findQualityFiles::size, and python.multivaluedict::sort().

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

109  {
110  using namespace edm;
111  using namespace std;
112  typedef std::pair<size_t, size_t> IndexPair;
113  typedef std::vector<IndexPair> MatchContainer;
114  // get collections from event
115  Handle<C2> matched;
116  evt.getByToken(matchedToken_, matched);
117  Handle<C1> cands;
118  evt.getByToken(srcToken_, cands);
119  // create product
120  auto_ptr<MatchMap> matchMap(new MatchMap(matched));
121  size_t size = cands->size();
122  if( size != 0 ) {
123  //
124  // create helpers
125  //
126  Q comparator(config_,*cands,*matched);
127  typename MatchMap::Filler filler(*matchMap);
129  vector<int> indices(master.size(), -1); // result: indices in target collection
130  vector<bool> mLock(matched->size(),false); // locks in target collection
131  MatchContainer matchPairs; // container of matched pairs
132  // loop over candidates
133  for(size_t c = 0; c != size; ++ c) {
134  const T1 & cand = (*cands)[c];
135  // no global comparison of match quality -> reset the container for each candidate
136  if ( !resolveByMatchQuality_ ) matchPairs.clear();
137  // loop over target collection
138  for(size_t m = 0; m != matched->size(); ++m) {
139  const T2 & match = (* matched)[m];
140  // check lock and preselection
141  if ( !mLock[m] && select(cand, match)) {
142 // double dist = testDR_(cand,match);
143 // cout << "dist between c = " << c << " and m = "
144 // << m << " is " << dist << " at pts of "
145 // << cand.pt() << " " << match.pt() << endl;
146  // matching requirement fulfilled -> store pair of indices
147  if ( distance_(cand,match) ) matchPairs.push_back(make_pair(c,m));
148  }
149  }
150  // if match(es) found and no global ambiguity resolution requested
151  if ( matchPairs.size()>0 && !resolveByMatchQuality_ ) {
152  // look for and store best match
153  size_t idx = master.index(c);
154  assert(idx < indices.size());
155  size_t index = min_element(matchPairs.begin(), matchPairs.end(), comparator)->second;
156  indices[idx] = index;
157  // if ambiguity resolution by order of (reco) candidates:
158  // lock element in target collection
159  if ( resolveAmbiguities_ ) mLock[index] = true;
160 // {
161 // MatchContainer::const_iterator i = min_element(matchPairs.begin(), matchPairs.end(), comparator);
162 // cout << "smallest distance for c = " << c << " is "
163 // << testDR_((*cands)[(*i).first],
164 // (*matched)[(*i).second]) << endl;
165 // }
166  }
167  }
168  // ambiguity resolution by global match quality (if requested)
169  if ( resolveByMatchQuality_ ) {
170  // sort container of all matches by quality
171  sort(matchPairs.begin(),matchPairs.end(),comparator);
172  vector<bool> cLock(master.size(),false);
173  // loop over sorted container
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;
178 // cout << "rel dp = " << ((*cands)[c].pt()-(*matched)[m].pt())/(*matched)[m].pt() << endl;
179  // accept only pairs without any lock
180  if ( mLock[m] || cLock[c] ) continue;
181  // store index to target collection and lock the two items
182  size_t idx = master.index(c);
183  assert(idx < indices.size());
184  indices[idx] = m;
185  mLock[m] = true;
186  cLock[c] = true;
187  }
188  }
189  filler.insert(master.get(), indices.begin(), indices.end());
190  filler.fill();
191  }
192  evt.put(matchMap);
193  }
std::vector< IndexPair > MatchContainer
int i
Definition: DBlmapReader.cc:9
bool select(const T1 &c1, const T2 &c2) const
edm::EDGetTokenT< C2 > matchedToken_
edm::ParameterSet config_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
assert(m_qm.get())
edm::EDGetTokenT< C1 > srcToken_
edm::Association< C2 > MatchMap
U second(std::pair< T, U > const &p)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
std::pair< size_t, size_t > IndexPair
helper::Filler< ValueMap< int > > Filler
Definition: ValueMap.h:170
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
tuple size
Write out results.
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
inlineprivate

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::EDGetTokenT<C2> reco::PhysObjectMatcher< C1, C2, S, D, Q >::matchedToken_
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::EDGetTokenT<C1> reco::PhysObjectMatcher< C1, C2, S, D, Q >::srcToken_
private

Definition at line 75 of file PhysObjectMatcher.h.