CMS 3D CMS Logo

GenJetClosestMatchSelectorDefinition.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PFCandProducer_GenJetClosestMatchSelectorDefinition
2 #define PhysicsTools_PFCandProducer_GenJetClosestMatchSelectorDefinition
3 
8 
10 
12 
13 #include <iostream>
14 
18  typedef std::vector<reco::GenJet *> container;
19  typedef container::const_iterator const_iterator;
20 
22  matchTo_ = iC.consumes<edm::View<reco::Candidate>>(cfg.getParameter<edm::InputTag>("MatchTo"));
23  }
24 
25  const_iterator begin() const { return selected_.begin(); }
26 
27  const_iterator end() const { return selected_.end(); }
28 
29  void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s) {
30  selected_.clear();
31 
33  e.getByToken(matchTo_, matchCandidates);
34 
35  unsigned key = 0;
36 
37  // std::cout<<"number of candidates
38  // "<<matchCandidates->size()<<std::endl;
39 
41  for (IC ic = matchCandidates->begin(); ic != matchCandidates->end(); ++ic) {
42  double eta2 = ic->eta();
43  double phi2 = ic->phi();
44 
45  // std::cout<<"cand "<<eta2<<" "<<phi2<<std::endl;
46 
47  // look for the closest gen jet
48  double deltaR2Min = 9999;
49  collection::const_iterator closest = hc->end();
50  for (collection::const_iterator genjet = hc->begin(); genjet != hc->end(); ++genjet, ++key) {
51  reco::GenJetRef genJetRef(hc, key);
52 
53  // is it matched?
54 
55  double eta1 = genjet->eta();
56  double phi1 = genjet->phi();
57 
58  double deltaR2 = reco::deltaR2(eta1, phi1, eta2, phi2);
59 
60  // std::cout<<" genjet "<<eta1<<" "<<phi1<<" "<<deltaR2<<std::endl;
61 
62  // cut should be a parameter
63  if (deltaR2 < deltaR2Min) {
64  deltaR2Min = deltaR2;
65  closest = genjet;
66  }
67  }
68 
69  if (deltaR2Min < 0.01) {
70  // std::cout<<deltaR2Min<<std::endl;
71  selected_.push_back(new reco::GenJet(*closest));
72  }
73  } // end collection iteration
74 
75  // std::cout<<selected_.size()<<std::endl;
76  } // end select()
77 
78  size_t size() const { return selected_.size(); }
79 
80 private:
81  container selected_;
83 };
84 
85 #endif
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
std::vector< GenJet > GenJetCollection
collection of GenJet objects
edm::EDGetTokenT< edm::View< reco::Candidate > > matchTo_
Jets made from MC generator particles.
Definition: GenJet.h:23
GenJetClosestMatchSelectorDefinition(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
susybsm::HSCParticleCollection hc
Definition: classes.h:25