Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef JetCorrectionESSource_h
0002 #define JetCorrectionESSource_h
0003 
0004 //
0005 // Original Author:  Fedor Ratnikov
0006 // Created:  Dec. 28, 2006 (originally JetCorrectionService, renamed in 2011)
0007 //
0008 
0009 #include <memory>
0010 #include <string>
0011 #include <iostream>
0012 
0013 #include "FWCore/Framework/interface/ESProducer.h"
0014 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/ParameterSet/interface/FileInPath.h"
0017 #include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"
0018 #include "FWCore/Framework/interface/IOVSyncValue.h"
0019 #include "FWCore/Framework/interface/ValidityInterval.h"
0020 #include "FWCore/Framework/interface/SourceFactory.h"
0021 
0022 class JetCorrector;
0023 class JetCorrectionsRecord;
0024 
0025 namespace edm {
0026   namespace eventsetup {
0027     class EventSetupRecordKey;
0028   }
0029 }  // namespace edm
0030 
0031 #define DEFINE_JET_CORRECTION_ESSOURCE(corrector_, name_) \
0032   typedef JetCorrectionESSource<corrector_> name_;        \
0033   DEFINE_FWK_EVENTSETUP_SOURCE(name_)
0034 
0035 template <class Corrector>
0036 class JetCorrectionESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0037 private:
0038   edm::ParameterSet mParameterSet;
0039   std::string mLevel;
0040   std::string mEra;
0041   std::string mAlgo;
0042   std::string mSection;
0043   bool mDebug;
0044 
0045 public:
0046   JetCorrectionESSource(edm::ParameterSet const& fConfig) : mParameterSet(fConfig) {
0047     std::string label = fConfig.getParameter<std::string>("@module_label");
0048     mLevel = fConfig.getParameter<std::string>("level");
0049     mEra = fConfig.getParameter<std::string>("era");
0050     mAlgo = fConfig.getParameter<std::string>("algorithm");
0051     mSection = fConfig.getParameter<std::string>("section");
0052     mDebug = fConfig.getUntrackedParameter<bool>("debug", false);
0053 
0054     setWhatProduced(this, label);
0055     findingRecord<JetCorrectionsRecord>();
0056   }
0057 
0058   ~JetCorrectionESSource() override {}
0059 
0060   std::unique_ptr<JetCorrector> produce(JetCorrectionsRecord const& iRecord) {
0061     std::string fileName("CondFormats/JetMETObjects/data/");
0062     if (!mEra.empty())
0063       fileName += mEra;
0064     if (!mLevel.empty())
0065       fileName += "_" + mLevel;
0066     if (!mAlgo.empty())
0067       fileName += "_" + mAlgo;
0068     fileName += ".txt";
0069     if (mDebug)
0070       std::cout << "Parameter File: " << fileName << std::endl;
0071     edm::FileInPath fip(fileName);
0072     JetCorrectorParameters tmpJetCorPar{fip.fullPath(), mSection};
0073     return std::make_unique<Corrector>(tmpJetCorPar, mParameterSet);
0074   }
0075 
0076   void setIntervalFor(edm::eventsetup::EventSetupRecordKey const&,
0077                       edm::IOVSyncValue const&,
0078                       edm::ValidityInterval& fIOV) override {
0079     fIOV = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());  // anytime
0080   }
0081 };
0082 #endif