CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
14 
15  jetCorrUncertaintyTag_ = cfg.getParameter<std::string>("jetCorrUncertaintyTag");
16 
17  jecValidFileName_ = cfg.exists("jetCorrInputFileName");
18  if ( jecValidFileName_ ) {
19  jetCorrInputFileName_ = cfg.getParameter<edm::FileInPath>("jetCorrInputFileName");
20  if ( jetCorrInputFileName_.location() == edm::FileInPath::Unknown) throw cms::Exception("ShiftedJetProducerT")
21  << " Failed to find JEC parameter file = " << jetCorrInputFileName_ << " !!\n";
22  edm::LogWarning("ShiftedPFCandidateProducerForPFNoPUMEt")
23  << "Reading JEC parameters = " << jetCorrUncertaintyTag_
24  << " from file = " << jetCorrInputFileName_.fullPath() << "." << std::endl;
27  } else {
28  edm::LogWarning("ShiftedPFCandidateProducerForPFNoPUMEt")
29  << "Reading JEC parameters = " << jetCorrUncertaintyTag_
30  << " from DB/SQLlite file." << std::endl;
31  jetCorrPayloadName_ = cfg.getParameter<std::string>("jetCorrPayloadName");
32  }
33 
34  minJetPt_ = cfg.getParameter<double>("minJetPt");
35 
36  shiftBy_ = cfg.getParameter<double>("shiftBy");
37 
38  unclEnUncertainty_ = cfg.getParameter<double>("unclEnUncertainty");
39 
40 
41  produces<reco::PFCandidateCollection>();
42 }
43 
45 {
46  if( jecValidFileName_ ) {
47  delete jetCorrParameters_;
48  delete jecUncertainty_;
49  }
50 }
51 
53 {
54  edm::Handle<reco::PFCandidateCollection> originalPFCandidates;
55  evt.getByToken(srcPFCandidatesToken_, originalPFCandidates);
56 
58  evt.getByToken(srcJetsToken_, jets);
59 
60  std::vector<const reco::PFJet*> selectedJets;
61  for ( reco::PFJetCollection::const_iterator jet = jets->begin();
62  jet != jets->end(); ++jet ) {
63  if ( jet->pt() > minJetPt_ ) selectedJets.push_back(&(*jet));
64  }
65 
66  if ( jetCorrPayloadName_ != "" ) {
68  es.get<JetCorrectionsRecord>().get(jetCorrPayloadName_, jetCorrParameterSet);
69  const JetCorrectorParameters& jetCorrParameters = (*jetCorrParameterSet)[jetCorrUncertaintyTag_];
70  delete jecUncertainty_;
71  jecUncertainty_ = new JetCorrectionUncertainty(jetCorrParameters);
72  }
73 
74  std::auto_ptr<reco::PFCandidateCollection> shiftedPFCandidates(new reco::PFCandidateCollection);
75 
76  for ( reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin();
77  originalPFCandidate != originalPFCandidates->end(); ++originalPFCandidate ) {
78 
79  const reco::PFJet* jet_matched = nullptr;
80  for ( std::vector<const reco::PFJet*>::iterator jet = selectedJets.begin();
81  jet != selectedJets.end(); ++jet ) {
82  for ( std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent = (*jet)->getPFConstituents().begin();
83  jetConstituent != (*jet)->getPFConstituents().end() && jet_matched==nullptr; ++jetConstituent ) {
84  if ( deltaR2(originalPFCandidate->p4(), (*jetConstituent)->p4()) < dR2Match ) jet_matched = (*jet);
85  }
86  }
87 
88  double shift = 0.;
89  if ( jet_matched!=nullptr ) {
90  jecUncertainty_->setJetEta(jet_matched->eta());
91  jecUncertainty_->setJetPt(jet_matched->pt());
92 
93  shift = jecUncertainty_->getUncertainty(true);
94  } else {
95  shift = unclEnUncertainty_;
96  }
97 
98  shift *= shiftBy_;
99 
100  reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4();
101  shiftedPFCandidateP4 *= (1. + shift);
102 
103  reco::PFCandidate shiftedPFCandidate(*originalPFCandidate);
104  shiftedPFCandidate.setP4(shiftedPFCandidateP4);
105 
106  shiftedPFCandidates->push_back(shiftedPFCandidate);
107  }
108 
109  evt.put(shiftedPFCandidates);
110 }
111 
113 
115 
116 
117 
T getParameter(std::string const &) const
tuple cfg
Definition: looper.py:259
void produce(edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidatesToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual void setP4(const LorentzVector &p4)
set 4-momentum
edm::EDGetTokenT< reco::PFJetCollection > srcJetsToken_
Jets made from PFObjects.
Definition: PFJet.h:21
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
vector< PseudoJet > jets
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
LocationCode location() const
Where was the file found?
Definition: FileInPath.cc:159
const T & get() const
Definition: EventSetup.h:55
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:39
static unsigned int const shift
float getUncertainty(bool fDirection)
std::string fullPath() const
Definition: FileInPath.cc:165