CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ShiftedPFCandidateProducerForNoPileUpPFMEt.cc
Go to the documentation of this file.
2 
5 
7 
9  : srcPFCandidatesToken_(consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("srcPFCandidates")))
10  , srcJetsToken_(consumes<reco::PFJetCollection>(cfg.getParameter<edm::InputTag>("srcJets")))
11 {
12 
13  jetCorrUncertaintyTag_ = cfg.getParameter<std::string>("jetCorrUncertaintyTag");
14  if ( cfg.exists("jetCorrInputFileName") ) {
15  jetCorrInputFileName_ = cfg.getParameter<edm::FileInPath>("jetCorrInputFileName");
16  if ( jetCorrInputFileName_.location() == edm::FileInPath::Unknown) throw cms::Exception("ShiftedJetProducerT")
17  << " Failed to find JEC parameter file = " << jetCorrInputFileName_ << " !!\n";
18  std::cout << "Reading JEC parameters = " << jetCorrUncertaintyTag_
19  << " from file = " << jetCorrInputFileName_.fullPath() << "." << std::endl;
22  } else {
23  std::cout << "Reading JEC parameters = " << jetCorrUncertaintyTag_
24  << " from DB/SQLlite file." << std::endl;
25  jetCorrPayloadName_ = cfg.getParameter<std::string>("jetCorrPayloadName");
26  }
27 
28  minJetPt_ = cfg.getParameter<double>("minJetPt");
29 
30  shiftBy_ = cfg.getParameter<double>("shiftBy");
31 
32  unclEnUncertainty_ = cfg.getParameter<double>("unclEnUncertainty");
33 
34  produces<reco::PFCandidateCollection>();
35 }
36 
38 {
39 // nothing to be done yet...
40 }
41 
43 {
44  edm::Handle<reco::PFCandidateCollection> originalPFCandidates;
45  evt.getByToken(srcPFCandidatesToken_, originalPFCandidates);
46 
48  evt.getByToken(srcJetsToken_, jets);
49 
50  std::vector<const reco::PFJet*> selectedJets;
51  for ( reco::PFJetCollection::const_iterator jet = jets->begin();
52  jet != jets->end(); ++jet ) {
53  if ( jet->pt() > minJetPt_ ) selectedJets.push_back(&(*jet));
54  }
55 
56  if ( jetCorrPayloadName_ != "" ) {
58  es.get<JetCorrectionsRecord>().get(jetCorrPayloadName_, jetCorrParameterSet);
59  const JetCorrectorParameters& jetCorrParameters = (*jetCorrParameterSet)[jetCorrUncertaintyTag_];
60  delete jecUncertainty_;
61  jecUncertainty_ = new JetCorrectionUncertainty(jetCorrParameters);
62  }
63 
64  std::auto_ptr<reco::PFCandidateCollection> shiftedPFCandidates(new reco::PFCandidateCollection);
65 
66  for ( reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin();
67  originalPFCandidate != originalPFCandidates->end(); ++originalPFCandidate ) {
68 
69  const reco::PFJet* jet_matched = 0;
70  for ( std::vector<const reco::PFJet*>::iterator jet = selectedJets.begin();
71  jet != selectedJets.end(); ++jet ) {
72  std::vector<reco::PFCandidatePtr> jetConstituents = (*jet)->getPFConstituents();
73  for ( std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent = jetConstituents.begin();
74  jetConstituent != jetConstituents.end() && !jet_matched; ++jetConstituent ) {
75  if ( deltaR(originalPFCandidate->p4(), (*jetConstituent)->p4()) < 1.e-2 ) jet_matched = (*jet);
76  }
77  }
78 
79  double shift = 0.;
80  if ( jet_matched ) {
81  jecUncertainty_->setJetEta(jet_matched->eta());
82  jecUncertainty_->setJetPt(jet_matched->pt());
83 
84  shift = jecUncertainty_->getUncertainty(true);
85  } else {
86  shift = unclEnUncertainty_;
87  }
88 
89  shift *= shiftBy_;
90 
91  reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4();
92  shiftedPFCandidateP4 *= (1. + shift);
93 
94  reco::PFCandidate shiftedPFCandidate(*originalPFCandidate);
95  shiftedPFCandidate.setP4(shiftedPFCandidateP4);
96 
97  shiftedPFCandidates->push_back(shiftedPFCandidate);
98  }
99 
100  evt.put(shiftedPFCandidates);
101 }
102 
104 
106 
107 
108 
T getParameter(std::string const &) const
tuple cfg
Definition: looper.py:237
virtual float pt() const
transverse momentum
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#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::PFCandidateCollection > srcPFCandidatesToken_
Jets made from PFObjects.
Definition: PFJet.h:21
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
virtual float eta() const
momentum pseudorapidity
vector< PseudoJet > jets
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
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:41
std::vector< PFJet > PFJetCollection
collection of PFJet objects
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
static unsigned int const shift
virtual std::vector< reco::PFCandidatePtr > getPFConstituents() const
get all constituents
Definition: PFJet.cc:52
tuple cout
Definition: gather_cfg.py:121
float getUncertainty(bool fDirection)
std::string fullPath() const
Definition: FileInPath.cc:165