CMS 3D CMS Logo

ShiftedPFCandidateProducerForNoPileUpPFMEt.cc
Go to the documentation of this file.
1 
36 
37 #include <string>
38 #include <vector>
39 
41 public:
44 
45 private:
46  void produce(edm::Event&, const edm::EventSetup&) override;
47 
50 
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";
75  } else {
76  jetCorrPayloadName_ = cfg.getParameter<std::string>("jetCorrPayloadName");
77  }
78 
79  minJetPt_ = cfg.getParameter<double>("minJetPt");
80 
81  shiftBy_ = cfg.getParameter<double>("shiftBy");
82 
83  unclEnUncertainty_ = cfg.getParameter<double>("unclEnUncertainty");
84 
85  produces<reco::PFCandidateCollection>();
86 }
87 
89  // nothing to be done yet...
90 }
91 
93  edm::Handle<reco::PFCandidateCollection> originalPFCandidates;
94  evt.getByToken(srcPFCandidatesToken_, originalPFCandidates);
95 
98 
99  std::vector<const reco::PFJet*> selectedJets;
100  for (reco::PFJetCollection::const_iterator jet = jets->begin(); jet != jets->end(); ++jet) {
101  if (jet->pt() > minJetPt_)
102  selectedJets.push_back(&(*jet));
103  }
104 
105  if (!jetCorrPayloadName_.empty()) {
107  es.get<JetCorrectionsRecord>().get(jetCorrPayloadName_, jetCorrParameterSet);
108  const JetCorrectorParameters& jetCorrParameters = (*jetCorrParameterSet)[jetCorrUncertaintyTag_];
109  delete jecUncertainty_;
110  jecUncertainty_ = new JetCorrectionUncertainty(jetCorrParameters);
111  }
112 
113  auto shiftedPFCandidates = std::make_unique<reco::PFCandidateCollection>();
114  for (reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin();
115  originalPFCandidate != originalPFCandidates->end();
116  ++originalPFCandidate) {
117  const reco::PFJet* jet_matched = nullptr;
118  for (std::vector<const reco::PFJet*>::iterator jet = selectedJets.begin(); jet != selectedJets.end(); ++jet) {
119  std::vector<reco::PFCandidatePtr> jetConstituents = (*jet)->getPFConstituents();
120  for (std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent = jetConstituents.begin();
121  jetConstituent != jetConstituents.end() && !jet_matched;
122  ++jetConstituent) {
123  if (deltaR(originalPFCandidate->p4(), (*jetConstituent)->p4()) < 1.e-2)
124  jet_matched = (*jet);
125  }
126  }
127 
128  double shift = 0.;
129  if (jet_matched) {
130  jecUncertainty_->setJetEta(jet_matched->eta());
131  jecUncertainty_->setJetPt(jet_matched->pt());
132 
134  } else {
136  }
137 
138  shift *= shiftBy_;
139 
140  reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4();
141  shiftedPFCandidateP4 *= (1. + shift);
142 
143  reco::PFCandidate shiftedPFCandidate(*originalPFCandidate);
144  shiftedPFCandidate.setP4(shiftedPFCandidateP4);
145 
146  shiftedPFCandidates->push_back(shiftedPFCandidate);
147  }
148 
149  evt.put(std::move(shiftedPFCandidates));
150 }
151 
153 
ShiftedPFCandidateProducerForNoPileUpPFMEt::ShiftedPFCandidateProducerForNoPileUpPFMEt
ShiftedPFCandidateProducerForNoPileUpPFMEt(const edm::ParameterSet &)
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:64
reco::PFJet::getPFConstituents
virtual std::vector< reco::PFCandidatePtr > getPFConstituents() const
get all constituents
Definition: PFJet.cc:41
ESHandle.h
PFCandidate.h
edm::EDGetTokenT< reco::PFCandidateCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
PFJet.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
PFJetCollection.h
ShiftedPFCandidateProducerForNoPileUpPFMEt::minJetPt_
double minJetPt_
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:57
EDProducer.h
ShiftedPFCandidateProducerForNoPileUpPFMEt
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:40
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::Handle
Definition: AssociativeIterator.h:50
JetCorrectionUncertainty::setJetEta
void setJetEta(float fEta)
Definition: JetCorrectionUncertainty.cc:204
JetCorrectionsRecord.h
edm::FileInPath
Definition: FileInPath.h:61
JetCorrectionUncertainty.h
MakerMacros.h
ShiftedPFCandidateProducerForNoPileUpPFMEt::jecUncertainty_
JetCorrectionUncertainty * jecUncertainty_
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:55
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ShiftedPFCandidateProducerForNoPileUpPFMEt::shiftBy_
double shiftBy_
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:59
JetCorrectorParameters.h
edm::ESHandle
Definition: DTSurvey.h:22
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
JetCorrectionsRecord
Definition: JetCorrectionsRecord.h:11
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
JetCorrectionUncertainty::setJetPt
void setJetPt(float fPt)
Definition: JetCorrectionUncertainty.cc:209
FileInPath.h
edm::FileInPath::location
LocationCode location() const
Where was the file found?
Definition: FileInPath.cc:159
edm::ParameterSet
Definition: ParameterSet.h:47
ShiftedPFCandidateProducerForNoPileUpPFMEt::jetCorrPayloadName_
std::string jetCorrPayloadName_
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:52
Event.h
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
deltaR.h
ShiftedPFCandidateProducerForNoPileUpPFMEt::jetCorrInputFileName_
edm::FileInPath jetCorrInputFileName_
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:51
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
ShiftedPFCandidateProducerForNoPileUpPFMEt::srcPFCandidatesToken_
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidatesToken_
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:48
get
#define get
JetCorrectionUncertainty
Definition: JetCorrectionUncertainty.h:11
l1t::PFCandidateCollection
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
InputTag.h
looper.cfg
cfg
Definition: looper.py:296
ShiftedPFCandidateProducerForNoPileUpPFMEt::jetCorrUncertaintyTag_
std::string jetCorrUncertaintyTag_
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:53
JetCorrectionUncertainty::getUncertainty
float getUncertainty(bool fDirection)
Definition: JetCorrectionUncertainty.cc:83
reco::LeafCandidate::setP4
void setP4(const LorentzVector &p4) final
set 4-momentum
Definition: LeafCandidate.h:158
eostools.move
def move(src, dest)
Definition: eostools.py:511
ShiftedPFCandidateProducerForNoPileUpPFMEt::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:92
ShiftedPFCandidateProducerForNoPileUpPFMEt::~ShiftedPFCandidateProducerForNoPileUpPFMEt
~ShiftedPFCandidateProducerForNoPileUpPFMEt() override
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:88
edm::FileInPath::Unknown
Definition: FileInPath.h:63
reco::PFJetCollection
std::vector< PFJet > PFJetCollection
collection of PFJet objects
Definition: PFJetCollection.h:14
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
metsig::jet
Definition: SignAlgoResolutions.h:47
reco::PFJet
Jets made from PFObjects.
Definition: PFJet.h:20
JetCorrectorParameters
Definition: JetCorrectorParameters.h:25
EventSetup.h
ShiftedPFCandidateProducerForNoPileUpPFMEt::jetCorrParameters_
JetCorrectorParameters * jetCorrParameters_
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:54
ShiftedPFCandidateProducerForNoPileUpPFMEt::unclEnUncertainty_
double unclEnUncertainty_
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:61
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
objectSelection_cff.selectedJets
selectedJets
Definition: objectSelection_cff.py:99
cms::Exception
Definition: Exception.h:70
Candidate.h
ShiftedPFCandidateProducerForNoPileUpPFMEt::srcJetsToken_
edm::EDGetTokenT< reco::PFJetCollection > srcJetsToken_
Definition: ShiftedPFCandidateProducerForNoPileUpPFMEt.cc:49
ParameterSet.h
reco::Candidate::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
edm::Event
Definition: Event.h:73
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161
PFCandidateFwd.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37