CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/GeneratorInterface/ThePEGInterface/plugins/ThePEGHadronizer.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/MessageLogger/interface/MessageLogger.h"
00011 
00012 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00013 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
00014 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
00015 
00016 #include "GeneratorInterface/Core/interface/BaseHadronizer.h"
00017 #include "GeneratorInterface/Core/interface/GeneratorFilter.h"
00018 #include "GeneratorInterface/Core/interface/HadronizerFilter.h"
00019 
00020 #include "GeneratorInterface/ThePEGInterface/interface/ThePEGInterface.h"
00021 
00022 class ThePEGHadronizer : public ThePEGInterface, public gen::BaseHadronizer {
00023     public:
00024         ThePEGHadronizer(const edm::ParameterSet &params);
00025         virtual ~ThePEGHadronizer();
00026 
00027         bool initializeForInternalPartons();
00028 //      bool initializeForExternalPartons();
00029         bool declareStableParticles(const std::vector<int> &pdgIds);
00030         bool declareSpecialSettings( const std::vector<std::string> ) { return true; }
00031 
00032         void statistics();
00033 
00034         bool generatePartonsAndHadronize();
00035 //      bool hadronize();
00036         bool decay();
00037         bool residualDecay();
00038         void finalizeEvent();
00039 
00040         const char *classname() const { return "ThePEGHadronizer"; }
00041 
00042     private:
00043         unsigned int                    eventsToPrint;
00044 
00045         ThePEG::EventPtr                thepegEvent;
00046 };
00047 
00048 ThePEGHadronizer::ThePEGHadronizer(const edm::ParameterSet &pset) :
00049         ThePEGInterface(pset),
00050         BaseHadronizer(pset),
00051         eventsToPrint(pset.getUntrackedParameter<unsigned int>("eventsToPrint", 0))
00052 {  
00053         initRepository(pset);
00054 
00055 }
00056 
00057 ThePEGHadronizer::~ThePEGHadronizer()
00058 {
00059 }
00060 
00061 bool ThePEGHadronizer::initializeForInternalPartons()
00062 {
00063         initGenerator();
00064         return true;
00065 }
00066 
00067 bool ThePEGHadronizer::declareStableParticles(const std::vector<int> &pdgIds)
00068 {
00069         return false;
00070 }
00071 
00072 void ThePEGHadronizer::statistics()
00073 {
00074         runInfo().setInternalXSec(GenRunInfoProduct::XSec(
00075                 eg_->integratedXSec() / ThePEG::picobarn,
00076                 eg_->integratedXSecErr() / ThePEG::picobarn));
00077 }
00078 
00079 bool ThePEGHadronizer::generatePartonsAndHadronize()
00080 {
00081         edm::LogInfo("Generator|ThePEGHadronizer") << "Start production";
00082 
00083         flushRandomNumberGenerator();
00084 
00085         thepegEvent = eg_->shoot();
00086         if (!thepegEvent) {
00087                 edm::LogWarning("Generator|ThePEGHadronizer") << "thepegEvent not initialized";
00088                 return false;
00089         }
00090 
00091         event() = convert(thepegEvent);
00092         if (!event().get()) {
00093                 edm::LogWarning("Generator|ThePEGHadronizer") << "genEvent not initialized";
00094                 return false;
00095         }
00096 
00097         return true;
00098 }
00099 
00100 void ThePEGHadronizer::finalizeEvent()
00101 {
00102         HepMC::PdfInfo pdf;
00103         clearAuxiliary(event().get(), &pdf);
00104         fillAuxiliary(event().get(), &pdf, thepegEvent);
00105         event()->set_pdf_info(pdf);
00106 
00107         eventInfo().reset(new GenEventInfoProduct(event().get()));
00108         eventInfo()->setBinningValues(
00109                         std::vector<double>(1, pthat(thepegEvent)));
00110 
00111         if (eventsToPrint) {
00112                 eventsToPrint--;
00113                 event()->print();
00114         }
00115 
00116         if (iobc_.get())
00117                 iobc_->write_event(event().get());
00118 
00119         edm::LogInfo("Generator|ThePEGHadronizer") << "Event produced";
00120 }
00121 
00122 bool ThePEGHadronizer::decay()
00123 {
00124         return true;
00125 }
00126 
00127 bool ThePEGHadronizer::residualDecay()
00128 {
00129         return true;
00130 }
00131 
00132 #include "GeneratorInterface/ExternalDecays/interface/ExternalDecayDriver.h"
00133 
00134 typedef edm::GeneratorFilter<ThePEGHadronizer, gen::ExternalDecayDriver> ThePEGGeneratorFilter;
00135 DEFINE_FWK_MODULE(ThePEGGeneratorFilter);
00136 
00137 #if 0
00138 typedef edm::HadronizerFilter<ThePEGHadronizer, gen::ExternalDecayDriver> ThePEGHadronizerFilter;
00139 DEFINE_FWK_MODULE(ThePEGHadronizerFilter);
00140 #endif