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 {
109  if(eg_) {
111  eg_->integratedXSec() / ThePEG::picobarn,
112  eg_->integratedXSecErr() / ThePEG::picobarn));
113  }
114 }
115 
117 {
118  edm::LogInfo("Generator|Herwig7Hadronizer") << "Start production";
119 
121 
122  try {
123  thepegEvent = eg_->shoot();
124  } catch (std::exception& exc) {
125  edm::LogWarning("Generator|Herwig7Hadronizer") << "EGPtr::shoot() thrown an exception, event skipped: " << exc.what();
126  return false;
127  }
128 
129  if (!thepegEvent) {
130  edm::LogWarning("Generator|Herwig7Hadronizer") << "thepegEvent not initialized";
131  return false;
132  }
133 
135  if (!event().get()) {
136  edm::LogWarning("Generator|Herwig7Hadronizer") << "genEvent not initialized";
137  return false;
138  }
139 
140  return true;
141 }
142 
144 {
145 
146  edm::LogError("Herwig7 interface") << "Read in of LHE files is not supported in this way. You can read them manually if necessary.";
147  return false;
148 }
149 
151 {
152  eventInfo().reset(new GenEventInfoProduct(event().get()));
153  eventInfo()->setBinningValues(
154  std::vector<double>(1, pthat(thepegEvent)));
155 
156  if (eventsToPrint) {
157  eventsToPrint--;
158  event()->print();
159  }
160 
161  if (iobc_.get())
162  iobc_->write_event(event().get());
163 
164  edm::LogInfo("Generator|Herwig7Hadronizer") << "Event produced";
165 }
166 
168 {
169  return true;
170 }
171 
173 {
174  return true;
175 }
176 
178 
181 
~Herwig7Hadronizer() override
static double pthat(const ThePEG::EventPtr &event)
void initRepository(const edm::ParameterSet &params)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::unique_ptr< HepMC::IO_BaseClass > iobc_
void setInternalXSec(const XSec &xsec)
GenRunInfoProduct & runInfo()
ThePEG::EGPtr eg_
bool declareSpecialSettings(const std::vector< std::string >)
bool initializeForExternalPartons()
edm::GeneratorFilter< Herwig7Hadronizer, gen::ExternalDecayDriver > Herwig7GeneratorFilter
unsigned int eventsToPrint
static std::unique_ptr< HepMC::GenEvent > convert(const ThePEG::EventPtr &event)
edm::ParameterSet paramSettings
edm::HadronizerFilter< Herwig7Hadronizer, gen::ExternalDecayDriver > Herwig7HadronizerFilter
bool initializeForInternalPartons()
std::unique_ptr< HepMC::GenEvent > & event()
boost::shared_ptr< lhef::LHEProxy > proxy_
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
std::unique_ptr< GenEventInfoProduct > & eventInfo()
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