CMS 3D CMS Logo

ThePEGProducer.cc

Go to the documentation of this file.
00001 #include <memory>
00002 
00003 #include <HepMC/GenEvent.h>
00004 #include <HepMC/IO_BaseClass.h>
00005 
00006 #include <ThePEG/Repository/Repository.h>
00007 #include <ThePEG/EventRecord/Event.h>
00008 #include <ThePEG/Config/ThePEG.h>
00009 
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/Framework/interface/Run.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/Framework/interface/EDProducer.h"
00014 #include "FWCore/Framework/interface/MakerMacros.h"
00015 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 #include "FWCore/ServiceRegistry/interface/Service.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 
00020 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00021 #include "SimDataFormats/HepMCProduct/interface/GenInfoProduct.h"
00022 
00023 #include "GeneratorInterface/ThePEGInterface/interface/ThePEGInterface.h"
00024 
00025 class ThePEGProducer : public edm::EDProducer, public ThePEGInterface {
00026     public:
00027         ThePEGProducer(const edm::ParameterSet &params);
00028         virtual ~ThePEGProducer();
00029 
00030     private:
00031         virtual void beginRun(edm::Run &run, const edm::EventSetup &es);
00032         virtual void endRun(edm::Run &run, const edm::EventSetup &es);
00033         virtual void produce(edm::Event &event, const edm::EventSetup &es);
00034 
00035         unsigned int    eventsToPrint;
00036         unsigned int    index;
00037 
00038         const double    extCrossSect;
00039         const double    extFilterEff;
00040 };
00041 
00042 ThePEGProducer::ThePEGProducer(const edm::ParameterSet &pset) :
00043         ThePEGInterface(pset),
00044         eventsToPrint(pset.getUntrackedParameter<unsigned int>("eventsToPrint", 0)),
00045         index(0),
00046         extCrossSect(pset.getUntrackedParameter<double>("crossSection", -1.0)),
00047         extFilterEff(pset.getUntrackedParameter<double>("filterEfficiency", -1.0))
00048 {  
00049         initRepository(pset);
00050 
00051         produces<edm::HepMCProduct>();
00052         produces<edm::GenInfoProduct, edm::InRun>();
00053 }
00054 
00055 ThePEGProducer::~ThePEGProducer()
00056 {
00057 }
00058 
00059 void ThePEGProducer::beginRun(edm::Run &run, const edm::EventSetup &es)
00060 {
00061         initGenerator();
00062 
00063         edm::Service<edm::RandomNumberGenerator> rng;
00064         eg_->setSeed(rng->mySeed());
00065 }
00066 
00067 void ThePEGProducer::endRun(edm::Run &run, const edm::EventSetup &es)
00068 {
00069         std::auto_ptr<edm::GenInfoProduct> genInfoProd(new edm::GenInfoProduct);
00070         genInfoProd->set_cross_section(eg_->integratedXSec() / ThePEG::picobarn);
00071         genInfoProd->set_external_cross_section(extCrossSect);
00072         genInfoProd->set_filter_efficiency(extFilterEff);
00073         run.put(genInfoProd);
00074 }
00075 
00076 void ThePEGProducer::produce(edm::Event &event, const edm::EventSetup &es)
00077 {
00078         edm::LogInfo("Generator|ThePEGProducer") << "Start production";
00079 
00080         ThePEG::EventPtr thepegEvent = eg_->shoot();
00081         if (!thepegEvent) {
00082                 edm::LogWarning("Generator|ThePEGProducer") << "thepegEvent not initialized";
00083                 return;
00084         }
00085 
00086         std::auto_ptr<HepMC::GenEvent> hepmcEvent = convert(thepegEvent);
00087         if (!hepmcEvent.get()) {
00088                 edm::LogWarning("Generator|ThePEGProducer") << "hepmcEvent not initialized";
00089                 return;
00090         }
00091 
00092         HepMC::PdfInfo pdf;
00093         clearAuxiliary(hepmcEvent.get(), &pdf);
00094         hepmcEvent->set_event_number(++index);
00095         fillAuxiliary(hepmcEvent.get(), &pdf, thepegEvent);
00096         hepmcEvent->set_pdf_info(pdf);
00097 
00098         if (eventsToPrint) {
00099                 eventsToPrint--;
00100                 hepmcEvent->print();
00101         }
00102 
00103         if (iobc_.get())
00104                 iobc_->write_event(hepmcEvent.get());
00105 
00106         std::auto_ptr<edm::HepMCProduct> result(new edm::HepMCProduct());
00107         result->addHepMCData(hepmcEvent.release());
00108         event.put(result);
00109         edm::LogInfo("Generator|ThePEGProducer") << "Event produced";
00110 }
00111 
00112 DEFINE_ANOTHER_FWK_MODULE(ThePEGProducer);

Generated on Tue Jun 9 17:37:10 2009 for CMSSW by  doxygen 1.5.4