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

Protected Attributes

std::shared_ptr< Herwig::HerwigUIProviderHwUI_
 
std::auto_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 50 of file Herwig7Interface.cc.

52  dataLocation_(ParameterCollector::resolve(pset.getParameter<string>("dataLocation"))),
53  generator_(pset.getParameter<string>("generatorModule")),
54  run_(pset.getParameter<string>("run")),
55  dumpConfig_(pset.getUntrackedParameter<string>("dumpConfig", "HerwigConfig.in")),
56  skipEvents_(pset.getUntrackedParameter<unsigned int>("skipEvents", 0)) {
57  // Write events in hepmc ascii format for debugging purposes
58  string dumpEvents = pset.getUntrackedParameter<string>("dumpEvents", "");
59  if (!dumpEvents.empty()) {
60  iobc_.reset(new HepMC::IO_GenEvent(dumpEvents, ios::out));
61  edm::LogInfo("ThePEGSource") << "Event logging switched on (=> " << dumpEvents << ")";
62  }
63  // Clear dumpConfig target
64  if (!dumpConfig_.empty())
65  ofstream cfgDump(dumpConfig_.c_str(), ios_base::trunc);
66 }

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

◆ ~Herwig7Interface()

Herwig7Interface::~Herwig7Interface ( )
noexcept

Definition at line 68 of file Herwig7Interface.cc.

68  {
69  if (eg_)
70  eg_->finalize();
71  edm::LogInfo("Herwig7Interface") << "Event generator finalized";
72 }

References eg_.

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

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

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

Referenced by initGenerator(), and initRepository().

◆ convert()

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

Definition at line 226 of file Herwig7Interface.cc.

226  {
227  return std::auto_ptr<HepMC::GenEvent>(ThePEG::HepMCConverter<HepMC::GenEvent>::convert(*event));
228 }

References fileCollector::convert().

Referenced by Herwig7Hadronizer::generatePartonsAndHadronize().

◆ createInputFile()

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

Definition at line 246 of file Herwig7Interface.cc.

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

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

Referenced by initRepository().

◆ flushRandomNumberGenerator()

void Herwig7Interface::flushRandomNumberGenerator ( )
protected

Definition at line 215 of file Herwig7Interface.cc.

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

Referenced by initGenerator().

◆ initGenerator()

bool Herwig7Interface::initGenerator ( )
protected

Definition at line 190 of file Herwig7Interface.cc.

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

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

Referenced by Herwig7Hadronizer::initializeForInternalPartons().

◆ initRepository()

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

Definition at line 83 of file Herwig7Interface.cc.

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

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

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

◆ pthat()

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

Definition at line 230 of file Herwig7Interface.cc.

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

References GeV, and createJobs::tmp.

Referenced by Herwig7Hadronizer::finalizeEvent().

◆ setPEGRandomEngine()

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

Definition at line 74 of file Herwig7Interface.cc.

74  {
75  randomEngineGlueProxy_->setRandomEngine(v);
76  randomEngine = v;
78  if (rnd) {
79  rnd->setRandomEngine(v);
80  }
81 }

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

Referenced by Herwig7Hadronizer::doSetRandomEngine().

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::auto_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().

init
int init
Definition: HydjetWrapper.h:64
mps_fire.i
i
Definition: mps_fire.py:428
Herwig7Interface::skipEvents_
const unsigned int skipEvents_
Definition: Herwig7Interface.h:82
pos
Definition: PixelAliasList.h:18
gen::ParameterCollector::const_iterator
Definition: ParameterCollector.h:35
ThePEG::Proxy< Proxy >::create
static std::shared_ptr< Proxy > create()
Definition: Proxy.h:45
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
findQualityFiles.v
v
Definition: findQualityFiles.py:179
newFWLiteAna.build
build
Definition: newFWLiteAna.py:126
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
gen::ParameterCollector
Definition: ParameterCollector.h:26
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
Herwig::HerwigUIProvider
Definition: HerwigUIProvider.h:18
ThePEG::RandomEngineGlue::setRandomEngine
void setRandomEngine(CLHEP::HepRandomEngine *v)
Definition: RandomEngineGlue.h:27
ThePEG
Definition: Herwig7Interface.h:24
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
Herwig7Interface::createInputFile
void createInputFile(const edm::ParameterSet &params)
Definition: Herwig7Interface.cc:246
Herwig7Interface::flushRandomNumberGenerator
void flushRandomNumberGenerator()
Definition: Herwig7Interface.cc:215
fileCollector.convert
def convert(infile, ofile)
Definition: fileCollector.py:47
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
GeV
const double GeV
Definition: MathUtil.h:16
Herwig7Interface::iobc_
std::auto_ptr< HepMC::IO_BaseClass > iobc_
Definition: Herwig7Interface.h:59
Herwig7Interface::callHerwigGenerator
void callHerwigGenerator()
Definition: Herwig7Interface.cc:139
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Herwig7Interface::pthat
static double pthat(const ThePEG::EventPtr &event)
Definition: Herwig7Interface.cc:230
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
ThePEG::RandomEngineGlue
Definition: RandomEngineGlue.h:22
Herwig7Interface::HwUI_
std::shared_ptr< Herwig::HerwigUIProvider > HwUI_
Definition: Herwig7Interface.h:62
Herwig7Interface::randomEngine
CLHEP::HepRandomEngine * randomEngine
Definition: Herwig7Interface.h:83
Herwig7Interface::dataLocation_
const std::string dataLocation_
Definition: Herwig7Interface.h:77
Exception
Definition: hltDiff.cc:245
Herwig7Interface::dumpConfig_
std::string dumpConfig_
Definition: Herwig7Interface.h:81
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
event
Definition: event.py:1
DYToLL_TuneCH3_13TeV_herwig7_cff.configFiles
configFiles
Definition: DYToLL_TuneCH3_13TeV_herwig7_cff.py:15
dqm::qstatus::ERROR
static const int ERROR
Definition: MonitorElement.h:55
Herwig7Interface::eg_
ThePEG::EGPtr eg_
Definition: Herwig7Interface.h:48
Herwig7Interface::generator_
const std::string generator_
Definition: Herwig7Interface.h:78
pileupReCalc_HLTpaths.trunc
trunc
Definition: pileupReCalc_HLTpaths.py:143
Herwig7Interface::run_
const std::string run_
Definition: Herwig7Interface.h:79
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
Herwig7Interface::randomEngineGlueProxy_
std::shared_ptr< ThePEG::RandomEngineGlue::Proxy > randomEngineGlueProxy_
Definition: Herwig7Interface.h:75