CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Attributes
Herwig7Interface Class Reference

#include <Herwig7Interface.h>

Inheritance diagram for Herwig7Interface:
Herwig7Hadronizer

Public Member Functions

 Herwig7Interface (const edm::ParameterSet &params)
 
void setPEGRandomEngine (CLHEP::HepRandomEngine *)
 
 ~Herwig7Interface ()
 

Public Attributes

ThePEG::EGPtr eg_
 

Protected Member Functions

void callHerwigGenerator ()
 
void createInputFile (const edm::ParameterSet &params)
 
void flushRandomNumberGenerator ()
 
bool initGenerator ()
 
void initRepository (const edm::ParameterSet &params)
 

Static Protected Member Functions

static std::unique_ptr< HepMC::GenEvent > convert (const ThePEG::EventPtr &event)
 
static double pthat (const ThePEG::EventPtr &event)
 

Protected Attributes

Herwig::HerwigUIProviderHwUI_
 
std::unique_ptr< HepMC::IO_BaseClass > iobc_
 

Private Attributes

const std::string dataLocation_
 
std::string dumpConfig_
 
const std::string generator_
 
boost::shared_ptr< ThePEG::RandomEngineGlue::ProxyrandomEngineGlueProxy_
 
const std::string run_
 
const unsigned int skipEvents_
 

Detailed Description

Marco A. Harrendorf marco.nosp@m..har.nosp@m.rendo.nosp@m.rf@c.nosp@m.ern.c.nosp@m.h Dominik Beutel domin.nosp@m.ik.b.nosp@m.eutel.nosp@m.@cer.nosp@m.n.ch

Definition at line 43 of file Herwig7Interface.h.

Constructor & Destructor Documentation

Herwig7Interface::Herwig7Interface ( const edm::ParameterSet params)

Definition at line 52 of file Herwig7Interface.cc.

References dumpConfig_, edm::ParameterSet::getUntrackedParameter(), iobc_, MillePedeFileConverter_cfg::out, and estimatePileup_makeJSON::trunc.

52  :
54  dataLocation_(ParameterCollector::resolve(pset.getParameter<string>("dataLocation"))),
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))
59 {
60  // Write events in hepmc ascii format for debugging purposes
61  string dumpEvents = pset.getUntrackedParameter<string>("dumpEvents", "");
62  if (!dumpEvents.empty()) {
63  iobc_.reset(new HepMC::IO_GenEvent(dumpEvents, ios::out));
64  edm::LogInfo("ThePEGSource") << "Event logging switched on (=> " << dumpEvents << ")";
65  }
66  // Clear dumpConfig target
67  if (!dumpConfig_.empty())
68  ofstream cfgDump(dumpConfig_.c_str(), ios_base::trunc);
69 }
const std::string dataLocation_
std::unique_ptr< HepMC::IO_BaseClass > iobc_
std::string dumpConfig_
static boost::shared_ptr< Proxy > create()
Definition: Proxy.h:44
const std::string run_
const std::string generator_
const unsigned int skipEvents_
boost::shared_ptr< ThePEG::RandomEngineGlue::Proxy > randomEngineGlueProxy_
Herwig7Interface::~Herwig7Interface ( )

Definition at line 71 of file Herwig7Interface.cc.

References eg_.

72 {
73  if (eg_)
74  eg_->finalize();
75  edm::LogInfo("Herwig7Interface") << "Event generator finalized";
76 }
ThePEG::EGPtr eg_

Member Function Documentation

void Herwig7Interface::callHerwigGenerator ( )
protected

Function calls Herwig event generator via API

According to the run mode different steps of event generation are done

Definition at line 157 of file Herwig7Interface.cc.

References MillePedeFileConverter_cfg::e, eg_, dqm::qstatus::ERROR, cppFunctionSkipper::exception, Exception, HwUI_, init, Herwig::HerwigUIProvider::quitWithHelp(), and Herwig::HerwigUIProvider::runMode().

Referenced by initGenerator(), and initRepository().

158 {
159  try {
160 
161  edm::LogInfo("Herwig7Interface") << "callHerwigGenerator function invoked with run mode " << HwUI_->runMode() << ".\n";
162 
163  // Call program switches according to runMode
164  switch ( HwUI_->runMode() ) {
165  case Herwig::RunMode::INIT: Herwig::API::init(*HwUI_); break;
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.";
174  return;
175  default:
176  HwUI_->quitWithHelp();
177  }
178 
179  return;
180 
181  }
182  catch ( ThePEG::Exception & e ) {
183  edm::LogError("Herwig7Interface") << ": ThePEG::Exception caught.\n"
184  << e.what() << '\n'
185  << "See logfile for details.\n";
186  return;
187  }
188  catch ( std::exception & e ) {
189  edm::LogError("Herwig7Interface") << ": " << e.what() << '\n';
190  return;
191  }
192  catch ( const char* what ) {
193  edm::LogError("Herwig7Interface") << ": caught exception: "
194  << what << "\n";
195  return;
196  }
197 
198 }
int init
Definition: HydjetWrapper.h:67
ThePEG::EGPtr eg_
RunMode::Mode runMode() const
Requested Herwig run mode.
Herwig::HerwigUIProvider * HwUI_
static const int ERROR
unique_ptr< HepMC::GenEvent > Herwig7Interface::convert ( const ThePEG::EventPtr &  event)
staticprotected

Definition at line 240 of file Herwig7Interface.cc.

References fileCollector::convert().

Referenced by Herwig7Hadronizer::generatePartonsAndHadronize().

242 {
243  return std::unique_ptr<HepMC::GenEvent>(
245 }
def convert(infile, ofile)
Definition: event.py:1
void Herwig7Interface::createInputFile ( const edm::ParameterSet params)
protected

Definition at line 272 of file Herwig7Interface.cc.

References gen::ParameterCollector::begin(), dumpConfig_, gen::ParameterCollector::end(), generator_, edm::ParameterSet::getParameter(), randomEngineGlueProxy_, and run_.

Referenced by initRepository().

273 {
274  /* Initialize the input config for Herwig from
275  * 1. the Herwig7 config files
276  * 2. the CMSSW config blocks
277  * Writes them to an output file which is read by Herwig
278  */
279 
280  stringstream logstream;
281 
282 
283  // Contains input config passed to Herwig
284  stringstream herwiginputconfig;
285 
286  // Define output file to which input config is written, too, if dumpConfig parameter is set.
287  // Otherwise use default file HerwigConfig.in which is read in by Herwig
288  ofstream cfgDump;
289  cfgDump.open(dumpConfig_.c_str(), ios_base::app);
290 
291 
292 
293  // Read Herwig config files as input
294  vector<string> configFiles = pset.getParameter<vector<string> >("configFiles");
295  // Loop over the config files
296  for ( const auto & iter : configFiles ) {
297  // Open external config file
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();
304 
305  // Comment out occurence of saverun in config file since it is set later considering run and generator option
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),"#");
310  }
311  herwiginputconfig << "# Begin Config file input" << endl << configFileContent << endl << "# End Config file input";
312  edm::LogInfo("Herwig7Interface") << "Finished reading config file (" << iter << ")" << endl;
313  }
314  else {
315  edm::LogWarning("Herwig7Interface") << "Could not read config file (" << iter << ")" << endl;
316  }
317  }
318 
319  edm::LogInfo("Herwig7Interface") << "Start with processing CMSSW config" << endl;
320  // Read CMSSW config file parameter sets starting from "parameterSets"
321  ParameterCollector collector(pset);
323  iter = collector.begin();
324  herwiginputconfig << endl << "# Begin Parameter set input\n" << endl;
325  for(; iter != collector.end(); ++iter) {
326  herwiginputconfig << *iter << endl;
327  }
328 
329  // Add some additional necessary lines to the Herwig input config
330  herwiginputconfig << "saverun " << run_ << " " << generator_ << endl;
331  // write the ProxyID for the RandomEngineGlue to fill its pointer in
332  ostringstream ss;
333  ss << randomEngineGlueProxy_->getID();
334  //herwiginputconfig << "set " << generator_ << ":RandomNumberGenerator:ProxyID " << ss.str() << endl;
335 
336 
337  // Dump Herwig input config to file, so that it can be read by Herwig
338  cfgDump << herwiginputconfig.str() << endl;
339  cfgDump.close();
340 }
std::string dumpConfig_
const std::string run_
const std::string generator_
boost::shared_ptr< ThePEG::RandomEngineGlue::Proxy > randomEngineGlueProxy_
void Herwig7Interface::flushRandomNumberGenerator ( )
protected

Definition at line 228 of file Herwig7Interface.cc.

Referenced by Herwig7Hadronizer::generatePartonsAndHadronize(), and initGenerator().

229 {
230  /*ThePEG::RandomEngineGlue *rnd = randomEngineGlueProxy_->getInstance();
231 
232  if (!rnd)
233  edm::LogWarning("ProxyMissing")
234  << "ThePEG not initialised with RandomEngineGlue.";
235  else
236  rnd->flush();
237  */
238 }
bool Herwig7Interface::initGenerator ( )
protected

Definition at line 201 of file Herwig7Interface.cc.

References callHerwigGenerator(), eg_, flushRandomNumberGenerator(), HwUI_, mps_fire::i, Herwig::HerwigUIProvider::runMode(), and skipEvents_.

Referenced by Herwig7Hadronizer::initializeForInternalPartons().

202 {
203  if ( HwUI_->runMode() == Herwig::RunMode::RUN) {
204  edm::LogInfo("Herwig7Interface") << "Starting EventGenerator initialization";
206  edm::LogInfo("Herwig7Interface") << "EventGenerator initialized";
207 
208  // Skip events
209  for (unsigned int i = 0; i < skipEvents_; i++) {
211  eg_->shoot();
212  edm::LogInfo("Herwig7Interface") << "Event discarded";
213  }
214 
215  return true;
216 
217  } else {
218  edm::LogInfo("Herwig7Interface") << "Stopped EventGenerator due to missing run mode.";
219  return false;
220 /*
221  throw cms::Exception("Herwig7Interface")
222  << "EventGenerator could not be initialized due to wrong run mode!" << endl;
223 */
224  }
225 
226 }
ThePEG::EGPtr eg_
const unsigned int skipEvents_
void flushRandomNumberGenerator()
RunMode::Mode runMode() const
Requested Herwig run mode.
Herwig::HerwigUIProvider * HwUI_
void Herwig7Interface::initRepository ( const edm::ParameterSet params)
protected

Definition at line 87 of file Herwig7Interface.cc.

References callHerwigGenerator(), createInputFile(), dumpConfig_, edm::ParameterSet::getUntrackedParameter(), HwUI_, run_, Herwig::HerwigUIProvider::runMode(), Herwig::HerwigUIProvider::setRunMode(), AlCaHLTBitMon_QueryRunRegistry::string, and create_public_lumi_plots::transform.

Referenced by Herwig7Hadronizer::Herwig7Hadronizer(), and Herwig7Hadronizer::initializeForInternalPartons().

88 {
89  std::string runModeTemp = pset.getUntrackedParameter<string>("runModeList","read,run");
90 
91  // To Lower
92  std::transform(runModeTemp.begin(), runModeTemp.end(), runModeTemp.begin(), ::tolower);
93 
94 
95 
96  while(!runModeTemp.empty())
97  {
98  // Split first part of List
99  std::string choice;
100  size_t pos = runModeTemp.find(",");
101  if (std::string::npos == pos)
102  choice=runModeTemp;
103  else
104  choice = runModeTemp.substr(0, pos);
105 
106  if (pos == std::string::npos)
107  runModeTemp.erase();
108  else
109  runModeTemp.erase(0, pos+1);
110 
111  // construct HerwigUIProvider object and return it as global object
112  HwUI_ = new Herwig::HerwigUIProvider(pset, dumpConfig_, Herwig::RunMode::READ);
113  edm::LogInfo("Herwig7Interface") << "HerwigUIProvider object with run mode " << HwUI_->runMode() << " created.\n";
114 
115 
116  // Chose run mode
117  if ( choice == "read" )
118  {
120  HwUI_->setRunMode(Herwig::RunMode::READ, pset, dumpConfig_);
121  edm::LogInfo("Herwig7Interface") << "Input file " << dumpConfig_ << " will be passed to Herwig for the read step.\n";
123  }
124  else if ( choice == "build" )
125  {
127  HwUI_->setRunMode(Herwig::RunMode::BUILD, pset, dumpConfig_);
128  edm::LogInfo("Herwig7Interface") << "Input file " << dumpConfig_ << " will be passed to Herwig for the build step.\n";
130 
131  }
132  else if ( choice == "integrate" )
133  {
134  std::string runFileName = run_ + ".run";
135  edm::LogInfo("Herwig7Interface") << "Run file " << runFileName << " will be passed to Herwig for the integrate step.\n";
136  HwUI_->setRunMode(Herwig::RunMode::INTEGRATE, pset, runFileName);
138 
139  }
140  else if ( choice == "run" )
141  {
142  std::string runFileName = run_ + ".run";
143  edm::LogInfo("Herwig7Interface") << "Run file " << runFileName << " will be passed to Herwig for the run step.\n";
144  HwUI_->setRunMode(Herwig::RunMode::RUN, pset, runFileName);
145  }
146  else
147  {
148  edm::LogInfo("Herwig7Interface") << "Cannot recognize \"" << choice << "\".\n"
149  << "Trying to skip step.\n";
150  continue;
151  }
152 
153  }
154 
155 }
void createInputFile(const edm::ParameterSet &params)
std::string dumpConfig_
void setRunMode(RunMode::Mode runMode, const edm::ParameterSet &pset, std::string inputFile="")
const std::string run_
RunMode::Mode runMode() const
Requested Herwig run mode.
Herwig::HerwigUIProvider * HwUI_
double Herwig7Interface::pthat ( const ThePEG::EventPtr &  event)
staticprotected

Definition at line 250 of file Herwig7Interface.cc.

References GeV, and tmp.

Referenced by Herwig7Hadronizer::finalizeEvent().

251 {
252  using namespace ThePEG;
253 
254  if (!event->primaryCollision())
255  return -1.0;
256 
257  tSubProPtr sub = event->primaryCollision()->primarySubProcess();
258  TmpTransform<tSubProPtr> tmp(sub, Utilities::getBoostToCM(
259  sub->incoming()));
260 
261  double pthat = (*sub->outgoing().begin())->momentum().perp() / ThePEG::GeV;
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);
265 
266  return pthat;
267 }
static double pthat(const ThePEG::EventPtr &event)
const double GeV
Definition: MathUtil.h:16
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
Definition: event.py:1
void Herwig7Interface::setPEGRandomEngine ( CLHEP::HepRandomEngine *  v)

Definition at line 78 of file Herwig7Interface.cc.

References randomEngineGlueProxy_, and ThePEG::RandomEngineGlue::setRandomEngine().

78  {
79  randomEngineGlueProxy_->setRandomEngine(v);
81  if(rnd) {
82  rnd->setRandomEngine(v);
83  }
84 }
boost::shared_ptr< ThePEG::RandomEngineGlue::Proxy > randomEngineGlueProxy_
void setRandomEngine(CLHEP::HepRandomEngine *v)

Member Data Documentation

const std::string Herwig7Interface::dataLocation_
private

Definition at line 88 of file Herwig7Interface.h.

std::string Herwig7Interface::dumpConfig_
private

Definition at line 92 of file Herwig7Interface.h.

Referenced by createInputFile(), Herwig7Interface(), and initRepository().

ThePEG::EGPtr Herwig7Interface::eg_
const std::string Herwig7Interface::generator_
private

Definition at line 89 of file Herwig7Interface.h.

Referenced by createInputFile().

Herwig::HerwigUIProvider* Herwig7Interface::HwUI_
protected

Definition at line 69 of file Herwig7Interface.h.

Referenced by callHerwigGenerator(), initGenerator(), and initRepository().

std::unique_ptr<HepMC::IO_BaseClass> Herwig7Interface::iobc_
protected

Definition at line 66 of file Herwig7Interface.h.

Referenced by Herwig7Hadronizer::finalizeEvent(), and Herwig7Interface().

boost::shared_ptr<ThePEG::RandomEngineGlue::Proxy> Herwig7Interface::randomEngineGlueProxy_
private

Definition at line 86 of file Herwig7Interface.h.

Referenced by createInputFile(), and setPEGRandomEngine().

const std::string Herwig7Interface::run_
private

Definition at line 90 of file Herwig7Interface.h.

Referenced by createInputFile(), and initRepository().

const unsigned int Herwig7Interface::skipEvents_
private

Definition at line 93 of file Herwig7Interface.h.

Referenced by initGenerator().