Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // Implementation of class L1JPTOffsetCorrector.
0002 // L1JPTOffset jet corrector class.
0003 
0004 #include "JetMETCorrections/Algorithms/interface/L1JPTOffsetCorrector.h"
0005 #include "CondFormats/JetMETObjects/interface/FactorizedJetCorrector.h"
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/FileInPath.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "DataFormats/JetReco/interface/Jet.h"
0013 #include "DataFormats/JetReco/interface/CaloJet.h"
0014 #include "DataFormats/JetReco/interface/JPTJet.h"
0015 #include "DataFormats/VertexReco/interface/Vertex.h"
0016 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0017 
0018 using namespace std;
0019 
0020 //------------------------------------------------------------------------
0021 //--- L1OffsetCorrector constructor ------------------------------------------
0022 //------------------------------------------------------------------------
0023 L1JPTOffsetCorrector::L1JPTOffsetCorrector(const JetCorrectorParameters& fParam, const edm::ParameterSet& fConfig) {
0024   mOffsetService = fConfig.getParameter<std::string>("offsetService");
0025   mIsOffsetSet = false;
0026   if (!mOffsetService.empty())
0027     mIsOffsetSet = true;
0028   if (fParam.definitions().level() != "L1JPTOffset")
0029     throw cms::Exception("L1OffsetCorrector")
0030         << " correction level: " << fParam.definitions().level() << " is not L1JPTOffset";
0031   vector<JetCorrectorParameters> vParam;
0032   vParam.push_back(fParam);
0033   mCorrector = new FactorizedJetCorrectorCalculator(vParam);
0034 }
0035 //------------------------------------------------------------------------
0036 //--- L1OffsetCorrector destructor -------------------------------------------
0037 //------------------------------------------------------------------------
0038 L1JPTOffsetCorrector::~L1JPTOffsetCorrector() { delete mCorrector; }
0039 //------------------------------------------------------------------------
0040 //--- Returns correction for a given 4-vector ----------------------------
0041 //------------------------------------------------------------------------
0042 double L1JPTOffsetCorrector::correction(const LorentzVector& fJet) const {
0043   throw cms::Exception("EventRequired") << "Wrong interface correction(LorentzVector), event required!";
0044   return 1.0;
0045 }
0046 //------------------------------------------------------------------------
0047 //--- Returns correction for a given jet ---------------------------------
0048 //------------------------------------------------------------------------
0049 double L1JPTOffsetCorrector::correction(const reco::Jet& fJet) const {
0050   throw cms::Exception("EventRequired") << "Wrong interface correction(reco::Jet), event required!";
0051   return 1.0;
0052 }
0053 //------------------------------------------------------------------------
0054 //--- Returns correction for a given jet using event indormation ---------
0055 //------------------------------------------------------------------------
0056 double L1JPTOffsetCorrector::correction(const reco::Jet& fJet,
0057                                         const edm::Event& fEvent,
0058                                         const edm::EventSetup& fSetup) const {
0059   double result = 1.;
0060   const reco::JPTJet& jptjet = dynamic_cast<const reco::JPTJet&>(fJet);
0061   const edm::RefToBase<reco::Jet>& jptjetRef = jptjet.getCaloJetRef();
0062   reco::CaloJet const* rawcalojet = dynamic_cast<reco::CaloJet const*>(&*jptjetRef);
0063   //------ access the offset correction service ----------------
0064   double offset = 1.0;
0065   if (mIsOffsetSet) {
0066     const JetCorrector* OffsetCorrector = JetCorrector::getJetCorrector(mOffsetService, fSetup);
0067     offset = OffsetCorrector->correction(*rawcalojet, fEvent, fSetup);
0068   }
0069   //------ calculate the correction for the JPT jet ------------
0070   TLorentzVector JPTrawP4(rawcalojet->px(), rawcalojet->py(), rawcalojet->pz(), rawcalojet->energy());
0071   FactorizedJetCorrectorCalculator::VariableValues values;
0072   values.setJPTrawP4(JPTrawP4);
0073   values.setJPTrawOff(offset);
0074   values.setJetE(fJet.energy());
0075   result = mCorrector->getCorrection(values);
0076   return result;
0077 }