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()) {
65 iobc_.reset(
new HepMC::IO_GenEvent(dumpEvents.c_str(),
ios::out));
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);
122 if ( choice ==
"read" )
126 edm::LogInfo(
"Herwig7Interface") <<
"Input file " <<
dumpConfig_ <<
" will be passed to Herwig for the read step.\n";
129 else if ( choice ==
"build" )
133 edm::LogInfo(
"Herwig7Interface") <<
"Input file " <<
dumpConfig_ <<
" will be passed to Herwig for the build step.\n";
137 else if ( choice ==
"integrate" )
140 edm::LogInfo(
"Herwig7Interface") <<
"Run file " << runFileName <<
" will be passed to Herwig for the integrate step.\n";
145 else if ( choice ==
"run" )
148 edm::LogInfo(
"Herwig7Interface") <<
"Run file " << runFileName <<
" will be passed to Herwig for the run step.\n";
153 edm::LogInfo(
"Herwig7Interface") <<
"Cannot recognize \"" << choice <<
"\".\n" 154 <<
"Trying to skip step.\n";
166 edm::LogInfo(
"Herwig7Interface") <<
"callHerwigGenerator function invoked with run mode " <<
HwUI_->
runMode() <<
".\n";
171 case Herwig::RunMode::READ: Herwig::API::read(*
HwUI_);
break;
172 case Herwig::RunMode::BUILD: Herwig::API::build(*
HwUI_);
break;
173 case Herwig::RunMode::INTEGRATE: Herwig::API::integrate(*
HwUI_);
break;
174 case Herwig::RunMode::MERGEGRIDS: Herwig::API::mergegrids(*
HwUI_);
break;
175 case Herwig::RunMode::RUN: {
177 eg_ = Herwig::API::prepareRun(*
HwUI_);
break;}
179 edm::LogError(
"Herwig7Interface") <<
"Error during read in of command line parameters.\n" 180 <<
"Program execution will stop now.";
190 edm::LogError(
"Herwig7Interface") <<
": ThePEG::Exception caught.\n" 192 <<
"See logfile for details.\n";
196 edm::LogError(
"Herwig7Interface") <<
": " << e.what() <<
'\n';
199 catch (
const char* what ) {
211 edm::LogInfo(
"Herwig7Interface") <<
"Starting EventGenerator initialization";
213 edm::LogInfo(
"Herwig7Interface") <<
"EventGenerator initialized";
225 edm::LogInfo(
"Herwig7Interface") <<
"Stopped EventGenerator due to missing run mode.";
248 const ThePEG::EventPtr &
event)
250 return std::auto_ptr<HepMC::GenEvent>(
261 if (!event->primaryCollision())
264 tSubProPtr sub =
event->primaryCollision()->primarySubProcess();
265 TmpTransform<tSubProPtr>
tmp(sub, Utilities::getBoostToCM(
269 for(PVector::const_iterator it = sub->outgoing().begin();
270 it != sub->outgoing().end(); ++it)
271 pthat = std::min<double>(pthat, (*it)->momentum().perp() /
ThePEG::GeV);
287 stringstream logstream;
291 stringstream herwiginputconfig;
301 vector<string> configFiles = pset.
getParameter<vector<string> >(
"configFiles");
303 for (
const auto & iter : configFiles ) {
305 ifstream externalConfigFile (iter);
306 if (externalConfigFile.is_open()) {
307 edm::LogInfo(
"Herwig7Interface") <<
"Reading config file (" << iter <<
")" << endl;
308 stringstream configFileStream;
309 configFileStream << externalConfigFile.rdbuf();
310 string configFileContent = configFileStream.str();
313 string searchKeyword(
"saverun");
314 if(configFileContent.find(searchKeyword) !=std::string::npos) {
315 edm::LogInfo(
"Herwig7Interface") <<
"Commented out saverun command in external input config file(" << iter <<
")" << endl;
316 configFileContent.insert(configFileContent.find(searchKeyword),
"#");
318 herwiginputconfig <<
"# Begin Config file input" << endl << configFileContent << endl <<
"# End Config file input";
319 edm::LogInfo(
"Herwig7Interface") <<
"Finished reading config file (" << iter <<
")" << endl;
322 edm::LogWarning(
"Herwig7Interface") <<
"Could not read config file (" << iter <<
")" << endl;
326 edm::LogInfo(
"Herwig7Interface") <<
"Start with processing CMSSW config" << endl;
330 iter = collector.
begin();
331 herwiginputconfig << endl <<
"# Begin Parameter set input\n" << endl;
332 for(; iter != collector.
end(); ++iter) {
333 herwiginputconfig << *iter << endl;
337 herwiginputconfig <<
"saverun " <<
run_ <<
" " <<
generator_ << endl;
345 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)
void setPEGRandomEngine(CLHEP::HepRandomEngine *)
std::auto_ptr< HepMC::IO_BaseClass > iobc_
CLHEP::HepRandomEngine * randomEngine
~Herwig7Interface() noexcept
void setRunMode(RunMode::Mode runMode, const edm::ParameterSet &pset, std::string inputFile="")
static std::auto_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)
Herwig::HerwigUIProvider * HwUI_
void quitWithHelp() const override
RunMode::Mode runMode() const override
Requested Herwig run mode.