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

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

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

◆ ~Herwig7Interface()

Herwig7Interface::~Herwig7Interface ( )
noexcept

Definition at line 70 of file Herwig7Interface.cc.

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

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

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

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

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

References fileCollector::convert().

Referenced by Herwig7Hadronizer::generatePartonsAndHadronize().

◆ createInputFile()

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

Definition at line 248 of file Herwig7Interface.cc.

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

References gen::ParameterCollector::begin(), Herwig7_Dummy_ConfigFile_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 217 of file Herwig7Interface.cc.

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

Referenced by initGenerator().

◆ initGenerator()

bool Herwig7Interface::initGenerator ( )
protected

Definition at line 192 of file Herwig7Interface.cc.

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

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

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

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

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

References GeV, and createJobs::tmp.

Referenced by Herwig7Hadronizer::finalizeEvent().

◆ setPEGRandomEngine()

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

Definition at line 76 of file Herwig7Interface.cc.

76  {
77  randomEngineGlueProxy_->setRandomEngine(v);
78  randomEngine = v;
80  if (rnd) {
81  rnd->setRandomEngine(v);
82  }
83 }

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:355
Herwig7Interface::skipEvents_
const unsigned int skipEvents_
Definition: Herwig7Interface.h:82
pos
Definition: PixelAliasList.h:18
edm::LogInfo
Definition: MessageLogger.h:254
gen::ParameterCollector::const_iterator
Definition: ParameterCollector.h:35
ThePEG::Proxy< Proxy >::create
static std::shared_ptr< Proxy > create()
Definition: Proxy.h:45
findQualityFiles.v
v
Definition: findQualityFiles.py:179
newFWLiteAna.build
build
Definition: newFWLiteAna.py:126
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
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:248
Herwig7Interface::flushRandomNumberGenerator
void flushRandomNumberGenerator()
Definition: Herwig7Interface.cc:217
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
fileCollector.convert
def convert(infile, ofile)
Definition: fileCollector.py:47
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
edm::LogError
Definition: MessageLogger.h:183
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:141
Herwig7Interface::pthat
static double pthat(const ThePEG::EventPtr &event)
Definition: Herwig7Interface.cc:232
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:246
Herwig7Interface::dumpConfig_
std::string dumpConfig_
Definition: Herwig7Interface.h:81
Herwig7_Dummy_ConfigFile_cff.configFiles
configFiles
Definition: Herwig7_Dummy_ConfigFile_cff.py:10
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
event
Definition: event.py:1
dqm::qstatus::ERROR
static const int ERROR
Definition: MonitorElement.h:54
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:144
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