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
 
std::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 41 of file Herwig7Interface.h.

Constructor & Destructor Documentation

◆ Herwig7Interface()

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

Definition at line 49 of file Herwig7Interface.cc.

References dumpConfig_, iobc_, MillePedeFileConverter_cfg::out, muonDTDigis_cfi::pset, and pileupReCalc_HLTpaths::trunc.

51  dataLocation_(ParameterCollector::resolve(pset.getParameter<string>("dataLocation"))),
52  generator_(pset.getParameter<string>("generatorModule")),
53  run_(pset.getParameter<string>("run")),
54  dumpConfig_(pset.getUntrackedParameter<string>("dumpConfig", "HerwigConfig.in")),
55  skipEvents_(pset.getUntrackedParameter<unsigned int>("skipEvents", 0)) {
56  // Write events in hepmc ascii format for debugging purposes
57  string dumpEvents = pset.getUntrackedParameter<string>("dumpEvents", "");
58  if (!dumpEvents.empty()) {
59  iobc_ = std::make_unique<HepMC::IO_GenEvent>(dumpEvents, ios::out);
60  edm::LogInfo("ThePEGSource") << "Event logging switched on (=> " << dumpEvents << ")";
61  }
62  // Clear dumpConfig target
63  if (!dumpConfig_.empty())
64  ofstream cfgDump(dumpConfig_.c_str(), ios_base::trunc);
65 }
const std::string dataLocation_
std::unique_ptr< HepMC::IO_BaseClass > iobc_
std::string dumpConfig_
std::shared_ptr< ThePEG::RandomEngineGlue::Proxy > randomEngineGlueProxy_
const std::string run_
static std::shared_ptr< Proxy > create()
Definition: Proxy.h:45
const std::string generator_
Log< level::Info, false > LogInfo
const unsigned int skipEvents_

◆ ~Herwig7Interface()

Herwig7Interface::~Herwig7Interface ( )
noexcept

Definition at line 67 of file Herwig7Interface.cc.

References eg_.

67  {
68  if (eg_)
69  eg_->finalize();
70  edm::LogInfo("Herwig7Interface") << "Event generator finalized";
71 }
ThePEG::EGPtr eg_
Log< level::Info, false > LogInfo

Member Function Documentation

◆ callHerwigGenerator()

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 138 of file Herwig7Interface.cc.

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

Referenced by initGenerator(), and initRepository().

138  {
139  try {
140  edm::LogInfo("Herwig7Interface") << "callHerwigGenerator function invoked with run mode " << HwUI_->runMode()
141  << ".\n";
142 
143  // Call program switches according to runMode
144  switch (HwUI_->runMode()) {
145  case Herwig::RunMode::INIT:
147  break;
148  case Herwig::RunMode::READ:
150  break;
151  case Herwig::RunMode::BUILD:
153  break;
154  case Herwig::RunMode::INTEGRATE:
155  Herwig::API::integrate(*HwUI_);
156  break;
157  case Herwig::RunMode::MERGEGRIDS:
158  Herwig::API::mergegrids(*HwUI_);
159  break;
160  case Herwig::RunMode::RUN: {
161  HwUI_->setSeed(randomEngine->getSeed());
162  eg_ = Herwig::API::prepareRun(*HwUI_);
163  break;
164  }
166  edm::LogError("Herwig7Interface") << "Error during read in of command line parameters.\n"
167  << "Program execution will stop now.";
168  return;
169  default:
170  HwUI_->quitWithHelp();
171  }
172 
173  return;
174 
175  } catch (ThePEG::Exception &e) {
176  edm::LogError("Herwig7Interface") << ": ThePEG::Exception caught.\n"
177  << e.what() << '\n'
178  << "See logfile for details.\n";
179  return;
180  } catch (std::exception &e) {
181  edm::LogError("Herwig7Interface") << ": " << e.what() << '\n';
182  return;
183  } catch (const char *what) {
184  edm::LogError("Herwig7Interface") << ": caught exception: " << what << "\n";
185  return;
186  }
187 }
std::shared_ptr< Herwig::HerwigUIProvider > HwUI_
int init
Definition: HydjetWrapper.h:66
CLHEP::HepRandomEngine * randomEngine
Log< level::Error, false > LogError
ThePEG::EGPtr eg_
Log< level::Info, false > LogInfo
static const int ERROR

◆ convert()

unique_ptr< HepMC::GenEvent > Herwig7Interface::convert ( const ThePEG::EventPtr &  event)
staticprotected

Definition at line 225 of file Herwig7Interface.cc.

References convert().

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

225  {
226  return std::unique_ptr<HepMC::GenEvent>(ThePEG::HepMCConverter<HepMC::GenEvent>::convert(*event));
227 }
W convert(V v)
Definition: ExtVec.h:66
Definition: event.py:1

◆ createInputFile()

void Herwig7Interface::createInputFile ( const edm::ParameterSet params)
protected

Definition at line 245 of file Herwig7Interface.cc.

References gen::ParameterCollector::begin(), Hadronizer_TuneEE5C_13TeV_madgraph_differentPDF_herwigpp_cff::configFiles, dumpConfig_, gen::ParameterCollector::end(), generator_, muonDTDigis_cfi::pset, randomEngineGlueProxy_, run_, and contentValuesCheck::ss.

Referenced by initRepository().

245  {
246  /* Initialize the input config for Herwig from
247  * 1. the Herwig7 config files
248  * 2. the CMSSW config blocks
249  * Writes them to an output file which is read by Herwig
250  */
251 
252  stringstream logstream;
253 
254  // Contains input config passed to Herwig
255  stringstream herwiginputconfig;
256 
257  // Define output file to which input config is written, too, if dumpConfig parameter is set.
258  // Otherwise use default file HerwigConfig.in which is read in by Herwig
259  ofstream cfgDump;
260  cfgDump.open(dumpConfig_.c_str(), ios_base::app);
261 
262  // Read Herwig config files as input
263  vector<string> configFiles = pset.getParameter<vector<string> >("configFiles");
264  // Loop over the config files
265  for (const auto &iter : configFiles) {
266  // Open external config file
267  ifstream externalConfigFile(iter);
268  if (externalConfigFile.is_open()) {
269  edm::LogInfo("Herwig7Interface") << "Reading config file (" << iter << ")" << endl;
270  stringstream configFileStream;
271  configFileStream << externalConfigFile.rdbuf();
272  string configFileContent = configFileStream.str();
273 
274  // Comment out occurence of saverun in config file since it is set later considering run and generator option
275  string searchKeyword("saverun");
276  if (configFileContent.find(searchKeyword) != std::string::npos) {
277  edm::LogInfo("Herwig7Interface") << "Commented out saverun command in external input config file(" << iter
278  << ")" << endl;
279  configFileContent.insert(configFileContent.find(searchKeyword), "#");
280  }
281  herwiginputconfig << "# Begin Config file input" << endl
282  << configFileContent << endl
283  << "# End Config file input";
284  edm::LogInfo("Herwig7Interface") << "Finished reading config file (" << iter << ")" << endl;
285  } else {
286  edm::LogWarning("Herwig7Interface") << "Could not read config file (" << iter << ")" << endl;
287  }
288  }
289 
290  edm::LogInfo("Herwig7Interface") << "Start with processing CMSSW config" << endl;
291  // Read CMSSW config file parameter sets starting from "parameterSets"
292  ParameterCollector collector(pset);
294  iter = collector.begin();
295  herwiginputconfig << endl << "# Begin Parameter set input\n" << endl;
296  for (; iter != collector.end(); ++iter) {
297  herwiginputconfig << *iter << endl;
298  }
299 
300  // Add some additional necessary lines to the Herwig input config
301  herwiginputconfig << "saverun " << run_ << " " << generator_ << endl;
302  // write the ProxyID for the RandomEngineGlue to fill its pointer in
303  ostringstream ss;
304  ss << randomEngineGlueProxy_->getID();
305  //herwiginputconfig << "set " << generator_ << ":RandomNumberGenerator:ProxyID " << ss.str() << endl;
306 
307  // Dump Herwig input config to file, so that it can be read by Herwig
308  cfgDump << herwiginputconfig.str() << endl;
309  cfgDump.close();
310 }
std::string dumpConfig_
std::shared_ptr< ThePEG::RandomEngineGlue::Proxy > randomEngineGlueProxy_
const std::string run_
const std::string generator_
Log< level::Info, false > LogInfo
Log< level::Warning, false > LogWarning

◆ flushRandomNumberGenerator()

void Herwig7Interface::flushRandomNumberGenerator ( )
protected

Definition at line 214 of file Herwig7Interface.cc.

Referenced by initGenerator().

214  {
215  /*ThePEG::RandomEngineGlue *rnd = randomEngineGlueProxy_->getInstance();
216 
217  if (!rnd)
218  edm::LogWarning("ProxyMissing")
219  << "ThePEG not initialised with RandomEngineGlue.";
220  else
221  rnd->flush();
222  */
223 }

◆ initGenerator()

bool Herwig7Interface::initGenerator ( )
protected

Definition at line 189 of file Herwig7Interface.cc.

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

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

189  {
190  if (HwUI_->runMode() == Herwig::RunMode::RUN) {
191  edm::LogInfo("Herwig7Interface") << "Starting EventGenerator initialization";
193  edm::LogInfo("Herwig7Interface") << "EventGenerator initialized";
194 
195  // Skip events
196  for (unsigned int i = 0; i < skipEvents_; i++) {
198  eg_->shoot();
199  edm::LogInfo("Herwig7Interface") << "Event discarded";
200  }
201 
202  return true;
203 
204  } else {
205  edm::LogInfo("Herwig7Interface") << "Stopped EventGenerator due to missing run mode.";
206  return false;
207  /*
208  throw cms::Exception("Herwig7Interface")
209  << "EventGenerator could not be initialized due to wrong run mode!" << endl;
210 */
211  }
212 }
std::shared_ptr< Herwig::HerwigUIProvider > HwUI_
ThePEG::EGPtr eg_
Log< level::Info, false > LogInfo
const unsigned int skipEvents_
void flushRandomNumberGenerator()

◆ initRepository()

void Herwig7Interface::initRepository ( const edm::ParameterSet params)
protected

Definition at line 82 of file Herwig7Interface.cc.

References callHerwigGenerator(), createInputFile(), dumpConfig_, HwUI_, muonDTDigis_cfi::pset, run_, AlCaHLTBitMon_QueryRunRegistry::string, and HcalDetIdTransform::transform().

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

82  {
83  std::string runModeTemp = pset.getUntrackedParameter<string>("runModeList", "read,run");
84 
85  // To Lower
86  std::transform(runModeTemp.begin(), runModeTemp.end(), runModeTemp.begin(), ::tolower);
87 
88  while (!runModeTemp.empty()) {
89  // Split first part of List
90  std::string choice;
91  size_t pos = runModeTemp.find(',');
92  if (std::string::npos == pos)
93  choice = runModeTemp;
94  else
95  choice = runModeTemp.substr(0, pos);
96 
97  if (pos == std::string::npos)
98  runModeTemp.erase();
99  else
100  runModeTemp.erase(0, pos + 1);
101 
102  HwUI_.reset(new Herwig::HerwigUIProvider(pset, dumpConfig_, Herwig::RunMode::READ));
103  edm::LogInfo("Herwig7Interface") << "HerwigUIProvider object with run mode " << HwUI_->runMode() << " created.\n";
104 
105  // Chose run mode
106  if (choice == "read") {
108  HwUI_->setRunMode(Herwig::RunMode::READ, pset, dumpConfig_);
109  edm::LogInfo("Herwig7Interface") << "Input file " << dumpConfig_
110  << " will be passed to Herwig for the read step.\n";
112  } else if (choice == "build") {
114  HwUI_->setRunMode(Herwig::RunMode::BUILD, pset, dumpConfig_);
115  edm::LogInfo("Herwig7Interface") << "Input file " << dumpConfig_
116  << " will be passed to Herwig for the build step.\n";
118 
119  } else if (choice == "integrate") {
120  std::string runFileName = run_ + ".run";
121  edm::LogInfo("Herwig7Interface") << "Run file " << runFileName
122  << " will be passed to Herwig for the integrate step.\n";
123  HwUI_->setRunMode(Herwig::RunMode::INTEGRATE, pset, runFileName);
125 
126  } else if (choice == "run") {
127  std::string runFileName = run_ + ".run";
128  edm::LogInfo("Herwig7Interface") << "Run file " << runFileName << " will be passed to Herwig for the run step.\n";
129  HwUI_->setRunMode(Herwig::RunMode::RUN, pset, runFileName);
130  } else {
131  edm::LogInfo("Herwig7Interface") << "Cannot recognize \"" << choice << "\".\n"
132  << "Trying to skip step.\n";
133  continue;
134  }
135  }
136 }
void createInputFile(const edm::ParameterSet &params)
std::shared_ptr< Herwig::HerwigUIProvider > HwUI_
std::string dumpConfig_
const std::string run_
Log< level::Info, false > LogInfo
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ pthat()

double Herwig7Interface::pthat ( const ThePEG::EventPtr &  event)
staticprotected

Definition at line 229 of file Herwig7Interface.cc.

References ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, and createJobs::tmp.

Referenced by Herwig7Hadronizer::finalizeEvent().

229  {
230  using namespace ThePEG;
231 
232  if (!event->primaryCollision())
233  return -1.0;
234 
235  tSubProPtr sub = event->primaryCollision()->primarySubProcess();
236  TmpTransform<tSubProPtr> tmp(sub, Utilities::getBoostToCM(sub->incoming()));
237 
238  double pthat = (*sub->outgoing().begin())->momentum().perp() / ThePEG::GeV;
239  for (PVector::const_iterator it = sub->outgoing().begin(); it != sub->outgoing().end(); ++it)
240  pthat = std::min<double>(pthat, (*it)->momentum().perp() / ThePEG::GeV);
241 
242  return pthat;
243 }
static double pthat(const ThePEG::EventPtr &event)
tmp
align.sh
Definition: createJobs.py:716
Definition: event.py:1

◆ setPEGRandomEngine()

void Herwig7Interface::setPEGRandomEngine ( CLHEP::HepRandomEngine *  v)

Definition at line 73 of file Herwig7Interface.cc.

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

Referenced by Herwig7Hadronizer::doSetRandomEngine().

73  {
74  randomEngineGlueProxy_->setRandomEngine(v);
75  randomEngine = v;
77  if (rnd) {
78  rnd->setRandomEngine(v);
79  }
80 }
CLHEP::HepRandomEngine * randomEngine
std::shared_ptr< ThePEG::RandomEngineGlue::Proxy > randomEngineGlueProxy_
void setRandomEngine(CLHEP::HepRandomEngine *v)

Member Data Documentation

◆ dataLocation_

const std::string Herwig7Interface::dataLocation_
private

Definition at line 77 of file Herwig7Interface.h.

◆ dumpConfig_

std::string Herwig7Interface::dumpConfig_
private

Definition at line 81 of file Herwig7Interface.h.

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

◆ eg_

ThePEG::EGPtr Herwig7Interface::eg_

◆ generator_

const std::string Herwig7Interface::generator_
private

Definition at line 78 of file Herwig7Interface.h.

Referenced by createInputFile().

◆ HwUI_

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

Definition at line 62 of file Herwig7Interface.h.

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

◆ iobc_

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

Definition at line 59 of file Herwig7Interface.h.

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

◆ randomEngine

CLHEP::HepRandomEngine* Herwig7Interface::randomEngine
private

Definition at line 83 of file Herwig7Interface.h.

Referenced by callHerwigGenerator(), and setPEGRandomEngine().

◆ randomEngineGlueProxy_

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

Definition at line 75 of file Herwig7Interface.h.

Referenced by createInputFile(), and setPEGRandomEngine().

◆ run_

const std::string Herwig7Interface::run_
private

Definition at line 79 of file Herwig7Interface.h.

Referenced by createInputFile(), and initRepository().

◆ skipEvents_

const unsigned int Herwig7Interface::skipEvents_
private

Definition at line 82 of file Herwig7Interface.h.

Referenced by initGenerator().