1 #ifndef PhysicsTools_PatUtils_SmearedJetProducerT_h
2 #define PhysicsTools_PatUtils_SmearedJetProducerT_h
49 namespace SmearedJetProducer_namespace
57 :
srcGenJets_(cfg.getParameter<edm::InputTag>(
"srcGenJets")),
60 TString dRmaxGenJetMatch_formula = cfg.
getParameter<std::string>(
"dRmaxGenJetMatch").
data();
61 dRmaxGenJetMatch_formula.ReplaceAll(
"genJetPt",
"x");
62 dRmaxGenJetMatch_ =
new TFormula(
"dRmaxGenJetMatch", dRmaxGenJetMatch_formula.Data());
78 double dRbestMatch = 1.e+6;
79 for ( reco::GenJetCollection::const_iterator genJet = genJets->begin();
80 genJet != genJets->end(); ++genJet ) {
83 double dR =
deltaR(jet.p4(), genJet->p4());
84 if ( dR < dRbestMatch && dR < dRmax ) {
101 template <
typename T>
112 <<
" Jets of type other than PF not supported yet !!\n";
116 template <
typename T>
136 else return jet.
p4();
141 template <
typename T,
typename Textractor>
150 :
moduleLabel_(cfg.getParameter<std::string>(
"@module_label")),
161 std::string lutName = cfg.
getParameter<std::string>(
"lutName");
164 <<
" Failed to find File = " << inputFileName <<
" !!\n";
166 inputFile_ =
new TFile(inputFileName.fullPath().data());
170 <<
" Failed to load LUT = " << lutName.data() <<
" from file = " << inputFileName.fullPath().data() <<
" !!\n";
185 if ( cfg.
exists(
"skipJetSelection") ) {
186 std::string skipJetSelection_string = cfg.
getParameter<std::string>(
"skipJetSelection");
191 cfg.
getParameter<
double>(
"skipRawJetPtThreshold") : 1.e-2;
193 cfg.
getParameter<
double>(
"skipCorrJetPtThreshold") : 1.e-2;
198 produces<JetCollection>();
199 produces<JetSmearingFlags>(
"jetSmearingFlags");
214 std::cout <<
"<SmearedJetProducerT::produce>:" << std::endl;
222 int numJets = jets->size();
225 std::vector<int> jetSmearingFlags_tmp(numJets);
227 for (
int jetIndex = 0; jetIndex < numJets; ++jetIndex ) {
228 const T&
jet = jets->at(jetIndex);
233 std::cout <<
"rawJet: Pt = " << rawJetP4.pt() <<
", eta = " << rawJetP4.eta() <<
", phi = " << rawJetP4.phi() << std::endl;
239 std::cout <<
"corrJet: Pt = " << corrJetP4.pt() <<
", eta = " << corrJetP4.eta() <<
", phi = " << corrJetP4.phi() << std::endl;
242 double smearFactor = 1.;
243 double x = TMath::Abs(corrJetP4.eta());
244 double y = corrJetP4.pt();
245 if ( x >
lut_->GetXaxis()->GetXmin() && x <
lut_->GetXaxis()->GetXmax() &&
246 y >
lut_->GetYaxis()->GetXmin() && y <
lut_->GetYaxis()->GetXmax() ) {
247 int binIndex =
lut_->FindBin(x, y);
250 double smearFactorErr =
lut_->GetBinError(binIndex);
251 if (
verbosity_ )
std::cout <<
"smearFactor = " << smearFactor <<
" +/- " << smearFactorErr << std::endl;
254 smearFactor += (
shiftBy_*smearFactorErr);
259 double smearedJetEn = jet.energy();
262 rawJet.setP4(rawJetP4);
264 double sigmaEn = jetResolution;
267 bool isGenMatched =
false;
270 std::cout <<
"genJet: Pt = " << genJet->
pt() <<
", eta = " << genJet->
eta() <<
", phi = " << genJet->
phi() << std::endl;
272 double dEn = corrJetP4.E() - genJet->
energy();
278 std::cout <<
" successfully matched to genJet" << std::endl;
279 std::cout <<
"corrJetEn = " << corrJetP4.E() <<
", genJetEn = " << genJet->
energy() <<
" --> dEn = " << dEn << std::endl;
283 smearedJetEn = jet.energy() + (smearFactor - 1.)*dEn;
287 if ( !isGenMatched ) {
292 std::cout <<
" not matched to genJet" << std::endl;
293 std::cout <<
"corrJetEn = " << corrJetP4.E() <<
", sigmaEn = " << sigmaEn << std::endl;
296 if ( smearFactor > 1. ) {
303 double addSigmaEn = jetResolution*TMath::Sqrt(smearFactor*smearFactor - 1.);
305 smearedJetEn = jet.energy() +
rnd_.Gaus(0., addSigmaEn);
310 const double minJetEn = 1.e-2;
311 if ( smearedJetEn < minJetEn ) smearedJetEn = minJetEn;
322 std::cout <<
" multiplying jetP4 by factor = " << (smearedJetEn/jet.energy()) <<
" --> smearedJetEn = " << smearedJetEn << std::endl;
324 smearedJetP4 *= (smearedJetEn/jet.energy());
328 std::cout <<
"smearedJet: Pt = " << smearedJetP4.pt() <<
", eta = " << smearedJetP4.eta() <<
", phi = " << smearedJetP4.phi() << std::endl;
329 std::cout <<
" dPt = " << (smearedJetP4.pt() - jet.pt())
330 <<
" (Px = " << (smearedJetP4.px() - jet.px()) <<
", Py = " << (smearedJetP4.py() - jet.py()) <<
")" << std::endl;
334 smearedJet.setP4(smearedJetP4);
336 smearedJets->push_back(smearedJet);
338 if ( isGenMatched ) jetSmearingFlags_tmp[jetIndex] = 1;
339 else jetSmearingFlags_tmp[jetIndex] = 0;
344 valueMapFiller.
insert(jets, jetSmearingFlags_tmp.begin(), jetSmearingFlags_tmp.end());
345 valueMapFiller.
fill();
348 evt.
put(smearedJets);
349 evt.
put(jetSmearingFlags,
"jetSmearingFlags");
T getParameter(std::string const &) const
Textractor jetCorrExtractor_
StringCutObjectSelector< T > * skipJetSelection_
bool jecSetsAvailable() const
double sigmaMaxGenJetMatch_
void insert(const H &h, I begin, I end)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
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
SmearedJetProducer_namespace::GenJetMatcherT< T > genJetMatcher_
SmearedJetProducerT(const edm::ParameterSet &cfg)
std::string jetCorrLabel_
virtual double energy() const
energy
edm::ValueMap< int > JetSmearingFlags
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Jets made from MC generator particles.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
double deltaR(double eta1, double eta2, double phi1, double phi2)
GenJetMatcherT(const edm::ParameterSet &cfg)
TFormula * dRmaxGenJetMatch_
virtual double pt() const
transverse momentum
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
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)