Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-13 13:14:01

0001 #include "FWCore/Framework/interface/stream/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/Run.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Utilities/interface/InputTag.h"
0009 #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
0010 #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
0011 #include "FWCore/Utilities/interface/EDMException.h"
0012 #include <iomanip>
0013 #include <iostream>
0014 using namespace std;
0015 using namespace edm;
0016 using namespace lhef;
0017 
0018 class DummyLHEAnalyzer : public edm::stream::EDAnalyzer<> {
0019 private:
0020   bool dumpEvent_;
0021   bool dumpHeader_;
0022 
0023 public:
0024   explicit DummyLHEAnalyzer(const ParameterSet& cfg)
0025       : dumpEvent_(cfg.getUntrackedParameter<bool>("dumpEvent", true)),
0026         dumpHeader_(cfg.getUntrackedParameter<bool>("dumpHeader", false)),
0027         tokenLHERunInfo_(consumes<LHERunInfoProduct, edm::InRun>(
0028             cfg.getUntrackedParameter<edm::InputTag>("moduleLabel", std::string("source")))),
0029         tokenLHEEvent_(
0030             consumes<LHEEventProduct>(cfg.getUntrackedParameter<edm::InputTag>("moduleLabel", std::string("source")))) {
0031   }
0032 
0033 private:
0034   void analyze(const Event& iEvent, const EventSetup& iSetup) override {
0035     Handle<LHEEventProduct> evt;
0036     iEvent.getByToken(tokenLHEEvent_, evt);
0037 
0038     const lhef::HEPEUP hepeup_ = evt->hepeup();
0039 
0040     const int nup_ = hepeup_.NUP;
0041     const std::vector<int> idup_ = hepeup_.IDUP;
0042     const std::vector<lhef::HEPEUP::FiveVector> pup_ = hepeup_.PUP;
0043 
0044     if (!dumpEvent_) {
0045       return;
0046     }
0047     std::cout << "Number of particles = " << nup_ << std::endl;
0048 
0049     if (evt->pdf() != NULL) {
0050       std::cout << "PDF scale = " << std::setw(14) << std::fixed << evt->pdf()->scalePDF << std::endl;
0051       std::cout << "PDF 1 : id = " << std::setw(14) << std::fixed << evt->pdf()->id.first << " x = " << std::setw(14)
0052                 << std::fixed << evt->pdf()->x.first << " xPDF = " << std::setw(14) << std::fixed
0053                 << evt->pdf()->xPDF.first << std::endl;
0054       std::cout << "PDF 2 : id = " << std::setw(14) << std::fixed << evt->pdf()->id.second << " x = " << std::setw(14)
0055                 << std::fixed << evt->pdf()->x.second << " xPDF = " << std::setw(14) << std::fixed
0056                 << evt->pdf()->xPDF.second << std::endl;
0057     }
0058 
0059     for (unsigned int icount = 0; icount < (unsigned int)nup_; icount++) {
0060       std::cout << "# " << std::setw(14) << std::fixed << icount << std::setw(14) << std::fixed << idup_[icount]
0061                 << std::setw(14) << std::fixed << (pup_[icount])[0] << std::setw(14) << std::fixed << (pup_[icount])[1]
0062                 << std::setw(14) << std::fixed << (pup_[icount])[2] << std::setw(14) << std::fixed << (pup_[icount])[3]
0063                 << std::setw(14) << std::fixed << (pup_[icount])[4] << std::endl;
0064     }
0065     if (evt->weights().size()) {
0066       std::cout << "weights:" << std::endl;
0067       for (size_t iwgt = 0; iwgt < evt->weights().size(); ++iwgt) {
0068         const LHEEventProduct::WGT& wgt = evt->weights().at(iwgt);
0069         std::cout << "\t" << wgt.id << ' ' << std::scientific << wgt.wgt << std::endl;
0070       }
0071     }
0072   }
0073 
0074   void endRun(edm::Run const& iRun, edm::EventSetup const& es) override {
0075     Handle<LHERunInfoProduct> run;
0076     //iRun.getByLabel( src_, run );

0077     iRun.getByToken(tokenLHERunInfo_, run);
0078 
0079     const lhef::HEPRUP thisHeprup_ = run->heprup();
0080 
0081     std::cout << "HEPRUP \n" << std::endl;
0082     std::cout << "IDBMUP " << std::setw(14) << std::fixed << thisHeprup_.IDBMUP.first << std::setw(14) << std::fixed
0083               << thisHeprup_.IDBMUP.second << std::endl;
0084     std::cout << "EBMUP  " << std::setw(14) << std::fixed << thisHeprup_.EBMUP.first << std::setw(14) << std::fixed
0085               << thisHeprup_.EBMUP.second << std::endl;
0086     std::cout << "PDFGUP " << std::setw(14) << std::fixed << thisHeprup_.PDFGUP.first << std::setw(14) << std::fixed
0087               << thisHeprup_.PDFGUP.second << std::endl;
0088     std::cout << "PDFSUP " << std::setw(14) << std::fixed << thisHeprup_.PDFSUP.first << std::setw(14) << std::fixed
0089               << thisHeprup_.PDFSUP.second << std::endl;
0090     std::cout << "IDWTUP " << std::setw(14) << std::fixed << thisHeprup_.IDWTUP << std::endl;
0091     std::cout << "NPRUP  " << std::setw(14) << std::fixed << thisHeprup_.NPRUP << std::endl;
0092     std::cout << "        XSECUP " << std::setw(14) << std::fixed << "        XERRUP " << std::setw(14) << std::fixed
0093               << "        XMAXUP " << std::setw(14) << std::fixed << "        LPRUP  " << std::setw(14) << std::fixed
0094               << std::endl;
0095     for (unsigned int iSize = 0; iSize < thisHeprup_.XSECUP.size(); iSize++) {
0096       std::cout << std::setw(14) << std::fixed << thisHeprup_.XSECUP[iSize] << std::setw(14) << std::fixed
0097                 << thisHeprup_.XERRUP[iSize] << std::setw(14) << std::fixed << thisHeprup_.XMAXUP[iSize]
0098                 << std::setw(14) << std::fixed << thisHeprup_.LPRUP[iSize] << std::endl;
0099     }
0100     std::cout << " " << std::endl;
0101 
0102     if (dumpHeader_) {
0103       std::cout << " HEADER " << std::endl;
0104       for (auto it = run->headers_begin(); it != run->headers_end(); ++it) {
0105         std::cout << "tag: '" << it->tag() << "'" << std::endl;
0106         for (auto const& l : it->lines()) {
0107           std::cout << "   " << l << std::endl;
0108         }
0109       }
0110     }
0111   }
0112 
0113   edm::EDGetTokenT<LHERunInfoProduct> tokenLHERunInfo_;
0114   edm::EDGetTokenT<LHEEventProduct> tokenLHEEvent_;
0115 };
0116 
0117 #include "FWCore/Framework/interface/MakerMacros.h"
0118 
0119 DEFINE_FWK_MODULE(DummyLHEAnalyzer);