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> 53 randomEngineGlueProxy_(
ThePEG::RandomEngineGlue::Proxy::
create()),
55 generator_(pset.getParameter<
string>(
"generatorModule")),
56 run_(pset.getParameter<
string>(
"run")),
57 dumpConfig_(pset.getUntrackedParameter<
string>(
"dumpConfig",
"HerwigConfig.in")),
58 skipEvents_(pset.getUntrackedParameter<unsigned
int>(
"skipEvents", 0))
62 if (!dumpEvents.empty()) {
63 iobc_.reset(
new HepMC::IO_GenEvent(dumpEvents.c_str(),
ios::out));
64 edm::LogInfo(
"ThePEGSource") <<
"Event logging switched on (=> " << dumpEvents <<
")";
75 edm::LogInfo(
"Herwig7Interface") <<
"Event generator finalized";
92 std::transform(runModeTemp.begin(), runModeTemp.end(), runModeTemp.begin(), ::tolower);
96 while(!runModeTemp.empty())
100 size_t pos = runModeTemp.find(
",");
101 if (std::string::npos == pos)
104 choice = runModeTemp.substr(0, pos);
106 if (pos == std::string::npos)
109 runModeTemp.erase(0, pos+1);
117 if ( choice ==
"read" )
121 edm::LogInfo(
"Herwig7Interface") <<
"Input file " <<
dumpConfig_ <<
" will be passed to Herwig for the read step.\n";
124 else if ( choice ==
"build" )
128 edm::LogInfo(
"Herwig7Interface") <<
"Input file " <<
dumpConfig_ <<
" will be passed to Herwig for the build step.\n";
132 else if ( choice ==
"integrate" )
135 edm::LogInfo(
"Herwig7Interface") <<
"Run file " << runFileName <<
" will be passed to Herwig for the integrate step.\n";
140 else if ( choice ==
"run" )
143 edm::LogInfo(
"Herwig7Interface") <<
"Run file " << runFileName <<
" will be passed to Herwig for the run step.\n";
148 edm::LogInfo(
"Herwig7Interface") <<
"Cannot recognize \"" << choice <<
"\".\n" 149 <<
"Trying to skip step.\n";
161 edm::LogInfo(
"Herwig7Interface") <<
"callHerwigGenerator function invoked with run mode " <<
HwUI_->
runMode() <<
".\n";
166 case Herwig::RunMode::READ: Herwig::API::read(*
HwUI_);
break;
167 case Herwig::RunMode::BUILD: Herwig::API::build(*
HwUI_);
break;
168 case Herwig::RunMode::INTEGRATE: Herwig::API::integrate(*
HwUI_);
break;
169 case Herwig::RunMode::MERGEGRIDS: Herwig::API::mergegrids(*
HwUI_);
break;
170 case Herwig::RunMode::RUN:
eg_ = Herwig::API::prepareRun(*
HwUI_);
break;
172 edm::LogError(
"Herwig7Interface") <<
"Error during read in of command line parameters.\n" 173 <<
"Program execution will stop now.";
183 edm::LogError(
"Herwig7Interface") <<
": ThePEG::Exception caught.\n" 185 <<
"See logfile for details.\n";
189 edm::LogError(
"Herwig7Interface") <<
": " << e.what() <<
'\n';
192 catch (
const char* what ) {
204 edm::LogInfo(
"Herwig7Interface") <<
"Starting EventGenerator initialization";
206 edm::LogInfo(
"Herwig7Interface") <<
"EventGenerator initialized";
218 edm::LogInfo(
"Herwig7Interface") <<
"Stopped EventGenerator due to missing run mode.";
241 const ThePEG::EventPtr &
event)
243 return std::auto_ptr<HepMC::GenEvent>(
254 if (!event->primaryCollision())
257 tSubProPtr sub =
event->primaryCollision()->primarySubProcess();
258 TmpTransform<tSubProPtr>
tmp(sub, Utilities::getBoostToCM(
262 for(PVector::const_iterator it = sub->outgoing().begin();
263 it != sub->outgoing().end(); ++it)
264 pthat = std::min<double>(pthat, (*it)->momentum().perp() /
ThePEG::GeV);
280 stringstream logstream;
284 stringstream herwiginputconfig;
294 vector<string> configFiles = pset.
getParameter<vector<string> >(
"configFiles");
296 for (
const auto & iter : configFiles ) {
298 ifstream externalConfigFile (iter);
299 if (externalConfigFile.is_open()) {
300 edm::LogInfo(
"Herwig7Interface") <<
"Reading config file (" << iter <<
")" << endl;
301 stringstream configFileStream;
302 configFileStream << externalConfigFile.rdbuf();
303 string configFileContent = configFileStream.str();
306 string searchKeyword(
"saverun");
307 if(configFileContent.find(searchKeyword) !=std::string::npos) {
308 edm::LogInfo(
"Herwig7Interface") <<
"Commented out saverun command in external input config file(" << iter <<
")" << endl;
309 configFileContent.insert(configFileContent.find(searchKeyword),
"#");
311 herwiginputconfig <<
"# Begin Config file input" << endl << configFileContent << endl <<
"# End Config file input";
312 edm::LogInfo(
"Herwig7Interface") <<
"Finished reading config file (" << iter <<
")" << endl;
315 edm::LogWarning(
"Herwig7Interface") <<
"Could not read config file (" << iter <<
")" << endl;
319 edm::LogInfo(
"Herwig7Interface") <<
"Start with processing CMSSW config" << endl;
323 iter = collector.
begin();
324 herwiginputconfig << endl <<
"# Begin Parameter set input\n" << endl;
325 for(; iter != collector.
end(); ++iter) {
326 herwiginputconfig << *iter << endl;
330 herwiginputconfig <<
"saverun " <<
run_ <<
" " <<
generator_ << endl;
338 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_
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_
void quitWithHelp() const
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)
RunMode::Mode runMode() const
Requested Herwig run mode.
Herwig::HerwigUIProvider * HwUI_