CMS 3D CMS Logo

CandOneToManyDeltaRMatcher.cc
Go to the documentation of this file.
1 /* \class CandOneToManyDeltaRMatcher
2  *
3  * Producer for simple match map:
4  * class to match two collections of candidate
5  * with one-to-Many matching
6  * All elements of class "matched" are matched to each element
7  * of class "source" orderd in DeltaR
8  *
9  */
10 
13 
15 
16 #include <vector>
17 #include <iostream>
18 
20 public:
22  ~CandOneToManyDeltaRMatcher() override;
23 
24 private:
25  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
26 
30 };
31 
39 
45 
46 #include <Math/VectorUtil.h>
47 #include <TMath.h>
48 
49 using namespace edm;
50 using namespace std;
51 using namespace reco;
52 using namespace ROOT::Math::VectorUtil;
53 
54 namespace reco {
55  namespace helper {
56  typedef pair<size_t, double> MatchPair;
57 
58  struct SortBySecond {
59  bool operator()(const MatchPair& p1, const MatchPair& p2) const { return p1.second < p2.second; }
60  };
61  } // namespace helper
62 } // namespace reco
63 
65  : sourceToken_(consumes<CandidateCollection>(cfg.getParameter<InputTag>("src"))),
66  matchedToken_(consumes<CandidateCollection>(cfg.getParameter<InputTag>("matched"))),
67  printdebug_(cfg.getUntrackedParameter<bool>("printDebug", false)) {
68  produces<CandMatchMapMany>();
69 }
70 
72 
78 
79  if (printdebug_) {
80  for (CandidateCollection::const_iterator c = source->begin(); c != source->end(); ++c) {
81  cout << "[CandOneToManyDeltaRMatcher] Et source " << c->et() << endl;
82  }
83  for (CandidateCollection::const_iterator c = matched->begin(); c != matched->end(); ++c) {
84  cout << "[CandOneToManyDeltaRMatcher] Et matched " << c->et() << endl;
85  }
86  }
87 
88  auto matchMap = std::make_unique<CandMatchMapMany>(
90  for (size_t c = 0; c != source->size(); ++c) {
91  const Candidate& src = (*source)[c];
92  if (printdebug_)
93  cout << "[CandOneToManyDeltaRMatcher] source (Et,Eta,Phi) =(" << src.et() << "," << src.eta() << "," << src.phi()
94  << ")" << endl;
95  vector<reco::helper::MatchPair> v;
96  for (size_t m = 0; m != matched->size(); ++m) {
97  const Candidate& match = (*matched)[m];
98  double dist = DeltaR(src.p4(), match.p4());
99  v.push_back(make_pair(m, dist));
100  }
101  if (!v.empty()) {
102  sort(v.begin(), v.end(), reco::helper::SortBySecond());
103  for (size_t m = 0; m != v.size(); ++m) {
104  if (printdebug_)
105  cout << "[CandOneToManyDeltaRMatcher] match (Et,Eta,Phi) =(" << (*matched)[v[m].first].et() << ","
106  << (*matched)[v[m].first].eta() << "," << (*matched)[v[m].first].phi() << ") DeltaR=" << v[m].second
107  << endl;
108  matchMap->insert(CandidateRef(source, c), make_pair(CandidateRef(matched, v[m].first), v[m].second));
109  }
110  }
111  }
112 
113  evt.put(std::move(matchMap));
114 }
115 
118 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
Definition: helper.py:1
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
bool operator()(const MatchPair &p1, const MatchPair &p2) const
edm::EDGetTokenT< reco::CandidateCollection > sourceToken_
U second(std::pair< T, U > const &p)
CandOneToManyDeltaRMatcher(const edm::ParameterSet &)
edm::EDGetTokenT< reco::CandidateCollection > matchedToken_
pair< size_t, double > MatchPair
edm::Ref< CandidateCollection > CandidateRef
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:29
fixed size matrix
HLT enums.
Tag::ref_type ref_type
Holds the RefProd or RefToBaseProd of 1 or 2 collections.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
edm::RefProd< CandidateCollection > CandidateRefProd
reference to a collection of Candidate objects
Definition: CandidateFwd.h:37
static std::string const source
Definition: EdmProvDump.cc:46
def move(src, dest)
Definition: eostools.py:511