CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Attributes

ThePEGInterface Class Reference

#include <ThePEGInterface.h>

Inheritance diagram for ThePEGInterface:
lhef::ThePEGHadronisation ThePEGHadronizer

List of all members.

Public Member Functions

 ThePEGInterface (const edm::ParameterSet &params)
virtual ~ThePEGInterface ()

Protected Member Functions

std::string dataFile (const std::string &fileName) const
std::string dataFile (const edm::ParameterSet &pset, const std::string &paramName) const
void flushRandomNumberGenerator ()
void initGenerator ()
void initRepository (const edm::ParameterSet &params) const

Static Protected Member Functions

static void clearAuxiliary (HepMC::GenEvent *hepmc, HepMC::PdfInfo *pdf)
static std::auto_ptr
< HepMC::GenEvent > 
convert (const ThePEG::EventPtr &event)
static void fillAuxiliary (HepMC::GenEvent *hepmc, HepMC::PdfInfo *pdf, const ThePEG::EventPtr &event)
static double pthat (const ThePEG::EventPtr &event)

Protected Attributes

ThePEG::EGPtr eg_
std::auto_ptr
< HepMC::IO_BaseClass > 
iobc_

Private Attributes

const std::string dataLocation_
const std::string dumpConfig_
const std::string generator_
boost::shared_ptr
< ThePEG::RandomEngineGlue::Proxy
randomEngineGlueProxy_
const std::string run_
const unsigned int skipEvents_

Detailed Description

Id:
ThePEGInterface.h,v 1.11 2009/11/04 18:28:40 stober Exp

Oliver Oberst <oberst@ekp.uni-karlsruhe.de> Fred-Markus Stober <stober@ekp.uni-karlsruhe.de>

Id:
ThePEGInterface.cc,v 1.16 2009/05/19 17:38:54 stober Exp

Oliver Oberst <oberst@ekp.uni-karlsruhe.de> Fred-Markus Stober <stober@ekp.uni-karlsruhe.de>

Definition at line 27 of file ThePEGInterface.h.


Constructor & Destructor Documentation

ThePEGInterface::ThePEGInterface ( const edm::ParameterSet params)

Definition at line 47 of file ThePEGInterface.cc.

References dumpConfig_, edm::ParameterSet::getUntrackedParameter(), iobc_, dbtoconf::out, and estimatePileup_makeJSON::trunc.

                                                            :
        randomEngineGlueProxy_(ThePEG::RandomEngineGlue::Proxy::create()),
        dataLocation_(ParameterCollector::resolve(pset.getParameter<string>("dataLocation"))),
        generator_(pset.getParameter<string>("generatorModule")),
        run_(pset.getParameter<string>("run")),
        dumpConfig_(pset.getUntrackedParameter<string>("dumpConfig", "")),
        skipEvents_(pset.getUntrackedParameter<unsigned int>("skipEvents", 0))
{
        // Write events in hepmc ascii format for debugging purposes
        string dumpEvents = pset.getUntrackedParameter<string>("dumpEvents", "");
        if (!dumpEvents.empty()) {
                iobc_.reset(new HepMC::IO_GenEvent(dumpEvents.c_str(), ios::out));
                edm::LogInfo("ThePEGSource") << "Event logging switched on (=> " << dumpEvents << ")";
        }
        // Clear dumpConfig target
        if (!dumpConfig_.empty())
                ofstream cfgDump(dumpConfig_.c_str(), ios_base::trunc);
}
ThePEGInterface::~ThePEGInterface ( ) [virtual]

Definition at line 66 of file ThePEGInterface.cc.

References eg_.

{
        if (eg_)
                eg_->finalize();
        edm::LogInfo("ThePEGInterface") << "Event generator finalized";
}

Member Function Documentation

void ThePEGInterface::clearAuxiliary ( HepMC::GenEvent *  hepmc,
HepMC::PdfInfo *  pdf 
) [static, protected]

Definition at line 215 of file ThePEGInterface.cc.

Referenced by lhef::ThePEGHadronisation::doHadronisation(), and ThePEGHadronizer::finalizeEvent().

{
        if (hepmc) {
                hepmc->set_event_scale(-1.0);
                hepmc->set_alphaQCD(-1.0);
                hepmc->set_alphaQED(-1.0);
        }
        if (pdf) {
                pdf->set_id1(-100);
                pdf->set_id2(-100);
                pdf->set_x1(-1.0);
                pdf->set_x2(-1.0);
                pdf->set_scalePDF(-1.0);
                pdf->set_pdf1(-1.0);
                pdf->set_pdf2(-1.0);
        }
}
auto_ptr< HepMC::GenEvent > ThePEGInterface::convert ( const ThePEG::EventPtr &  event) [static, protected]
std::string ThePEGInterface::dataFile ( const edm::ParameterSet pset,
const std::string &  paramName 
) const [protected]
std::string ThePEGInterface::dataFile ( const std::string &  fileName) const [protected]

Referenced by initRepository().

void ThePEGInterface::fillAuxiliary ( HepMC::GenEvent *  hepmc,
HepMC::PdfInfo *  pdf,
const ThePEG::EventPtr &  event 
) [static, protected]

Definition at line 234 of file ThePEGInterface.cc.

References pileupReCalc_HLTpaths::scale, funct::sqr(), mathSSE::sqrt(), and findQualityFiles::v.

Referenced by lhef::ThePEGHadronisation::doHadronisation(), and ThePEGHadronizer::finalizeEvent().

{
        if (!event->primaryCollision())
                return;

        ThePEG::tcEHPtr eh = ThePEG::dynamic_ptr_cast<ThePEG::tcEHPtr>(
                                event->primaryCollision()->handler());
        double scale = eh->lastScale();

        if (hepmc) {
                if (hepmc->event_scale() < 0 && scale > 0)
                        hepmc->set_event_scale(std::sqrt(scale) / ThePEG::GeV);

                if (hepmc->alphaQCD() < 0)
                        hepmc->set_alphaQCD(eh->lastAlphaS());
                if (hepmc->alphaQED() < 0)
                        hepmc->set_alphaQED(eh->lastAlphaEM());
        }

        if (pdf) {
                const ThePEG::PPair &beams = eh->lastParticles();
                const ThePEG::PPair &partons = eh->lastPartons();
                ThePEG::tcPDFPtr pdf1 = eh->lastExtractor()->getPDF(
                                                beams.first->dataPtr());
                ThePEG::tcPDFPtr pdf2 = eh->lastExtractor()->getPDF(
                                                beams.second->dataPtr());
                double x1, x2;

                if (pdf->id1() == -100) {
                        int id = partons.first->id();
                        pdf->set_id1(id == 21 ? 0 : id);
                }
                if (pdf->id2() == -100) {
                        int id = partons.second->id();
                        pdf->set_id2(id == 21 ? 0 : id);
                }

                if (pdf->scalePDF() < 0)
                        pdf->set_scalePDF(std::sqrt(scale) / ThePEG::GeV);
                else
                        scale = ThePEG::sqr(pdf->scalePDF()) * ThePEG::GeV;

                if (pdf->x1() < 0) {
                        x1 = eh->lastX1();
                        pdf->set_x1(x1);
                } else
                        x1 = pdf->x1();

                if (pdf->x2() < 0) {
                        x2 = eh->lastX2();
                        pdf->set_x2(x2);
                } else
                        x2 = pdf->x2();

                if (pdf1 && pdf->pdf1() < 0) {
                        double v = pdf1->xfx(beams.first->dataPtr(),
                                             partons.first->dataPtr(),
                                             scale, x1);
                        if (v > 0 && x1 > 0)
                                pdf->set_pdf1(v / x1);
                        else
                                pdf->set_pdf2(-1.0);
                }
                if (pdf2 && pdf->pdf2() < 0) {
                        double v = pdf2->xfx(beams.first->dataPtr(),
                                             partons.first->dataPtr(),
                                             scale, x2);
                        if (v > 0 && x2 > 0)
                                pdf->set_pdf2(v / x2);
                        else
                                pdf->set_pdf2(-1.0);
                }
        }

}
void ThePEGInterface::flushRandomNumberGenerator ( ) [protected]

Definition at line 197 of file ThePEGInterface.cc.

References ThePEG::RandomEngineGlue::flush(), and randomEngineGlueProxy_.

Referenced by lhef::ThePEGHadronisation::doHadronisation(), ThePEGHadronizer::generatePartonsAndHadronize(), and initGenerator().

{
        ThePEG::RandomEngineGlue *rnd = randomEngineGlueProxy_->getInstance();

        if (!rnd)
                edm::LogWarning("ProxyMissing")
                        << "ThePEG not initialised with RandomEngineGlue.";
        else
                rnd->flush();
}
void ThePEGInterface::initGenerator ( ) [protected]

Definition at line 176 of file ThePEGInterface.cc.

References eg_, Exception, flushRandomNumberGenerator(), generator_, i, run_, skipEvents_, and tmp.

Referenced by ThePEGHadronizer::initializeForInternalPartons(), and lhef::ThePEGHadronisation::newRunInfo().

{
        // Get generator from the repository and initialize it
        ThePEG::BaseRepository::CheckObjectDirectory(generator_);
        ThePEG::EGPtr tmp = ThePEG::BaseRepository::GetObject<ThePEG::EGPtr>(generator_);
        if (tmp) {
                eg_ = ThePEG::Repository::makeRun(tmp, run_);
                eg_->initialize();
                edm::LogInfo("ThePEGInterface") << "EventGenerator initialized";
        } else
                throw cms::Exception("ThePEGInterface")
                        << "EventGenerator could not be initialized!" << endl;

        // Skip events
        for (unsigned int i = 0; i < skipEvents_; i++) {
                flushRandomNumberGenerator();
                eg_->shoot();
                edm::LogInfo("ThePEGInterface") << "Event discarded";
        }
}
void ThePEGInterface::initRepository ( const edm::ParameterSet params) const [protected]

Definition at line 91 of file ThePEGInterface.cc.

References gen::ParameterCollector::begin(), dtNoiseDBValidation_cfg::cerr, dataFile(), dumpConfig_, gen::ParameterCollector::end(), generator_, edm::ParameterSet::getParameter(), svgfig::load(), dbtoconf::out, randomEngineGlueProxy_, SiPixelLorentzAngle_cfi::read, and run_.

Referenced by lhef::ThePEGHadronisation::ThePEGHadronisation(), and ThePEGHadronizer::ThePEGHadronizer().

{
        /* Initialize the repository from
         * 1. the repository file (default values)
         * 2. the ThePEG config files
         * 3. the CMSSW config blocks
         */
        stringstream logstream;

        // Read the repository of serialized default values
        string repository = dataFile(pset, "repository");
        if (!repository.empty()) {
                edm::LogInfo("ThePEGInterface") << "Loading repository (" << repository << ")";
                ThePEG::Repository::load(repository);
        }

        if (!getenv("ThePEG_INSTALL_PATH")) {
                vector<string> libdirlist = ThePEG::DynamicLoader::allPaths();
                for(vector<string>::const_iterator libdir = libdirlist.begin();
                    libdir < libdirlist.end(); ++libdir) {
                        if (libdir->empty() || (*libdir)[0] != '/')
                                continue;
                        if (boost::filesystem::exists(*libdir +
                                        "/../../share/ThePEG/PDFsets.index")) {
                                setenv("ThePEG_INSTALL_PATH",
                                       libdir->c_str(), 0);
                                break;
                        }
                }
        }

        // Read ThePEG config files to read
        vector<string> configFiles = pset.getParameter<vector<string> >("configFiles");

        // Loop over the config files
        for(vector<string>::const_iterator iter = configFiles.begin();
            iter != configFiles.end(); ++iter) {
                edm::LogInfo("ThePEGInterface") << "Reading config file (" << *iter << ")";
                ThePEG::Repository::read(dataFile(*iter), logstream);
                edm::LogInfo("ThePEGSource") << logstream.str();
        }

        // Read CMSSW config file parameter sets starting from "parameterSets"

        ofstream cfgDump;
        ParameterCollector collector(pset);
        ParameterCollector::const_iterator iter;
        if (!dumpConfig_.empty()) {
                cfgDump.open(dumpConfig_.c_str(), ios_base::app);
                iter = collector.begin(cfgDump);
        } else
                iter = collector.begin();

        for(; iter != collector.end(); ++iter) {
                string out = ThePEG::Repository::exec(*iter, logstream);
                if (!out.empty()) {
                        edm::LogInfo("ThePEGInterface") << *iter << " => " << out;
                        cerr << "Error in ThePEG configuration!\n"
                                "\tLine: " << *iter << "\n" << out << endl;
                }
        }

        if (!dumpConfig_.empty()) {
                cfgDump << "saverun " << run_ << " " << generator_ << endl;
                cfgDump.close();
        }

        // write the ProxyID for the RandomEngineGlue to fill its pointer in
        ostringstream ss;
        ss << randomEngineGlueProxy_->getID();
        ThePEG::Repository::exec("set " + generator_ +
                                 ":RandomNumberGenerator:ProxyID " + ss.str(),
                                 logstream);

        // Print the directories where ThePEG looks for libs
        vector<string> libdirlist = ThePEG::DynamicLoader::allPaths();
        for(vector<string>::const_iterator libdir = libdirlist.begin();
            libdir < libdirlist.end(); ++libdir)
                edm::LogInfo("ThePEGInterface") << "DynamicLoader path = " << *libdir << endl;

        // Output status information about the repository
        ThePEG::Repository::stats(logstream);
        edm::LogInfo("ThePEGInterface") << logstream.str();
}
double ThePEGInterface::pthat ( const ThePEG::EventPtr &  event) [static, protected]

Definition at line 312 of file ThePEGInterface.cc.

References min, and tmp.

Referenced by ThePEGHadronizer::finalizeEvent().

{
        using namespace ThePEG;

        if (!event->primaryCollision())
                return -1.0;

        tSubProPtr sub = event->primaryCollision()->primarySubProcess();
        TmpTransform<tSubProPtr> tmp(sub, Utilities::getBoostToCM(
                                                        sub->incoming()));

        double pthat = (*sub->outgoing().begin())->momentum().perp();
        for(PVector::const_iterator it = sub->outgoing().begin();
            it != sub->outgoing().end(); ++it)
                pthat = std::min(pthat, (*it)->momentum().perp());

        return pthat / ThePEG::GeV;
}

Member Data Documentation

const std::string ThePEGInterface::dataLocation_ [private]

Definition at line 58 of file ThePEGInterface.h.

const std::string ThePEGInterface::dumpConfig_ [private]

Definition at line 61 of file ThePEGInterface.h.

Referenced by initRepository(), and ThePEGInterface().

ThePEG::EGPtr ThePEGInterface::eg_ [protected]
const std::string ThePEGInterface::generator_ [private]

Definition at line 59 of file ThePEGInterface.h.

Referenced by initGenerator(), and initRepository().

std::auto_ptr<HepMC::IO_BaseClass> ThePEGInterface::iobc_ [protected]

Definition at line 52 of file ThePEGInterface.h.

Referenced by ThePEGHadronizer::finalizeEvent(), and ThePEGInterface().

Definition at line 56 of file ThePEGInterface.h.

Referenced by flushRandomNumberGenerator(), and initRepository().

const std::string ThePEGInterface::run_ [private]

Definition at line 60 of file ThePEGInterface.h.

Referenced by initGenerator(), and initRepository().

const unsigned int ThePEGInterface::skipEvents_ [private]

Definition at line 62 of file ThePEGInterface.h.

Referenced by initGenerator().