Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    METCorrectorDBReader
0004 // Class:
0005 //
0006 /**\class METCorrectorDBReader
0007 
0008  Description: Reads out *.db format for MET corrections 
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 
0015 // system include files
0016 #include <memory>
0017 
0018 // user include files
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0022 
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Framework/interface/MakerMacros.h"
0025 #include "FWCore/Framework/interface/EventSetup.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "FWCore/Framework/interface/ESHandle.h"
0028 #include "CondFormats/JetMETObjects/interface/MEtXYcorrectParameters.h"
0029 #include "JetMETCorrections/Objects/interface/MEtXYcorrectRecord.h"
0030 #include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h"
0031 
0032 //
0033 // class declaration
0034 //
0035 namespace {
0036 
0037   class METCorrectorDBReader : public edm::one::EDAnalyzer<> {
0038   public:
0039     explicit METCorrectorDBReader(const edm::ParameterSet&);
0040     ~METCorrectorDBReader() 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     edm::ESGetToken<MEtXYcorrectParametersCollection, MEtXYcorrectRecord> mPayloadToken;
0049     bool mCreateTextFile, mPrintScreen;
0050   };
0051 
0052 }  // namespace
0053 
0054 METCorrectorDBReader::METCorrectorDBReader(const edm::ParameterSet& iConfig) {
0055   mPayloadName = iConfig.getUntrackedParameter<std::string>("payloadName");
0056   mPayloadToken = esConsumes(edm::ESInputTag("", mPayloadName));
0057   mGlobalTag = iConfig.getUntrackedParameter<std::string>("globalTag");
0058   mPrintScreen = iConfig.getUntrackedParameter<bool>("printScreen");
0059   mCreateTextFile = iConfig.getUntrackedParameter<bool>("createTextFile");
0060 }
0061 
0062 METCorrectorDBReader::~METCorrectorDBReader() {}
0063 
0064 void METCorrectorDBReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0065   edm::ESHandle<MEtXYcorrectParametersCollection> MEtXYcorParaColl = iSetup.getHandle(mPayloadToken);
0066   edm::LogInfo("METCorrectorDBReader") << "Inspecting MET payload with label: " << mPayloadName;
0067 
0068   // get the sections from Collection (pair of section and METCorr.Par class)
0069   std::vector<MEtXYcorrectParametersCollection::key_type> keys;
0070   // save level to keys for each METParameter in METParameter collection
0071   MEtXYcorParaColl->validKeys(keys);
0072   //MEtXYcorParaColl->validSections( sections );
0073   for (std::vector<MEtXYcorrectParametersCollection::key_type>::const_iterator ikey = keys.begin(); ikey != keys.end();
0074        ++ikey) {
0075     std::string sectionName = MEtXYcorParaColl->findLabel(*ikey);
0076     edm::LogInfo("METCorrectorDBReader") << "Processing key = " << *ikey << "object label: " << sectionName;
0077     MEtXYcorrectParameters const& MEtXYcorParams = (*MEtXYcorParaColl)[*ikey];
0078 
0079     if (mCreateTextFile) {
0080       std::string outFileName(mGlobalTag + "_Shift");
0081       std::string shiftType("MC");
0082 
0083       if (MEtXYcorParaColl->isShiftMC(*ikey)) {
0084         shiftType = "MC";
0085       } else if (MEtXYcorParaColl->isShiftDY(*ikey)) {
0086         shiftType = "DY";
0087       } else if (MEtXYcorParaColl->isShiftTTJets(*ikey)) {
0088         shiftType = "TTJets";
0089       } else if (MEtXYcorParaColl->isShiftWJets(*ikey)) {
0090         shiftType = "WTJets";
0091       } else if (MEtXYcorParaColl->isShiftData(*ikey)) {
0092         shiftType = "Data";
0093       } else {
0094         throw cms::Exception("InvalidKey") << "************** Can't interpret the stored key: " << *ikey << std::endl;
0095       }
0096       outFileName += shiftType + "_" + mPayloadName + ".txt";
0097       edm::LogInfo("METCorrectorDBReader") << "outFileName: " << outFileName;
0098       MEtXYcorParams.printFile(outFileName, sectionName);
0099     }
0100 
0101     if (mPrintScreen) {
0102       edm::LogInfo("METCorrectorDBReader") << "Level: " << MEtXYcorParaColl->levelName(*ikey);
0103       MEtXYcorParams.printScreen(sectionName);
0104     }
0105   }
0106 
0107   edm::LogInfo("METCorrectorDBReader") << "Finished --------------------------";
0108 }
0109 
0110 void METCorrectorDBReader::beginJob() {}
0111 
0112 void METCorrectorDBReader::endJob() {}
0113 
0114 //define this as a plug-in
0115 DEFINE_FWK_MODULE(METCorrectorDBReader);