1 #ifndef PhysicsTools_PatUtils_SmearedJetProducerT_h
2 #define PhysicsTools_PatUtils_SmearedJetProducerT_h
49 namespace SmearedJetProducer_namespace
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 ) {
102 template <
typename T>
113 <<
" Jets of type other than PF not supported yet !!\n";
117 template <
typename T>
137 else return jet.
p4();
142 template <
typename T,
typename Textractor>
165 <<
" Failed to find File = " << inputFileName <<
" !!\n";
167 inputFile_ =
new TFile(inputFileName.fullPath().data());
171 <<
" Failed to load LUT = " << lutName.data() <<
" from file = " << inputFileName.fullPath().data() <<
" !!\n";
186 if ( cfg.
exists(
"skipJetSelection") ) {
192 cfg.
getParameter<
double>(
"skipRawJetPtThreshold") : 1.e-2;
194 cfg.
getParameter<
double>(
"skipCorrJetPtThreshold") : 1.e-2;
199 produces<JetCollection>();
213 std::cout <<
"<SmearedJetProducerT::produce>:" << std::endl;
223 int numJets = jets->size();
224 for (
int jetIndex = 0; jetIndex < numJets; ++jetIndex ) {
225 const T&
jet = jets->at(jetIndex);
230 std::cout <<
"rawJet: Pt = " << rawJetP4.pt() <<
", eta = " << rawJetP4.eta() <<
", phi = " << rawJetP4.phi() << std::endl;
236 std::cout <<
"corrJet: Pt = " << corrJetP4.pt() <<
", eta = " << corrJetP4.eta() <<
", phi = " << corrJetP4.phi() << std::endl;
239 double smearFactor = 1.;
240 double x = TMath::Abs(corrJetP4.eta());
241 double y = corrJetP4.pt();
242 if ( x >
lut_->GetXaxis()->GetXmin() && x <
lut_->GetXaxis()->GetXmax() &&
243 y >
lut_->GetYaxis()->GetXmin() && y <
lut_->GetYaxis()->GetXmax() ) {
244 int binIndex =
lut_->FindBin(x, y);
247 double smearFactorErr =
lut_->GetBinError(binIndex);
248 if (
verbosity_ )
std::cout <<
"smearFactor = " << smearFactor <<
" +/- " << smearFactorErr << std::endl;
251 smearFactor += (
shiftBy_*smearFactorErr);
256 double smearedJetEn = jet.energy();
259 bool isGenMatched =
false;
262 std::cout <<
"genJet: Pt = " << genJet->
pt() <<
", eta = " << genJet->
eta() <<
", phi = " << genJet->
phi() << std::endl;
264 double dEn = corrJetP4.E() - genJet->
energy();
270 std::cout <<
" successfully matched to genJet" << std::endl;
271 std::cout <<
"corrJetEn = " << corrJetP4.E() <<
", genJetEn = " << genJet->
energy() <<
" --> dEn = " << dEn << std::endl;
274 smearedJetEn = jet.energy()*(1. + (smearFactor - 1.)*dEn/
TMath::Max(rawJetP4.E(), corrJetP4.E()));
278 if ( !isGenMatched ) {
283 std::cout <<
" not matched to genJet" << std::endl;
284 std::cout <<
"corrJetEn = " << corrJetP4.E() <<
", sigmaEn = " << sigmaEn << std::endl;
287 if ( smearFactor > 1. ) {
294 smearedJetEn = jet.energy()*(1. +
rnd_.Gaus(0., sigmaEn)/
TMath::Max(rawJetP4.E(), corrJetP4.E()));
299 const double minJetEn = 1.e-2;
300 if ( smearedJetEn < minJetEn ) smearedJetEn = minJetEn;
311 std::cout <<
" smearing jetP4 by factor = " << (smearedJetEn/jet.energy()) <<
" --> smearedJetEn = " << smearedJetEn << std::endl;
313 smearedJetP4 *= (smearedJetEn/jet.energy());
317 std::cout <<
"smearedJet: Pt = " << smearedJetP4.pt() <<
", eta = " << smearedJetP4.eta() <<
", phi = " << smearedJetP4.phi() << std::endl;
318 std::cout <<
" dPt = " << (smearedJetP4.pt() - jet.pt())
319 <<
" (Px = " << (smearedJetP4.px() - jet.px()) <<
", Py = " << (smearedJetP4.py() - jet.py()) <<
")" << std::endl;
322 T smearedJet = (
jet);
323 smearedJet.setP4(smearedJetP4);
325 smearedJets->push_back(smearedJet);
329 evt.
put(smearedJets);
virtual double energy() const GCC11_FINAL
energy
T getParameter(std::string const &) const
Textractor jetCorrExtractor_
edm::EDGetTokenT< JetCollection > srcToken_
StringCutObjectSelector< T > * skipJetSelection_
bool jecSetsAvailable() const
virtual const LorentzVector & p4() const GCC11_FINAL
four-momentum Lorentz vector
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
double skipCorrJetPtThreshold_
edm::InputTag srcGenJets_
const LorentzVector & correctedP4(const std::string &level, const std::string &flavor="none", const std::string &set="") const
double skipRawJetPtThreshold_
SmearedJetProducer_namespace::GenJetMatcherT< T > genJetMatcher_
SmearedJetProducerT(const edm::ParameterSet &cfg)
std::string jetCorrLabel_
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Jets made from MC generator particles.
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
double deltaR(double eta1, double eta2, double phi1, double phi2)
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 float pt() const GCC11_FINAL
transverse momentum
std::vector< T > JetCollection
virtual void produce(edm::Event &evt, const edm::EventSetup &es)