Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-06 04:00:39

0001 // -*- C++ -*-
0002 //
0003 // Package:    JetCorrectorDBReader
0004 // Class:
0005 //
0006 /**\class JetCorrectorDBReader
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Benedikt Hegner
0015 //         Created:  Tue Mar 09 01:32:51 CET 2010
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/Framework/interface/EventSetup.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Framework/interface/ESHandle.h"
0031 #include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"
0032 #include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h"
0033 //
0034 // class declaration
0035 //
0036 
0037 class JetCorrectorDBReader : public edm::one::EDAnalyzer<> {
0038 public:
0039   explicit JetCorrectorDBReader(const edm::ParameterSet&);
0040   ~JetCorrectorDBReader() override;
0041 
0042 private:
0043   void beginJob() override;
0044   void analyze(const edm::Event&, const edm::EventSetup&) override;
0045   void endJob() override;
0046 
0047   std::string mPayloadName, mGlobalTag;
0048   bool mCreateTextFile, mPrintScreen;
0049   edm::ESGetToken<JetCorrectorParametersCollection, JetCorrectionsRecord> mPayloadToken;
0050 };
0051 
0052 JetCorrectorDBReader::JetCorrectorDBReader(const edm::ParameterSet& iConfig) {
0053   mPayloadName = iConfig.getUntrackedParameter<std::string>("payloadName");
0054   mPayloadToken = esConsumes(edm::ESInputTag("", mPayloadName));
0055   mGlobalTag = iConfig.getUntrackedParameter<std::string>("globalTag");
0056   mPrintScreen = iConfig.getUntrackedParameter<bool>("printScreen");
0057   mCreateTextFile = iConfig.getUntrackedParameter<bool>("createTextFile");
0058 }
0059 
0060 JetCorrectorDBReader::~JetCorrectorDBReader() {}
0061 
0062 void JetCorrectorDBReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0063   std::cout << "Inspecting JEC payload with label: " << mPayloadName << std::endl;
0064   auto const& JetCorParamsColl = iSetup.getData(mPayloadToken);
0065   std::vector<JetCorrectorParametersCollection::key_type> keys;
0066   JetCorParamsColl.validKeys(keys);
0067   for (std::vector<JetCorrectorParametersCollection::key_type>::const_iterator ibegin = keys.begin(),
0068                                                                                iend = keys.end(),
0069                                                                                ikey = ibegin;
0070        ikey != iend;
0071        ++ikey) {
0072     std::cout << "-------------------------------------------------" << std::endl;
0073     std::cout << "Processing key = " << *ikey << std::endl;
0074     std::cout << "object label: " << JetCorParamsColl.findLabel(*ikey) << std::endl;
0075     JetCorrectorParameters const& JetCorParams = JetCorParamsColl[*ikey];
0076 
0077     if (mCreateTextFile) {
0078       std::cout << "Creating txt file: "
0079                 << mGlobalTag + "_" + mPayloadName + "_" + JetCorParamsColl.findLabel(*ikey) + ".txt" << std::endl;
0080       JetCorParams.printFile(mGlobalTag + "_" + JetCorParamsColl.findLabel(*ikey) + "_" + mPayloadName + ".txt");
0081     }
0082     if (mPrintScreen)
0083       JetCorParams.printScreen();
0084   }
0085 }
0086 
0087 void JetCorrectorDBReader::beginJob() {}
0088 
0089 void JetCorrectorDBReader::endJob() {}
0090 
0091 //define this as a plug-in
0092 DEFINE_FWK_MODULE(JetCorrectorDBReader);