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 () noexcept
 

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::GenEventconvert (const ThePEG::EventPtr &event)
 
static double pthat (const ThePEG::EventPtr &event)
 

Protected Attributes

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

Private Attributes

const std::string dataLocation_
 
std::string dumpConfig_
 
const std::string generator_
 
CLHEP::HepRandomEngine * randomEngine
 
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 46 of file Herwig7Interface.h.

Constructor & Destructor Documentation

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

Definition at line 54 of file Herwig7Interface.cc.

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

54  :
56  dataLocation_(ParameterCollector::resolve(pset.getParameter<string>("dataLocation"))),
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))
61 {
62  // Write events in hepmc ascii format for debugging purposes
63  string dumpEvents = pset.getUntrackedParameter<string>("dumpEvents", "");
64  if (!dumpEvents.empty()) {
65  iobc_.reset(new HepMC::IO_GenEvent(dumpEvents, ios::out));
66  edm::LogInfo("ThePEGSource") << "Event logging switched on (=> " << dumpEvents << ")";
67  }
68  // Clear dumpConfig target
69  if (!dumpConfig_.empty())
70  ofstream cfgDump(dumpConfig_.c_str(), ios_base::trunc);
71 }
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 ( )
noexcept

Definition at line 73 of file Herwig7Interface.cc.

References eg_.

74 {
75  if (eg_)
76  eg_->finalize();
77  edm::LogInfo("Herwig7Interface") << "Event generator finalized";
78 }
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 161 of file Herwig7Interface.cc.

References MillePedeFileConverter_cfg::e, eg_, dqm::qstatus::ERROR, cppFunctionSkipper::exception, Exception, HwUI_, init, and randomEngine.

Referenced by initGenerator(), and initRepository().

162 {
163  try {
164 
165  edm::LogInfo("Herwig7Interface") << "callHerwigGenerator function invoked with run mode " << HwUI_->runMode() << ".\n";
166 
167  // Call program switches according to runMode
168  switch ( HwUI_->runMode() ) {
169  case Herwig::RunMode::INIT: Herwig::API::init(*HwUI_); break;
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: {
175  HwUI_->setSeed(randomEngine->getSeed());
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.";
180  return;
181  default:
182  HwUI_->quitWithHelp();
183  }
184 
185  return;
186 
187  }
188  catch ( ThePEG::Exception & e ) {
189  edm::LogError("Herwig7Interface") << ": ThePEG::Exception caught.\n"
190  << e.what() << '\n'
191  << "See logfile for details.\n";
192  return;
193  }
194  catch ( std::exception & e ) {
195  edm::LogError("Herwig7Interface") << ": " << e.what() << '\n';
196  return;
197  }
198  catch ( const char* what ) {
199  edm::LogError("Herwig7Interface") << ": caught exception: "
200  << what << "\n";
201  return;
202  }
203 
204 }
std::shared_ptr< Herwig::HerwigUIProvider > HwUI_
int init
Definition: HydjetWrapper.h:67
CLHEP::HepRandomEngine * randomEngine
ThePEG::EGPtr eg_
static const int ERROR
unique_ptr< HepMC::GenEvent > Herwig7Interface::convert ( const ThePEG::EventPtr &  event)
staticprotected

Definition at line 246 of file Herwig7Interface.cc.

References fileCollector::convert().

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

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

Definition at line 278 of file Herwig7Interface.cc.

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

Referenced by initRepository().

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

Referenced by initGenerator().

235 {
236  /*ThePEG::RandomEngineGlue *rnd = randomEngineGlueProxy_->getInstance();
237 
238  if (!rnd)
239  edm::LogWarning("ProxyMissing")
240  << "ThePEG not initialised with RandomEngineGlue.";
241  else
242  rnd->flush();
243  */
244 }
bool Herwig7Interface::initGenerator ( )
protected

Definition at line 207 of file Herwig7Interface.cc.

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

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

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

Definition at line 91 of file Herwig7Interface.cc.

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

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

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

Definition at line 256 of file Herwig7Interface.cc.

References GeV, and tmp.

Referenced by Herwig7Hadronizer::finalizeEvent().

257 {
258  using namespace ThePEG;
259 
260  if (!event->primaryCollision())
261  return -1.0;
262 
263  tSubProPtr sub = event->primaryCollision()->primarySubProcess();
264  TmpTransform<tSubProPtr> tmp(sub, Utilities::getBoostToCM(
265  sub->incoming()));
266 
267  double pthat = (*sub->outgoing().begin())->momentum().perp() / ThePEG::GeV;
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);
271 
272  return pthat;
273 }
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 80 of file Herwig7Interface.cc.

References randomEngine, randomEngineGlueProxy_, ThePEG::RandomEngineGlue::setRandomEngine(), and findQualityFiles::v.

80  {
81 
82  randomEngineGlueProxy_->setRandomEngine(v);
83  randomEngine = v;
85  if(rnd) {
86  rnd->setRandomEngine(v);
87  }
88 }
CLHEP::HepRandomEngine * randomEngine
boost::shared_ptr< ThePEG::RandomEngineGlue::Proxy > randomEngineGlueProxy_
void setRandomEngine(CLHEP::HepRandomEngine *v)

Member Data Documentation

const std::string Herwig7Interface::dataLocation_
private

Definition at line 91 of file Herwig7Interface.h.

std::string Herwig7Interface::dumpConfig_
private

Definition at line 95 of file Herwig7Interface.h.

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

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

Definition at line 92 of file Herwig7Interface.h.

Referenced by createInputFile().

std::shared_ptr<Herwig::HerwigUIProvider> Herwig7Interface::HwUI_
protected

Definition at line 72 of file Herwig7Interface.h.

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

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

Definition at line 69 of file Herwig7Interface.h.

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

CLHEP::HepRandomEngine* Herwig7Interface::randomEngine
private

Definition at line 97 of file Herwig7Interface.h.

Referenced by callHerwigGenerator(), and setPEGRandomEngine().

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

Definition at line 89 of file Herwig7Interface.h.

Referenced by createInputFile(), and setPEGRandomEngine().

const std::string Herwig7Interface::run_
private

Definition at line 93 of file Herwig7Interface.h.

Referenced by createInputFile(), and initRepository().

const unsigned int Herwig7Interface::skipEvents_
private

Definition at line 96 of file Herwig7Interface.h.

Referenced by initGenerator().