CMS 3D CMS Logo

ShiftedPFCandidateProducerForNoPileUpPFMEt.cc
Go to the documentation of this file.
1 
36 
37 #include <string>
38 #include <vector>
39 
41 public:
43 
44 private:
45  void produce(edm::Event&, const edm::EventSetup&) override;
46 
49 
54  std::unique_ptr<JetCorrectorParameters> jetCorrParameters_;
55  std::unique_ptr<JetCorrectionUncertainty> jecUncertainty_;
56 
57  double minJetPt_;
58 
59  double shiftBy_;
60 
62 };
63 
65  : srcPFCandidatesToken_(consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("srcPFCandidates"))),
66  srcJetsToken_(consumes<reco::PFJetCollection>(cfg.getParameter<edm::InputTag>("srcJets"))) {
67  jetCorrUncertaintyTag_ = cfg.getParameter<std::string>("jetCorrUncertaintyTag");
68  if (cfg.exists("jetCorrInputFileName")) {
69  jetCorrInputFileName_ = cfg.getParameter<edm::FileInPath>("jetCorrInputFileName");
71  throw cms::Exception("ShiftedJetProducerT")
72  << " Failed to find JEC parameter file = " << jetCorrInputFileName_ << " !!\n";
74  std::make_unique<JetCorrectorParameters>(jetCorrInputFileName_.fullPath(), jetCorrUncertaintyTag_);
75  jecUncertainty_ = std::make_unique<JetCorrectionUncertainty>(*jetCorrParameters_);
76  } else {
77  jetCorrPayloadName_ = cfg.getParameter<std::string>("jetCorrPayloadName");
79  }
80 
81  minJetPt_ = cfg.getParameter<double>("minJetPt");
82 
83  shiftBy_ = cfg.getParameter<double>("shiftBy");
84 
85  unclEnUncertainty_ = cfg.getParameter<double>("unclEnUncertainty");
86 
87  produces<reco::PFCandidateCollection>();
88 }
89 
91  edm::Handle<reco::PFCandidateCollection> originalPFCandidates;
92  evt.getByToken(srcPFCandidatesToken_, originalPFCandidates);
93 
96 
97  std::vector<const reco::PFJet*> selectedJets;
98  for (reco::PFJetCollection::const_iterator jet = jets->begin(); jet != jets->end(); ++jet) {
99  if (jet->pt() > minJetPt_)
100  selectedJets.push_back(&(*jet));
101  }
102 
103  if (!jetCorrPayloadName_.empty()) {
104  const JetCorrectorParametersCollection& jetCorrParameterSet = es.getData(jetCorrPayloadToken_);
105  const JetCorrectorParameters& jetCorrParameters = (jetCorrParameterSet)[jetCorrUncertaintyTag_];
106  jecUncertainty_ = std::make_unique<JetCorrectionUncertainty>(jetCorrParameters);
107  }
108 
109  auto shiftedPFCandidates = std::make_unique<reco::PFCandidateCollection>();
110  for (reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin();
111  originalPFCandidate != originalPFCandidates->end();
112  ++originalPFCandidate) {
113  const reco::PFJet* jet_matched = nullptr;
114  for (std::vector<const reco::PFJet*>::iterator jet = selectedJets.begin(); jet != selectedJets.end(); ++jet) {
115  std::vector<reco::PFCandidatePtr> jetConstituents = (*jet)->getPFConstituents();
116  for (std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent = jetConstituents.begin();
117  jetConstituent != jetConstituents.end() && !jet_matched;
118  ++jetConstituent) {
119  if (deltaR(originalPFCandidate->p4(), (*jetConstituent)->p4()) < 1.e-2)
120  jet_matched = (*jet);
121  }
122  }
123 
124  double shift = 0.;
125  if (jet_matched) {
126  jecUncertainty_->setJetEta(jet_matched->eta());
127  jecUncertainty_->setJetPt(jet_matched->pt());
128 
129  shift = jecUncertainty_->getUncertainty(true);
130  } else {
132  }
133 
134  shift *= shiftBy_;
135 
136  reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4();
137  shiftedPFCandidateP4 *= (1. + shift);
138 
139  reco::PFCandidate shiftedPFCandidate(*originalPFCandidate);
140  shiftedPFCandidate.setP4(shiftedPFCandidateP4);
141 
142  shiftedPFCandidates->push_back(shiftedPFCandidate);
143  }
144 
145  evt.put(std::move(shiftedPFCandidates));
146 }
147 
149 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
double pt() const final
transverse momentum
edm::ESGetToken< JetCorrectorParametersCollection, JetCorrectionsRecord > jetCorrPayloadToken_
std::string fullPath() const
Definition: FileInPath.cc:161
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:82
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidatesToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:540
Jets made from PFObjects.
Definition: PFJet.h:20
void produce(edm::Event &, const edm::EventSetup &) override
virtual std::vector< reco::PFCandidatePtr > getPFConstituents() const
get all constituents
Definition: PFJet.cc:41
LocationCode location() const
Where was the file found?
Definition: FileInPath.cc:159
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
std::vector< PFJet > PFJetCollection
collection of PFJet objects
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
fixed size matrix
HLT enums.
static unsigned int const shift
void setP4(const LorentzVector &p4) final
set 4-momentum
def move(src, dest)
Definition: eostools.py:511
double eta() const final
momentum pseudorapidity