Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-19 23:59:39

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