Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-06 04:13:48

0001 // Implementation of class L1JPTOffsetCorrector.
0002 // L1JPTOffset jet corrector class.
0003 
0004 #include "JetMETCorrections/Algorithms/interface/L1JPTOffsetCorrectorImpl.h"
0005 #include "CondFormats/JetMETObjects/interface/FactorizedJetCorrector.h"
0006 #include "JetMETCorrections/JetCorrector/interface/JetCorrector.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/Framework/interface/ConsumesCollector.h"
0015 #include "DataFormats/JetReco/interface/Jet.h"
0016 #include "DataFormats/JetReco/interface/CaloJet.h"
0017 #include "DataFormats/JetReco/interface/JPTJet.h"
0018 #include "DataFormats/VertexReco/interface/Vertex.h"
0019 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0020 
0021 using namespace std;
0022 
0023 L1JPTOffsetCorrectorImplMaker::L1JPTOffsetCorrectorImplMaker(edm::ParameterSet const& fConfig,
0024                                                              edm::ConsumesCollector fCollector)
0025     : JetCorrectorImplMakerBase(fConfig, fCollector), useOffset_(false) {
0026   auto const& offsetService = fConfig.getParameter<edm::InputTag>("offsetService");
0027   if (not offsetService.label().empty()) {
0028     useOffset_ = true;
0029     offsetCorrectorToken_ = fCollector.consumes<reco::JetCorrector>(offsetService);
0030   }
0031 }
0032 
0033 std::unique_ptr<reco::JetCorrectorImpl> L1JPTOffsetCorrectorImplMaker::make(edm::Event const& fEvent,
0034                                                                             edm::EventSetup const& fSetup) {
0035   reco::JetCorrector const* offset = nullptr;
0036   if (useOffset_) {
0037     edm::Handle<reco::JetCorrector> hOffset;
0038     fEvent.getByToken(offsetCorrectorToken_, hOffset);
0039     offset = &(*hOffset);
0040   }
0041   auto calculator = getCalculator(fSetup, [](std::string const& level) {
0042     if (level != "L1JPTOffset") {
0043       throw cms::Exception("L1OffsetCorrector") << " correction level: " << level << " is not L1JPTOffset";
0044     }
0045   });
0046   return std::unique_ptr<reco::JetCorrectorImpl>(new L1JPTOffsetCorrectorImpl(calculator, offset));
0047 }
0048 
0049 void L1JPTOffsetCorrectorImplMaker::fillDescriptions(edm::ConfigurationDescriptions& iDescriptions) {
0050   edm::ParameterSetDescription desc;
0051   addToDescription(desc);
0052   desc.add<edm::InputTag>("offsetService");
0053   iDescriptions.addDefault(desc);
0054 }
0055 
0056 //------------------------------------------------------------------------
0057 //--- L1OffsetCorrectorImpl constructor ------------------------------------------
0058 //------------------------------------------------------------------------
0059 L1JPTOffsetCorrectorImpl::L1JPTOffsetCorrectorImpl(std::shared_ptr<FactorizedJetCorrectorCalculator const> corrector,
0060                                                    const reco::JetCorrector* offsetService)
0061     : offsetService_(offsetService), corrector_(corrector) {}
0062 //------------------------------------------------------------------------
0063 //--- L1OffsetCorrectorImpl destructor -------------------------------------------
0064 //------------------------------------------------------------------------
0065 
0066 //------------------------------------------------------------------------
0067 //--- Returns correction for a given 4-vector ----------------------------
0068 //------------------------------------------------------------------------
0069 double L1JPTOffsetCorrectorImpl::correction(const LorentzVector& fJet) const {
0070   throw cms::Exception("EventRequired") << "Wrong interface correction(LorentzVector), event required!";
0071   return 1.0;
0072 }
0073 //------------------------------------------------------------------------
0074 //--- Returns correction for a given jet ---------------------------------
0075 //------------------------------------------------------------------------
0076 double L1JPTOffsetCorrectorImpl::correction(const reco::Jet& fJet) const {
0077   double result = 1.;
0078   const reco::JPTJet& jptjet = dynamic_cast<const reco::JPTJet&>(fJet);
0079   const edm::RefToBase<reco::Jet>& jptjetRef = jptjet.getCaloJetRef();
0080   reco::CaloJet const* rawcalojet = dynamic_cast<reco::CaloJet const*>(&*jptjetRef);
0081   //------ access the offset correction service ----------------
0082   double offset = 1.0;
0083   if (offsetService_) {
0084     offset = offsetService_->correction(*rawcalojet);
0085   }
0086   //------ calculate the correction for the JPT jet ------------
0087   TLorentzVector JPTrawP4(rawcalojet->px(), rawcalojet->py(), rawcalojet->pz(), rawcalojet->energy());
0088   FactorizedJetCorrectorCalculator::VariableValues values;
0089   values.setJPTrawP4(JPTrawP4);
0090   values.setJPTrawOff(offset);
0091   values.setJetE(fJet.energy());
0092   result = corrector_->getCorrection(values);
0093   return result;
0094 }