Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Author: S├ębastien Brochet
0004 //
0005 
0006 // system include files
0007 #include <memory>
0008 #include <iostream>
0009 
0010 // user include files
0011 #include "FWCore/Framework/interface/Frameworkfwd.h"
0012 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0013 
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/Framework/interface/ESHandle.h"
0019 
0020 #include "CondFormats/JetMETObjects/interface/JetResolutionObject.h"
0021 #include "CondFormats/DataRecord/interface/JetResolutionRcd.h"
0022 #include "CondFormats/DataRecord/interface/JetResolutionScaleFactorRcd.h"
0023 
0024 //
0025 // class declaration
0026 //
0027 
0028 class JetResolutionDBReader : public edm::one::EDAnalyzer<> {
0029 public:
0030   explicit JetResolutionDBReader(const edm::ParameterSet&);
0031   ~JetResolutionDBReader() override;
0032 
0033 private:
0034   void beginJob() override;
0035   void analyze(const edm::Event&, const edm::EventSetup&) override;
0036   void endJob() override;
0037 
0038   std::string m_era;
0039   std::string m_label;
0040   edm::ESGetToken<JME::JetResolutionObject, JetResolutionRcd> m_token;
0041 
0042   bool m_save_file;
0043   bool m_print;
0044 };
0045 
0046 class JetResolutionScaleFactorDBReader : public edm::one::EDAnalyzer<> {
0047 public:
0048   explicit JetResolutionScaleFactorDBReader(const edm::ParameterSet&);
0049 
0050 private:
0051   void analyze(const edm::Event&, const edm::EventSetup&) override;
0052 
0053   std::string m_era;
0054   std::string m_label;
0055   edm::ESGetToken<JME::JetResolutionObject, JetResolutionScaleFactorRcd> m_token;
0056 
0057   bool m_save_file;
0058   bool m_print;
0059 };
0060 
0061 JetResolutionDBReader::JetResolutionDBReader(const edm::ParameterSet& iConfig) {
0062   m_era = iConfig.getUntrackedParameter<std::string>("era");
0063   m_label = iConfig.getUntrackedParameter<std::string>("label");
0064   m_token = esConsumes(edm::ESInputTag("", m_label));
0065   m_print = iConfig.getUntrackedParameter<bool>("dump", true);
0066   m_save_file = iConfig.getUntrackedParameter<bool>("saveFile", false);
0067 }
0068 
0069 JetResolutionDBReader::~JetResolutionDBReader() {}
0070 
0071 void JetResolutionDBReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0072   std::cout << "Inspecting JER payload for label: " << m_label << std::endl;
0073 
0074   auto jerObjectHandle = iSetup.getTransientHandle(m_token);
0075 
0076   if (m_print) {
0077     jerObjectHandle->dump();
0078   }
0079 
0080   if (m_save_file) {
0081     std::string f = m_era + "_" + m_label + ".txt";
0082     jerObjectHandle->saveToFile(f);
0083     std::cout << "JER payload saved as " << f << std::endl;
0084   }
0085 }
0086 
0087 void JetResolutionDBReader::beginJob() {}
0088 
0089 void JetResolutionDBReader::endJob() {}
0090 
0091 JetResolutionScaleFactorDBReader::JetResolutionScaleFactorDBReader(const edm::ParameterSet& iConfig) {
0092   m_era = iConfig.getUntrackedParameter<std::string>("era");
0093   m_label = iConfig.getUntrackedParameter<std::string>("label");
0094   m_token = esConsumes(edm::ESInputTag("", m_label));
0095   m_print = iConfig.getUntrackedParameter<bool>("dump", true);
0096   m_save_file = iConfig.getUntrackedParameter<bool>("saveFile", false);
0097 }
0098 
0099 void JetResolutionScaleFactorDBReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0100   std::cout << "Inspecting JER SF payload for label: " << m_label << std::endl;
0101 
0102   auto jerObjectHandle = iSetup.getTransientHandle(m_token);
0103 
0104   if (m_print) {
0105     jerObjectHandle->dump();
0106   }
0107 
0108   if (m_save_file) {
0109     std::string f = m_era + "_" + m_label + ".txt";
0110     jerObjectHandle->saveToFile(f);
0111     std::cout << "JER SF payload saved as " << f << std::endl;
0112   }
0113 }
0114 
0115 //define this as a plug-in
0116 DEFINE_FWK_MODULE(JetResolutionDBReader);
0117 DEFINE_FWK_MODULE(JetResolutionScaleFactorDBReader);