Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-12 04:16:47

0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/LuminosityBlock.h"
0005 #include "FWCore/Framework/interface/NoRecordException.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/EventSetupRecord.h"
0010 #include "RecoLuminosity/LumiProducer/interface/LumiCorrectionParam.h"
0011 #include "RecoLuminosity/LumiProducer/interface/LumiCorrectionParamRcd.h"
0012 #include "DataFormats/Luminosity/interface/LumiSummary.h"
0013 #include <iostream>
0014 
0015 namespace edm {
0016   class EventSetup;
0017 }
0018 
0019 using namespace std;
0020 using namespace edm;
0021 
0022 class TestLumiCorrectionSource : public edm::one::EDAnalyzer<> {
0023 public:
0024   explicit TestLumiCorrectionSource(edm::ParameterSet const&);
0025   virtual ~TestLumiCorrectionSource();
0026 
0027   virtual void analyze(edm::Event const& e, edm::EventSetup const& c);
0028   virtual void endLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c);
0029 
0030 private:
0031   const edm::ESGetToken<LumiCorrectionParam, LumiCorrectionParamRcd> lumiCorrectionToken_;
0032 };
0033 
0034 // -----------------------------------------------------------------
0035 
0036 TestLumiCorrectionSource::TestLumiCorrectionSource(edm::ParameterSet const& ps)
0037     : lumiCorrectionToken_(esConsumes<edm::Transition::EndLuminosityBlock>()) {
0038   consumes<LumiSummary, edm::InLumi>(edm::InputTag("lumiProducer", ""));
0039 }
0040 
0041 // -----------------------------------------------------------------
0042 
0043 TestLumiCorrectionSource::~TestLumiCorrectionSource() {}
0044 
0045 // -----------------------------------------------------------------
0046 
0047 void TestLumiCorrectionSource::analyze(edm::Event const& e, edm::EventSetup const&) {}
0048 
0049 // -----------------------------------------------------------------
0050 
0051 void TestLumiCorrectionSource::endLuminosityBlock(edm::LuminosityBlock const& lumiBlock, EventSetup const& es) {
0052   std::cout << " I AM IN RUN NUMBER " << lumiBlock.run() << " LS NUMBER " << lumiBlock.luminosityBlock() << std::endl;
0053   edm::eventsetup::EventSetupRecordKey recordKey(
0054       edm::eventsetup::EventSetupRecordKey::TypeTag::findType("LumiCorrectionParamRcd"));
0055   if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0056     std::cout << "Record \"LumiCorrectionParamRcd"
0057               << "\" does not exist " << std::endl;
0058   }
0059   try {
0060     edm::Handle<LumiSummary> lumisummary;
0061     lumiBlock.getByLabel("lumiProducer", lumisummary);
0062     float instlumi = lumisummary->avgInsDelLumi();
0063     std::cout << "raw data tag " << lumisummary->lumiVersion() << std::endl;
0064     ;
0065     float correctedinstlumi = instlumi;
0066     float recinstlumi = lumisummary->avgInsRecLumi();
0067     float corrfac = 1.;
0068     auto datahandle = es.getHandle(lumiCorrectionToken_);
0069     if (datahandle.isValid()) {
0070       const LumiCorrectionParam* mydata = datahandle.product();
0071       std::cout << "correctionparams " << *mydata << std::endl;
0072       corrfac = mydata->getCorrection(instlumi);
0073     } else {
0074       std::cout << "no valid record found" << std::endl;
0075     }
0076     correctedinstlumi = instlumi * corrfac;
0077     std::cout << "correctedinstlumi " << correctedinstlumi << std::endl;
0078     float correctedinstRecLumi = recinstlumi * corrfac;
0079     std::cout << "corrected rec instlumi " << correctedinstRecLumi << std::endl;
0080   } catch (const edm::eventsetup::NoRecordException<LumiCorrectionParamRcd>& er) {
0081     std::cout << "no data found" << std::endl;
0082   } catch (const cms::Exception& ee) {
0083     std::cout << ee.what() << std::endl;
0084   }
0085 }
0086 
0087 DEFINE_FWK_MODULE(TestLumiCorrectionSource);