17 #include <boost/filesystem.hpp>
19 #include <HepMC/GenEvent.h>
20 #include <HepMC/PdfInfo.h>
21 #include <HepMC/IO_GenEvent.h>
23 #include <Herwig/API/HerwigAPI.h>
25 #include <ThePEG/Utilities/DynamicLoader.h>
26 #include <ThePEG/Repository/Repository.h>
27 #include <ThePEG/Handlers/EventHandler.h>
28 #include <ThePEG/Handlers/XComb.h>
29 #include <ThePEG/EventRecord/Event.h>
30 #include <ThePEG/EventRecord/Particle.h>
31 #include <ThePEG/EventRecord/Collision.h>
32 #include <ThePEG/EventRecord/TmpTransform.h>
33 #include <ThePEG/Config/ThePEG.h>
34 #include <ThePEG/PDF/PartonExtractor.h>
35 #include <ThePEG/PDF/PDFBase.h>
36 #include <ThePEG/Utilities/UtilityBase.h>
37 #include <ThePEG/Vectors/HepMCConverter.h>
47 #include "CLHEP/Random/RandomEngine.h"
53 : randomEngineGlueProxy_(
ThePEG::RandomEngineGlue::Proxy::
create()),
55 generator_(
pset.getParameter<
string>(
"generatorModule")),
57 dumpConfig_(
pset.getUntrackedParameter<
string>(
"dumpConfig",
"HerwigConfig.in")),
58 skipEvents_(
pset.getUntrackedParameter<unsigned
int>(
"skipEvents", 0)) {
60 string dumpEvents =
pset.getUntrackedParameter<
string>(
"dumpEvents",
"");
61 if (!dumpEvents.empty()) {
63 edm::LogInfo(
"ThePEGSource") <<
"Event logging switched on (=> " << dumpEvents <<
")";
73 edm::LogInfo(
"Herwig7Interface") <<
"Event generator finalized";
86 std::string runModeTemp =
pset.getUntrackedParameter<
string>(
"runModeList",
"read,run");
89 std::transform(runModeTemp.begin(), runModeTemp.end(), runModeTemp.begin(), ::tolower);
91 while (!runModeTemp.empty()) {
94 size_t pos = runModeTemp.find(
',');
95 if (std::string::npos ==
pos)
98 choice = runModeTemp.substr(0,
pos);
100 if (
pos == std::string::npos)
103 runModeTemp.erase(0,
pos + 1);
106 edm::LogInfo(
"Herwig7Interface") <<
"HerwigUIProvider object with run mode " <<
HwUI_->runMode() <<
" created.\n";
109 if (choice ==
"read") {
113 <<
" will be passed to Herwig for the read step.\n";
115 }
else if (choice ==
"build") {
119 <<
" will be passed to Herwig for the build step.\n";
122 }
else if (choice ==
"integrate") {
124 edm::LogInfo(
"Herwig7Interface") <<
"Run file " << runFileName
125 <<
" will be passed to Herwig for the integrate step.\n";
126 HwUI_->setRunMode(Herwig::RunMode::INTEGRATE,
pset, runFileName);
129 }
else if (choice ==
"run") {
131 edm::LogInfo(
"Herwig7Interface") <<
"Run file " << runFileName <<
" will be passed to Herwig for the run step.\n";
132 HwUI_->setRunMode(Herwig::RunMode::RUN,
pset, runFileName);
134 edm::LogInfo(
"Herwig7Interface") <<
"Cannot recognize \"" << choice <<
"\".\n"
135 <<
"Trying to skip step.\n";
143 edm::LogInfo(
"Herwig7Interface") <<
"callHerwigGenerator function invoked with run mode " <<
HwUI_->runMode()
147 switch (
HwUI_->runMode()) {
148 case Herwig::RunMode::INIT:
151 case Herwig::RunMode::READ:
154 case Herwig::RunMode::BUILD:
157 case Herwig::RunMode::INTEGRATE:
158 Herwig::API::integrate(*
HwUI_);
160 case Herwig::RunMode::MERGEGRIDS:
161 Herwig::API::mergegrids(*
HwUI_);
163 case Herwig::RunMode::RUN: {
165 eg_ = Herwig::API::prepareRun(*
HwUI_);
169 edm::LogError(
"Herwig7Interface") <<
"Error during read in of command line parameters.\n"
170 <<
"Program execution will stop now.";
173 HwUI_->quitWithHelp();
179 edm::LogError(
"Herwig7Interface") <<
": ThePEG::Exception caught.\n"
181 <<
"See logfile for details.\n";
186 }
catch (
const char *what) {
187 edm::LogError(
"Herwig7Interface") <<
": caught exception: " << what <<
"\n";
193 if (
HwUI_->runMode() == Herwig::RunMode::RUN) {
194 edm::LogInfo(
"Herwig7Interface") <<
"Starting EventGenerator initialization";
196 edm::LogInfo(
"Herwig7Interface") <<
"EventGenerator initialized";
208 edm::LogInfo(
"Herwig7Interface") <<
"Stopped EventGenerator due to missing run mode.";
235 if (!
event->primaryCollision())
238 tSubProPtr sub =
event->primaryCollision()->primarySubProcess();
239 TmpTransform<tSubProPtr>
tmp(sub, Utilities::getBoostToCM(sub->incoming()));
242 for (PVector::const_iterator it = sub->outgoing().begin(); it != sub->outgoing().end(); ++it)
255 stringstream logstream;
258 stringstream herwiginputconfig;
266 vector<string>
configFiles =
pset.getParameter<vector<string> >(
"configFiles");
270 ifstream externalConfigFile(iter);
271 if (externalConfigFile.is_open()) {
272 edm::LogInfo(
"Herwig7Interface") <<
"Reading config file (" << iter <<
")" << endl;
273 stringstream configFileStream;
274 configFileStream << externalConfigFile.rdbuf();
275 string configFileContent = configFileStream.str();
278 string searchKeyword(
"saverun");
279 if (configFileContent.find(searchKeyword) != std::string::npos) {
280 edm::LogInfo(
"Herwig7Interface") <<
"Commented out saverun command in external input config file(" << iter
282 configFileContent.insert(configFileContent.find(searchKeyword),
"#");
284 herwiginputconfig <<
"# Begin Config file input" << endl
285 << configFileContent << endl
286 <<
"# End Config file input";
287 edm::LogInfo(
"Herwig7Interface") <<
"Finished reading config file (" << iter <<
")" << endl;
289 edm::LogWarning(
"Herwig7Interface") <<
"Could not read config file (" << iter <<
")" << endl;
293 edm::LogInfo(
"Herwig7Interface") <<
"Start with processing CMSSW config" << endl;
297 iter = collector.
begin();
298 herwiginputconfig << endl <<
"# Begin Parameter set input\n" << endl;
299 for (; iter != collector.
end(); ++iter) {
300 herwiginputconfig << *iter << endl;
304 herwiginputconfig <<
"saverun " <<
run_ <<
" " <<
generator_ << endl;
311 cfgDump << herwiginputconfig.str() << endl;