14 #include <boost/shared_ptr.hpp> 15 #include <boost/filesystem.hpp> 17 #include <HepMC/GenEvent.h> 18 #include <HepMC/PdfInfo.h> 19 #include <HepMC/IO_GenEvent.h> 21 #include <ThePEG/Utilities/DynamicLoader.h> 22 #include <ThePEG/Repository/Repository.h> 23 #include <ThePEG/Handlers/EventHandler.h> 24 #include <ThePEG/Handlers/XComb.h> 25 #include <ThePEG/EventRecord/Event.h> 26 #include <ThePEG/EventRecord/Particle.h> 27 #include <ThePEG/EventRecord/Collision.h> 28 #include <ThePEG/EventRecord/TmpTransform.h> 29 #include <ThePEG/Config/ThePEG.h> 30 #include <ThePEG/PDF/PartonExtractor.h> 31 #include <ThePEG/PDF/PDFBase.h> 32 #include <ThePEG/Utilities/UtilityBase.h> 33 #include <ThePEG/Vectors/HepMCConverter.h> 48 randomEngineGlueProxy_(
ThePEG::RandomEngineGlue::Proxy::
create()),
50 generator_(pset.getParameter<
string>(
"generatorModule")),
51 run_(pset.getParameter<
string>(
"run")),
52 dumpConfig_(pset.getUntrackedParameter<
string>(
"dumpConfig",
"")),
53 skipEvents_(pset.getUntrackedParameter<unsigned
int>(
"skipEvents", 0))
57 if (!dumpEvents.empty()) {
59 edm::LogInfo(
"ThePEGSource") <<
"Event logging switched on (=> " << dumpEvents <<
")";
70 edm::LogInfo(
"ThePEGInterface") <<
"Event generator finalized";
83 if (fileName.empty() || fileName[0] ==
'/')
90 const string ¶mName)
const 106 stringstream logstream;
109 string repository =
dataFile(pset,
"repository");
110 if (!repository.empty()) {
111 edm::LogInfo(
"ThePEGInterface") <<
"Loading repository (" << repository <<
")";
115 if (!getenv(
"ThePEG_INSTALL_PATH")) {
116 vector<string> libdirlist = ThePEG::DynamicLoader::allPaths();
117 for(vector<string>::const_iterator libdir = libdirlist.begin();
118 libdir < libdirlist.end(); ++libdir) {
119 if (libdir->empty() || (*libdir)[0] !=
'/')
121 if (boost::filesystem::exists(*libdir +
122 "/../../share/ThePEG/PDFsets.index")) {
123 setenv(
"ThePEG_INSTALL_PATH",
131 vector<string> configFiles = pset.
getParameter<vector<string> >(
"configFiles");
134 for(vector<string>::const_iterator iter = configFiles.begin();
135 iter != configFiles.end(); ++iter) {
136 edm::LogInfo(
"ThePEGInterface") <<
"Reading config file (" << *iter <<
")";
137 ThePEG::Repository::read(
dataFile(*iter), logstream);
148 iter = collector.
begin(cfgDump);
150 iter = collector.
begin();
152 for(; iter != collector.
end(); ++iter) {
153 string out = ThePEG::Repository::exec(*iter, logstream);
156 cerr <<
"Error in ThePEG configuration!\n" 157 "\tLine: " << *iter <<
"\n" << out << endl;
169 ThePEG::Repository::exec(
"set " +
generator_ +
170 ":RandomNumberGenerator:ProxyID " + ss.str(),
174 vector<string> libdirlist = ThePEG::DynamicLoader::allPaths();
175 for(vector<string>::const_iterator libdir = libdirlist.begin();
176 libdir < libdirlist.end(); ++libdir)
177 edm::LogInfo(
"ThePEGInterface") <<
"DynamicLoader path = " << *libdir << endl;
180 ThePEG::Repository::stats(logstream);
187 ThePEG::BaseRepository::CheckObjectDirectory(
generator_);
188 ThePEG::EGPtr
tmp = ThePEG::BaseRepository::GetObject<ThePEG::EGPtr>(
generator_);
190 eg_ = ThePEG::Repository::makeRun(tmp,
run_);
192 edm::LogInfo(
"ThePEGInterface") <<
"EventGenerator initialized";
195 <<
"EventGenerator could not be initialized!" << endl;
211 <<
"ThePEG not initialised with RandomEngineGlue.";
217 const ThePEG::EventPtr &
event)
219 return std::auto_ptr<HepMC::GenEvent>(
227 hepmc->set_event_scale(-1.0);
228 hepmc->set_alphaQCD(-1.0);
229 hepmc->set_alphaQED(-1.0);
236 pdf->set_scalePDF(-1.0);
244 const ThePEG::EventPtr &
event)
246 if (!event->primaryCollision())
249 ThePEG::tcEHPtr eh = ThePEG::dynamic_ptr_cast<ThePEG::tcEHPtr>(
250 event->primaryCollision()->handler());
251 double scale = eh->lastScale();
254 if (hepmc->event_scale() < 0 && scale > 0)
257 if (hepmc->alphaQCD() < 0)
258 hepmc->set_alphaQCD(eh->lastAlphaS());
259 if (hepmc->alphaQED() < 0)
260 hepmc->set_alphaQED(eh->lastAlphaEM());
264 const ThePEG::PPair &beams = eh->lastParticles();
265 const ThePEG::PPair &
partons = eh->lastPartons();
266 ThePEG::tcPDFPtr pdf1 = eh->lastExtractor()->getPDF(
267 beams.first->dataPtr());
268 ThePEG::tcPDFPtr pdf2 = eh->lastExtractor()->getPDF(
269 beams.second->dataPtr());
272 if (pdf->id1() == -100) {
273 int id = partons.first->id();
274 pdf->set_id1(
id == 21 ? 0 :
id);
276 if (pdf->id2() == -100) {
277 int id = partons.second->id();
278 pdf->set_id2(
id == 21 ? 0 :
id);
281 if (pdf->scalePDF() < 0)
298 if (pdf1 && pdf->pdf1() < 0) {
299 double v = pdf1->xfx(beams.first->dataPtr(),
300 partons.first->dataPtr(),
303 pdf->set_pdf1(v / x1);
307 if (pdf2 && pdf->pdf2() < 0) {
308 double v = pdf2->xfx(beams.first->dataPtr(),
309 partons.first->dataPtr(),
312 pdf->set_pdf2(v / x2);
324 if (!event->primaryCollision())
327 tSubProPtr sub =
event->primaryCollision()->primarySubProcess();
328 TmpTransform<tSubProPtr>
tmp(sub, Utilities::getBoostToCM(
331 double pthat = (*sub->outgoing().begin())->momentum().perp();
332 for(PVector::const_iterator it = sub->outgoing().begin();
333 it != sub->outgoing().end(); ++it)
334 pthat =
std::min(pthat, (*it)->momentum().perp());
T getParameter(std::string const &) const
Entry const & retrieve(char const *) const
T getUntrackedParameter(std::string const &, T const &) const
void initRepository(const edm::ParameterSet ¶ms) const
ThePEGInterface(const edm::ParameterSet ¶ms)
def create(alignables, pedeDump, additionalData, outputFile, config)
static double pthat(const ThePEG::EventPtr &event)
std::string dataFile(const std::string &fileName) const
void flushRandomNumberGenerator()
std::auto_ptr< HepMC::IO_BaseClass > iobc_
const std::string dumpConfig_
def convert(infile, ofile)
static std::auto_ptr< HepMC::GenEvent > convert(const ThePEG::EventPtr &event)
const std::string generator_
FileInPath getFileInPath() const
virtual ~ThePEGInterface()
std::vector< std::vector< double > > tmp
const unsigned int skipEvents_
const std::string dataLocation_
Square< F >::type sqr(const F &f)
const_iterator end() const
void setPEGRandomEngine(CLHEP::HepRandomEngine *)
const_iterator begin() const
std::string fullPath() const
void setRandomEngine(CLHEP::HepRandomEngine *v)
boost::shared_ptr< ThePEG::RandomEngineGlue::Proxy > randomEngineGlueProxy_
static void clearAuxiliary(HepMC::GenEvent *hepmc, HepMC::PdfInfo *pdf)
std::string getString() const
static void fillAuxiliary(HepMC::GenEvent *hepmc, HepMC::PdfInfo *pdf, const ThePEG::EventPtr &event)