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 
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 (auto jet : selectedJets) {
76  for (const auto& jetc : jet->getPFConstituents()) {
77  if (deltaR2(originalPFCandidate->p4(), jetc->p4()) < dR2Match) {
78  jet_matched = jet;
79  break;
80  }
81  }
82  if (jet_matched)
83  break;
84  }
85 
86  double shift = 0.;
87  if (jet_matched != nullptr) {
88  jecUncertainty_->setJetEta(jet_matched->eta());
89  jecUncertainty_->setJetPt(jet_matched->pt());
90 
92  } else {
94  }
95 
96  shift *= shiftBy_;
97 
98  reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4();
99  shiftedPFCandidateP4 *= (1. + shift);
100 
101  reco::PFCandidate shiftedPFCandidate(*originalPFCandidate);
102  shiftedPFCandidate.setP4(shiftedPFCandidateP4);
103 
104  shiftedPFCandidates->push_back(shiftedPFCandidate);
105  }
106 
107  evt.put(std::move(shiftedPFCandidates));
108 }
109 
111 
ShiftedPFCandidateProducerForPFNoPUMEt::jetCorrInputFileName_
edm::FileInPath jetCorrInputFileName_
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:55
ESHandle.h
ShiftedPFCandidateProducerForPFNoPUMEt::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.cc:48
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
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:45
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
ShiftedPFCandidateProducerForPFNoPUMEt::shiftBy_
double shiftBy_
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:65
dR2Match
const double dR2Match
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.cc:8
edm::Handle
Definition: AssociativeIterator.h:50
ShiftedPFCandidateProducerForPFNoPUMEt::jecUncertainty_
JetCorrectionUncertainty * jecUncertainty_
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:59
JetCorrectionUncertainty::setJetEta
void setJetEta(float fEta)
Definition: JetCorrectionUncertainty.cc:204
ShiftedPFCandidateProducerForPFNoPUMEt::ShiftedPFCandidateProducerForPFNoPUMEt
ShiftedPFCandidateProducerForPFNoPUMEt(const edm::ParameterSet &)
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.cc:10
JetCorrectionsRecord.h
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
ShiftedPFCandidateProducerForPFNoPUMEt.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ShiftedPFCandidateProducerForPFNoPUMEt
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:42
edm::ESHandle
Definition: DTSurvey.h:22
ShiftedPFCandidateProducerForPFNoPUMEt::srcPFCandidatesToken_
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidatesToken_
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:52
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
JetCorrectionsRecord
Definition: JetCorrectionsRecord.h:11
JetCorrectionUncertainty::setJetPt
void setJetPt(float fPt)
Definition: JetCorrectionUncertainty.cc:209
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::FileInPath::location
LocationCode location() const
Where was the file found?
Definition: FileInPath.cc:161
edm::ParameterSet
Definition: ParameterSet.h:47
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
deltaR.h
ShiftedPFCandidateProducerForPFNoPUMEt::jetCorrParameters_
JetCorrectorParameters * jetCorrParameters_
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:58
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
ShiftedPFCandidateProducerForPFNoPUMEt::unclEnUncertainty_
double unclEnUncertainty_
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:67
edm::EventSetup
Definition: EventSetup.h:57
ShiftedPFCandidateProducerForPFNoPUMEt::minJetPt_
double minJetPt_
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:63
get
#define get
JetCorrectionUncertainty
Definition: JetCorrectionUncertainty.h:11
l1t::PFCandidateCollection
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
looper.cfg
cfg
Definition: looper.py:297
ShiftedPFCandidateProducerForPFNoPUMEt::~ShiftedPFCandidateProducerForPFNoPUMEt
~ShiftedPFCandidateProducerForPFNoPUMEt() override
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.cc:41
ShiftedPFCandidateProducerForPFNoPUMEt::jetCorrUncertaintyTag_
std::string jetCorrUncertaintyTag_
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:57
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
edm::FileInPath::Unknown
Definition: FileInPath.h:66
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
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
metsig::jet
Definition: SignAlgoResolutions.h:47
reco::PFJet
Jets made from PFObjects.
Definition: PFJet.h:20
JetCorrectorParameters
Definition: JetCorrectorParameters.h:25
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
reco::Candidate::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
edm::Event
Definition: Event.h:73
ShiftedPFCandidateProducerForPFNoPUMEt::jetCorrPayloadName_
std::string jetCorrPayloadName_
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:56
ShiftedPFCandidateProducerForPFNoPUMEt::srcJetsToken_
edm::EDGetTokenT< reco::PFJetCollection > srcJetsToken_
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:53
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
ShiftedPFCandidateProducerForPFNoPUMEt::jecValidFileName_
bool jecValidFileName_
Definition: ShiftedPFCandidateProducerForPFNoPUMEt.h:61