![]() |
![]() |
00001 #include <algorithm> 00002 #include <iostream> 00003 #include <iterator> 00004 #include <fstream> 00005 #include <string> 00006 #include <memory> 00007 00008 #include "FWCore/Framework/interface/EDAnalyzer.h" 00009 #include "FWCore/Framework/interface/MakerMacros.h" 00010 #include "FWCore/Framework/interface/Event.h" 00011 #include "FWCore/Framework/interface/Run.h" 00012 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00013 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00014 #include "FWCore/Utilities/interface/InputTag.h" 00015 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" 00016 00017 #include "HepMC/IO_GenEvent.h" 00018 00019 00020 class HepMCEventWriter : public edm::EDAnalyzer { 00021 public: 00022 explicit HepMCEventWriter(const edm::ParameterSet ¶ms); 00023 virtual ~HepMCEventWriter(); 00024 00025 protected: 00026 virtual void beginRun(const edm::Run &run, const edm::EventSetup &es); 00027 virtual void endRun(const edm::Run &run, const edm::EventSetup &es); 00028 virtual void analyze(const edm::Event &event, const edm::EventSetup &es); 00029 00030 private: 00031 HepMC::IO_GenEvent* _output; 00032 edm::InputTag hepMCProduct_; 00033 }; 00034 00035 HepMCEventWriter::HepMCEventWriter(const edm::ParameterSet ¶ms) : 00036 hepMCProduct_(params.getParameter<edm::InputTag>("hepMCProduct")) 00037 { 00038 } 00039 00040 HepMCEventWriter::~HepMCEventWriter() 00041 { 00042 } 00043 00044 void HepMCEventWriter::beginRun(const edm::Run &run, const edm::EventSetup &es) 00045 { 00046 00047 _output = new HepMC::IO_GenEvent("GenEvent_ASCII.dat",std::ios::out); 00048 00049 } 00050 00051 00052 void HepMCEventWriter::endRun(const edm::Run &run, const edm::EventSetup &es) 00053 { 00054 if (_output) delete _output; 00055 } 00056 00057 void HepMCEventWriter::analyze(const edm::Event &event, const edm::EventSetup &es) 00058 { 00059 00060 edm::Handle<edm::HepMCProduct> product; 00061 event.getByLabel(hepMCProduct_, product); 00062 00063 const HepMC::GenEvent* evt = product->GetEvent(); 00064 00065 _output->write_event(evt); 00066 00067 } 00068 00069 DEFINE_FWK_MODULE(HepMCEventWriter);