CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
ShiftedJetProducerT< T, Textractor > Class Template Reference

#include <ShiftedJetProducerT.h>

Inheritance diagram for ShiftedJetProducerT< T, Textractor >:
edm::stream::EDProducer<>

Public Member Functions

 ShiftedJetProducerT (const edm::ParameterSet &cfg)
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Types

typedef std::vector< TJetCollection
 

Private Member Functions

void produce (edm::Event &evt, const edm::EventSetup &es) override
 

Private Attributes

bool addResidualJES_
 
std::unique_ptr< JetCorrectionUncertaintyjecUncertainty_
 
double jecUncertaintyValue_
 
double jetCorrEtaMax_
 
Textractor jetCorrExtractor_
 
edm::FileInPath jetCorrInputFileName_
 
edm::InputTag jetCorrLabelUpToL3_
 
edm::InputTag jetCorrLabelUpToL3Res_
 
std::unique_ptr< JetCorrectorParametersjetCorrParameters_
 
std::string jetCorrPayloadName_
 
edm::ESGetToken< JetCorrectorParametersCollection, JetCorrectionsRecordjetCorrPayloadToken_
 
edm::EDGetTokenT< reco::JetCorrectorjetCorrTokenUpToL3_
 
edm::EDGetTokenT< reco::JetCorrectorjetCorrTokenUpToL3Res_
 
std::string jetCorrUncertaintyTag_
 
std::string moduleLabel_
 
double shiftBy_
 
edm::InputTag src_
 
edm::EDGetTokenT< JetCollectionsrcToken_
 
int verbosity_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

template<typename T, typename Textractor>
class ShiftedJetProducerT< T, Textractor >

Vary energy of jets by +/- 1 standard deviation, in order to estimate resulting uncertainty on MET

NOTE: energy scale uncertainties are taken from the Database

Author
Christian Veelken, LLR

Definition at line 37 of file ShiftedJetProducerT.h.

Member Typedef Documentation

◆ JetCollection

template<typename T , typename Textractor >
typedef std::vector<T> ShiftedJetProducerT< T, Textractor >::JetCollection
private

Definition at line 38 of file ShiftedJetProducerT.h.

Constructor & Destructor Documentation

◆ ShiftedJetProducerT()

template<typename T , typename Textractor >
ShiftedJetProducerT< T, Textractor >::ShiftedJetProducerT ( const edm::ParameterSet cfg)
inlineexplicit

Definition at line 41 of file ShiftedJetProducerT.h.

References ShiftedJetProducerT< T, Textractor >::addResidualJES_, looper::cfg, deDxTools::esConsumes(), edm::FileInPath::fullPath(), ShiftedJetProducerT< T, Textractor >::jecUncertainty_, ShiftedJetProducerT< T, Textractor >::jecUncertaintyValue_, ShiftedJetProducerT< T, Textractor >::jetCorrEtaMax_, ShiftedJetProducerT< T, Textractor >::jetCorrInputFileName_, ShiftedJetProducerT< T, Textractor >::jetCorrLabelUpToL3_, ShiftedJetProducerT< T, Textractor >::jetCorrLabelUpToL3Res_, ShiftedJetProducerT< T, Textractor >::jetCorrParameters_, ShiftedJetProducerT< T, Textractor >::jetCorrPayloadName_, ShiftedJetProducerT< T, Textractor >::jetCorrPayloadToken_, ShiftedJetProducerT< T, Textractor >::jetCorrTokenUpToL3_, ShiftedJetProducerT< T, Textractor >::jetCorrTokenUpToL3Res_, ShiftedJetProducerT< T, Textractor >::jetCorrUncertaintyTag_, edm::FileInPath::location(), ShiftedJetProducerT< T, Textractor >::shiftBy_, AlCaHLTBitMon_QueryRunRegistry::string, edm::FileInPath::Unknown, and ShiftedJetProducerT< T, Textractor >::verbosity_.

42  : moduleLabel_(cfg.getParameter<std::string>("@module_label")),
43  src_(cfg.getParameter<edm::InputTag>("src")),
44  srcToken_(consumes<JetCollection>(src_)),
46  jetCorrParameters_(nullptr),
47  jecUncertainty_(nullptr),
49  if (cfg.exists("jecUncertaintyValue")) {
50  jecUncertaintyValue_ = cfg.getParameter<double>("jecUncertaintyValue");
51  } else {
52  jetCorrUncertaintyTag_ = cfg.getParameter<std::string>("jetCorrUncertaintyTag");
53  if (cfg.exists("jetCorrInputFileName")) {
54  jetCorrInputFileName_ = cfg.getParameter<edm::FileInPath>("jetCorrInputFileName");
56  throw cms::Exception("ShiftedJetProducerT")
57  << " Failed to find JEC parameter file = " << jetCorrInputFileName_ << " !!\n";
59  std::make_unique<JetCorrectorParameters>(jetCorrInputFileName_.fullPath(), jetCorrUncertaintyTag_);
60  jecUncertainty_ = std::make_unique<JetCorrectionUncertainty>(*jetCorrParameters_);
61  } else {
62  jetCorrPayloadName_ = cfg.getParameter<std::string>("jetCorrPayloadName");
64  }
65  }
66 
67  addResidualJES_ = cfg.getParameter<bool>("addResidualJES");
68  if (cfg.exists("jetCorrLabelUpToL3")) {
69  jetCorrLabelUpToL3_ = cfg.getParameter<edm::InputTag>("jetCorrLabelUpToL3");
70  jetCorrTokenUpToL3_ = mayConsume<reco::JetCorrector>(jetCorrLabelUpToL3_);
71  }
72  if (cfg.exists("jetCorrLabelUpToL3Res") && addResidualJES_) {
73  jetCorrLabelUpToL3Res_ = cfg.getParameter<edm::InputTag>("jetCorrLabelUpToL3Res");
74  jetCorrTokenUpToL3Res_ = mayConsume<reco::JetCorrector>(jetCorrLabelUpToL3Res_);
75  }
76  jetCorrEtaMax_ = (cfg.exists("jetCorrEtaMax")) ? cfg.getParameter<double>("jetCorrEtaMax") : 9.9;
77 
78  shiftBy_ = cfg.getParameter<double>("shiftBy");
79 
80  verbosity_ = (cfg.exists("verbosity")) ? cfg.getParameter<int>("verbosity") : 0;
81 
82  produces<JetCollection>();
83  }
edm::EDGetTokenT< reco::JetCorrector > jetCorrTokenUpToL3_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::InputTag jetCorrLabelUpToL3Res_
edm::InputTag jetCorrLabelUpToL3_
std::string fullPath() const
Definition: FileInPath.cc:161
edm::ESGetToken< JetCorrectorParametersCollection, JetCorrectionsRecord > jetCorrPayloadToken_
std::string jetCorrUncertaintyTag_
std::unique_ptr< JetCorrectionUncertainty > jecUncertainty_
edm::EDGetTokenT< reco::JetCorrector > jetCorrTokenUpToL3Res_
LocationCode location() const
Where was the file found?
Definition: FileInPath.cc:159
std::unique_ptr< JetCorrectorParameters > jetCorrParameters_
edm::FileInPath jetCorrInputFileName_
edm::EDGetTokenT< JetCollection > srcToken_

Member Function Documentation

◆ produce()

template<typename T , typename Textractor >
void ShiftedJetProducerT< T, Textractor >::produce ( edm::Event evt,
const edm::EventSetup es 
)
inlineoverrideprivate

Definition at line 86 of file ShiftedJetProducerT.h.

References ShiftedJetProducerT< T, Textractor >::addResidualJES_, gather_cfg::cout, edm::Event::getByToken(), edm::EventSetup::getData(), edm::EventBase::isRealData(), ShiftedJetProducerT< T, Textractor >::jecUncertainty_, ShiftedJetProducerT< T, Textractor >::jecUncertaintyValue_, ShiftedJetProducerT< T, Textractor >::jetCorrEtaMax_, ShiftedJetProducerT< T, Textractor >::jetCorrExtractor_, ShiftedJetProducerT< T, Textractor >::jetCorrLabelUpToL3_, ShiftedJetProducerT< T, Textractor >::jetCorrLabelUpToL3Res_, ShiftedJetProducerT< T, Textractor >::jetCorrPayloadName_, ShiftedJetProducerT< T, Textractor >::jetCorrPayloadToken_, ShiftedJetProducerT< T, Textractor >::jetCorrTokenUpToL3_, ShiftedJetProducerT< T, Textractor >::jetCorrTokenUpToL3Res_, ShiftedJetProducerT< T, Textractor >::jetCorrUncertaintyTag_, edm::InputTag::label(), ShiftedJetProducerT< T, Textractor >::moduleLabel_, eostools::move(), edm::Handle< T >::product(), edm::Event::put(), edm::shift, ShiftedJetProducerT< T, Textractor >::shiftBy_, mathSSE::sqrt(), ShiftedJetProducerT< T, Textractor >::src_, ShiftedJetProducerT< T, Textractor >::srcToken_, relativeConstraints::value, and ShiftedJetProducerT< T, Textractor >::verbosity_.

86  {
87  if (verbosity_) {
88  std::cout << "<ShiftedJetProducerT::produce>:" << std::endl;
89  std::cout << " moduleLabel = " << moduleLabel_ << std::endl;
90  std::cout << " src = " << src_.label() << std::endl;
91  }
92 
93  edm::Handle<JetCollection> originalJets;
94  evt.getByToken(srcToken_, originalJets);
95  edm::Handle<reco::JetCorrector> jetCorrUpToL3;
96  evt.getByToken(jetCorrTokenUpToL3_, jetCorrUpToL3);
97  edm::Handle<reco::JetCorrector> jetCorrUpToL3Res;
98  if (evt.isRealData() && addResidualJES_) {
99  evt.getByToken(jetCorrTokenUpToL3Res_, jetCorrUpToL3Res);
100  }
101  auto shiftedJets = std::make_unique<JetCollection>();
102 
103  if (!jetCorrPayloadName_.empty()) {
104  const JetCorrectorParametersCollection& jetCorrParameterSet = es.getData(jetCorrPayloadToken_);
105  const JetCorrectorParameters& jetCorrParameters = (jetCorrParameterSet)[jetCorrUncertaintyTag_];
106  jecUncertainty_ = std::make_unique<JetCorrectionUncertainty>(jetCorrParameters);
107  }
108 
109  for (typename JetCollection::const_iterator originalJet = originalJets->begin(); originalJet != originalJets->end();
110  ++originalJet) {
111  reco::Candidate::LorentzVector originalJetP4 = originalJet->p4();
112  if (verbosity_) {
113  std::cout << "originalJet: Pt = " << originalJetP4.pt() << ", eta = " << originalJetP4.eta()
114  << ", phi = " << originalJetP4.phi() << std::endl;
115  }
116 
117  double shift = 0.;
118  if (jecUncertaintyValue_ != -1.) {
120  } else {
121  jecUncertainty_->setJetEta(originalJetP4.eta());
122  jecUncertainty_->setJetPt(originalJetP4.pt());
123 
124  shift = jecUncertainty_->getUncertainty(true);
125  }
126  if (verbosity_) {
127  std::cout << "shift = " << shift << std::endl;
128  }
129 
130  if (evt.isRealData() && addResidualJES_) {
131  const static pat::RawJetExtractorT<T> rawJetExtractor{};
132  reco::Candidate::LorentzVector rawJetP4 = rawJetExtractor(*originalJet);
133  if (rawJetP4.E() > 1.e-1) {
134  reco::Candidate::LorentzVector corrJetP4upToL3 =
136  ? jetCorrExtractor_(*originalJet, jetCorrLabelUpToL3_.label(), jetCorrEtaMax_, &rawJetP4)
137  : jetCorrExtractor_(*originalJet, jetCorrUpToL3.product(), jetCorrEtaMax_, &rawJetP4);
138  reco::Candidate::LorentzVector corrJetP4upToL3Res =
140  ? jetCorrExtractor_(*originalJet, jetCorrLabelUpToL3Res_.label(), jetCorrEtaMax_, &rawJetP4)
141  : jetCorrExtractor_(*originalJet, jetCorrUpToL3Res.product(), jetCorrEtaMax_, &rawJetP4);
142  if (corrJetP4upToL3.E() > 1.e-1 && corrJetP4upToL3Res.E() > 1.e-1) {
143  double residualJES = (corrJetP4upToL3Res.E() / corrJetP4upToL3.E()) - 1.;
144  shift = sqrt(shift * shift + residualJES * residualJES);
145  }
146  }
147  }
148 
149  shift *= shiftBy_;
150  if (verbosity_) {
151  std::cout << "shift*shiftBy = " << shift << std::endl;
152  }
153 
154  T shiftedJet(*originalJet);
155  shiftedJet.setP4((1. + shift) * originalJetP4);
156  if (verbosity_) {
157  std::cout << "shiftedJet: Pt = " << shiftedJet.pt() << ", eta = " << shiftedJet.eta()
158  << ", phi = " << shiftedJet.phi() << std::endl;
159  }
160 
161  shiftedJets->push_back(shiftedJet);
162  }
163 
164  evt.put(std::move(shiftedJets));
165  }
edm::EDGetTokenT< reco::JetCorrector > jetCorrTokenUpToL3_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::InputTag jetCorrLabelUpToL3Res_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
edm::InputTag jetCorrLabelUpToL3_
T const * product() const
Definition: Handle.h:70
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:536
std::string const & label() const
Definition: InputTag.h:36
edm::ESGetToken< JetCorrectorParametersCollection, JetCorrectionsRecord > jetCorrPayloadToken_
std::string jetCorrUncertaintyTag_
std::unique_ptr< JetCorrectionUncertainty > jecUncertainty_
edm::EDGetTokenT< reco::JetCorrector > jetCorrTokenUpToL3Res_
T sqrt(T t)
Definition: SSEVec.h:19
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
bool isRealData() const
Definition: EventBase.h:66
static unsigned int const shift
long double T
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< JetCollection > srcToken_

Member Data Documentation

◆ addResidualJES_

template<typename T , typename Textractor >
bool ShiftedJetProducerT< T, Textractor >::addResidualJES_
private

◆ jecUncertainty_

template<typename T , typename Textractor >
std::unique_ptr<JetCorrectionUncertainty> ShiftedJetProducerT< T, Textractor >::jecUncertainty_
private

◆ jecUncertaintyValue_

template<typename T , typename Textractor >
double ShiftedJetProducerT< T, Textractor >::jecUncertaintyValue_
private

◆ jetCorrEtaMax_

template<typename T , typename Textractor >
double ShiftedJetProducerT< T, Textractor >::jetCorrEtaMax_
private

◆ jetCorrExtractor_

template<typename T , typename Textractor >
Textractor ShiftedJetProducerT< T, Textractor >::jetCorrExtractor_
private

◆ jetCorrInputFileName_

template<typename T , typename Textractor >
edm::FileInPath ShiftedJetProducerT< T, Textractor >::jetCorrInputFileName_
private

◆ jetCorrLabelUpToL3_

template<typename T , typename Textractor >
edm::InputTag ShiftedJetProducerT< T, Textractor >::jetCorrLabelUpToL3_
private

◆ jetCorrLabelUpToL3Res_

template<typename T , typename Textractor >
edm::InputTag ShiftedJetProducerT< T, Textractor >::jetCorrLabelUpToL3Res_
private

◆ jetCorrParameters_

template<typename T , typename Textractor >
std::unique_ptr<JetCorrectorParameters> ShiftedJetProducerT< T, Textractor >::jetCorrParameters_
private

◆ jetCorrPayloadName_

template<typename T , typename Textractor >
std::string ShiftedJetProducerT< T, Textractor >::jetCorrPayloadName_
private

◆ jetCorrPayloadToken_

template<typename T , typename Textractor >
edm::ESGetToken<JetCorrectorParametersCollection, JetCorrectionsRecord> ShiftedJetProducerT< T, Textractor >::jetCorrPayloadToken_
private

◆ jetCorrTokenUpToL3_

template<typename T , typename Textractor >
edm::EDGetTokenT<reco::JetCorrector> ShiftedJetProducerT< T, Textractor >::jetCorrTokenUpToL3_
private

◆ jetCorrTokenUpToL3Res_

template<typename T , typename Textractor >
edm::EDGetTokenT<reco::JetCorrector> ShiftedJetProducerT< T, Textractor >::jetCorrTokenUpToL3Res_
private

◆ jetCorrUncertaintyTag_

template<typename T , typename Textractor >
std::string ShiftedJetProducerT< T, Textractor >::jetCorrUncertaintyTag_
private

◆ moduleLabel_

template<typename T , typename Textractor >
std::string ShiftedJetProducerT< T, Textractor >::moduleLabel_
private

◆ shiftBy_

template<typename T , typename Textractor >
double ShiftedJetProducerT< T, Textractor >::shiftBy_
private

◆ src_

template<typename T , typename Textractor >
edm::InputTag ShiftedJetProducerT< T, Textractor >::src_
private

◆ srcToken_

template<typename T , typename Textractor >
edm::EDGetTokenT<JetCollection> ShiftedJetProducerT< T, Textractor >::srcToken_
private

◆ verbosity_

template<typename T , typename Textractor >
int ShiftedJetProducerT< T, Textractor >::verbosity_
private