Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-30 23:17:16

0001 
0002 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/LuminosityBlock.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "DataFormats/Luminosity/interface/LumiDetails.h"
0008 #include "DataFormats/Luminosity/interface/LumiSummary.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 
0011 #include <cmath>
0012 #include <iostream>
0013 
0014 namespace edm {
0015   class EventSetup;
0016 }
0017 
0018 using namespace std;
0019 using namespace edm;
0020 
0021 namespace edmtest {
0022 
0023   class TestLumiProducer : public edm::one::EDAnalyzer<edm::one::WatchLuminosityBlocks> {
0024   public:
0025     explicit TestLumiProducer(edm::ParameterSet const&);
0026 
0027     void beginLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) override {}
0028     void analyze(edm::Event const& e, edm::EventSetup const& c) override;
0029     void endLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) override;
0030   };
0031 
0032   // -----------------------------------------------------------------
0033 
0034   TestLumiProducer::TestLumiProducer(edm::ParameterSet const& ps) {
0035     consumes<LumiSummary, edm::InLumi>(edm::InputTag("lumiProducer", ""));
0036     consumes<LumiDetails, edm::InLumi>(edm::InputTag("lumiProducer", ""));
0037   }
0038 
0039   // -----------------------------------------------------------------
0040 
0041   void TestLumiProducer::analyze(edm::Event const& e, edm::EventSetup const&) {}
0042 
0043   // -----------------------------------------------------------------
0044 
0045   void TestLumiProducer::endLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
0046     Handle<LumiSummary> lumiSummary;
0047     lumiBlock.getByLabel("lumiProducer", lumiSummary);
0048     if (lumiSummary->isValid()) {
0049       std::cout << *lumiSummary << "\n";
0050     } else {
0051       std::cout << "no valid lumi summary data" << std::endl;
0052     }
0053     Handle<LumiDetails> lumiDetails;
0054     lumiBlock.getByLabel("lumiProducer", lumiDetails);
0055     if (lumiDetails->isValid()) {
0056       //std::cout << *lumiDetails << "\n";
0057       std::cout << "lumivalue beamintensity 1 " << lumiDetails->lumiBeam1Intensity(1) << " "
0058                 << lumiDetails->lumiBeam2Intensity(1) << std::endl;
0059       std::cout << "lumivalue 1 " << lumiDetails->lumiValue(LumiDetails::kOCC1, 1) * 6.37 << " "
0060                 << lumiDetails->lumiBeam1Intensity(1) << std::endl;
0061       std::cout << "lumivalue 214 " << lumiDetails->lumiValue(LumiDetails::kOCC1, 214) * 6.37 << " "
0062                 << lumiDetails->lumiBeam1Intensity(214) << std::endl;
0063       std::cout << "lumivalue 643 " << lumiDetails->lumiValue(LumiDetails::kOCC1, 643) * 6.37 << " "
0064                 << lumiDetails->lumiBeam1Intensity(643) << std::endl;
0065       std::cout << "lumivalue 895 " << lumiDetails->lumiValue(LumiDetails::kOCC1, 895) * 6.37 << " "
0066                 << lumiDetails->lumiBeam1Intensity(895) << std::endl;
0067       std::cout << "lumivalue 901 " << lumiDetails->lumiValue(LumiDetails::kOCC1, 901) * 6.37 << " "
0068                 << lumiDetails->lumiBeam1Intensity(901) << std::endl;
0069       std::cout << "lumivalue 1000 " << lumiDetails->lumiValue(LumiDetails::kOCC1, 1000) * 6.37 << " "
0070                 << lumiDetails->lumiBeam1Intensity(1000) << std::endl;
0071       std::cout << "lumivalue 1475 " << lumiDetails->lumiValue(LumiDetails::kOCC1, 1475) * 6.37 << " "
0072                 << lumiDetails->lumiBeam1Intensity(1475) << std::endl;
0073       std::cout << "lumivalue 2053 " << lumiDetails->lumiValue(LumiDetails::kOCC1, 2053) * 6.37 << " "
0074                 << lumiDetails->lumiBeam1Intensity(2053) << std::endl;
0075       std::cout << "lumivalue 2765 " << lumiDetails->lumiValue(LumiDetails::kOCC1, 2765) * 6.37 << " "
0076                 << lumiDetails->lumiBeam1Intensity(2765) << std::endl;
0077       std::cout << "lumivalue 3500 " << lumiDetails->lumiValue(LumiDetails::kOCC1, 3500) * 6.37 << " "
0078                 << lumiDetails->lumiBeam1Intensity(3500) << std::endl;
0079     } else {
0080       std::cout << "no valid lumi detail data" << std::endl;
0081     }
0082     // We know the content we put into the objects in the
0083     // configuration, manually check to see that we can
0084     // retrieve the same values.
0085 
0086     // A small value to allow for machine precision variations when
0087     // comparing small numbers.
0088     /*
0089     double epsilon = 0.001;
0090 
0091     for (int i = 0; i < 5; ++i) {
0092 
0093       if ( (fabs(lumiDetails->lumiEtSum(i)     - (100.0 + i)) > epsilon) ||
0094            (fabs(lumiDetails->lumiEtSumErr(i)  - (200.0 + i)) > epsilon) ||
0095            (lumiDetails->lumiEtSumQual(i) != (300 + i)) ||
0096            (fabs(lumiDetails->lumiOcc(i)       - (400.0 + i)) > epsilon) ||
0097            (fabs(lumiDetails->lumiOccErr(i)    - (500.0 + i)) > epsilon) ||
0098            (lumiDetails->lumiOccQual(i) != (600 + i)) ) {
0099     std::cerr << "TestLumiProducer: Values read from LumiDetails object do not match input values (1)\n";
0100         abort();
0101       }    
0102       if ( (fabs(lumiDetails->lumiEtSum()[i]     - (100.0 + i)) > epsilon) ||
0103            (fabs(lumiDetails->lumiEtSumErr()[i]  - (200.0 + i)) > epsilon) ||
0104            (lumiDetails->lumiEtSumQual()[i] != (300 + i)) ||
0105            (fabs(lumiDetails->lumiOcc()[i]       - (400.0 + i)) > epsilon) ||
0106            (fabs(lumiDetails->lumiOccErr()[i]    - (500.0 + i)) > epsilon) ||
0107            (lumiDetails->lumiOccQual()[i] != (600 + i)) ) {
0108     std::cerr << "TestLumiProducer: Values read from LumiDetails object do not match input values (2)\n";
0109         abort();
0110       }    
0111 
0112       if ( (lumiSummary->l1RateCounter(i)  != (10 + i)) ||
0113            (lumiSummary->l1Scaler(i)       != (20 + i)) ||
0114            (lumiSummary->hltRateCounter(i) != (30 + i)) ||
0115            (lumiSummary->hltScaler(i)      != (40 + i)) ||
0116            (lumiSummary->hltInput(i)       != (50 + i)) ) {
0117         std::cerr << "TestLumiProducer: Values read from LumiSummary object do not match input values (1)\n";
0118         abort();
0119       }
0120 
0121       if ( (lumiSummary->l1RateCounter()[i]  != (10 + i)) ||
0122            (lumiSummary->l1Scaler()[i]       != (20 + i)) ||
0123            (lumiSummary->hltRateCounter()[i] != (30 + i)) ||
0124            (lumiSummary->hltScaler()[i]      != (40 + i)) ||
0125            (lumiSummary->hltInput()[i]       != (50 + i)) ) {
0126         std::cerr << "TestLumiProducer: Values read from LumiSummary object do not match input values (2)\n";
0127         abort();
0128       }
0129     }
0130 
0131     if ( (fabs(lumiSummary->avgInsDelLumi()    - 1.0)  > epsilon) ||
0132          (fabs(lumiSummary->avgInsDelLumiErr() - 2.0)  > epsilon) ||
0133          (fabs(lumiSummary->avgInsRecLumi()    - 1.0 * 0.95)  > epsilon) ||
0134          (fabs(lumiSummary->avgInsRecLumiErr() - 2.0 * 0.95)  > epsilon) ||
0135          (fabs(lumiSummary->deadFrac()      - 0.05) > epsilon) ||
0136          (fabs(lumiSummary->liveFrac()      - 0.95) > epsilon) ||
0137          (lumiSummary->lumiSecQual() != 3) ||
0138          (lumiSummary->lsNumber() != 5) ) {
0139       std::cerr << "TestLumiProducer: Values read from LumiSummary object do not match input values (3)\n";
0140       abort();
0141     }
0142     */
0143   }
0144 }  // namespace edmtest
0145 
0146 using edmtest::TestLumiProducer;
0147 
0148 DEFINE_FWK_MODULE(TestLumiProducer);