test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NewMatcher.h
Go to the documentation of this file.
1 #ifndef UtilAlgos_NewMatcher_h
2 #define UtilAlgos_NewMatcher_h
3 /* \class Matcher
4  *
5  * \author Luca Lista, INFN
6  *
7  */
18 
19 namespace reco {
20  namespace modulesNew {
21 
22  template<typename C1, typename C2,
24  class Matcher : public edm::EDProducer {
25  public:
26  Matcher(const edm::ParameterSet & cfg);
27  ~Matcher();
28  private:
29  typedef typename C1::value_type T1;
30  typedef typename C2::value_type T2;
32  void produce(edm::Event&, const edm::EventSetup&) override;
35  double distMin_;
36  double matchDistance(const T1 & c1, const T2 & c2) const {
37  return distance_(c1, c2);
38  }
39  bool select(const T1 & c1, const T2 & c2) const {
40  return select_(c1, c2);
41  }
44  };
45 
46  namespace helper {
47  typedef std::pair<size_t, double> MatchPair;
48 
49  struct SortBySecond {
50  bool operator()(const MatchPair & p1, const MatchPair & p2) const {
51  return p1.second < p2.second;
52  }
53  };
54  }
55 
56  template<typename C1, typename C2, typename S, typename D>
58  srcToken_(consumes<C1>(cfg.template getParameter<edm::InputTag>("src"))),
59  matchedToken_(consumes<C2>(cfg.template getParameter<edm::InputTag>("matched"))),
60  distMin_(cfg.template getParameter<double>("distMin")),
61  select_(reco::modules::make<S>(cfg)),
62  distance_(reco::modules::make<D>(cfg)) {
63  produces<MatchMap>();
64  }
65 
66  template<typename C1, typename C2, typename S, typename D>
68 
69  template<typename C1, typename C2, typename S, typename D>
71  using namespace edm;
72  using namespace std;
73  Handle<C2> matched;
74  evt.getByToken(matchedToken_, matched);
75  Handle<C1> cands;
76  evt.getByToken(srcToken_, cands);
77  auto_ptr<MatchMap> matchMap(new MatchMap(matched));
78  size_t size = cands->size();
79  if( size != 0 ) {
80  typename MatchMap::Filler filler(*matchMap);
82  std::vector<int> indices(master.size(), -1);
83  for(size_t c = 0; c != size; ++ c) {
84  const T1 & cand = (*cands)[c];
85  vector<helper::MatchPair> v;
86  for(size_t m = 0; m != matched->size(); ++m) {
87  const T2 & match = (* matched)[m];
88  if (select(cand, match)) {
89  double dist = matchDistance(cand, match);
90  if (dist < distMin_) v.push_back(make_pair(m, dist));
91  }
92  }
93  if(v.size() > 0) {
94  size_t idx = master.index(c);
95  assert(idx < indices.size());
96  indices[idx] = min_element(v.begin(), v.end(), helper::SortBySecond())->first;
97  }
98  }
99  filler.insert(master.get(), indices.begin(), indices.end());
100  filler.fill();
101  }
102  evt.put(matchMap);
103  }
104 
105  }
106 }
107 
108 #endif
const edm::Handle< C1 > & get() const
edm::EDGetTokenT< C1 > srcToken_
Definition: NewMatcher.h:33
Definition: deltaR.h:79
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::Association< C2 > MatchMap
Definition: NewMatcher.h:31
S make(const edm::ParameterSet &cfg)
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
bool operator()(const MatchPair &p1, const MatchPair &p2) const
Definition: NewMatcher.h:50
edm::EDGetTokenT< C2 > matchedToken_
Definition: NewMatcher.h:34
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
size_t index(size_t i) const
bool select(const T1 &c1, const T2 &c2) const
Definition: NewMatcher.h:39
bool first
Definition: L1TdeRCT.cc:75
Container::value_type value_type
double p2[4]
Definition: TauolaWrapper.h:90
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void produce(edm::Event &, const edm::EventSetup &) override
Definition: NewMatcher.h:70
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
double p1[4]
Definition: TauolaWrapper.h:89
std::pair< size_t, double > MatchPair
Definition: NewMatcher.h:47
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
double matchDistance(const T1 &c1, const T2 &c2) const
Definition: NewMatcher.h:36
tuple size
Write out results.
def template
Definition: svgfig.py:520
Matcher(const edm::ParameterSet &cfg)
Definition: NewMatcher.h:57