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>
139 else return jet.
p4();
144 template <
typename T,
typename Textractor>
167 <<
" Failed to find File = " << inputFileName <<
" !!\n";
169 inputFile_ =
new TFile(inputFileName.fullPath().data());
173 <<
" Failed to load LUT = " << lutName.data() <<
" from file = " << inputFileName.fullPath().data() <<
" !!\n";
188 if ( cfg.
exists(
"skipJetSelection") ) {
194 cfg.
getParameter<
double>(
"skipRawJetPtThreshold") : 1.e-2;
196 cfg.
getParameter<
double>(
"skipCorrJetPtThreshold") : 1.e-2;
201 produces<JetCollection>();
215 std::cout <<
"<SmearedJetProducerT::produce>:" << std::endl;
225 int numJets = jets->size();
226 for (
int jetIndex = 0; jetIndex < numJets; ++jetIndex ) {
227 const T&
jet = jets->at(jetIndex);
232 std::cout <<
"rawJet: Pt = " << rawJetP4.pt() <<
", eta = " << rawJetP4.eta() <<
", phi = " << rawJetP4.phi() << std::endl;
238 std::cout <<
"corrJet: Pt = " << corrJetP4.pt() <<
", eta = " << corrJetP4.eta() <<
", phi = " << corrJetP4.phi() << std::endl;
241 double smearFactor = 1.;
242 double x = TMath::Abs(corrJetP4.eta());
243 double y = corrJetP4.pt();
244 if ( x >
lut_->GetXaxis()->GetXmin() && x <
lut_->GetXaxis()->GetXmax() &&
245 y >
lut_->GetYaxis()->GetXmin() && y <
lut_->GetYaxis()->GetXmax() ) {
246 int binIndex =
lut_->FindBin(x, y);
249 double smearFactorErr =
lut_->GetBinError(binIndex);
250 if (
verbosity_ )
std::cout <<
"smearFactor = " << smearFactor <<
" +/- " << smearFactorErr << std::endl;
253 smearFactor += (
shiftBy_*smearFactorErr);
258 double smearedJetEn = jet.energy();
261 bool isGenMatched =
false;
264 std::cout <<
"genJet: Pt = " << genJet->
pt() <<
", eta = " << genJet->
eta() <<
", phi = " << genJet->
phi() << std::endl;
266 double dEn = corrJetP4.E() - genJet->
energy();
272 std::cout <<
" successfully matched to genJet" << std::endl;
273 std::cout <<
"corrJetEn = " << corrJetP4.E() <<
", genJetEn = " << genJet->
energy() <<
" --> dEn = " << dEn << std::endl;
276 smearedJetEn = jet.energy()*(1. + (smearFactor - 1.)*dEn/
TMath::Max(rawJetP4.E(), corrJetP4.E()));
280 if ( !isGenMatched ) {
285 std::cout <<
" not matched to genJet" << std::endl;
286 std::cout <<
"corrJetEn = " << corrJetP4.E() <<
", sigmaEn = " << sigmaEn << std::endl;
289 if ( smearFactor > 1. ) {
296 smearedJetEn = jet.energy()*(1. +
rnd_.Gaus(0., sigmaEn)/
TMath::Max(rawJetP4.E(), corrJetP4.E()));
301 const double minJetEn = 1.e-2;
302 if ( smearedJetEn < minJetEn ) smearedJetEn = minJetEn;
313 std::cout <<
" smearing jetP4 by factor = " << (smearedJetEn/jet.energy()) <<
" --> smearedJetEn = " << smearedJetEn << std::endl;
315 smearedJetP4 *= (smearedJetEn/jet.energy());
319 std::cout <<
"smearedJet: Pt = " << smearedJetP4.pt() <<
", eta = " << smearedJetP4.eta() <<
", phi = " << smearedJetP4.phi() << std::endl;
320 std::cout <<
" dPt = " << (smearedJetP4.pt() - jet.pt())
321 <<
" (Px = " << (smearedJetP4.px() - jet.px()) <<
", Py = " << (smearedJetP4.py() - jet.py()) <<
")" << std::endl;
324 T smearedJet = (
jet);
325 smearedJet.setP4(smearedJetP4);
327 smearedJets->push_back(smearedJet);
331 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)