test
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 
6 
8 
10  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
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  if ( cfg.exists("jetCorrInputFileName") ) {
17  jetCorrInputFileName_ = cfg.getParameter<edm::FileInPath>("jetCorrInputFileName");
18  if ( jetCorrInputFileName_.location() == edm::FileInPath::Unknown) throw cms::Exception("ShiftedJetProducerT")
19  << " Failed to find JEC parameter file = " << jetCorrInputFileName_ << " !!\n";
20  std::cout << "Reading JEC parameters = " << jetCorrUncertaintyTag_
21  << " from file = " << jetCorrInputFileName_.fullPath() << "." << std::endl;
24  } else {
25  std::cout << "Reading JEC parameters = " << jetCorrUncertaintyTag_
26  << " from DB/SQLlite file." << std::endl;
27  jetCorrPayloadName_ = cfg.getParameter<std::string>("jetCorrPayloadName");
28  }
29 
30  minJetPt_ = cfg.getParameter<double>("minJetPt");
31 
32  shiftBy_ = cfg.getParameter<double>("shiftBy");
33 
34  unclEnUncertainty_ = cfg.getParameter<double>("unclEnUncertainty");
35 
36  produces<reco::PFCandidateCollection>();
37 }
38 
40 {
41 // nothing to be done yet...
42 }
43 
45 {
46  edm::Handle<reco::PFCandidateCollection> originalPFCandidates;
47  evt.getByToken(srcPFCandidatesToken_, originalPFCandidates);
48 
50  evt.getByToken(srcJetsToken_, jets);
51 
52  std::vector<const reco::PFJet*> selectedJets;
53  for ( reco::PFJetCollection::const_iterator jet = jets->begin();
54  jet != jets->end(); ++jet ) {
55  if ( jet->pt() > minJetPt_ ) selectedJets.push_back(&(*jet));
56  }
57 
58  if ( jetCorrPayloadName_ != "" ) {
60  es.get<JetCorrectionsRecord>().get(jetCorrPayloadName_, jetCorrParameterSet);
61  const JetCorrectorParameters& jetCorrParameters = (*jetCorrParameterSet)[jetCorrUncertaintyTag_];
62  delete jecUncertainty_;
63  jecUncertainty_ = new JetCorrectionUncertainty(jetCorrParameters);
64  }
65 
66  std::auto_ptr<reco::PFCandidateCollection> shiftedPFCandidates(new reco::PFCandidateCollection);
67 
68  for ( reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin();
69  originalPFCandidate != originalPFCandidates->end(); ++originalPFCandidate ) {
70 
71  const reco::PFJet* jet_matched = 0;
72  for ( std::vector<const reco::PFJet*>::iterator jet = selectedJets.begin();
73  jet != selectedJets.end(); ++jet ) {
74  std::vector<reco::PFCandidatePtr> jetConstituents = (*jet)->getPFConstituents();
75  for ( std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent = jetConstituents.begin();
76  jetConstituent != jetConstituents.end() && !jet_matched; ++jetConstituent ) {
77  if ( deltaR(originalPFCandidate->p4(), (*jetConstituent)->p4()) < 1.e-2 ) jet_matched = (*jet);
78  }
79  }
80 
81  double shift = 0.;
82  if ( jet_matched ) {
83  jecUncertainty_->setJetEta(jet_matched->eta());
84  jecUncertainty_->setJetPt(jet_matched->pt());
85 
86  shift = jecUncertainty_->getUncertainty(true);
87  } else {
88  shift = unclEnUncertainty_;
89  }
90 
91  shift *= shiftBy_;
92 
93  reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4();
94  shiftedPFCandidateP4 *= (1. + shift);
95 
96  reco::PFCandidate shiftedPFCandidate(*originalPFCandidate);
97  shiftedPFCandidate.setP4(shiftedPFCandidateP4);
98 
99  shiftedPFCandidates->push_back(shiftedPFCandidate);
100  }
101 
102  evt.put(shiftedPFCandidates);
103 }
104 
106 
108 
109 
110 
T getParameter(std::string const &) const
virtual float pt() const
transverse momentum
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#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:116
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:38
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
moduleLabel_(iConfig.getParameter< string >("@module_label"))