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)
 
 ~ShiftedJetProducerT () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Private Types

typedef std::vector< TJetCollection
 

Private Member Functions

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

Private Attributes

bool addResidualJES_
 
JetCorrectionUncertaintyjecUncertainty_
 
double jecUncertaintyValue_
 
double jetCorrEtaMax_
 
Textractor jetCorrExtractor_
 
edm::FileInPath jetCorrInputFileName_
 
edm::InputTag jetCorrLabelUpToL3_
 
edm::InputTag jetCorrLabelUpToL3Res_
 
JetCorrectorParametersjetCorrParameters_
 
std::string jetCorrPayloadName_
 
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<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache 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

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

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_, edm::ParameterSet::exists(), edm::FileInPath::fullPath(), edm::ParameterSet::getParameter(), 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 >::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";
60  } else {
61  jetCorrPayloadName_ = cfg.getParameter<std::string>("jetCorrPayloadName");
62  }
63  }
64 
65  addResidualJES_ = cfg.getParameter<bool>("addResidualJES");
66  if (cfg.exists("jetCorrLabelUpToL3")) {
67  jetCorrLabelUpToL3_ = cfg.getParameter<edm::InputTag>("jetCorrLabelUpToL3");
68  jetCorrTokenUpToL3_ = mayConsume<reco::JetCorrector>(jetCorrLabelUpToL3_);
69  }
70  if (cfg.exists("jetCorrLabelUpToL3Res") && addResidualJES_) {
71  jetCorrLabelUpToL3Res_ = cfg.getParameter<edm::InputTag>("jetCorrLabelUpToL3Res");
72  jetCorrTokenUpToL3Res_ = mayConsume<reco::JetCorrector>(jetCorrLabelUpToL3Res_);
73  }
74  jetCorrEtaMax_ = (cfg.exists("jetCorrEtaMax")) ? cfg.getParameter<double>("jetCorrEtaMax") : 9.9;
75 
76  shiftBy_ = cfg.getParameter<double>("shiftBy");
77 
78  verbosity_ = (cfg.exists("verbosity")) ? cfg.getParameter<int>("verbosity") : 0;
79 
80  produces<JetCollection>();
81  }
JetCorrectorParameters * jetCorrParameters_
edm::EDGetTokenT< reco::JetCorrector > jetCorrTokenUpToL3_
T getParameter(std::string const &) const
edm::InputTag jetCorrLabelUpToL3Res_
edm::InputTag jetCorrLabelUpToL3_
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string jetCorrUncertaintyTag_
edm::EDGetTokenT< reco::JetCorrector > jetCorrTokenUpToL3Res_
JetCorrectionUncertainty * jecUncertainty_
LocationCode location() const
Where was the file found?
Definition: FileInPath.cc:161
std::string fullPath() const
Definition: FileInPath.cc:163
edm::FileInPath jetCorrInputFileName_
edm::EDGetTokenT< JetCollection > srcToken_
template<typename T , typename Textractor >
ShiftedJetProducerT< T, Textractor >::~ShiftedJetProducerT ( )
inlineoverride

Definition at line 82 of file ShiftedJetProducerT.h.

References ShiftedJetProducerT< T, Textractor >::jecUncertainty_, and ShiftedJetProducerT< T, Textractor >::jetCorrParameters_.

82  {
83  delete jetCorrParameters_;
84  delete jecUncertainty_;
85  }
JetCorrectorParameters * jetCorrParameters_
JetCorrectionUncertainty * jecUncertainty_

Member Function Documentation

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

Definition at line 88 of file ShiftedJetProducerT.h.

References ShiftedJetProducerT< T, Textractor >::addResidualJES_, gather_cfg::cout, edm::EventSetup::get(), edm::Event::getByToken(), JetCorrectionUncertainty::getUncertainty(), 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 >::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(), JetCorrectionUncertainty::setJetEta(), JetCorrectionUncertainty::setJetPt(), edm::shift, ShiftedJetProducerT< T, Textractor >::shiftBy_, mathSSE::sqrt(), ShiftedJetProducerT< T, Textractor >::src_, ShiftedJetProducerT< T, Textractor >::srcToken_, relativeConstraints::value, and ShiftedJetProducerT< T, Textractor >::verbosity_.

88  {
89  if (verbosity_) {
90  std::cout << "<ShiftedJetProducerT::produce>:" << std::endl;
91  std::cout << " moduleLabel = " << moduleLabel_ << std::endl;
92  std::cout << " src = " << src_.label() << std::endl;
93  }
94 
95  edm::Handle<JetCollection> originalJets;
96  evt.getByToken(srcToken_, originalJets);
97  edm::Handle<reco::JetCorrector> jetCorrUpToL3;
98  evt.getByToken(jetCorrTokenUpToL3_, jetCorrUpToL3);
99  edm::Handle<reco::JetCorrector> jetCorrUpToL3Res;
100  if (evt.isRealData() && addResidualJES_) {
101  evt.getByToken(jetCorrTokenUpToL3Res_, jetCorrUpToL3Res);
102  }
103  auto shiftedJets = std::make_unique<JetCollection>();
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  for (typename JetCollection::const_iterator originalJet = originalJets->begin(); originalJet != originalJets->end();
114  ++originalJet) {
115  reco::Candidate::LorentzVector originalJetP4 = originalJet->p4();
116  if (verbosity_) {
117  std::cout << "originalJet: Pt = " << originalJetP4.pt() << ", eta = " << originalJetP4.eta()
118  << ", phi = " << originalJetP4.phi() << std::endl;
119  }
120 
121  double shift = 0.;
122  if (jecUncertaintyValue_ != -1.) {
123  shift = jecUncertaintyValue_;
124  } else {
125  jecUncertainty_->setJetEta(originalJetP4.eta());
126  jecUncertainty_->setJetPt(originalJetP4.pt());
127 
128  shift = jecUncertainty_->getUncertainty(true);
129  }
130  if (verbosity_) {
131  std::cout << "shift = " << shift << std::endl;
132  }
133 
134  if (evt.isRealData() && addResidualJES_) {
135  const static pat::RawJetExtractorT<T> rawJetExtractor{};
136  reco::Candidate::LorentzVector rawJetP4 = rawJetExtractor(*originalJet);
137  if (rawJetP4.E() > 1.e-1) {
138  reco::Candidate::LorentzVector corrJetP4upToL3 =
140  ? jetCorrExtractor_(*originalJet, jetCorrLabelUpToL3_.label(), jetCorrEtaMax_, &rawJetP4)
141  : jetCorrExtractor_(*originalJet, jetCorrUpToL3.product(), jetCorrEtaMax_, &rawJetP4);
142  reco::Candidate::LorentzVector corrJetP4upToL3Res =
144  ? jetCorrExtractor_(*originalJet, jetCorrLabelUpToL3Res_.label(), jetCorrEtaMax_, &rawJetP4)
145  : jetCorrExtractor_(*originalJet, jetCorrUpToL3Res.product(), jetCorrEtaMax_, &rawJetP4);
146  if (corrJetP4upToL3.E() > 1.e-1 && corrJetP4upToL3Res.E() > 1.e-1) {
147  double residualJES = (corrJetP4upToL3Res.E() / corrJetP4upToL3.E()) - 1.;
148  shift = sqrt(shift * shift + residualJES * residualJES);
149  }
150  }
151  }
152 
153  shift *= shiftBy_;
154  if (verbosity_) {
155  std::cout << "shift*shiftBy = " << shift << std::endl;
156  }
157 
158  T shiftedJet(*originalJet);
159  shiftedJet.setP4((1. + shift) * originalJetP4);
160  if (verbosity_) {
161  std::cout << "shiftedJet: Pt = " << shiftedJet.pt() << ", eta = " << shiftedJet.eta()
162  << ", phi = " << shiftedJet.phi() << std::endl;
163  }
164 
165  shiftedJets->push_back(shiftedJet);
166  }
167 
168  evt.put(std::move(shiftedJets));
169  }
edm::EDGetTokenT< reco::JetCorrector > jetCorrTokenUpToL3_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
edm::InputTag jetCorrLabelUpToL3Res_
edm::InputTag jetCorrLabelUpToL3_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
bool isRealData() const
Definition: EventBase.h:62
std::string jetCorrUncertaintyTag_
edm::EDGetTokenT< reco::JetCorrector > jetCorrTokenUpToL3Res_
T sqrt(T t)
Definition: SSEVec.h:19
JetCorrectionUncertainty * jecUncertainty_
T const * product() const
Definition: Handle.h:69
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
std::string const & label() const
Definition: InputTag.h:36
T get() const
Definition: EventSetup.h:73
static unsigned int const shift
float getUncertainty(bool fDirection)
long double T
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< JetCollection > srcToken_

Member Data Documentation

template<typename T , typename Textractor >
bool ShiftedJetProducerT< T, Textractor >::addResidualJES_
private
template<typename T , typename Textractor >
JetCorrectionUncertainty* ShiftedJetProducerT< T, Textractor >::jecUncertainty_
private
template<typename T , typename Textractor >
double ShiftedJetProducerT< T, Textractor >::jecUncertaintyValue_
private
template<typename T , typename Textractor >
double ShiftedJetProducerT< T, Textractor >::jetCorrEtaMax_
private
template<typename T , typename Textractor >
Textractor ShiftedJetProducerT< T, Textractor >::jetCorrExtractor_
private
template<typename T , typename Textractor >
edm::FileInPath ShiftedJetProducerT< T, Textractor >::jetCorrInputFileName_
private
template<typename T , typename Textractor >
edm::InputTag ShiftedJetProducerT< T, Textractor >::jetCorrLabelUpToL3_
private
template<typename T , typename Textractor >
edm::InputTag ShiftedJetProducerT< T, Textractor >::jetCorrLabelUpToL3Res_
private
template<typename T , typename Textractor >
JetCorrectorParameters* ShiftedJetProducerT< T, Textractor >::jetCorrParameters_
private
template<typename T , typename Textractor >
std::string ShiftedJetProducerT< T, Textractor >::jetCorrPayloadName_
private
template<typename T , typename Textractor >
edm::EDGetTokenT<reco::JetCorrector> ShiftedJetProducerT< T, Textractor >::jetCorrTokenUpToL3_
private
template<typename T , typename Textractor >
edm::EDGetTokenT<reco::JetCorrector> ShiftedJetProducerT< T, Textractor >::jetCorrTokenUpToL3Res_
private
template<typename T , typename Textractor >
std::string ShiftedJetProducerT< T, Textractor >::jetCorrUncertaintyTag_
private
template<typename T , typename Textractor >
std::string ShiftedJetProducerT< T, Textractor >::moduleLabel_
private
template<typename T , typename Textractor >
double ShiftedJetProducerT< T, Textractor >::shiftBy_
private
template<typename T , typename Textractor >
edm::InputTag ShiftedJetProducerT< T, Textractor >::src_
private
template<typename T , typename Textractor >
edm::EDGetTokenT<JetCollection> ShiftedJetProducerT< T, Textractor >::srcToken_
private
template<typename T , typename Textractor >
int ShiftedJetProducerT< T, Textractor >::verbosity_
private