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") ) {
193 if ( cfg.
exists(
"skipJetSelection") ) {
199 cfg.
getParameter<
double>(
"skipRawJetPtThreshold") : 1.e-2;
201 cfg.
getParameter<
double>(
"skipCorrJetPtThreshold") : 1.e-2;
206 produces<JetCollection>();
220 std::cout <<
"<SmearedJetProducerT::produce>:" << std::endl;
230 int numJets = jets->size();
231 for (
int jetIndex = 0; jetIndex < numJets; ++jetIndex ) {
232 const T&
jet = jets->at(jetIndex);
237 std::cout <<
"rawJet: Pt = " << rawJetP4.pt() <<
", eta = " << rawJetP4.eta() <<
", phi = " << rawJetP4.phi() << std::endl;
250 std::cout <<
"corrJet: Pt = " << corrJetP4.pt() <<
", eta = " << corrJetP4.eta() <<
", phi = " << corrJetP4.phi() << std::endl;
253 double smearFactor = 1.;
255 double y = corrJetP4.pt();
256 if ( x >
lut_->GetXaxis()->GetXmin() && x <
lut_->GetXaxis()->GetXmax() &&
257 y >
lut_->GetYaxis()->GetXmin() && y <
lut_->GetYaxis()->GetXmax() ) {
258 int binIndex =
lut_->FindBin(x, y);
261 double smearFactorErr =
lut_->GetBinError(binIndex);
262 if (
verbosity_ )
std::cout <<
"smearFactor = " << smearFactor <<
" +/- " << smearFactorErr << std::endl;
265 smearFactor += (
shiftBy_*smearFactorErr);
270 double smearedJetEn = jet.energy();
273 bool isGenMatched =
false;
276 std::cout <<
"genJet: Pt = " << genJet->
pt() <<
", eta = " << genJet->
eta() <<
", phi = " << genJet->
phi() << std::endl;
278 double dEn = corrJetP4.E() - genJet->
energy();
284 std::cout <<
" successfully matched to genJet" << std::endl;
285 std::cout <<
"corrJetEn = " << corrJetP4.E() <<
", genJetEn = " << genJet->
energy() <<
" --> dEn = " << dEn << std::endl;
288 smearedJetEn = jet.energy()*(1. + (smearFactor - 1.)*dEn/
std::max( rawJetP4.E(), corrJetP4.E()));
292 if ( !isGenMatched ) {
297 std::cout <<
" not matched to genJet" << std::endl;
298 std::cout <<
"corrJetEn = " << corrJetP4.E() <<
", sigmaEn = " << sigmaEn << std::endl;
301 if ( smearFactor > 1. ) {
308 smearedJetEn = jet.energy()*(1. +
rnd_.Gaus(0., sigmaEn)/
std::max( rawJetP4.E(), corrJetP4.E()) );
313 const double minJetEn = 1.e-2;
314 if ( smearedJetEn < minJetEn ) smearedJetEn = minJetEn;
325 std::cout <<
" smearing jetP4 by factor = " << (smearedJetEn/jet.energy()) <<
" --> smearedJetEn = " << smearedJetEn << std::endl;
327 smearedJetP4 *= (smearedJetEn/jet.energy());
331 std::cout <<
"smearedJet: Pt = " << smearedJetP4.pt() <<
", eta = " << smearedJetP4.eta() <<
", phi = " << smearedJetP4.phi() << std::endl;
332 std::cout <<
" dPt = " << (smearedJetP4.pt() - jet.pt())
333 <<
" (Px = " << (smearedJetP4.px() - jet.px()) <<
", Py = " << (smearedJetP4.py() - jet.py()) <<
")" << std::endl;
336 T smearedJet = (
jet);
337 smearedJet.setP4(smearedJetP4);
339 smearedJets->push_back(smearedJet);
343 evt.
put(smearedJets);
T getParameter(std::string const &) const
Textractor jetCorrExtractor_
edm::EDGetTokenT< JetCollection > srcToken_
StringCutObjectSelector< T > * skipJetSelection_
bool jecSetsAvailable() const
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
edm::InputTag jetCorrLabel_
double skipCorrJetPtThreshold_
edm::InputTag srcGenJets_
const LorentzVector & correctedP4(const std::string &level, const std::string &flavor="none", const std::string &set="") const
double skipRawJetPtThreshold_
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
SmearedJetProducer_namespace::GenJetMatcherT< T > genJetMatcher_
SmearedJetProducerT(const edm::ParameterSet &cfg)
virtual double energy() const
energy
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]
std::vector< T > JetCollection
virtual double phi() const
momentum azimuthal angle
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
virtual void produce(edm::Event &evt, const edm::EventSetup &es)