1 #ifndef PhysicsTools_PatUtils_SmearedJetProducerT_h
2 #define PhysicsTools_PatUtils_SmearedJetProducerT_h
48 #include <type_traits>
50 namespace SmearedJetProducer_namespace
62 dRmaxGenJetMatch_formula.ReplaceAll(
"genJetPt",
"x");
63 dRmaxGenJetMatch_ =
new TFormula(
"dRmaxGenJetMatch", dRmaxGenJetMatch_formula.Data());
79 double dRbestMatch = 1.e+6;
80 for ( reco::GenJetCollection::const_iterator genJet = genJets->begin();
81 genJet != genJets->end(); ++genJet ) {
84 double dR =
deltaR(jet.p4(), genJet->p4());
85 if ( dR < dRbestMatch && dR < dRmax ) {
103 template <
typename T>
114 <<
" Jets of type other than PF not supported yet !!\n";
118 template <
typename T>
140 else return jet.
p4();
145 template <
typename T,
typename Textractor>
169 <<
" Failed to find File = " << inputFileName <<
" !!\n";
171 inputFile_ =
new TFile(inputFileName.fullPath().data());
175 <<
" Failed to load LUT = " << lutName.data() <<
" from file = " << inputFileName.fullPath().data() <<
" !!\n";
177 if ( cfg.
exists(
"jetCorrLabel") ) {
195 if ( cfg.
exists(
"skipJetSelection") ) {
201 cfg.
getParameter<
double>(
"skipRawJetPtThreshold") : 1.e-2;
203 cfg.
getParameter<
double>(
"skipCorrJetPtThreshold") : 1.e-2;
208 produces<JetCollection>();
222 std::cout <<
"<SmearedJetProducerT::produce>:" << std::endl;
232 int numJets = jets->size();
233 for (
int jetIndex = 0; jetIndex < numJets; ++jetIndex ) {
234 const T&
jet = jets->at(jetIndex);
239 std::cout <<
"rawJet: Pt = " << rawJetP4.pt() <<
", eta = " << rawJetP4.eta() <<
", phi = " << rawJetP4.phi() << std::endl;
252 std::cout <<
"corrJet: Pt = " << corrJetP4.pt() <<
", eta = " << corrJetP4.eta() <<
", phi = " << corrJetP4.phi() << std::endl;
255 double smearFactor = 1.;
257 double y = corrJetP4.pt();
258 if ( x >
lut_->GetXaxis()->GetXmin() && x <
lut_->GetXaxis()->GetXmax() &&
259 y >
lut_->GetYaxis()->GetXmin() && y <
lut_->GetYaxis()->GetXmax() ) {
260 int binIndex =
lut_->FindBin(x, y);
263 double smearFactorErr =
lut_->GetBinError(binIndex);
264 if (
verbosity_ )
std::cout <<
"smearFactor = " << smearFactor <<
" +/- " << smearFactorErr << std::endl;
267 smearFactor += (
shiftBy_*smearFactorErr);
272 double smearedJetEn = jet.energy();
275 bool isGenMatched =
false;
278 std::cout <<
"genJet: Pt = " << genJet->
pt() <<
", eta = " << genJet->
eta() <<
", phi = " << genJet->
phi() << std::endl;
280 double dEn = corrJetP4.E() - genJet->
energy();
286 std::cout <<
" successfully matched to genJet" << std::endl;
287 std::cout <<
"corrJetEn = " << corrJetP4.E() <<
", genJetEn = " << genJet->
energy() <<
" --> dEn = " << dEn << std::endl;
290 smearedJetEn = jet.energy()*(1. + (smearFactor - 1.)*dEn/
std::max( rawJetP4.E(), corrJetP4.E()));
294 if ( !isGenMatched ) {
299 std::cout <<
" not matched to genJet" << std::endl;
300 std::cout <<
"corrJetEn = " << corrJetP4.E() <<
", sigmaEn = " << sigmaEn << std::endl;
303 if ( smearFactor > 1. ) {
310 smearedJetEn = jet.energy()*(1. +
rnd_.Gaus(0., sigmaEn)/
std::max( rawJetP4.E(), corrJetP4.E()) );
315 const double minJetEn = 1.e-2;
316 if ( smearedJetEn < minJetEn ) smearedJetEn = minJetEn;
327 std::cout <<
" smearing jetP4 by factor = " << (smearedJetEn/jet.energy()) <<
" --> smearedJetEn = " << smearedJetEn << std::endl;
329 smearedJetP4 *= (smearedJetEn/jet.energy());
333 std::cout <<
"smearedJet: Pt = " << smearedJetP4.pt() <<
", eta = " << smearedJetP4.eta() <<
", phi = " << smearedJetP4.phi() << std::endl;
334 std::cout <<
" dPt = " << (smearedJetP4.pt() - jet.pt())
335 <<
" (Px = " << (smearedJetP4.px() - jet.px()) <<
", Py = " << (smearedJetP4.py() - jet.py()) <<
")" << std::endl;
338 T smearedJet = (
jet);
339 smearedJet.setP4(smearedJetP4);
341 smearedJets->push_back(smearedJet);
345 evt.
put(smearedJets);
const LorentzVector correctedP4(const std::string &level, const std::string &flavor="none", const std::string &set="") const
T getParameter(std::string const &) const
Textractor jetCorrExtractor_
edm::EDGetTokenT< JetCollection > srcToken_
StringCutObjectSelector< T > * skipJetSelection_
bool jecSetsAvailable() const
virtual double energy() const final
energy
double sigmaMaxGenJetMatch_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::vector< GenJet > GenJetCollection
collection of GenJet objects
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual double phi() const final
momentum azimuthal angle
edm::InputTag jetCorrLabel_
double skipCorrJetPtThreshold_
edm::InputTag srcGenJets_
double skipRawJetPtThreshold_
SmearedJetProducer_namespace::GenJetMatcherT< T > genJetMatcher_
SmearedJetProducerT(const edm::ParameterSet &cfg)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Abs< T >::type abs(const T &t)
Jets made from MC generator particles.
edm::EDGetTokenT< reco::JetCorrector > jetCorrToken_
double deltaR(double eta1, double eta2, double phi1, double phi2)
T const * product() const
TFormula * dRmaxGenJetMatch_
GenJetMatcherT(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
SmearedJetProducer_namespace::JetResolutionExtractorT< T > jetResolutionExtractor_
Analysis-level calorimeter jet class.
math::XYZTLorentzVector LorentzVector
Lorentz vector.
const reco::GenJet * operator()(const T &jet, edm::Event *evt=0) const
edm::EDGetTokenT< reco::GenJetCollection > srcGenJetsToken_
char data[epos_bytes_allocation]
virtual double eta() const final
momentum pseudorapidity
std::vector< T > JetCollection
virtual const LorentzVector & p4() const final
four-momentum Lorentz vector
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
virtual double pt() const final
transverse momentum