CMS 3D CMS Logo

ShiftedPFCandidateProducerForPFNoPUMEt.cc
Go to the documentation of this file.
2 
5 
7 
8 const double dR2Match = 0.01 * 0.01;
9 
11  : srcPFCandidatesToken_(consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("srcPFCandidates"))),
12  srcJetsToken_(consumes<reco::PFJetCollection>(cfg.getParameter<edm::InputTag>("srcJets"))) {
13  jetCorrUncertaintyTag_ = cfg.getParameter<std::string>("jetCorrUncertaintyTag");
14 
15  jecValidFileName_ = cfg.exists("jetCorrInputFileName");
16  if (jecValidFileName_) {
17  jetCorrInputFileName_ = cfg.getParameter<edm::FileInPath>("jetCorrInputFileName");
19  throw cms::Exception("ShiftedJetProducerT")
20  << " Failed to find JEC parameter file = " << jetCorrInputFileName_ << " !!\n";
21  edm::LogInfo("ShiftedPFCandidateProducerForPFNoPUMEt")
22  << "Reading JEC parameters = " << jetCorrUncertaintyTag_ << " from file = " << jetCorrInputFileName_.fullPath()
23  << "." << std::endl;
26  } else {
27  edm::LogInfo("ShiftedPFCandidateProducerForPFNoPUMEt")
28  << "Reading JEC parameters = " << jetCorrUncertaintyTag_ << " from DB/SQLlite file." << std::endl;
29  jetCorrPayloadName_ = cfg.getParameter<std::string>("jetCorrPayloadName");
30  }
31 
32  minJetPt_ = cfg.getParameter<double>("minJetPt");
33 
34  shiftBy_ = cfg.getParameter<double>("shiftBy");
35 
36  unclEnUncertainty_ = cfg.getParameter<double>("unclEnUncertainty");
37 
38  produces<reco::PFCandidateCollection>();
39 }
40 
42  if (jecValidFileName_) {
43  delete jetCorrParameters_;
44  delete jecUncertainty_;
45  }
46 }
47 
49  edm::Handle<reco::PFCandidateCollection> originalPFCandidates;
50  evt.getByToken(srcPFCandidatesToken_, originalPFCandidates);
51 
53  evt.getByToken(srcJetsToken_, jets);
54 
55  std::vector<const reco::PFJet*> selectedJets;
56  for (reco::PFJetCollection::const_iterator jet = jets->begin(); jet != jets->end(); ++jet) {
57  if (jet->pt() > minJetPt_)
58  selectedJets.push_back(&(*jet));
59  }
60 
61  if (!jetCorrPayloadName_.empty()) {
63  es.get<JetCorrectionsRecord>().get(jetCorrPayloadName_, jetCorrParameterSet);
64  const JetCorrectorParameters& jetCorrParameters = (*jetCorrParameterSet)[jetCorrUncertaintyTag_];
65  delete jecUncertainty_;
66  jecUncertainty_ = new JetCorrectionUncertainty(jetCorrParameters);
67  }
68 
69  auto shiftedPFCandidates = std::make_unique<reco::PFCandidateCollection>();
70 
71  for (reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin();
72  originalPFCandidate != originalPFCandidates->end();
73  ++originalPFCandidate) {
74  const reco::PFJet* jet_matched = nullptr;
75  for (std::vector<const reco::PFJet*>::iterator jet = selectedJets.begin(); jet != selectedJets.end(); ++jet) {
76  for (std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent = (*jet)->getPFConstituents().begin();
77  jetConstituent != (*jet)->getPFConstituents().end() && jet_matched == nullptr;
78  ++jetConstituent) {
79  if (deltaR2(originalPFCandidate->p4(), (*jetConstituent)->p4()) < dR2Match)
80  jet_matched = (*jet);
81  }
82  }
83 
84  double shift = 0.;
85  if (jet_matched != nullptr) {
86  jecUncertainty_->setJetEta(jet_matched->eta());
87  jecUncertainty_->setJetPt(jet_matched->pt());
88 
89  shift = jecUncertainty_->getUncertainty(true);
90  } else {
91  shift = unclEnUncertainty_;
92  }
93 
94  shift *= shiftBy_;
95 
96  reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4();
97  shiftedPFCandidateP4 *= (1. + shift);
98 
99  reco::PFCandidate shiftedPFCandidate(*originalPFCandidate);
100  shiftedPFCandidate.setP4(shiftedPFCandidateP4);
101 
102  shiftedPFCandidates->push_back(shiftedPFCandidate);
103  }
104 
105  evt.put(std::move(shiftedPFCandidates));
106 }
107 
109 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
double eta() const final
momentum pseudorapidity
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidatesToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
bool exists(std::string const &parameterName) const
checks if a parameter exists
double pt() const final
transverse momentum
edm::EDGetTokenT< reco::PFJetCollection > srcJetsToken_
Jets made from PFObjects.
Definition: PFJet.h:20
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
LocationCode location() const
Where was the file found?
Definition: FileInPath.cc:161
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
std::vector< PFJet > PFJetCollection
collection of PFJet objects
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:73
void produce(edm::Event &, const edm::EventSetup &) override
static unsigned int const shift
std::string fullPath() const
Definition: FileInPath.cc:163
float getUncertainty(bool fDirection)
void setP4(const LorentzVector &p4) final
set 4-momentum
def move(src, dest)
Definition: eostools.py:511