CMS 3D CMS Logo

Herwig7Hadronizer.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <sstream>
3 
4 #include <HepMC/GenEvent.h>
5 #include <HepMC/IO_BaseClass.h>
6 
7 #include <ThePEG/Repository/Repository.h>
8 #include <ThePEG/EventRecord/Event.h>
9 #include <ThePEG/Config/ThePEG.h>
10 #include <ThePEG/LesHouches/LesHouchesReader.h>
11 
13 
17 
21 
23 
25 
26 namespace CLHEP {
27  class HepRandomEngine;
28 }
29 
31  public:
32  Herwig7Hadronizer(const edm::ParameterSet &params);
33  ~Herwig7Hadronizer() override;
34 
35  bool readSettings( int ) { return true; }
36  bool initializeForInternalPartons();
37  bool initializeForExternalPartons();
38  bool declareStableParticles(const std::vector<int> &pdgIds);
39  bool declareSpecialSettings( const std::vector<std::string> ) { return true; }
40 
41  void statistics();
42 
43  bool generatePartonsAndHadronize();
44  bool hadronize();
45  bool decay();
46  bool residualDecay();
47  void finalizeEvent();
48 
49  const char *classname() const { return "Herwig7Hadronizer"; }
50 
51  private:
52 
53  void doSetRandomEngine(CLHEP::HepRandomEngine* v) override { setPEGRandomEngine(v); }
54 
55  unsigned int eventsToPrint;
56 
57  ThePEG::EventPtr thepegEvent;
58 
59  boost::shared_ptr<lhef::LHEProxy> proxy_;
61 };
62 
64  Herwig7Interface(pset),
65  BaseHadronizer(pset),
66  eventsToPrint(pset.getUntrackedParameter<unsigned int>("eventsToPrint", 0)),
67  handlerDirectory_(pset.getParameter<std::string>("eventHandlers"))
68 {
69  initRepository(pset);
70 
71 }
72 
74 {
75 }
76 
78 {
79  if (!initGenerator())
80  {
81  edm::LogInfo("Generator|Herwig7Hadronizer") << "No run step for Herwig chosen. Program will be aborted.";
82  exit(0);
83  }
84  return true;
85 }
86 
88 {
89  edm::LogError("Herwig7 interface") << "Read in of LHE files is not supported in this way. You can read them manually if necessary.";
90  return false;
91 }
92 
93 bool Herwig7Hadronizer::declareStableParticles(const std::vector<int> &pdgIds)
94 {
95  return false;
96 }
97 
99 {
101  eg_->integratedXSec() / ThePEG::picobarn,
102  eg_->integratedXSecErr() / ThePEG::picobarn));
103 }
104 
106 {
107  edm::LogInfo("Generator|Herwig7Hadronizer") << "Start production";
108 
110 
111  try {
112  thepegEvent = eg_->shoot();
113  } catch (std::exception& exc) {
114  edm::LogWarning("Generator|Herwig7Hadronizer") << "EGPtr::shoot() thrown an exception, event skipped: " << exc.what();
115  return false;
116  }
117 
118  if (!thepegEvent) {
119  edm::LogWarning("Generator|Herwig7Hadronizer") << "thepegEvent not initialized";
120  return false;
121  }
122 
124  if (!event().get()) {
125  edm::LogWarning("Generator|Herwig7Hadronizer") << "genEvent not initialized";
126  return false;
127  }
128 
129  return true;
130 }
131 
133 {
134 
135  edm::LogError("Herwig7 interface") << "Read in of LHE files is not supported in this way. You can read them manually if necessary.";
136  return false;
137 }
138 
140 {
141  eventInfo().reset(new GenEventInfoProduct(event().get()));
142  eventInfo()->setBinningValues(
143  std::vector<double>(1, pthat(thepegEvent)));
144 
145  if (eventsToPrint) {
146  eventsToPrint--;
147  event()->print();
148  }
149 
150  if (iobc_.get())
151  iobc_->write_event(event().get());
152 
153  edm::LogInfo("Generator|Herwig7Hadronizer") << "Event produced";
154 }
155 
157 {
158  return true;
159 }
160 
162 {
163  return true;
164 }
165 
167 
170 
~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::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_
bool declareStableParticles(const std::vector< int > &pdgIds)
Definition: event.py:1