DummyLHEAnalyzer

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
#include "FWCore/Framework/interface/stream/EDAnalyzer.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include <iomanip>
#include <iostream>
using namespace std;
using namespace edm;
using namespace lhef;

class DummyLHEAnalyzer : public edm::stream::EDAnalyzer<> {
private:
  bool dumpEvent_;
  bool dumpHeader_;

public:
  explicit DummyLHEAnalyzer(const ParameterSet& cfg)
      : dumpEvent_(cfg.getUntrackedParameter<bool>("dumpEvent", true)),
        dumpHeader_(cfg.getUntrackedParameter<bool>("dumpHeader", false)),
        tokenLHERunInfo_(consumes<LHERunInfoProduct, edm::InRun>(
            cfg.getUntrackedParameter<edm::InputTag>("moduleLabel", std::string("source")))),
        tokenLHEEvent_(
            consumes<LHEEventProduct>(cfg.getUntrackedParameter<edm::InputTag>("moduleLabel", std::string("source")))) {
  }

private:
  void analyze(const Event& iEvent, const EventSetup& iSetup) override {
    Handle<LHEEventProduct> evt;
    iEvent.getByToken(tokenLHEEvent_, evt);

    const lhef::HEPEUP hepeup_ = evt->hepeup();

    const int nup_ = hepeup_.NUP;
    const std::vector<int> idup_ = hepeup_.IDUP;
    const std::vector<lhef::HEPEUP::FiveVector> pup_ = hepeup_.PUP;

    if (!dumpEvent_) {
      return;
    }
    std::cout << "Number of particles = " << nup_ << std::endl;

    if (evt->pdf() != NULL) {
      std::cout << "PDF scale = " << std::setw(14) << std::fixed << evt->pdf()->scalePDF << std::endl;
      std::cout << "PDF 1 : id = " << std::setw(14) << std::fixed << evt->pdf()->id.first << " x = " << std::setw(14)
                << std::fixed << evt->pdf()->x.first << " xPDF = " << std::setw(14) << std::fixed
                << evt->pdf()->xPDF.first << std::endl;
      std::cout << "PDF 2 : id = " << std::setw(14) << std::fixed << evt->pdf()->id.second << " x = " << std::setw(14)
                << std::fixed << evt->pdf()->x.second << " xPDF = " << std::setw(14) << std::fixed
                << evt->pdf()->xPDF.second << std::endl;
    }

    for (unsigned int icount = 0; icount < (unsigned int)nup_; icount++) {
      std::cout << "# " << std::setw(14) << std::fixed << icount << std::setw(14) << std::fixed << idup_[icount]
                << std::setw(14) << std::fixed << (pup_[icount])[0] << std::setw(14) << std::fixed << (pup_[icount])[1]
                << std::setw(14) << std::fixed << (pup_[icount])[2] << std::setw(14) << std::fixed << (pup_[icount])[3]
                << std::setw(14) << std::fixed << (pup_[icount])[4] << std::endl;
    }
    if (evt->weights().size()) {
      std::cout << "weights:" << std::endl;
      for (size_t iwgt = 0; iwgt < evt->weights().size(); ++iwgt) {
        const LHEEventProduct::WGT& wgt = evt->weights().at(iwgt);
        std::cout << "\t" << wgt.id << ' ' << std::scientific << wgt.wgt << std::endl;
      }
    }
  }

  void endRun(edm::Run const& iRun, edm::EventSetup const& es) override {
    Handle<LHERunInfoProduct> run;
    //iRun.getByLabel( src_, run );
    iRun.getByToken(tokenLHERunInfo_, run);

    const lhef::HEPRUP thisHeprup_ = run->heprup();

    std::cout << "HEPRUP \n" << std::endl;
    std::cout << "IDBMUP " << std::setw(14) << std::fixed << thisHeprup_.IDBMUP.first << std::setw(14) << std::fixed
              << thisHeprup_.IDBMUP.second << std::endl;
    std::cout << "EBMUP  " << std::setw(14) << std::fixed << thisHeprup_.EBMUP.first << std::setw(14) << std::fixed
              << thisHeprup_.EBMUP.second << std::endl;
    std::cout << "PDFGUP " << std::setw(14) << std::fixed << thisHeprup_.PDFGUP.first << std::setw(14) << std::fixed
              << thisHeprup_.PDFGUP.second << std::endl;
    std::cout << "PDFSUP " << std::setw(14) << std::fixed << thisHeprup_.PDFSUP.first << std::setw(14) << std::fixed
              << thisHeprup_.PDFSUP.second << std::endl;
    std::cout << "IDWTUP " << std::setw(14) << std::fixed << thisHeprup_.IDWTUP << std::endl;
    std::cout << "NPRUP  " << std::setw(14) << std::fixed << thisHeprup_.NPRUP << std::endl;
    std::cout << "        XSECUP " << std::setw(14) << std::fixed << "        XERRUP " << std::setw(14) << std::fixed
              << "        XMAXUP " << std::setw(14) << std::fixed << "        LPRUP  " << std::setw(14) << std::fixed
              << std::endl;
    for (unsigned int iSize = 0; iSize < thisHeprup_.XSECUP.size(); iSize++) {
      std::cout << std::setw(14) << std::fixed << thisHeprup_.XSECUP[iSize] << std::setw(14) << std::fixed
                << thisHeprup_.XERRUP[iSize] << std::setw(14) << std::fixed << thisHeprup_.XMAXUP[iSize]
                << std::setw(14) << std::fixed << thisHeprup_.LPRUP[iSize] << std::endl;
    }
    std::cout << " " << std::endl;

    if (dumpHeader_) {
      std::cout << " HEADER " << std::endl;
      for (auto it = run->headers_begin(); it != run->headers_end(); ++it) {
        std::cout << "tag: '" << it->tag() << "'" << std::endl;
        for (auto const& l : it->lines()) {
          std::cout << "   " << l << std::endl;
        }
      }
    }
  }

  edm::EDGetTokenT<LHERunInfoProduct> tokenLHERunInfo_;
  edm::EDGetTokenT<LHEEventProduct> tokenLHEEvent_;
};

#include "FWCore/Framework/interface/MakerMacros.h"

DEFINE_FWK_MODULE(DummyLHEAnalyzer);