CMS 3D CMS Logo

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::stream::EDProducer<>

Public Member Functions

 PhysObjectMatcher (const edm::ParameterSet &cfg)
 
 ~PhysObjectMatcher () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

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::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

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 58 of file PhysObjectMatcher.h.

Member Typedef Documentation

◆ IndexPair

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 67 of file PhysObjectMatcher.h.

◆ MatchContainer

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 68 of file PhysObjectMatcher.h.

◆ 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>>
typedef edm::Association<C2> reco::PhysObjectMatcher< C1, C2, S, D, Q >::MatchMap
private

Definition at line 66 of file PhysObjectMatcher.h.

◆ T1

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 64 of file PhysObjectMatcher.h.

◆ T2

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 65 of file PhysObjectMatcher.h.

Constructor & Destructor Documentation

◆ PhysObjectMatcher()

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 85 of file PhysObjectMatcher.h.

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

86  : config_(cfg),
87  srcToken_(consumes<C1>(cfg.template getParameter<edm::InputTag>("src"))),
88  matchedToken_(consumes<C2>(cfg.template getParameter<edm::InputTag>("matched"))),
89  resolveAmbiguities_(cfg.template getParameter<bool>("resolveAmbiguities")),
90  resolveByMatchQuality_(cfg.template getParameter<bool>("resolveByMatchQuality")),
91  select_(reco::modules::make<S>(cfg)),
92  distance_(reco::modules::make<D>(cfg)) {
93  // definition of the product
94  produces<MatchMap>();
95  // set resolveByMatchQuality only if ambiguities are to be resolved
97  }
edm::EDGetTokenT< C2 > matchedToken_
edm::ParameterSet config_
edm::EDGetTokenT< C1 > srcToken_

◆ ~PhysObjectMatcher()

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

Definition at line 100 of file PhysObjectMatcher.h.

100 {}

Member Function Documentation

◆ produce()

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

Definition at line 103 of file PhysObjectMatcher.h.

References cms::cuda::assert(), HltBtagPostValidation_cff::c, HLT_2023v12_cff::cands, distance_, trigObjTnPSource_cfi::filler, edm::Event::getByToken(), mps_fire::i, heavyIonCSV_trainingSettings::idx, dqmdumpme::indices, visualization-live-secondInstance_cfg::m, volumeBasedMagneticField_160812_cfi::master, muonTagProbeFilters_cff::matched, eostools::move(), edm::Event::put(), edm::second(), singleTopDQM_cfi::select, findQualityFiles::size, and jetUpdater_cfi::sort.

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

◆ 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>>
bool reco::PhysObjectMatcher< C1, C2, S, D, Q >::select ( const T1 c1,
const T2 c2 
) const
inlineprivate

Member Data Documentation

◆ config_

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 70 of file PhysObjectMatcher.h.

◆ distance_

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 80 of file PhysObjectMatcher.h.

◆ matchedToken_

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 72 of file PhysObjectMatcher.h.

◆ resolveAmbiguities_

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

◆ resolveByMatchQuality_

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

◆ 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>>
S reco::PhysObjectMatcher< C1, C2, S, D, Q >::select_
private

◆ srcToken_

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 71 of file PhysObjectMatcher.h.