00001 #include <string> 00002 #include <iostream> 00003 #include <sstream> 00004 #include <memory> 00005 #include <assert.h> 00006 00007 #include <boost/shared_ptr.hpp> 00008 00009 #include <HepMC/GenEvent.h> 00010 #include <HepMC/GenParticle.h> 00011 #include <HepMC/PdfInfo.h> 00012 #include <HepMC/IO_ExtendedAscii.h> 00013 #include <HepMC/IO_BaseClass.h> 00014 00015 #include <ThePEG/Repository/Repository.h> 00016 #include <ThePEG/EventRecord/Event.h> 00017 #include <ThePEG/Config/ThePEG.h> 00018 #include <ThePEG/LesHouches/LesHouchesReader.h> 00019 00020 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00021 #include "FWCore/ServiceRegistry/interface/Service.h" 00022 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00023 #include "FWCore/Utilities/interface/RandomNumberGenerator.h" 00024 #include "FWCore/Framework/interface/Event.h" 00025 00026 #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" 00027 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h" 00028 00029 #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" 00030 #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" 00031 #include "GeneratorInterface/LHEInterface/interface/LHEProxy.h" 00032 #include "GeneratorInterface/LHEInterface/interface/Hadronisation.h" 00033 00034 #include "GeneratorInterface/ThePEGInterface/interface/ThePEGInterface.h" 00035 00036 using namespace std; 00037 using namespace ThePEG; 00038 using namespace lhef; 00039 00040 namespace lhef { 00041 00042 class ThePEGHadronisation : public ThePEGInterface, public Hadronisation { 00043 public: 00044 ThePEGHadronisation(const edm::ParameterSet ¶ms); 00045 ~ThePEGHadronisation(); 00046 00047 private: 00048 void doInit(); 00049 std::auto_ptr<HepMC::GenEvent> doHadronisation(); 00050 void newRunInfo(const boost::shared_ptr<LHERunInfo> &runInfo); 00051 00052 void initLHE(); 00053 00054 const string handlerDirectory_; 00055 00056 boost::shared_ptr<LHEProxy> proxy_; 00057 }; 00058 00059 void ThePEGHadronisation::initLHE() 00060 { 00061 ostringstream ss; 00062 ss << proxy_->getID(); 00063 00064 ostringstream logstream; 00065 00066 ThePEG::Repository::exec("cd " + handlerDirectory_, logstream); 00067 ThePEG::Repository::exec("set LHEReader:ProxyID " + ss.str(), logstream); 00068 00069 edm::LogInfo("Generator|LHEInterface") << logstream.str(); 00070 } 00071 00072 ThePEGHadronisation::ThePEGHadronisation(const edm::ParameterSet ¶ms) : 00073 ThePEGInterface(params), 00074 Hadronisation(params), 00075 handlerDirectory_(params.getParameter<string>("eventHandlers")) 00076 { 00077 initRepository(params); 00078 00079 proxy_ = LHEProxy::create(); 00080 00081 initLHE(); 00082 } 00083 00084 void ThePEGHadronisation::doInit() 00085 { 00086 } 00087 00088 ThePEGHadronisation::~ThePEGHadronisation() 00089 { 00090 } 00091 00092 std::auto_ptr<HepMC::GenEvent> ThePEGHadronisation::doHadronisation() 00093 { 00094 edm::LogInfo("Generator|LHEInterface") << "Start production"; 00095 00096 proxy_->loadEvent(getRawEvent()); 00097 00098 ThePEG::EventPtr thepegEvent; 00099 try { 00100 thepegEvent = eg_->shoot(); 00101 } catch(ThePEG::Stop) { 00102 // no event 00103 } 00104 00105 if (!thepegEvent) { 00106 edm::LogWarning("Generator|LHEInterface") 00107 << "thepegEvent not initialized"; 00108 return std::auto_ptr<HepMC::GenEvent>(); 00109 } 00110 00111 std::auto_ptr<HepMC::GenEvent> event = convert(thepegEvent); 00112 if (!event.get()) 00113 return event; 00114 00115 HepMC::PdfInfo pdf; 00116 clearAuxiliary(event.get(), &pdf); 00117 getRawEvent()->fillPdfInfo(&pdf); 00118 fillAuxiliary(event.get(), &pdf, thepegEvent); 00119 event->set_pdf_info(pdf); 00120 00121 return event; 00122 } 00123 00124 void ThePEGHadronisation::newRunInfo( 00125 const boost::shared_ptr<LHERunInfo> &runInfo) 00126 { 00127 proxy_->loadRunInfo(runInfo); 00128 00129 initGenerator(); 00130 00131 edm::Service<edm::RandomNumberGenerator> rng; 00132 eg_->setSeed(rng->mySeed()); 00133 } 00134 00135 DEFINE_LHE_HADRONISATION_PLUGIN(ThePEGHadronisation); 00136 00137 } // namespace lhef