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:
83 };
84 
85 #endif
GenJetClosestMatchSelectorDefinition::collection
reco::GenJetCollection collection
Definition: GenJetClosestMatchSelectorDefinition.h:16
reco::GenJet
Jets made from MC generator particles.
Definition: GenJet.h:23
reco::GenJetCollection
std::vector< GenJet > GenJetCollection
collection of GenJet objects
Definition: GenJetCollection.h:14
edm::EDGetTokenT
Definition: EDGetToken.h:33
GenJetClosestMatchSelectorDefinition::container
std::vector< reco::GenJet * > container
Definition: GenJetClosestMatchSelectorDefinition.h:18
GenJetClosestMatchSelectorDefinition
Definition: GenJetClosestMatchSelectorDefinition.h:15
HLT_2018_cff.eta1
eta1
Definition: HLT_2018_cff.py:8220
GenJetClosestMatchSelectorDefinition::const_iterator
container::const_iterator const_iterator
Definition: GenJetClosestMatchSelectorDefinition.h:19
GenJetClosestMatchSelectorDefinition::selected_
container selected_
Definition: GenJetClosestMatchSelectorDefinition.h:81
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref
Definition: AssociativeIterator.h:58
deltaR.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
GenJetClosestMatchSelectorDefinition::size
size_t size() const
Definition: GenJetClosestMatchSelectorDefinition.h:78
GenJetClosestMatchSelectorDefinition::HandleToCollection
edm::Handle< collection > HandleToCollection
Definition: GenJetClosestMatchSelectorDefinition.h:17
HLT_2018_cff.eta2
eta2
Definition: HLT_2018_cff.py:8221
edm::View
Definition: CaloClusterFwd.h:14
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
GenJetClosestMatchSelectorDefinition::end
const_iterator end() const
Definition: GenJetClosestMatchSelectorDefinition.h:27
GenJetClosestMatchSelectorDefinition::begin
const_iterator begin() const
Definition: GenJetClosestMatchSelectorDefinition.h:25
edm::EventSetup
Definition: EventSetup.h:57
looper.cfg
cfg
Definition: looper.py:297
GenJetClosestMatchSelectorDefinition::GenJetClosestMatchSelectorDefinition
GenJetClosestMatchSelectorDefinition(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
Definition: GenJetClosestMatchSelectorDefinition.h:21
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
GenJetClosestMatchSelectorDefinition::select
void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s)
Definition: GenJetClosestMatchSelectorDefinition.h:29
EventSetup.h
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
GenJet.h
ConsumesCollector.h
ParameterSet.h
edm::Event
Definition: Event.h:73
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
GenJetClosestMatchSelectorDefinition::matchTo_
edm::EDGetTokenT< edm::View< reco::Candidate > > matchTo_
Definition: GenJetClosestMatchSelectorDefinition.h:82