Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:39

0001 #ifndef JetMETCorrections_Type1MET_JetCorrExtractorT_h
0002 #define JetMETCorrections_Type1MET_JetCorrExtractorT_h
0003 
0004 /** \class JetCorrExtractorT
0005  *
0006  * Retrieve jet energy correction factor for
0007  *  o reco::CaloJets
0008  *  o reco::PFJets
0009  *  o pat::Jets (of either PF-type or Calo-type)
0010  *
0011  * NOTE: this "general" implementation is to be used for reco::CaloJets and reco::PFJets, **not** for pat::Jets
0012  *
0013  * \author Christian Veelken, LLR
0014  *
0015  *
0016  *
0017  */
0018 
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "FWCore/Utilities/interface/Exception.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 
0024 #include "JetMETCorrections/JetCorrector/interface/JetCorrector.h"
0025 #include "DataFormats/Common/interface/RefToBase.h"
0026 #include "DataFormats/JetReco/interface/Jet.h"
0027 #include "DataFormats/Candidate/interface/Candidate.h"
0028 
0029 namespace jetcorrextractor {
0030   // never heard of copysign?
0031   inline double sign(double x) {
0032     if (x > 0.)
0033       return +1.;
0034     else if (x < 0.)
0035       return -1.;
0036     else
0037       return 0.;
0038   }
0039 }  // namespace jetcorrextractor
0040 
0041 template <typename T>
0042 class JetCorrExtractorT {
0043 public:
0044   reco::Candidate::LorentzVector operator()(
0045       const T& rawJet,
0046       const reco::JetCorrector* jetCorr,
0047       double jetCorrEtaMax = 9.9,
0048       const reco::Candidate::LorentzVector* const rawJetP4_specified = nullptr) const {
0049     // allow to specify four-vector to be used as "raw" (uncorrected) jet momentum,
0050     // call 'rawJet.p4()' in case four-vector not specified explicitely
0051     reco::Candidate::LorentzVector rawJetP4 = (rawJetP4_specified) ? (*rawJetP4_specified) : rawJet.p4();
0052 
0053     double jetCorrFactor = 1.;
0054     if (fabs(rawJetP4.eta()) < jetCorrEtaMax) {
0055       jetCorrFactor = getCorrection(rawJet, jetCorr);
0056     } else {
0057       reco::Candidate::PolarLorentzVector modJetPolarP4(rawJetP4);
0058       modJetPolarP4.SetEta(jetcorrextractor::sign(rawJetP4.eta()) * jetCorrEtaMax);
0059 
0060       reco::Candidate::LorentzVector modJetP4(modJetPolarP4);
0061 
0062       T modJet(rawJet);
0063       modJet.setP4(modJetP4);
0064 
0065       jetCorrFactor = getCorrection(modJet, jetCorr);
0066       if (jetCorrFactor < 0) {
0067         edm::LogWarning("JetCorrExtractor") << "Negative jet energy scale correction noticed"
0068                                             << ".\n";
0069       }
0070     }
0071 
0072     reco::Candidate::LorentzVector corrJetP4 = rawJetP4;
0073     corrJetP4 *= jetCorrFactor;
0074 
0075     return corrJetP4;
0076   }
0077 
0078   reco::Candidate::LorentzVector operator()(
0079       const T& rawJet,
0080       const std::string& jetCorrLabel,
0081       double jetCorrEtaMax = 9.9,
0082       const reco::Candidate::LorentzVector* const rawJetP4_specified = nullptr) const {
0083     edm::LogWarning("JetCorrExtractor")
0084         << "JetCorrExtractorT<T>::operator(const T&, const std::string&, ...) is deprecated.\n"
0085         << "Please use JetCorrExtractorT<T>::operator(const T&, const reco::JetCorrector*, ...) instead.\n"
0086         << "Jet remains uncorrected!";
0087     reco::Candidate::LorentzVector rawJetP4 = (rawJetP4_specified) ? (*rawJetP4_specified) : rawJet.p4();
0088     return rawJetP4;
0089   }
0090 
0091 private:
0092   static double getCorrection(const T& jet, const reco::JetCorrector* jetCorr) { return jetCorr->correction(jet); }
0093 };
0094 
0095 #endif