17 #include <boost/shared_ptr.hpp> 18 #include <boost/filesystem.hpp> 20 #include <HepMC/GenEvent.h> 21 #include <HepMC/PdfInfo.h> 22 #include <HepMC/IO_GenEvent.h> 24 #include <Herwig/API/HerwigAPI.h> 26 #include <ThePEG/Utilities/DynamicLoader.h> 27 #include <ThePEG/Repository/Repository.h> 28 #include <ThePEG/Handlers/EventHandler.h> 29 #include <ThePEG/Handlers/XComb.h> 30 #include <ThePEG/EventRecord/Event.h> 31 #include <ThePEG/EventRecord/Particle.h> 32 #include <ThePEG/EventRecord/Collision.h> 33 #include <ThePEG/EventRecord/TmpTransform.h> 34 #include <ThePEG/Config/ThePEG.h> 35 #include <ThePEG/PDF/PartonExtractor.h> 36 #include <ThePEG/PDF/PDFBase.h> 37 #include <ThePEG/Utilities/UtilityBase.h> 38 #include <ThePEG/Vectors/HepMCConverter.h> 49 #include "CLHEP/Random/RandomEngine.h" 55 randomEngineGlueProxy_(
ThePEG::RandomEngineGlue::Proxy::
create()),
57 generator_(pset.getParameter<
string>(
"generatorModule")),
58 run_(pset.getParameter<
string>(
"run")),
59 dumpConfig_(pset.getUntrackedParameter<
string>(
"dumpConfig",
"HerwigConfig.in")),
60 skipEvents_(pset.getUntrackedParameter<unsigned
int>(
"skipEvents", 0))
64 if (!dumpEvents.empty()) {
66 edm::LogInfo(
"ThePEGSource") <<
"Event logging switched on (=> " << dumpEvents <<
")";
77 edm::LogInfo(
"Herwig7Interface") <<
"Event generator finalized";
96 std::transform(runModeTemp.begin(), runModeTemp.end(), runModeTemp.begin(), ::tolower);
100 while(!runModeTemp.empty())
104 size_t pos = runModeTemp.find(
",");
105 if (std::string::npos == pos)
108 choice = runModeTemp.substr(0, pos);
110 if (pos == std::string::npos)
113 runModeTemp.erase(0, pos+1);
117 edm::LogInfo(
"Herwig7Interface") <<
"HerwigUIProvider object with run mode " <<
HwUI_->runMode() <<
" created.\n";
121 if ( choice ==
"read" )
125 edm::LogInfo(
"Herwig7Interface") <<
"Input file " <<
dumpConfig_ <<
" will be passed to Herwig for the read step.\n";
128 else if ( choice ==
"build" )
132 edm::LogInfo(
"Herwig7Interface") <<
"Input file " <<
dumpConfig_ <<
" will be passed to Herwig for the build step.\n";
136 else if ( choice ==
"integrate" )
139 edm::LogInfo(
"Herwig7Interface") <<
"Run file " << runFileName <<
" will be passed to Herwig for the integrate step.\n";
140 HwUI_->setRunMode(Herwig::RunMode::INTEGRATE, pset, runFileName);
144 else if ( choice ==
"run" )
147 edm::LogInfo(
"Herwig7Interface") <<
"Run file " << runFileName <<
" will be passed to Herwig for the run step.\n";
148 HwUI_->setRunMode(Herwig::RunMode::RUN, pset, runFileName);
152 edm::LogInfo(
"Herwig7Interface") <<
"Cannot recognize \"" << choice <<
"\".\n" 153 <<
"Trying to skip step.\n";
165 edm::LogInfo(
"Herwig7Interface") <<
"callHerwigGenerator function invoked with run mode " <<
HwUI_->runMode() <<
".\n";
168 switch (
HwUI_->runMode() ) {
170 case Herwig::RunMode::READ: Herwig::API::read(*
HwUI_);
break;
171 case Herwig::RunMode::BUILD: Herwig::API::build(*
HwUI_);
break;
172 case Herwig::RunMode::INTEGRATE: Herwig::API::integrate(*
HwUI_);
break;
173 case Herwig::RunMode::MERGEGRIDS: Herwig::API::mergegrids(*
HwUI_);
break;
174 case Herwig::RunMode::RUN: {
176 eg_ = Herwig::API::prepareRun(*
HwUI_);
break;}
178 edm::LogError(
"Herwig7Interface") <<
"Error during read in of command line parameters.\n" 179 <<
"Program execution will stop now.";
182 HwUI_->quitWithHelp();
189 edm::LogError(
"Herwig7Interface") <<
": ThePEG::Exception caught.\n" 191 <<
"See logfile for details.\n";
195 edm::LogError(
"Herwig7Interface") <<
": " << e.what() <<
'\n';
198 catch (
const char* what ) {
209 if (
HwUI_->runMode() == Herwig::RunMode::RUN) {
210 edm::LogInfo(
"Herwig7Interface") <<
"Starting EventGenerator initialization";
212 edm::LogInfo(
"Herwig7Interface") <<
"EventGenerator initialized";
224 edm::LogInfo(
"Herwig7Interface") <<
"Stopped EventGenerator due to missing run mode.";
247 const ThePEG::EventPtr &
event)
249 return std::unique_ptr<HepMC::GenEvent>(
260 if (!event->primaryCollision())
263 tSubProPtr sub =
event->primaryCollision()->primarySubProcess();
264 TmpTransform<tSubProPtr>
tmp(sub, Utilities::getBoostToCM(
268 for(PVector::const_iterator it = sub->outgoing().begin();
269 it != sub->outgoing().end(); ++it)
270 pthat = std::min<double>(pthat, (*it)->momentum().perp() /
ThePEG::GeV);
286 stringstream logstream;
290 stringstream herwiginputconfig;
300 vector<string> configFiles = pset.
getParameter<vector<string> >(
"configFiles");
302 for (
const auto & iter : configFiles ) {
304 ifstream externalConfigFile (iter);
305 if (externalConfigFile.is_open()) {
306 edm::LogInfo(
"Herwig7Interface") <<
"Reading config file (" << iter <<
")" << endl;
307 stringstream configFileStream;
308 configFileStream << externalConfigFile.rdbuf();
309 string configFileContent = configFileStream.str();
312 string searchKeyword(
"saverun");
313 if(configFileContent.find(searchKeyword) !=std::string::npos) {
314 edm::LogInfo(
"Herwig7Interface") <<
"Commented out saverun command in external input config file(" << iter <<
")" << endl;
315 configFileContent.insert(configFileContent.find(searchKeyword),
"#");
317 herwiginputconfig <<
"# Begin Config file input" << endl << configFileContent << endl <<
"# End Config file input";
318 edm::LogInfo(
"Herwig7Interface") <<
"Finished reading config file (" << iter <<
")" << endl;
321 edm::LogWarning(
"Herwig7Interface") <<
"Could not read config file (" << iter <<
")" << endl;
325 edm::LogInfo(
"Herwig7Interface") <<
"Start with processing CMSSW config" << endl;
329 iter = collector.
begin();
330 herwiginputconfig << endl <<
"# Begin Parameter set input\n" << endl;
331 for(; iter != collector.
end(); ++iter) {
332 herwiginputconfig << *iter << endl;
336 herwiginputconfig <<
"saverun " <<
run_ <<
" " <<
generator_ << endl;
344 cfgDump << herwiginputconfig.str() << endl;
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
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 *)
CLHEP::HepRandomEngine * randomEngine
std::unique_ptr< HepMC::IO_BaseClass > iobc_
~Herwig7Interface() noexcept
static std::unique_ptr< HepMC::GenEvent > convert(const ThePEG::EventPtr &event)
def convert(infile, ofile)
Herwig7Interface(const edm::ParameterSet ¶ms)
const std::string generator_
const unsigned int skipEvents_
std::vector< std::vector< double > > tmp
const_iterator end() const
boost::shared_ptr< ThePEG::RandomEngineGlue::Proxy > randomEngineGlueProxy_
const_iterator begin() const
void flushRandomNumberGenerator()
void setRandomEngine(CLHEP::HepRandomEngine *v)