16 #include <HepMC/GenEvent.h> 17 #include <HepMC/PdfInfo.h> 18 #include <HepMC/IO_GenEvent.h> 20 #include <Herwig/API/HerwigAPI.h> 22 #include <ThePEG/Utilities/DynamicLoader.h> 23 #include <ThePEG/Repository/Repository.h> 24 #include <ThePEG/Handlers/EventHandler.h> 25 #include <ThePEG/Handlers/XComb.h> 26 #include <ThePEG/EventRecord/Event.h> 27 #include <ThePEG/EventRecord/Particle.h> 28 #include <ThePEG/EventRecord/Collision.h> 29 #include <ThePEG/EventRecord/TmpTransform.h> 30 #include <ThePEG/Config/ThePEG.h> 31 #include <ThePEG/PDF/PartonExtractor.h> 32 #include <ThePEG/PDF/PDFBase.h> 33 #include <ThePEG/Utilities/UtilityBase.h> 34 #include <ThePEG/Vectors/HepMCConverter.h> 44 #include "CLHEP/Random/RandomEngine.h" 50 : randomEngineGlueProxy_(
ThePEG::RandomEngineGlue::Proxy::
create()),
52 generator_(
pset.getParameter<
string>(
"generatorModule")),
54 dumpConfig_(
pset.getUntrackedParameter<
string>(
"dumpConfig",
"HerwigConfig.in")),
55 skipEvents_(
pset.getUntrackedParameter<unsigned
int>(
"skipEvents", 0)) {
57 string dumpEvents =
pset.getUntrackedParameter<
string>(
"dumpEvents",
"");
58 if (!dumpEvents.empty()) {
59 iobc_ = std::make_unique<HepMC::IO_GenEvent>(dumpEvents,
ios::out);
60 edm::LogInfo(
"ThePEGSource") <<
"Event logging switched on (=> " << dumpEvents <<
")";
70 edm::LogInfo(
"Herwig7Interface") <<
"Event generator finalized";
83 std::string runModeTemp =
pset.getUntrackedParameter<
string>(
"runModeList",
"read,run");
86 std::transform(runModeTemp.begin(), runModeTemp.end(), runModeTemp.begin(), ::tolower);
88 while (!runModeTemp.empty()) {
91 size_t pos = runModeTemp.find(
',');
92 if (std::string::npos ==
pos)
95 choice = runModeTemp.substr(0,
pos);
97 if (
pos == std::string::npos)
100 runModeTemp.erase(0,
pos + 1);
103 edm::LogInfo(
"Herwig7Interface") <<
"HerwigUIProvider object with run mode " <<
HwUI_->runMode() <<
" created.\n";
106 if (choice ==
"read") {
110 <<
" will be passed to Herwig for the read step.\n";
112 }
else if (choice ==
"build") {
116 <<
" will be passed to Herwig for the build step.\n";
119 }
else if (choice ==
"integrate") {
121 edm::LogInfo(
"Herwig7Interface") <<
"Run file " << runFileName
122 <<
" will be passed to Herwig for the integrate step.\n";
123 HwUI_->setRunMode(Herwig::RunMode::INTEGRATE,
pset, runFileName);
126 }
else if (choice ==
"run") {
128 edm::LogInfo(
"Herwig7Interface") <<
"Run file " << runFileName <<
" will be passed to Herwig for the run step.\n";
129 HwUI_->setRunMode(Herwig::RunMode::RUN,
pset, runFileName);
131 edm::LogInfo(
"Herwig7Interface") <<
"Cannot recognize \"" << choice <<
"\".\n" 132 <<
"Trying to skip step.\n";
140 edm::LogInfo(
"Herwig7Interface") <<
"callHerwigGenerator function invoked with run mode " <<
HwUI_->runMode()
144 switch (
HwUI_->runMode()) {
145 case Herwig::RunMode::INIT:
148 case Herwig::RunMode::READ:
151 case Herwig::RunMode::BUILD:
154 case Herwig::RunMode::INTEGRATE:
155 Herwig::API::integrate(*
HwUI_);
157 case Herwig::RunMode::MERGEGRIDS:
158 Herwig::API::mergegrids(*
HwUI_);
160 case Herwig::RunMode::RUN: {
162 eg_ = Herwig::API::prepareRun(*
HwUI_);
166 edm::LogError(
"Herwig7Interface") <<
"Error during read in of command line parameters.\n" 167 <<
"Program execution will stop now.";
170 HwUI_->quitWithHelp();
176 edm::LogError(
"Herwig7Interface") <<
": ThePEG::Exception caught.\n" 178 <<
"See logfile for details.\n";
183 }
catch (
const char *what) {
184 edm::LogError(
"Herwig7Interface") <<
": caught exception: " << what <<
"\n";
190 if (
HwUI_->runMode() == Herwig::RunMode::RUN) {
191 edm::LogInfo(
"Herwig7Interface") <<
"Starting EventGenerator initialization";
193 edm::LogInfo(
"Herwig7Interface") <<
"EventGenerator initialized";
205 edm::LogInfo(
"Herwig7Interface") <<
"Stopped EventGenerator due to missing run mode.";
232 if (!
event->primaryCollision())
235 tSubProPtr sub =
event->primaryCollision()->primarySubProcess();
236 TmpTransform<tSubProPtr>
tmp(sub, Utilities::getBoostToCM(sub->incoming()));
238 double pthat = (*sub->outgoing().begin())->momentum().perp() / ThePEG::GeV;
239 for (PVector::const_iterator
it = sub->outgoing().begin();
it != sub->outgoing().end(); ++
it)
240 pthat = std::min<double>(
pthat, (*it)->momentum().perp() / ThePEG::GeV);
252 stringstream logstream;
255 stringstream herwiginputconfig;
263 vector<string>
configFiles =
pset.getParameter<vector<string> >(
"configFiles");
267 ifstream externalConfigFile(iter);
268 if (externalConfigFile.is_open()) {
269 edm::LogInfo(
"Herwig7Interface") <<
"Reading config file (" << iter <<
")" << endl;
270 stringstream configFileStream;
271 configFileStream << externalConfigFile.rdbuf();
272 string configFileContent = configFileStream.str();
275 string searchKeyword(
"saverun");
276 if (configFileContent.find(searchKeyword) != std::string::npos) {
277 edm::LogInfo(
"Herwig7Interface") <<
"Commented out saverun command in external input config file(" << iter
279 configFileContent.insert(configFileContent.find(searchKeyword),
"#");
281 herwiginputconfig <<
"# Begin Config file input" << endl
282 << configFileContent << endl
283 <<
"# End Config file input";
284 edm::LogInfo(
"Herwig7Interface") <<
"Finished reading config file (" << iter <<
")" << endl;
286 edm::LogWarning(
"Herwig7Interface") <<
"Could not read config file (" << iter <<
")" << endl;
290 edm::LogInfo(
"Herwig7Interface") <<
"Start with processing CMSSW config" << endl;
294 iter = collector.
begin();
295 herwiginputconfig << endl <<
"# Begin Parameter set input\n" << endl;
296 for (; iter != collector.
end(); ++iter) {
297 herwiginputconfig << *iter << endl;
301 herwiginputconfig <<
"saverun " <<
run_ <<
" " <<
generator_ << endl;
308 cfgDump << herwiginputconfig.str() << endl;
static double pthat(const ThePEG::EventPtr &event)
void initRepository(const edm::ParameterSet ¶ms)
void callHerwigGenerator()
void createInputFile(const edm::ParameterSet ¶ms)
def create(alignables, pedeDump, additionalData, outputFile, config)
std::shared_ptr< Herwig::HerwigUIProvider > HwUI_
void setPEGRandomEngine(CLHEP::HepRandomEngine *)
const_iterator begin() const
CLHEP::HepRandomEngine * randomEngine
std::unique_ptr< HepMC::IO_BaseClass > iobc_
const_iterator end() const
~Herwig7Interface() noexcept
Log< level::Error, false > LogError
std::shared_ptr< ThePEG::RandomEngineGlue::Proxy > randomEngineGlueProxy_
static std::unique_ptr< HepMC::GenEvent > convert(const ThePEG::EventPtr &event)
Herwig7Interface(const edm::ParameterSet ¶ms)
const std::string generator_
Log< level::Info, false > LogInfo
const unsigned int skipEvents_
void flushRandomNumberGenerator()
void setRandomEngine(CLHEP::HepRandomEngine *v)
Log< level::Warning, false > LogWarning