CMS 3D CMS Logo

Herwig7Hadronizer.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <sstream>
3 #include <fstream>
4 
5 #include <HepMC/GenEvent.h>
6 #include <HepMC/IO_BaseClass.h>
7 
8 #include <ThePEG/Repository/Repository.h>
9 #include <ThePEG/EventRecord/Event.h>
10 #include <ThePEG/Config/ThePEG.h>
11 #include <ThePEG/LesHouches/LesHouchesReader.h>
12 
14 
18 
22 
24 
26 
27 namespace CLHEP {
28  class HepRandomEngine;
29 }
30 
32  public:
33  Herwig7Hadronizer(const edm::ParameterSet &params);
34  ~Herwig7Hadronizer() override;
35 
36  bool readSettings( int ) { return true; }
37  bool initializeForInternalPartons();
38  bool initializeForExternalPartons();
39  bool declareStableParticles(const std::vector<int> &pdgIds);
40  bool declareSpecialSettings( const std::vector<std::string> ) { return true; }
41 
42  void statistics();
43 
44  bool generatePartonsAndHadronize();
45  bool hadronize();
46  bool decay();
47  bool residualDecay();
48  void finalizeEvent();
49 
50  const char *classname() const { return "Herwig7Hadronizer"; }
51 
52  private:
53 
54  void doSetRandomEngine(CLHEP::HepRandomEngine* v) override { setPEGRandomEngine(v); }
55 
56  unsigned int eventsToPrint;
57 
58  ThePEG::EventPtr thepegEvent;
59 
60  boost::shared_ptr<lhef::LHEProxy> proxy_;
64 };
65 
67  Herwig7Interface(pset),
68  BaseHadronizer(pset),
69  eventsToPrint(pset.getUntrackedParameter<unsigned int>("eventsToPrint", 0)),
70  handlerDirectory_(pset.getParameter<std::string>("eventHandlers")),
71  runFileName(pset.getParameter<std::string>("run"))
72 {
73  initRepository(pset);
75 }
76 
78 {
79 }
80 
82 {
83  std::ifstream runFile(runFileName+".run");
84  if (runFile.fail()) //required for showering of LHE files
85  {
87  }
88  if (!initGenerator())
89  {
90  edm::LogInfo("Generator|Herwig7Hadronizer") << "No run step for Herwig chosen. Program will be aborted.";
91  exit(0);
92  }
93  return true;
94 }
95 
97 {
98  edm::LogError("Herwig7 interface") << "Read in of LHE files is not supported in this way. You can read them manually if necessary.";
99  return false;
100 }
101 
102 bool Herwig7Hadronizer::declareStableParticles(const std::vector<int> &pdgIds)
103 {
104  return false;
105 }
106 
108 {
110  eg_->integratedXSec() / ThePEG::picobarn,
111  eg_->integratedXSecErr() / ThePEG::picobarn));
112 }
113 
115 {
116  edm::LogInfo("Generator|Herwig7Hadronizer") << "Start production";
117 
119 
120  try {
121  thepegEvent = eg_->shoot();
122  } catch (std::exception& exc) {
123  edm::LogWarning("Generator|Herwig7Hadronizer") << "EGPtr::shoot() thrown an exception, event skipped: " << exc.what();
124  return false;
125  }
126 
127  if (!thepegEvent) {
128  edm::LogWarning("Generator|Herwig7Hadronizer") << "thepegEvent not initialized";
129  return false;
130  }
131 
133  if (!event().get()) {
134  edm::LogWarning("Generator|Herwig7Hadronizer") << "genEvent not initialized";
135  return false;
136  }
137 
138  return true;
139 }
140 
142 {
143 
144  edm::LogError("Herwig7 interface") << "Read in of LHE files is not supported in this way. You can read them manually if necessary.";
145  return false;
146 }
147 
149 {
150  eventInfo().reset(new GenEventInfoProduct(event().get()));
151  eventInfo()->setBinningValues(
152  std::vector<double>(1, pthat(thepegEvent)));
153 
154  if (eventsToPrint) {
155  eventsToPrint--;
156  event()->print();
157  }
158 
159  if (iobc_.get())
160  iobc_->write_event(event().get());
161 
162  edm::LogInfo("Generator|Herwig7Hadronizer") << "Event produced";
163 }
164 
166 {
167  return true;
168 }
169 
171 {
172  return true;
173 }
174 
176 
179 
~Herwig7Hadronizer() override
static double pthat(const ThePEG::EventPtr &event)
void initRepository(const edm::ParameterSet &params)
std::auto_ptr< HepMC::IO_BaseClass > iobc_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setInternalXSec(const XSec &xsec)
std::auto_ptr< HepMC::GenEvent > & event()
GenRunInfoProduct & runInfo()
ThePEG::EGPtr eg_
bool declareSpecialSettings(const std::vector< std::string >)
bool initializeForExternalPartons()
edm::GeneratorFilter< Herwig7Hadronizer, gen::ExternalDecayDriver > Herwig7GeneratorFilter
unsigned int eventsToPrint
edm::ParameterSet paramSettings
edm::HadronizerFilter< Herwig7Hadronizer, gen::ExternalDecayDriver > Herwig7HadronizerFilter
static std::auto_ptr< HepMC::GenEvent > convert(const ThePEG::EventPtr &event)
bool initializeForInternalPartons()
std::auto_ptr< GenEventInfoProduct > & eventInfo()
boost::shared_ptr< lhef::LHEProxy > proxy_
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
Herwig7Hadronizer(const edm::ParameterSet &params)
ThePEG::EventPtr thepegEvent
const char * classname() const
void flushRandomNumberGenerator()
const std::string handlerDirectory_
const std::string runFileName
bool declareStableParticles(const std::vector< int > &pdgIds)
Definition: event.py:1