CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenJetClosestMatchSelectorDefinition.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PFCandProducer_GenJetClosestMatchSelectorDefinition
2 #define PhysicsTools_PFCandProducer_GenJetClosestMatchSelectorDefinition
3 
5 
7 
9 
10 #include <iostream>
11 
13 
14 
17  typedef std::vector< reco::GenJet *> container;
18  typedef container::const_iterator const_iterator;
19 
21 
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,
30  const edm::Event & e,
31  const edm::EventSetup& s)
32  {
33 
34  selected_.clear();
35 
37  e.getByToken( matchTo_, matchCandidates);
38 
39 
40  unsigned key=0;
41 
42  // std::cout<<"number of candidates "<<matchCandidates->size()<<std::endl;
43 
45  for( IC ic = matchCandidates->begin();
46  ic!= matchCandidates->end(); ++ic ) {
47 
48  double eta2 = ic->eta();
49  double phi2 = ic->phi();
50 
51  // std::cout<<"cand "<<eta2<<" "<<phi2<<std::endl;
52 
53 
54  // look for the closest gen jet
55  double deltaR2Min = 9999;
56  collection::const_iterator closest = hc->end();
57  for( collection::const_iterator genjet = hc->begin();
58  genjet != hc->end();
59  ++genjet, ++key) {
60 
61  reco::GenJetRef genJetRef(hc, key);
62 
63  // is it matched?
64 
65  double eta1 = genjet->eta();
66  double phi1 = genjet->phi();
67 
68 
69  double deltaR2 = reco::deltaR2(eta1, phi1, eta2, phi2);
70 
71  // std::cout<<" genjet "<<eta1<<" "<<phi1<<" "<<deltaR2<<std::endl;
72 
73  // cut should be a parameter
74  if( deltaR2<deltaR2Min ) {
75  deltaR2Min = deltaR2;
76  closest = genjet;
77  }
78  }
79 
80  if(deltaR2Min<0.01 ) {
81  // std::cout<<deltaR2Min<<std::endl;
82  selected_.push_back( new reco::GenJet(*closest) );
83  }
84  } // end collection iteration
85 
86  // std::cout<<selected_.size()<<std::endl;
87  } // end select()
88 
89  size_t size() const { return selected_.size(); }
90 
91 private:
94 };
95 
96 #endif
T getParameter(std::string const &) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< GenJet > GenJetCollection
collection of GenJet objects
edm::EDGetTokenT< edm::View< reco::Candidate > > matchTo_
Jets made from MC generator particles.
Definition: GenJet.h:24
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
GenJetClosestMatchSelectorDefinition(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s)
list key
Definition: combine.py:13
susybsm::HSCParticleCollection hc
Definition: classes.h:25